topologicpy 0.8.11__py3-none-any.whl → 0.8.13__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
@@ -522,7 +522,7 @@ class Graph:
522
522
  return adjDict
523
523
 
524
524
  @staticmethod
525
- def AdjacencyMatrix(graph, vertexKey=None, reverse=False, edgeKeyFwd=None, edgeKeyBwd=None, bidirKey=None, bidirectional=True, useEdgeIndex=False, useEdgeLength=False, tolerance=0.0001):
525
+ def AdjacencyMatrix(graph, vertexKey=None, reverse=False, edgeKeyFwd=None, edgeKeyBwd=None, bidirKey=None, bidirectional=True, useEdgeIndex=False, useEdgeLength=False, mantissa: int = 6, tolerance=0.0001):
526
526
  """
527
527
  Returns the adjacency matrix of the input Graph. See https://en.wikipedia.org/wiki/Adjacency_matrix.
528
528
 
@@ -542,10 +542,12 @@ class Graph:
542
542
  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
543
543
  bidirectional : bool , optional
544
544
  If set to True, the edges in the graph that do not have a bidireKey in their dictionaries will be treated as being bidirectional. Otherwise, the start vertex and end vertex of the connecting edge will determine the direction. The default is True.
545
- useEdgeIndex : bool , False
545
+ useEdgeIndex : bool , optional
546
546
  If set to True, the adjacency matrix values will the index of the edge in Graph.Edges(graph). The default is False. Both useEdgeIndex, useEdgeLength should not be True at the same time. If they are, useEdgeLength will be used.
547
- useEdgeLength : bool , False
547
+ useEdgeLength : bool , optional
548
548
  If set to True, the adjacency matrix values will the length of the edge in Graph.Edges(graph). The default is False. Both useEdgeIndex, useEdgeLength should not be True at the same time. If they are, useEdgeLength will be used.
549
+ mantissa : int , optional
550
+ The desired length of the mantissa. The default is 6.
549
551
  tolerance : float , optional
550
552
  The desired tolerance. The default is 0.0001.
551
553
 
@@ -599,12 +601,16 @@ class Graph:
599
601
  bidir = bidirectional
600
602
  if edgeKeyFwd == None:
601
603
  valueFwd = 1
604
+ elif "len" in edgeKeyFwd.lower() or "dis" in edgeKeyFwd.lower():
605
+ valueFwd = Edge.Length(edge, mantissa=mantissa)
602
606
  else:
603
607
  valueFwd = Dictionary.ValueAtKey(Topology.Dictionary(edge), edgeKeyFwd)
604
608
  if valueFwd == None:
605
609
  valueFwd = 1
606
610
  if edgeKeyBwd == None:
607
611
  valueBwd = 1
612
+ elif "len" in edgeKeyBwd.lower() or "dis" in edgeKeyBwd.lower():
613
+ valueBwd = Edge.Length(edge, mantissa=mantissa)
608
614
  else:
609
615
  valueBwd = Dictionary.ValueAtKey(Topology.Dictionary(edge), edgeKeyBwd)
610
616
  if valueBwd == None:
@@ -613,8 +619,8 @@ class Graph:
613
619
  valueFwd = i+1
614
620
  valueBwd = i+1
615
621
  if useEdgeLength:
616
- valueFwd = Edge.Length(edge)
617
- valueBwd = Edge.Length(edge)
622
+ valueFwd = Edge.Length(edge, mantissa=mantissa)
623
+ valueBwd = Edge.Length(edge, mantissa=mantissa)
618
624
  if not svi == None and not evi == None:
619
625
  matrix[svi][evi] = valueFwd
620
626
  if bidir:
@@ -1352,7 +1358,7 @@ class Graph:
1352
1358
  return bot_graph.serialize(format=format)
1353
1359
 
1354
1360
  @staticmethod
1355
- def BetweennessCentrality(graph, method: str = "vertex", weightKey="length", normalize: bool = False, nx: bool = False, key: str = "betweenness_centrality", colorKey="bc_color", colorScale="viridis", mantissa: int = 6, tolerance: float = 0.001, silent: bool = False):
1361
+ def BetweennessCentrality(graph, method: str = "vertex", weightKey="length", normalize: bool = False, nxCompatible: bool = False, key: str = "betweenness_centrality", colorKey="bc_color", colorScale="viridis", mantissa: int = 6, tolerance: float = 0.001, silent: bool = False):
1356
1362
  """
1357
1363
  Returns the betweenness centrality of the input graph. The order of the returned list is the same as the order of vertices/edges. See https://en.wikipedia.org/wiki/Betweenness_centrality.
1358
1364
 
@@ -1363,21 +1369,20 @@ class Graph:
1363
1369
  method : str , optional
1364
1370
  The method of computing the betweenness centrality. The options are "vertex" or "edge". The default is "vertex".
1365
1371
  weightKey : str , optional
1366
- If None, all edge weights are considered equal. Otherwise holds the name of the edge dictionary key to be used as weight.
1367
- Weights are used to calculate weighted shortest paths, so they are interpreted as distances.
1368
- If you wish to use the actual length of the edge, then use the "length" as key. the default is "length".
1372
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
1373
+ the shortest path. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
1374
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
1369
1375
  normalize : bool , optional
1370
1376
  If set to True, the values are normalized to be in the range 0 to 1. Otherwise they are not. The default is False.
1371
- nx : bool , optional
1377
+ nxCompatible : bool , optional
1372
1378
  If set to True, and normalize input parameter is also set to True, the values are set to be identical to NetworkX values. Otherwise, they are normalized between 0 and 1. The default is False.
1373
1379
  key : str , optional
1374
- The desired dictionary key under which to store the betweeness centrality score. The default is "betweenness_centrality".
1380
+ The desired dictionary key under which to store the betweenness centrality score. The default is "betweenness_centrality".
1375
1381
  colorKey : str , optional
1376
- The desired dictionary key under which to store the betweeness centrality color. The default is "betweenness_centrality".
1382
+ The desired dictionary key under which to store the betweenness centrality color. The default is "betweenness_centrality".
1377
1383
  colorScale : str , optional
1378
1384
  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/.
1379
1385
  In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
1380
-
1381
1386
  mantissa : int , optional
1382
1387
  The desired length of the mantissa. The default is 6.
1383
1388
  tolerance : float , optional
@@ -1412,19 +1417,22 @@ class Graph:
1412
1417
  from topologicpy.Helper import Helper
1413
1418
 
1414
1419
  if weightKey:
1415
- if "len" in weightKey.lower():
1420
+ if "len" in weightKey.lower() or "dis" in wireightKey.lower():
1416
1421
  weightKey = "length"
1417
1422
  nx_graph = Graph.NetworkXGraph(graph)
1418
1423
  if "vert" in method.lower():
1419
1424
  elements = Graph.Vertices(graph)
1420
1425
  elements_dict = nx.betweenness_centrality(nx_graph, normalized=normalize, weight=weightKey)
1421
- values = list(elements_dict.values())
1426
+ values = [round(value, mantissa) for value in list(elements_dict.values())]
1422
1427
  else:
1423
1428
  elements = Graph.Edges(graph)
1424
1429
  elements_dict = nx.edge_betweenness_centrality(nx_graph, normalized=normalize, weight=weightKey)
1425
- values = list(elements_dict.values())
1426
- if nx == False:
1427
- values = Helper.Normalize(values)
1430
+ values = [round(value, mantissa) for value in list(elements_dict.values())]
1431
+ if nxCompatible == False:
1432
+ if mantissa > 0: # We cannot have values in the range 0 to 1 with a mantissa < 1
1433
+ values = [round(v, mantissa) for v in Helper.Normalize(values)]
1434
+ else:
1435
+ values = Helper.Normalize(values)
1428
1436
  min_value = 0
1429
1437
  max_value = 1
1430
1438
  else:
@@ -4677,9 +4685,8 @@ class Graph:
4677
4685
  graph = Graph.RemoveVertex(graph,ev, tolerance=tolerance)
4678
4686
  return graph
4679
4687
 
4680
-
4681
4688
  @staticmethod
4682
- def ClosenessCentrality(graph, weightKey="length", normalize: bool = False, nx: bool = True, key: str = "closeness_centrality", colorKey="cc_color", colorScale="viridis", mantissa: int = 6, tolerance: float = 0.001, silent: bool = False):
4689
+ def ClosenessCentrality(graph, weightKey="length", normalize: bool = False, nxCompatible: bool = True, key: str = "closeness_centrality", colorKey="cc_color", colorScale="viridis", mantissa: int = 6, tolerance: float = 0.001, silent: bool = False):
4683
4690
  """
4684
4691
  Returns the closeness centrality of the input graph. The order of the returned list is the same as the order of vertices/edges. See https://en.wikipedia.org/wiki/Betweenness_centrality.
4685
4692
 
@@ -4688,12 +4695,12 @@ class Graph:
4688
4695
  graph : topologic_core.Graph
4689
4696
  The input graph.
4690
4697
  weightKey : str , optional
4691
- If None, all edge weights are considered equal. Otherwise holds the name of the edge dictionary key to be used as weight.
4692
- Weights are used to calculate weighted shortest paths, so they are interpreted as distances.
4693
- If you wish to use the actual length of the edge, then use the "length" as key. the default is "length".
4698
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
4699
+ the shortest path. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
4700
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
4694
4701
  normalize : bool , optional
4695
4702
  If set to True, the values are normalized to be in the range 0 to 1. Otherwise they are not. The default is False.
4696
- nx : bool , optional
4703
+ nxCompatible : bool , optional
4697
4704
  If set to True, use networkX to scale by the fraction of nodes reachable. This gives the Wasserman and Faust improved formula.
4698
4705
  For single component graphs it is the same as the original formula.
4699
4706
  key : str , optional
@@ -4719,7 +4726,7 @@ class Graph:
4719
4726
  try:
4720
4727
  import networkx as nx
4721
4728
  except:
4722
- print("Graph.BetwennessCentrality - Information: Installing required networkx library.")
4729
+ print("Graph.ClosenessCentrality - Information: Installing required networkx library.")
4723
4730
  try:
4724
4731
  os.system("pip install networkx")
4725
4732
  except:
@@ -4742,14 +4749,17 @@ class Graph:
4742
4749
  return None
4743
4750
 
4744
4751
  if weightKey:
4745
- if "len" in weightKey.lower():
4752
+ if "len" in weightKey.lower() or "dis" in weightKey.lower():
4746
4753
  weightKey = "length"
4747
4754
  nx_graph = Graph.NetworkXGraph(graph)
4748
4755
  elements = Graph.Vertices(graph)
4749
- elements_dict = nx.closeness_centrality(nx_graph, distance=weightKey, wf_improved=nx)
4750
- values = list(elements_dict.values())
4756
+ elements_dict = nx.closeness_centrality(nx_graph, distance=weightKey, wf_improved=nxCompatible)
4757
+ values = [round(v, mantissa) for v in list(elements_dict.values())]
4751
4758
  if normalize == True:
4752
- values = Helper.Normalize(values)
4759
+ if mantissa > 0: # We cannot round numbers from 0 to 1 with a mantissa = 0.
4760
+ values = [round(v, mantissa) for v in Helper.Normalize(values)]
4761
+ else:
4762
+ values = Helper.Normalize(values)
4753
4763
  min_value = 0
4754
4764
  max_value = 1
4755
4765
  else:
@@ -4930,7 +4940,7 @@ class Graph:
4930
4940
  return graph
4931
4941
 
4932
4942
  @staticmethod
4933
- def Connectivity(graph, vertices=None, key: str = "connectivity", edgeKey: str = None, tolerance = 0.0001, silent = False):
4943
+ def Connectivity(graph, vertices=None, weightKey: str = None, normalize: bool = False, key: str = "connectivity", colorKey: str = "cn_color", colorScale="Viridis", mantissa: int = 6, tolerance = 0.0001, silent = False):
4934
4944
  """
4935
4945
  Return the connectivity measure of the input list of vertices within the input graph. The order of the returned list is the same as the order of the input list of vertices. If no vertices are specified, the connectivity of all the vertices in the input graph is computed. See https://www.spacesyntax.online/term/connectivity/.
4936
4946
 
@@ -4939,15 +4949,22 @@ class Graph:
4939
4949
  graph : topologic_core.Graph
4940
4950
  The input graph.
4941
4951
  vertices : list , optional
4942
- The input list of vertices. The default is None.
4952
+ The input list of vertices. The default is None which means all graph vertices are computed.
4953
+ normalize : bool , optional
4954
+ If set to True, the values are normalized to be in the range 0 to 1. Otherwise they are not. The default is False.
4955
+ weightKey : str , optional
4956
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
4957
+ the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
4958
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
4943
4959
  key : str , optional
4944
4960
  The dictionary key under which to store the connectivity score. The default is "connectivity".
4945
- edgeKey : str , optional
4946
- If specified, the value in the connected edges' dictionary specified by the edgeKey string will be aggregated to calculate
4947
- the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead. This is used in weighted graphs.
4948
- tolerance : float , optional
4949
- The desired tolerance. The default is 0.0001.
4950
-
4961
+ colorKey : str , optional
4962
+ The desired dictionary key under which to store the connectivity color. The default is "cn_color".
4963
+ colorScale : str , optional
4964
+ 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/.
4965
+ In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
4966
+ mantissa : int , optional
4967
+ The desired length of the mantissa. The default is 6.
4951
4968
  tolerance : float , optional
4952
4969
  The desired tolerance. The default is 0.0001.
4953
4970
  silent : bool , optional
@@ -4956,25 +4973,40 @@ class Graph:
4956
4973
  Returns
4957
4974
  -------
4958
4975
  list
4959
- The closeness centrality of the input list of vertices within the input graph. The values are in the range 0 to 1.
4976
+ The connectivity score of the input list of vertices within the input graph. The values are in the range 0 to 1 if normalized.
4960
4977
 
4961
4978
  """
4962
4979
 
4963
4980
  from topologicpy.Topology import Topology
4964
4981
  from topologicpy.Dictionary import Dictionary
4982
+ from topologicpy.Helper import Helper
4983
+ from topologicpy.Color import Color
4965
4984
 
4966
4985
  if not Topology.IsInstance(graph, "Graph"):
4967
4986
  if not silent:
4968
- print("Graph.ClosenessCentrality - Error: The input graph is not a valid graph. Returning None.")
4987
+ print("Graph.Connectivity - Error: The input graph is not a valid graph. Returning None.")
4969
4988
  return None
4970
4989
  if vertices == None:
4971
4990
  vertices = Graph.Vertices(graph)
4972
- connectivities = [Graph.VertexDegree(graph, v, edgeKey=edgeKey, tolerance=tolerance, silent=silent) for v in vertices]
4973
- for i, v in enumerate(vertices):
4974
- d = Topology.Dictionary(v)
4975
- d = Dictionary.SetValueAtKey(d, key, connectivities[i])
4976
- v = Topology.SetDictionary(v, d)
4977
- return connectivities
4991
+ values = [Graph.VertexDegree(graph, v, weightKey=weightKey, mantissa=mantissa, tolerance=tolerance, silent=silent) for v in vertices]
4992
+ values = [round(v, mantissa) for v in values]
4993
+ if normalize == True:
4994
+ if mantissa > 0:
4995
+ values = [round(v, mantissa) for v in Helper.Normalize(values)]
4996
+ else:
4997
+ values = Helper.Normalize(values)
4998
+ min_value = 0
4999
+ max_value = 1
5000
+ else:
5001
+ min_value = min(values)
5002
+ max_value = max(values)
5003
+
5004
+ for i, value in enumerate(values):
5005
+ color = Color.AnyToHex(Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale))
5006
+ d = Topology.Dictionary(vertices[i])
5007
+ d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [value, color])
5008
+ v = Topology.SetDictionary(vertices[i], d)
5009
+ return values
4978
5010
 
4979
5011
  @staticmethod
4980
5012
  def ContainsEdge(graph, edge, tolerance=0.0001):
@@ -5097,23 +5129,38 @@ class Graph:
5097
5129
  vertex = Topology.SetDictionary(vertex, d)
5098
5130
 
5099
5131
  return cut_vertices
5100
-
5132
+
5101
5133
  @staticmethod
5102
- def Degree(graph, vertices=None, key: str = "degree", edgeKey: str = None, mantissa: int = 6, tolerance = 0.0001):
5103
- """
5104
- Return the degree measure of the input list of vertices within the input graph. The order of the returned list is the same as the order of the input list of vertices. If no vertices are specified, the closeness centrality of all the vertices in the input graph is computed. See https://en.wikipedia.org/wiki/Degree_(graph_theory).
5134
+ def DegreeCentrality(graph,
5135
+ vertices: list = None,
5136
+ weightKey: str= None,
5137
+ normalize: bool = False,
5138
+ key: str = "degree_centrality",
5139
+ colorKey="dc_color",
5140
+ colorScale="viridis",
5141
+ mantissa: int = 6,
5142
+ tolerance: float = 0.001,
5143
+ silent: bool = False):
5144
+ """
5145
+ Returns the degree centrality of the input graph. The order of the returned list is the same as the order of vertices. See https://en.wikipedia.org/wiki/Degree_centrality.
5105
5146
 
5106
5147
  Parameters
5107
5148
  ----------
5108
5149
  graph : topologic_core.Graph
5109
5150
  The input graph.
5110
- vertices : list , optional
5111
- The input list of vertices. The default is None.
5151
+ weightKey : str , optional
5152
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
5153
+ the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
5154
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
5155
+ normalize : bool , optional
5156
+ If set to True, the values are normalized to be in the range 0 to 1. Otherwise they are not. The default is False.
5112
5157
  key : str , optional
5113
- The dictionary key under which to store the closeness centrality score. The default is "degree".
5114
- edgeKey : str , optional
5115
- If specified, the value in the connected edges' dictionary specified by the edgeKey string will be aggregated to calculate
5116
- the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead. This is used in weighted graphs.
5158
+ The desired dictionary key under which to store the degree centrality score. The default is "degree_centrality".
5159
+ colorKey : str , optional
5160
+ The desired dictionary key under which to store the degree centrality color. The default is "dc_color".
5161
+ colorScale : str , optional
5162
+ 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/.
5163
+ In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
5117
5164
  mantissa : int , optional
5118
5165
  The desired length of the mantissa. The default is 6.
5119
5166
  tolerance : float , optional
@@ -5122,35 +5169,30 @@ class Graph:
5122
5169
  Returns
5123
5170
  -------
5124
5171
  list
5125
- The degree of the input list of vertices within the input graph.
5172
+ The betweenness centrality of the input list of vertices within the input graph. The values are in the range 0 to 1.
5126
5173
 
5127
5174
  """
5128
- from topologicpy.Topology import Topology
5175
+
5129
5176
  from topologicpy.Dictionary import Dictionary
5177
+ from topologicpy.Color import Color
5178
+ from topologicpy.Topology import Topology
5179
+ from topologicpy.Helper import Helper
5130
5180
 
5131
- if not Topology.IsInstance(graph, "Graph"):
5132
- print("Graph.ClosenessCentrality - Error: The input graph is not a valid graph. Returning None.")
5133
- return None
5134
- graphVertices = Graph.Vertices(graph)
5135
- if not isinstance(vertices, list):
5136
- vertices = graphVertices
5137
- else:
5138
- vertices = [v for v in vertices if Topology.IsInstance(v, "Vertex")]
5139
- if len(vertices) < 1:
5140
- print("Graph.Degree - Error: The input list of vertices does not contain any valid vertices. Returning None.")
5141
- return None
5142
- n = len(graphVertices)
5143
-
5144
- scores = []
5145
- for i, v in enumerate(vertices):
5146
- degree = Graph.VertexDegree(graph, v, edgeKey= edgeKey, tolerance = tolerance)
5147
- if isinstance(degree, float):
5148
- degree = round(degree, mantissa)
5149
- d = Topology.Dictionary(v)
5150
- d = Dictionary.SetValueAtKey(d, key, degree)
5151
- v = Topology.SetDictionary(v, d)
5152
- scores.append(degree)
5153
- return scores
5181
+ if not Topology.IsInstance(graph, "graph"):
5182
+ if not silent:
5183
+ print("Graph.DegreeCentrality - Error: The input graph is not a valid graph. Returning None.")
5184
+ return None
5185
+
5186
+ return Graph.Connectivity(graph,
5187
+ vertices=vertices,
5188
+ weightKey=weightKey,
5189
+ normalize=normalize,
5190
+ key=key,
5191
+ colorKey=colorKey,
5192
+ colorScale=colorScale,
5193
+ mantissa=mantissa,
5194
+ tolerance=tolerance,
5195
+ silent=silent)
5154
5196
 
5155
5197
  @staticmethod
5156
5198
  def DegreeMatrix(graph):
@@ -8372,7 +8414,7 @@ class Graph:
8372
8414
  return laplacian.tolist()
8373
8415
 
8374
8416
  @staticmethod
8375
- def Leaves(graph, edgeKey: str = None, tolerance: float = 0.0001, silent: bool = False):
8417
+ def Leaves(graph, weightKey: str = None, mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
8376
8418
  """
8377
8419
  Returns a list of all vertices that have a degree of 1, also called leaf nodes.
8378
8420
 
@@ -8380,9 +8422,12 @@ class Graph:
8380
8422
  ----------
8381
8423
  graph : topologic_core.Graph
8382
8424
  The input graph.
8383
- edgeKey : str , optional
8384
- If specified, the value in the connected edges' dictionary specified by the edgeKey string will be aggregated to calculate
8385
- the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead. This is used in weighted graphs.
8425
+ weightKey : str , optional
8426
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
8427
+ the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
8428
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
8429
+ mantissa : int , optional
8430
+ The desired length of the mantissa. The default is 6.
8386
8431
  tolerance : float , optional
8387
8432
  The desired tolerance. The default is 0.0001.
8388
8433
  silent : bool , optional
@@ -8400,7 +8445,7 @@ class Graph:
8400
8445
  if not silent:
8401
8446
  print("Graph.Leaves - Error: The input graph parameter is not a valid graph. Returning None.")
8402
8447
  return None
8403
- return [v for v in Graph.Vertices(graph) if Graph.VertexDegree(graph, v, edgeKey=edgeKey, tolerance=tolerance, silent=silent) == 1]
8448
+ return [v for v in Graph.Vertices(graph) if Graph.VertexDegree(graph, v, weightKey=weightKey, mantissa=mantissa, tolerance=tolerance, silent=silent) == 1]
8404
8449
 
8405
8450
  @staticmethod
8406
8451
  def LineGraph(graph, transferVertexDictionaries=False, transferEdgeDictionaries=False, tolerance=0.0001, silent=False):
@@ -9231,93 +9276,6 @@ class Graph:
9231
9276
  nx.set_node_attributes(nxGraph, pos, "pos")
9232
9277
  return nxGraph
9233
9278
 
9234
- @staticmethod
9235
- def NetworkXGraph_old(graph, xKey='x', yKey='y', zKey='z', mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
9236
- """
9237
- Converts the input graph into a NetworkX Graph. See http://networkx.org
9238
-
9239
- Parameters
9240
- ----------
9241
- graph : topologic_core.Graph
9242
- The input graph.
9243
- xKey : str , optional
9244
- The dictionary key under which to store the X-Coordinate of the vertex. The default is 'x'.
9245
- yKey : str , optional
9246
- The dictionary key under which to store the Y-Coordinate of the vertex. The default is 'y'.
9247
- zKey : str , optional
9248
- The dictionary key under which to store the Z-Coordinate of the vertex. The default is 'z'.
9249
- mantissa : int , optional
9250
- The desired length of the mantissa. The default is 6.
9251
- tolerance : float , optional
9252
- The desired tolerance. The default is 0.0001.
9253
- silent : bool , optional
9254
- If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
9255
-
9256
- Returns
9257
- -------
9258
- networkX Graph
9259
- The created networkX Graph
9260
-
9261
- """
9262
- from topologicpy.Vertex import Vertex
9263
- from topologicpy.Topology import Topology
9264
- from topologicpy.Dictionary import Dictionary
9265
- import warnings
9266
-
9267
- try:
9268
- import networkx as nx
9269
- except:
9270
- print("Graph.NetworkXGraph - Information: Installing required networkx library.")
9271
- try:
9272
- os.system("pip install networkx")
9273
- except:
9274
- os.system("pip install networkx --user")
9275
- try:
9276
- import networkx as nx
9277
- print("Graph.NetworkXGraph - Infromation: networkx library installed correctly.")
9278
- except:
9279
- warnings.warn("Graph - Error: Could not import networkx. Please try to install networkx manually. Returning None.")
9280
- return None
9281
-
9282
- if not Topology.IsInstance(graph, "Graph"):
9283
- if not silent:
9284
- print("Graph.NetworkXGraph - Error: The input graph is not a valid graph. Returning None.")
9285
- return None
9286
-
9287
- nxGraph = nx.Graph()
9288
- vertices = Graph.Vertices(graph)
9289
- order = len(vertices)
9290
- nodes = []
9291
- for i in range(order):
9292
- v = vertices[i]
9293
- d = Topology.Dictionary(vertices[i])
9294
- if d:
9295
- keys = Dictionary.Keys(d)
9296
- if not keys:
9297
- keys = []
9298
- values = Dictionary.Values(d)
9299
- if not values:
9300
- values = []
9301
- keys += [xKey,yKey,zKey]
9302
- values += [Vertex.X(v, mantissa=mantissa), Vertex.Y(v, mantissa=mantissa), Vertex.Z(v, mantissa=mantissa)]
9303
- d = Dictionary.ByKeysValues(keys,values)
9304
- pythonD = Dictionary.PythonDictionary(d)
9305
- nodes.append((i, pythonD))
9306
- else:
9307
- nodes.append((i, {"name": str(i)}))
9308
- nxGraph.add_nodes_from(nodes)
9309
- for i in range(order):
9310
- v = vertices[i]
9311
- adjVertices = Graph.AdjacentVertices(graph, vertices[i])
9312
- for adjVertex in adjVertices:
9313
- adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=True, tolerance=tolerance)
9314
- if not adjIndex == None:
9315
- nxGraph.add_edge(i,adjIndex, length=(Vertex.Distance(v, adjVertex, mantissa=mantissa)))
9316
-
9317
- pos=nx.spring_layout(nxGraph, k=0.2)
9318
- nx.set_node_attributes(nxGraph, pos, "pos")
9319
- return nxGraph
9320
-
9321
9279
  @staticmethod
9322
9280
  def Order(graph):
9323
9281
  """
@@ -10514,7 +10472,7 @@ class Graph:
10514
10472
  return Graph.ByVerticesEdges(dictionary['vertices'], dictionary['edges'])
10515
10473
 
10516
10474
  @staticmethod
10517
- def VertexDegree(graph, vertex, edgeKey: str = None, tolerance: float = 0.0001, silent: bool = False):
10475
+ def VertexDegree(graph, vertex, weightKey: str = None, mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
10518
10476
  """
10519
10477
  Returns the degree of the input vertex. See https://en.wikipedia.org/wiki/Degree_(graph_theory).
10520
10478
 
@@ -10524,9 +10482,12 @@ class Graph:
10524
10482
  The input graph.
10525
10483
  vertex : topologic_core.Vertex
10526
10484
  The input vertex.
10527
- edgeKey : str , optional
10528
- If specified, the value in the connected edges' dictionary specified by the edgeKey string will be aggregated to calculate
10529
- the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead. This is used in weighted graphs.
10485
+ weightKey : str , optional
10486
+ If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
10487
+ the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
10488
+ This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
10489
+ mantissa : int , optional
10490
+ The desired length of the mantissa. The default is 6.
10530
10491
  tolerance : float , optional
10531
10492
  The desired tolerance. The default is 0.0001.
10532
10493
  silent : bool , optional
@@ -10538,6 +10499,7 @@ class Graph:
10538
10499
  The degree of the input vertex.
10539
10500
 
10540
10501
  """
10502
+ from topologicpy.Edge import Edge
10541
10503
  from topologicpy.Topology import Topology
10542
10504
  from topologicpy.Dictionary import Dictionary
10543
10505
  import numbers
@@ -10550,18 +10512,20 @@ class Graph:
10550
10512
  if not silent:
10551
10513
  print("Graph.VertexDegree - Error: The input vertex is not a valid vertex. Returning None.")
10552
10514
  return None
10553
- if not isinstance(edgeKey, str):
10554
- edgeKey = ""
10555
10515
  edges = Graph.Edges(graph, [vertex], tolerance=tolerance)
10556
10516
  degree = 0
10557
10517
  for edge in edges:
10558
- d = Topology.Dictionary(edge)
10559
- value = Dictionary.ValueAtKey(d, edgeKey)
10560
- if isinstance(value, numbers.Number):
10561
- degree += value
10518
+ if weightKey == None:
10519
+ value = 1
10520
+ elif "len" in weightKey.lower() or "dis" in weightKey.lower():
10521
+ value = Edge.Length(edge, mantissa=mantissa)
10562
10522
  else:
10563
- degree += 1
10564
- return degree
10523
+ d = Topology.Dictionary(edge)
10524
+ value = Dictionary.ValueAtKey(d, weightKey)
10525
+ if not isinstance(value, numbers.Number):
10526
+ value = 1
10527
+ degree += value
10528
+ return round(degree, mantissa)
10565
10529
 
10566
10530
  @staticmethod
10567
10531
  def Vertices(graph, vertexKey=None, reverse=False):
topologicpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.8.11'
1
+ __version__ = '0.8.13'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: topologicpy
3
- Version: 0.8.11
3
+ Version: 0.8.13
4
4
  Summary: An AI-Powered Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
5
5
  Author-email: Wassim Jabi <wassim.jabi@gmail.com>
6
6
  License: AGPL v3 License
@@ -11,7 +11,7 @@ topologicpy/Dictionary.py,sha256=t0O7Du-iPq46FyKqZfcjHfsUK1E8GS_e67R2V5cpkbw,331
11
11
  topologicpy/Edge.py,sha256=yxkCVDYBflJNEYxnjMmlyvbkpg8TNy7y5bSH3yQ4jzs,71418
12
12
  topologicpy/EnergyModel.py,sha256=UoQ9Jm-hYsN383CbcLKw-y6BKitRHj0uyh84yQ-8ACg,53856
13
13
  topologicpy/Face.py,sha256=tn3PI-t9rXikgI1QMclw0PFwQ5vvyLi-wJKqZZZ9xmw,182755
14
- topologicpy/Graph.py,sha256=hrJYK0CboyxNjCRLoc75PeQzf9uI64OVxDyevbJUlZg,498342
14
+ topologicpy/Graph.py,sha256=FBmiMObzztPwZFJ2T846Ivz0Y1kpzMF0sF-PDUMPk4o,498946
15
15
  topologicpy/Grid.py,sha256=2s9cSlWldivn1i9EUz4OOokJyANveqmRe_vR93CAndI,18245
16
16
  topologicpy/Helper.py,sha256=4H5KPiv_eiEs489UOOyGLe9RaeoZIfmMh3mk_YCHmXg,29100
17
17
  topologicpy/Honeybee.py,sha256=Y_El6M8x3ixvvIe_VcRiwj_4C89ZZg5_WlT7adbCkpw,21849
@@ -28,9 +28,9 @@ topologicpy/Vector.py,sha256=GkGt-aJ591IJ2IPffMAudvITLDPi2qZibZc4UAav6m8,42407
28
28
  topologicpy/Vertex.py,sha256=xr8KSgKnx-hgVp-eIvMPAKRv04R-wk-_4zc57xVyEqE,80793
29
29
  topologicpy/Wire.py,sha256=x7tOeR1o5qi5cXp_d9JrQrSXfYztCWiBC1OnVl6Yp7A,228463
30
30
  topologicpy/__init__.py,sha256=vlPCanUbxe5NifC4pHcnhSzkmmYcs_UrZrTlVMsxcFs,928
31
- topologicpy/version.py,sha256=37n3GuNviuek888I4WoUQ7KvWprxXex9ltIoHwZWFxM,23
32
- topologicpy-0.8.11.dist-info/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
33
- topologicpy-0.8.11.dist-info/METADATA,sha256=_ggJ77QM3ok-OsVcQdXNC6Er-VH_AuQg3tZroNFpyYk,10513
34
- topologicpy-0.8.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
35
- topologicpy-0.8.11.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
36
- topologicpy-0.8.11.dist-info/RECORD,,
31
+ topologicpy/version.py,sha256=XjaqL6H5ZzfJyu62UXI4UhwezcxfWWIh4nGQ9YuybtM,23
32
+ topologicpy-0.8.13.dist-info/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
33
+ topologicpy-0.8.13.dist-info/METADATA,sha256=5SZpCgIN0s9DGq8P0heNOhibtizlRvUZIb2fP0gJAtE,10513
34
+ topologicpy-0.8.13.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
35
+ topologicpy-0.8.13.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
36
+ topologicpy-0.8.13.dist-info/RECORD,,