topologicpy 0.8.11__py3-none-any.whl → 0.8.12__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 +141 -177
- topologicpy/version.py +1 -1
- {topologicpy-0.8.11.dist-info → topologicpy-0.8.12.dist-info}/METADATA +1 -1
- {topologicpy-0.8.11.dist-info → topologicpy-0.8.12.dist-info}/RECORD +7 -7
- {topologicpy-0.8.11.dist-info → topologicpy-0.8.12.dist-info}/LICENSE +0 -0
- {topologicpy-0.8.11.dist-info → topologicpy-0.8.12.dist-info}/WHEEL +0 -0
- {topologicpy-0.8.11.dist-info → topologicpy-0.8.12.dist-info}/top_level.txt +0 -0
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 ,
|
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 ,
|
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:
|
@@ -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
|
1367
|
-
|
1368
|
-
|
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
1377
|
nx : 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
|
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
|
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,7 +1417,7 @@ 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():
|
@@ -1422,9 +1427,12 @@ class Graph:
|
|
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())
|
1430
|
+
values = [round(value, mantissa) for value in list(elements_dict.values())]
|
1426
1431
|
if nx == False:
|
1427
|
-
values
|
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,7 +4685,6 @@ class Graph:
|
|
4677
4685
|
graph = Graph.RemoveVertex(graph,ev, tolerance=tolerance)
|
4678
4686
|
return graph
|
4679
4687
|
|
4680
|
-
|
4681
4688
|
@staticmethod
|
4682
4689
|
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):
|
4683
4690
|
"""
|
@@ -4688,9 +4695,9 @@ class Graph:
|
|
4688
4695
|
graph : topologic_core.Graph
|
4689
4696
|
The input graph.
|
4690
4697
|
weightKey : str , optional
|
4691
|
-
If
|
4692
|
-
|
4693
|
-
|
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
4703
|
nx : bool , optional
|
@@ -4719,7 +4726,7 @@ class Graph:
|
|
4719
4726
|
try:
|
4720
4727
|
import networkx as nx
|
4721
4728
|
except:
|
4722
|
-
print("Graph.
|
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
4756
|
elements_dict = nx.closeness_centrality(nx_graph, distance=weightKey, wf_improved=nx)
|
4750
|
-
values = list(elements_dict.values())
|
4757
|
+
values = [round(v, mantissa) for v in list(elements_dict.values())]
|
4751
4758
|
if normalize == True:
|
4752
|
-
|
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",
|
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
|
-
|
4946
|
-
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
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
|
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.
|
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
|
-
|
4973
|
-
|
4974
|
-
|
4975
|
-
|
4976
|
-
|
4977
|
-
|
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
|
5103
|
-
|
5104
|
-
|
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
|
-
|
5111
|
-
|
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
|
5114
|
-
|
5115
|
-
|
5116
|
-
|
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
|
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
|
-
|
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, "
|
5132
|
-
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5138
|
-
|
5139
|
-
|
5140
|
-
|
5141
|
-
|
5142
|
-
|
5143
|
-
|
5144
|
-
|
5145
|
-
|
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,
|
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
|
-
|
8384
|
-
If specified, the value in the connected edges' dictionary specified by the
|
8385
|
-
the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
|
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,
|
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,
|
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
|
-
|
10528
|
-
If specified, the value in the connected edges' dictionary specified by the
|
10529
|
-
the vertex degree. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
|
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
|
-
|
10559
|
-
|
10560
|
-
|
10561
|
-
|
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
|
-
|
10564
|
-
|
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.
|
1
|
+
__version__ = '0.8.12'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: topologicpy
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.12
|
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=
|
14
|
+
topologicpy/Graph.py,sha256=4zO0ntmRFz4k1WtsLmsbzjlor1tuQGLBIkpFk2Y_4hI,498848
|
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=
|
32
|
-
topologicpy-0.8.
|
33
|
-
topologicpy-0.8.
|
34
|
-
topologicpy-0.8.
|
35
|
-
topologicpy-0.8.
|
36
|
-
topologicpy-0.8.
|
31
|
+
topologicpy/version.py,sha256=VV54c1MEFjYlfKiA8ImJRkIYgUTfdMJOJs5zzf-BKgE,23
|
32
|
+
topologicpy-0.8.12.dist-info/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
|
33
|
+
topologicpy-0.8.12.dist-info/METADATA,sha256=owpJTXYjSfnJDFWPqrGOm1DoEVeWTghesziE4T-nt2I,10513
|
34
|
+
topologicpy-0.8.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
35
|
+
topologicpy-0.8.12.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
|
36
|
+
topologicpy-0.8.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|