topologicpy 0.7.15__py3-none-any.whl → 0.7.18__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
topologicpy/Graph.py CHANGED
@@ -152,10 +152,10 @@ class WorkerProcess(Process):
152
152
  destinations = [Topology.ByBREPString(s) for s in self.destinations]
153
153
  for i in range(len(sources)):
154
154
  source = sources[i]
155
- index_b = Vertex.Index(source, destinations)
155
+ index_b = Vertex.Index(source, destinations, tolerance=self.tolerance)
156
156
  for j in range(len(destinations)):
157
157
  destination = destinations[j]
158
- index_a = Vertex.Index(destination, sources)
158
+ index_a = Vertex.Index(destination, sources, tolerance=self.tolerance)
159
159
  if self.used[i + self.start_index][j] == 1 or self.used[j][i + self.start_index]:
160
160
  continue
161
161
  if Vertex.Distance(source, destination) > self.tolerance:
@@ -269,6 +269,88 @@ class _DrawTree(object):
269
269
  return self.__str__()
270
270
 
271
271
  class Graph:
272
+ def AdjacencyDictionary(graph, vertexLabelKey: str = "label", edgeKey: str = "Length", reverse: bool = False, mantissa: int = 6):
273
+ """
274
+ Returns the adjacency dictionary of the input Graph.
275
+
276
+ Parameters
277
+ ----------
278
+ graph : topologic_core.Graph
279
+ The input graph.
280
+ vertexLabelKey : str , optional
281
+ The returned vertices are labelled according to the dictionary values stored under this key.
282
+ If the vertexLabelKey does not exist, it will be created and the vertices are labelled numerically and stored in the vertex dictionary under this key. The default is "label".
283
+ edgeWeightKey : str , optional
284
+ If set, the edges' dictionaries will be searched for this key to set their weight. If the key is set to "length" (case insensitive), the length of the edge will be used as its weight. If set to None, a weight of 1 will be used. The default is "Length".
285
+ reverse : bool , optional
286
+ If set to True, the vertices are sorted in reverse order (only if vertexKey is set). Otherwise, they are not. The default is False.
287
+ mantissa : int , optional
288
+ The desired length of the mantissa. The default is 6.
289
+
290
+ Returns
291
+ -------
292
+ dict
293
+ The adjacency dictionary.
294
+ """
295
+ from topologicpy.Vertex import Vertex
296
+ from topologicpy.Edge import Edge
297
+ from topologicpy.Dictionary import Dictionary
298
+ from topologicpy.Topology import Topology
299
+ from topologicpy.Helper import Helper
300
+
301
+ if not Topology.IsInstance(graph, "Graph"):
302
+ print("Graph.AdjacencyDictionary - Error: The input graph is not a valid graph. Returning None.")
303
+ return None
304
+ if not isinstance(vertexLabelKey, str):
305
+ print("Graph.AdjacencyDictionary - Error: The input vertexLabelKey is not a valid string. Returning None.")
306
+ return None
307
+ vertices = Graph.Vertices(graph)
308
+ labels = []
309
+ n = max(len(str(len(vertices))), 3)
310
+ for i, v in enumerate(vertices):
311
+ d = Topology.Dictionary(v)
312
+ value = Dictionary.ValueAtKey(d, vertexLabelKey)
313
+ if value == None:
314
+ value = str(i).zfill(n)
315
+ if d == None:
316
+ d = Dictionary.ByKeyValue(vertexLabelKey, value)
317
+ else:
318
+ d = Dictionary.SetValueAtKey(d, vertexLabelKey, value)
319
+ v = Topology.SetDictionary(v, d)
320
+ labels.append(value)
321
+ vertices = Helper.Sort(vertices, labels)
322
+ labels.sort()
323
+ if reverse == True:
324
+ vertices.reverse()
325
+ labels.reverse()
326
+ order = len(vertices)
327
+ adjDict = {}
328
+ for i in range(order):
329
+ v = Graph.NearestVertex(graph, vertices[i])
330
+ vertex_label = labels[i]
331
+ adjVertices = Graph.AdjacentVertices(graph, v)
332
+ temp_list = []
333
+ for adjVertex in adjVertices:
334
+ if edgeKey == None:
335
+ weight = 1
336
+ elif "length" in edgeKey.lower():
337
+ edge = Graph.Edge(graph, v, adjVertex)
338
+ weight = Edge.Length(edge, mantissa=mantissa)
339
+ else:
340
+ edge = Graph.Edge(graph, v, adjVertex)
341
+ weight = Dictionary.ValueAtKey(Topology.Dictionary(edge), edgeKey)
342
+ if weight == None:
343
+ weight = Edge.Length(edge, mantissa=mantissa)
344
+ else:
345
+ weight = round(weight, mantissa)
346
+ adjIndex = Vertex.Index(adjVertex, vertices)
347
+ adjLabel = labels[adjIndex]
348
+ if not adjIndex == None:
349
+ temp_list.append((adjLabel, weight))
350
+ temp_list.sort()
351
+ adjDict[vertex_label] = temp_list
352
+ return adjDict
353
+
272
354
  @staticmethod
273
355
  def AdjacencyMatrix(graph, vertexKey=None, reverse=False, edgeKeyFwd=None, edgeKeyBwd=None, bidirKey=None, bidirectional=True, useEdgeIndex=False, useEdgeLength=False, tolerance=0.0001):
274
356
  """
@@ -279,13 +361,13 @@ class Graph:
279
361
  graph : topologic_core.Graph
280
362
  The input graph.
281
363
  vertexKey : str , optional
282
- If set, the returned list of vertices is sorted according to the dicitonary values stored under this key. The default is None.
364
+ If set, the returned list of vertices is sorted according to the dictionary values stored under this key. The default is None.
283
365
  reverse : bool , optional
284
366
  If set to True, the vertices are sorted in reverse order (only if vertexKey is set). Otherwise, they are not. The default is False.
285
367
  edgeKeyFwd : str , optional
286
- If set, the value at this key in the connecting edge from start vertex to end verrtex (forward) will be used instead of the value 1. The default is None. useEdgeIndex and useEdgeLength override this setting.
368
+ If set, the value at this key in the connecting edge from start vertex to end vertex (forward) will be used instead of the value 1. The default is None. useEdgeIndex and useEdgeLength override this setting.
287
369
  edgeKeyBwd : str , optional
288
- If set, the value at this key in the connecting edge from end vertex to start verrtex (backward) will be used instead of the value 1. The default is None. useEdgeIndex and useEdgeLength override this setting.
370
+ If set, the value at this key in the connecting edge from end vertex to start vertex (backward) will be used instead of the value 1. The default is None. useEdgeIndex and useEdgeLength override this setting.
289
371
  bidirKey : bool , optional
290
372
  If set to True or False, this key in the connecting edge will be used to determine is the edge is supposed to be bidirectional or not. If set to None, the input variable bidrectional will be used instead. The default is None
291
373
  bidirectional : bool , optional
@@ -363,9 +445,10 @@ class Graph:
363
445
  if useEdgeLength:
364
446
  valueFwd = Edge.Length(edge)
365
447
  valueBwd = Edge.Length(edge)
366
- matrix[svi][evi] = valueFwd
367
- if bidir:
368
- matrix[evi][svi] = valueBwd
448
+ if not svi == None and not evi == None:
449
+ matrix[svi][evi] = valueFwd
450
+ if bidir:
451
+ matrix[evi][svi] = valueBwd
369
452
  return matrix
370
453
 
371
454
  @staticmethod
@@ -378,7 +461,7 @@ class Graph:
378
461
  graph : topologic_core.Graph
379
462
  The input graph.
380
463
  vertexKey : str , optional
381
- If set, the returned list of vertices is sorted according to the dicitonary values stored under this key. The default is None.
464
+ If set, the returned list of vertices is sorted according to the dictionary values stored under this key. The default is None.
382
465
  reverse : bool , optional
383
466
  If set to True, the vertices are sorted in reverse order (only if vertexKey is set). Otherwise, they are not. The default is False.
384
467
  tolerance : float , optional
@@ -433,7 +516,7 @@ class Graph:
433
516
  edge : topologic_core.Edge
434
517
  The input edge.
435
518
  transferDictionaries : bool, optional
436
- If set to True, the dictionaries of the edge and its vertices are transfered to the graph.
519
+ If set to True, the dictionaries of the edge and its vertices are transferred to the graph.
437
520
  tolerance : float , optional
438
521
  The desired tolerance. The default is 0.0001.
439
522
 
@@ -1521,7 +1604,7 @@ class Graph:
1521
1604
  edgeFeaturesHeader : str , optional
1522
1605
  The column header string used to specify the features of edges. The default is "feat".
1523
1606
  edgeFeaturesKeys : list , optional
1524
- The list of dicitonary keys to use to index the edge features. The length of this list must match the length of edge features. The default is [].
1607
+ The list of dictionary keys to use to index the edge features. The length of this list must match the length of edge features. The default is [].
1525
1608
  nodeIDHeader : str , optional
1526
1609
  The column header string used to specify the id of nodes. The default is "node_id".
1527
1610
  nodeLabelHeader : str , optional
@@ -1898,7 +1981,11 @@ class Graph:
1898
1981
 
1899
1982
 
1900
1983
  @staticmethod
1901
- def ByIFCFile(file, includeTypes=[], excludeTypes=[], includeRels=[], excludeRels=[], xMin=-0.5, yMin=-0.5, zMin=-0.5, xMax=0.5, yMax=0.5, zMax=0.5):
1984
+ def ByIFCFile(file, includeTypes: list = [], excludeTypes: list = [],
1985
+ includeRels: list = [], excludeRels: list = [],
1986
+ xMin: float = -0.5, yMin: float = -0.5, zMin: float = -0.5,
1987
+ xMax: float = 0.5, yMax: float = 0.5, zMax: float = 0.5,
1988
+ tolerance: float = 0.0001):
1902
1989
  """
1903
1990
  Create a Graph from an IFC file. This code is partially based on code from Bruno Postle.
1904
1991
 
@@ -1926,6 +2013,8 @@ class Graph:
1926
2013
  The desired maximum value to assign for a vertex's Y coordinate. The default is 0.5.
1927
2014
  zMax : float, optional
1928
2015
  The desired maximum value to assign for a vertex's Z coordinate. The default is 0.5.
2016
+ tolerance : float , optional
2017
+ The desired tolerance. The default is 0.0001.
1929
2018
 
1930
2019
  Returns
1931
2020
  -------
@@ -2094,19 +2183,21 @@ class Graph:
2094
2183
  if source:
2095
2184
  sv = vertexAtKeyValue(vertices, key="id", value=source.id())
2096
2185
  if sv:
2097
- si = Vertex.Index(sv, vertices)
2098
- for destination in destinations:
2099
- if destination == None:
2100
- continue
2101
- ev = vertexAtKeyValue(vertices, key="id", value=destination.id())
2102
- if ev:
2103
- ei = Vertex.Index(ev, vertices)
2104
- if not([si,ei] in tuples or [ei,si] in tuples):
2105
- tuples.append([si,ei])
2106
- e = Edge.ByVertices([sv,ev])
2107
- d = Dictionary.ByKeysValues(["id", "name", "type"], [ifc_rel.id(), ifc_rel.Name, ifc_rel.is_a()])
2108
- e = Topology.SetDictionary(e, d)
2109
- edges.append(e)
2186
+ si = Vertex.Index(sv, vertices, tolerance=tolerance)
2187
+ if not si == None:
2188
+ for destination in destinations:
2189
+ if destination == None:
2190
+ continue
2191
+ ev = vertexAtKeyValue(vertices, key="id", value=destination.id())
2192
+ if ev:
2193
+ ei = Vertex.Index(ev, vertices, tolerance=tolerance)
2194
+ if not ei == None:
2195
+ if not([si,ei] in tuples or [ei,si] in tuples):
2196
+ tuples.append([si,ei])
2197
+ e = Edge.ByVertices([sv,ev])
2198
+ d = Dictionary.ByKeysValues(["id", "name", "type"], [ifc_rel.id(), ifc_rel.Name, ifc_rel.is_a()])
2199
+ e = Topology.SetDictionary(e, d)
2200
+ edges.append(e)
2110
2201
  return edges
2111
2202
 
2112
2203
  ifc_types = IFCObjectTypes(file)
@@ -4811,7 +4902,7 @@ class Graph:
4811
4902
  nodeTrainMaskHeader="train_mask", nodeValidateMaskHeader="val_mask", nodeTestMaskHeader="test_mask",
4812
4903
  nodeMaskKey=None,
4813
4904
  nodeTrainRatio=0.8, nodeValidateRatio=0.1, nodeTestRatio=0.1,
4814
- mantissa=6, overwrite=False):
4905
+ mantissa=6, tolerance=0.0001, overwrite=False):
4815
4906
  """
4816
4907
  Exports the input graph into a set of CSV files compatible with DGL.
4817
4908
 
@@ -4894,6 +4985,8 @@ class Graph:
4894
4985
  This value is ignored if an nodeMaskKey is foud.
4895
4986
  mantissa : int , optional
4896
4987
  The desired length of the mantissa. The default is 6.
4988
+ tolerance : float , optional
4989
+ The desired tolerance. The default is 0.0001.
4897
4990
  overwrite : bool , optional
4898
4991
  If set to True, any existing files are overwritten. Otherwise, the input list of graphs is appended to the end of each file. The default is False.
4899
4992
 
@@ -5138,14 +5231,15 @@ class Graph:
5138
5231
  else:
5139
5232
  edge_features = str(round(float(Dictionary.ValueAtKey(ed, edge_feature_key)), mantissa))
5140
5233
  # Get the Source and Destination vertex indices
5141
- src = Vertex.Index(Edge.StartVertex(edge), vertices)
5142
- dst = Vertex.Index(Edge.EndVertex(edge), vertices)
5143
- single_edge_data = [graph_id, src, dst, edge_label, train_mask, validate_mask, test_mask, edge_features]
5144
- edge_data.append(single_edge_data)
5145
-
5146
- if bidirectional == True:
5234
+ src = Vertex.Index(Edge.StartVertex(edge), vertices, tolerance=tolerance)
5235
+ dst = Vertex.Index(Edge.EndVertex(edge), vertices, tolerance=tolerance)
5236
+ if not src == None and not dst == None:
5147
5237
  single_edge_data = [graph_id, src, dst, edge_label, train_mask, validate_mask, test_mask, edge_features]
5148
5238
  edge_data.append(single_edge_data)
5239
+
5240
+ if bidirectional == True:
5241
+ single_edge_data = [graph_id, src, dst, edge_label, train_mask, validate_mask, test_mask, edge_features]
5242
+ edge_data.append(single_edge_data)
5149
5243
  df = pd.DataFrame(edge_data, columns=edge_columns)
5150
5244
 
5151
5245
  if graph_id == 0:
@@ -5167,7 +5261,8 @@ class Graph:
5167
5261
  defaultVertexColor: str = "black", defaultVertexSize: float = 3,
5168
5262
  vertexLabelKey: str = None, vertexColorKey: str = None, vertexSizeKey: str = None,
5169
5263
  defaultEdgeColor: str = "black", defaultEdgeWeight: float = 1, defaultEdgeType: str = "undirected",
5170
- edgeLabelKey: str = None, edgeColorKey: str = None, edgeWeightKey: str = None, overwrite: bool = False, mantissa: int = 6):
5264
+ edgeLabelKey: str = None, edgeColorKey: str = None, edgeWeightKey: str = None,
5265
+ overwrite: bool = False, mantissa: int = 6, tolerance: float = 0.0001):
5171
5266
  """
5172
5267
  Exports the input graph to a Graph Exchange XML (GEXF) file format. See https://gexf.net/
5173
5268
 
@@ -5215,6 +5310,8 @@ class Graph:
5215
5310
  If set to True, any existing file is overwritten. Otherwise, it is not. The default is False.
5216
5311
  mantissa : int , optional
5217
5312
  The desired length of the mantissa. The default is 6.
5313
+ tolerance : float , optional
5314
+ The desired tolerance. The default is 0.0001.
5218
5315
 
5219
5316
  Returns
5220
5317
  -------
@@ -5487,20 +5584,20 @@ class Graph:
5487
5584
  edge_dict['weight'] = edge_weight
5488
5585
 
5489
5586
 
5490
- sv = g_vertices[Vertex.Index(Edge.StartVertex(edge), g_vertices)]
5491
- ev = g_vertices[Vertex.Index(Edge.EndVertex(edge), g_vertices)]
5492
- svid = Vertex.Index(sv, g_vertices)
5493
- edge_dict['source'] = svid
5494
- evid = Vertex.Index(ev, g_vertices)
5495
- edge_dict['target'] = evid
5496
-
5497
- edge_label = "Edge "+str(svid)+"-"+str(evid)
5498
- if isinstance(edgeLabelKey, str):
5499
- edge_label = Dictionary.ValueAtKey(d, edgeLabelKey)
5500
- if not isinstance(edge_label, str):
5587
+ sv = g_vertices[Vertex.Index(Edge.StartVertex(edge), g_vertices, tolerance=tolerance)]
5588
+ ev = g_vertices[Vertex.Index(Edge.EndVertex(edge), g_vertices, tolerance=tolerance)]
5589
+ svid = Vertex.Index(sv, g_vertices, tolerance=tolerance)
5590
+ evid = Vertex.Index(ev, g_vertices, tolerance=tolerance)
5591
+ if not svid == None and not evid == None:
5592
+ edge_dict['source'] = svid
5593
+ edge_dict['target'] = evid
5501
5594
  edge_label = "Edge "+str(svid)+"-"+str(evid)
5502
- edge_dict['label'] = edge_label
5503
- edges[(str(svid), str(evid))] = edge_dict
5595
+ if isinstance(edgeLabelKey, str):
5596
+ edge_label = Dictionary.ValueAtKey(d, edgeLabelKey)
5597
+ if not isinstance(edge_label, str):
5598
+ edge_label = "Edge "+str(svid)+"-"+str(evid)
5599
+ edge_dict['label'] = edge_label
5600
+ edges[(str(svid), str(evid))] = edge_dict
5504
5601
 
5505
5602
  create_gexf_file(nodes, edges, defaultEdgeType, node_attributes, edge_attributes, path)
5506
5603
  return True
@@ -5596,6 +5693,8 @@ class Graph:
5596
5693
  The desired maximum number of iterations to solve the forces in the 'spring' mode. The default is 50.
5597
5694
  rootVertex : topologic_core.Vertex , optional
5598
5695
  The desired vertex to use as the root of the tree and radial layouts.
5696
+ tolerance : float , optional
5697
+ The desired tolerance. The default is 0.0001.
5599
5698
 
5600
5699
  Returns
5601
5700
  -------
@@ -5725,9 +5824,12 @@ class Graph:
5725
5824
  Returns:
5726
5825
  A numpy array representing the adjacency matrix.
5727
5826
  """
5728
-
5827
+ from topologicpy.Helper import Helper
5729
5828
  # Get the number of nodes from the edge list.
5730
- num_nodes = max([max(edge) for edge in edge_list]) + 1
5829
+ flat_list = Helper.Flatten(edge_list)
5830
+ flat_list = [x for x in flat_list if not x == None]
5831
+ num_nodes = max(flat_list) + 1
5832
+ print("Number of Nodes:", num_nodes)
5731
5833
 
5732
5834
  # Create an adjacency matrix.
5733
5835
  adjacency_matrix = np.zeros((num_nodes, num_nodes))
@@ -5913,8 +6015,9 @@ class Graph:
5913
6015
  if rootVertex == None:
5914
6016
  rootVertex, root_index = vertex_max_degree(graph, vertices)
5915
6017
  else:
5916
- root_index = Vertex.Index(rootVertex, vertices)
5917
-
6018
+ root_index = Vertex.Index(rootVertex, vertices, tolerance=tolerance)
6019
+ if root_index == None:
6020
+ root_index = 0
5918
6021
  if 'rad' in layout.lower():
5919
6022
  positions = radial_layout(edges, root_index=root_index)
5920
6023
  elif 'spring' in layout.lower():
@@ -6248,7 +6351,8 @@ class Graph:
6248
6351
  yKey: str = "y",
6249
6352
  zKey: str = "z",
6250
6353
  geometryKey: str = "brep",
6251
- mantissa: int = 6):
6354
+ mantissa: int = 6,
6355
+ tolerance: float = 0.0001):
6252
6356
  """
6253
6357
  Converts the input graph into JSON data.
6254
6358
 
@@ -6280,6 +6384,8 @@ class Graph:
6280
6384
  The desired key name to use for geometry. The default is "brep".
6281
6385
  mantissa : int , optional
6282
6386
  The desired length of the mantissa. The default is 6.
6387
+ tolerance : float , optional
6388
+ The desired tolerance. The default is 0.0001.
6283
6389
 
6284
6390
  Returns
6285
6391
  -------
@@ -6329,22 +6435,23 @@ class Graph:
6329
6435
  for i, e in enumerate(edges):
6330
6436
  sv = Edge.StartVertex(e)
6331
6437
  ev = Edge.EndVertex(e)
6332
- svi = Vertex.Index(sv, vertices)
6333
- evi = Vertex.Index(ev, vertices)
6334
- sv_label = v_labels[svi]
6335
- ev_label = v_labels[evi]
6336
- d = Topology.Dictionary(e)
6337
-
6338
- d = Dictionary.SetValueAtKey(d, sourceKey, sv_label)
6339
- d = Dictionary.SetValueAtKey(d, targetKey, ev_label)
6340
- e_dict = Dictionary.PythonDictionary(d)
6341
- e_label = Dictionary.ValueAtKey(d, edgeLabelKey)
6342
- if isinstance(e_label, str):
6438
+ svi = Vertex.Index(sv, vertices, tolerance=tolerance)
6439
+ evi = Vertex.Index(ev, vertices, tolerance=tolerance)
6440
+ if not svi == None and not evi == None:
6441
+ sv_label = v_labels[svi]
6442
+ ev_label = v_labels[evi]
6443
+ d = Topology.Dictionary(e)
6444
+
6445
+ d = Dictionary.SetValueAtKey(d, sourceKey, sv_label)
6446
+ d = Dictionary.SetValueAtKey(d, targetKey, ev_label)
6447
+ e_dict = Dictionary.PythonDictionary(d)
6343
6448
  e_label = Dictionary.ValueAtKey(d, edgeLabelKey)
6344
- else:
6345
- e_label = "Edge_"+str(i).zfill(n)
6346
- e_labels.append(e_label)
6347
- e_dicts.append(e_dict)
6449
+ if isinstance(e_label, str):
6450
+ e_label = Dictionary.ValueAtKey(d, edgeLabelKey)
6451
+ else:
6452
+ e_label = "Edge_"+str(i).zfill(n)
6453
+ e_labels.append(e_label)
6454
+ e_dicts.append(e_dict)
6348
6455
  e_labels = Helper.MakeUnique(e_labels)
6349
6456
  for i, e_label in enumerate(e_labels):
6350
6457
  j_data[edgesKey][e_label] = e_dicts[i]
@@ -6405,7 +6512,7 @@ class Graph:
6405
6512
  return json_string
6406
6513
 
6407
6514
  @staticmethod
6408
- def LocalClusteringCoefficient(graph, vertices=None, mantissa=6):
6515
+ def LocalClusteringCoefficient(graph, vertices: list = None, mantissa: int = 6, tolerance: float = 0.0001):
6409
6516
  """
6410
6517
  Returns the local clustering coefficient of the input list of vertices within the input graph. See https://en.wikipedia.org/wiki/Clustering_coefficient.
6411
6518
 
@@ -6414,9 +6521,11 @@ class Graph:
6414
6521
  graph : topologic_core.Graph
6415
6522
  The input graph.
6416
6523
  vertices : list , optional
6417
- The input list of vertices. If set to None, the local clustering coefficient of all vertices will be computed.
6524
+ The input list of vertices. If set to None, the local clustering coefficient of all vertices will be computed. The default is None.
6418
6525
  mantissa : int , optional
6419
6526
  The desired length of the mantissa. The default is 6.
6527
+ tolerance : float , optional
6528
+ The desired tolerance. The default is 0.0001.
6420
6529
 
6421
6530
  Returns
6422
6531
  -------
@@ -6470,7 +6579,7 @@ class Graph:
6470
6579
  adjacency_matrix = Graph.AdjacencyMatrix(graph)
6471
6580
  lcc = []
6472
6581
  for v in vertices:
6473
- i = Vertex.Index(v, g_vertices)
6582
+ i = Vertex.Index(v, g_vertices, tolerance=tolerance)
6474
6583
  if not i == None:
6475
6584
  lcc.append(round(local_clustering_coefficient(adjacency_matrix, i), mantissa))
6476
6585
  else:
@@ -6556,9 +6665,10 @@ class Graph:
6556
6665
  vertices = Topology.Vertices(path)
6557
6666
  pathCost = 0
6558
6667
  for vertex in vertices:
6559
- index = Vertex.Index(vertex, g_vertices)
6560
- d = Topology.Dictionary(g_vertices[index])
6561
- value = Dictionary.ValueAtKey(d, vertexKey)
6668
+ index = Vertex.Index(vertex, g_vertices, tolerance=tolerance)
6669
+ if not index == None:
6670
+ d = Topology.Dictionary(g_vertices[index])
6671
+ value = Dictionary.ValueAtKey(d, vertexKey)
6562
6672
  if not value == None:
6563
6673
  pathCost += value
6564
6674
  lengths[i] += pathCost
@@ -6697,29 +6807,31 @@ class Graph:
6697
6807
  edgeMatrix = Graph.AdjacencyMatrix(graph, edgeKeyFwd=edgeKeyFwd, edgeKeyBwd=edgeKeyBwd, bidirKey=bidirKey, bidirectional=bidirectional, useEdgeIndex = True, useEdgeLength=False, tolerance=tolerance)
6698
6808
  vertices = Graph.Vertices(graph)
6699
6809
  edges = Graph.Edges(graph)
6700
- sourceIndex = Vertex.Index(source, vertices)
6701
- sinkIndex = Vertex.Index(sink, vertices)
6702
- max_flow, am = ford_fulkerson(adjMatrix=adjMatrix, source=sourceIndex, sink=sinkIndex)
6703
- for i in range(len(am)):
6704
- row = am[i]
6705
- for j in range(len(row)):
6706
- residual = am[i][j]
6707
- edge = edges[edgeMatrix[i][j]-1]
6708
- d = Topology.Dictionary(edge)
6709
- if not d == None:
6710
- keys = Dictionary.Keys(d)
6711
- values = Dictionary.Values(d)
6712
- else:
6713
- keys = []
6714
- values = []
6715
- keys.append(residualKey)
6716
- values.append(residual)
6717
- d = Dictionary.ByKeysValues(keys, values)
6718
- edge = Topology.SetDictionary(edge, d)
6810
+ sourceIndex = Vertex.Index(source, vertices, tolerance=tolerance)
6811
+ sinkIndex = Vertex.Index(sink, vertices, tolerance=tolerance)
6812
+ max_flow = None
6813
+ if not sourceIndex == None and not sinkIndex == None:
6814
+ max_flow, am = ford_fulkerson(adjMatrix=adjMatrix, source=sourceIndex, sink=sinkIndex)
6815
+ for i in range(len(am)):
6816
+ row = am[i]
6817
+ for j in range(len(row)):
6818
+ residual = am[i][j]
6819
+ edge = edges[edgeMatrix[i][j]-1]
6820
+ d = Topology.Dictionary(edge)
6821
+ if not d == None:
6822
+ keys = Dictionary.Keys(d)
6823
+ values = Dictionary.Values(d)
6824
+ else:
6825
+ keys = []
6826
+ values = []
6827
+ keys.append(residualKey)
6828
+ values.append(residual)
6829
+ d = Dictionary.ByKeysValues(keys, values)
6830
+ edge = Topology.SetDictionary(edge, d)
6719
6831
  return max_flow
6720
6832
 
6721
6833
  @staticmethod
6722
- def MeshData(g):
6834
+ def MeshData(g, tolerance: float = 0.0001):
6723
6835
  """
6724
6836
  Returns the mesh data of the input graph.
6725
6837
 
@@ -6727,6 +6839,8 @@ class Graph:
6727
6839
  ----------
6728
6840
  graph : topologic_core.Graph
6729
6841
  The input graph.
6842
+ tolerance : float , optional
6843
+ The desired tolerance. The default is 0.0001.
6730
6844
 
6731
6845
  Returns
6732
6846
  -------
@@ -6755,11 +6869,12 @@ class Graph:
6755
6869
  for g_edge in g_edges:
6756
6870
  sv = g_edge.StartVertex()
6757
6871
  ev = g_edge.EndVertex()
6758
- si = Vertex.Index(sv, g_vertices)
6759
- ei = Vertex.Index(ev, g_vertices)
6760
- m_edges.append([si, ei])
6761
- d = Dictionary.PythonDictionary(Topology.Dictionary(g_edge))
6762
- e_dicts.append(d)
6872
+ si = Vertex.Index(sv, g_vertices, tolerance=tolerance)
6873
+ ei = Vertex.Index(ev, g_vertices, tolerance=tolerance)
6874
+ if (not si == None) and (not ei == None):
6875
+ m_edges.append([si, ei])
6876
+ d = Dictionary.PythonDictionary(Topology.Dictionary(g_edge))
6877
+ e_dicts.append(d)
6763
6878
  return {'vertices':m_vertices,
6764
6879
  'edges': m_edges,
6765
6880
  'vertexDictionaries': v_dicts,
@@ -7231,7 +7346,9 @@ class Graph:
7231
7346
  incoming_score = 0
7232
7347
  for incoming_vertex in Graph.IncomingVertices(graph, vertex, directed=directed):
7233
7348
  if len(Graph.IncomingVertices(graph, incoming_vertex, directed=directed)) > 0:
7234
- incoming_score += scores[Vertex.Index(incoming_vertex, vertices)] / len(Graph.IncomingVertices(graph, incoming_vertex, directed=directed))
7349
+ vi = Vertex.Index(incoming_vertex, vertices, tolerance=tolerance)
7350
+ if not vi == None:
7351
+ incoming_score += scores[vi] / len(Graph.IncomingVertices(graph, incoming_vertex, directed=directed))
7235
7352
  new_scores[i] = alpha * incoming_score + (1 - alpha) / num_vertices
7236
7353
 
7237
7354
  # Check for convergence
@@ -7286,9 +7403,14 @@ class Graph:
7286
7403
 
7287
7404
 
7288
7405
  @staticmethod
7289
- def PyvisGraph(graph, path, overwrite=True, height=900, backgroundColor="white", fontColor="black", notebook=False,
7290
- vertexSize=6, vertexSizeKey=None, vertexColor="black", vertexColorKey=None, vertexLabelKey=None, vertexGroupKey=None, vertexGroups=None, minVertexGroup=None, maxVertexGroup=None,
7291
- edgeLabelKey=None, edgeWeight=0, edgeWeightKey=None, showNeighbours=True, selectMenu=True, filterMenu=True, colorScale="viridis"):
7406
+ def PyvisGraph(graph, path, overwrite: bool = True, height: int = 900, backgroundColor: str = "white",
7407
+ fontColor: str = "black", notebook: bool = False,
7408
+ vertexSize: int = 6, vertexSizeKey: str = None, vertexColor: str = "black",
7409
+ vertexColorKey: str = None, vertexLabelKey: str = None, vertexGroupKey: str = None,
7410
+ vertexGroups: list = None, minVertexGroup: float = None, maxVertexGroup: float = None,
7411
+ edgeLabelKey: str = None, edgeWeight: int = 0, edgeWeightKey: str = None,
7412
+ showNeighbours: bool = True, selectMenu: bool = True,
7413
+ filterMenu: bool = True, colorScale: str = "viridis", tolerance: float = 0.0001):
7292
7414
  """
7293
7415
  Displays a pyvis graph. See https://pyvis.readthedocs.io/.
7294
7416
 
@@ -7341,7 +7463,8 @@ class Graph:
7341
7463
  If set to True, a filtering menu will be displayed. The default is True.
7342
7464
  colorScale : str , optional
7343
7465
  The desired type of plotly color scales to use (e.g. "viridis", "plasma"). The default is "viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
7344
-
7466
+ tolerance : float , optional
7467
+ The desired tolerance. The default is 0.0001.
7345
7468
  Returns
7346
7469
  -------
7347
7470
  None
@@ -7367,7 +7490,7 @@ class Graph:
7367
7490
  from pyvis.network import Network
7368
7491
  print("Graph.PyvisGraph - Information: pyvis library installed correctly.")
7369
7492
  except:
7370
- warnings.warn("Graph - Error: Could not import pyvis. Please try to install pyvis manually. Retruning None.")
7493
+ warnings.warn("Graph - Error: Could not import pyvis. Please try to install pyvis manually. Returning None.")
7371
7494
  return None
7372
7495
 
7373
7496
  net = Network(height=str(height)+"px", width="100%", bgcolor=backgroundColor, font_color=fontColor, select_menu=selectMenu, filter_menu=filterMenu, cdn_resources="remote", notebook=notebook)
@@ -7443,9 +7566,10 @@ class Graph:
7443
7566
  w = weightValue
7444
7567
  sv = Edge.StartVertex(e)
7445
7568
  ev = Edge.EndVertex(e)
7446
- svi = Vertex.Index(sv, vertices)
7447
- evi = Vertex.Index(ev, vertices)
7448
- net.add_edge(svi, evi, weight=w, label=edge_label)
7569
+ svi = Vertex.Index(sv, vertices, tolerance=tolerance)
7570
+ evi = Vertex.Index(ev, vertices, tolerance=tolerance)
7571
+ if (not svi == None) and (not evi == None):
7572
+ net.add_edge(svi, evi, weight=w, label=edge_label)
7449
7573
  net.inherit_edge_colors(False)
7450
7574
 
7451
7575
  # add neighbor data to node hover data and compute vertexSize
topologicpy/Neo4j.py CHANGED
@@ -339,8 +339,8 @@ class Neo4j:
339
339
  e = edges[i]
340
340
  sv = e.StartVertex()
341
341
  ev = e.EndVertex()
342
- sn = nodes[Vertex.Index(sv, vertices, tolerance)]
343
- en = nodes[Vertex.Index(ev, vertices, tolerance)]
342
+ sn = nodes[Vertex.Index(sv, vertices, tolerance=tolerance)]
343
+ en = nodes[Vertex.Index(ev, vertices, tolerance=tolerance)]
344
344
  relationshipType = Dictionary.ValueAtKey(e, relationshipKey)
345
345
  if not (relationshipType):
346
346
  relationshipType = "Connected To"