@@ -540,6 +540,8 @@ class Graph(Atom):
540540 def __init__ (self , G , ** kwargs ):
541541 super (Graph , self ).__init__ ()
542542 self .G = G
543+ self .mixed = kwargs .get ("mixed" , False )
544+ print ("creating" , self .G , self .mixed )
543545
544546 def __hash__ (self ):
545547 return hash (("Pymathics`Graph" , self .G ))
@@ -636,12 +638,17 @@ def empty(self):
636638 def head (self ):
637639 return SymbolGraph
638640
641+ def is_directed (self ):
642+ if self .G .is_directed ():
643+ return not self .mixed
644+ return False
645+
639646 def is_loop_free (self ):
640647 return not any (True for _ in nx .nodes_with_selfloops (self .G ))
641648
642649 # networkx graphs can't be for mixed
643650 def is_mixed_graph (self ):
644- return False
651+ return self . mixed
645652 # return self.edges. ... is_mixed()
646653
647654 def is_multigraph (self ):
@@ -900,6 +907,7 @@ def full_new_edge_properties(new_edge_style):
900907 return None
901908
902909 empty_dict = {}
910+ mixed = False
903911 if directed_edges :
904912 G = nx .MultiDiGraph () if multigraph [0 ] else nx .DiGraph ()
905913 nodes_seen = set ()
@@ -913,6 +921,8 @@ def full_new_edge_properties(new_edge_style):
913921 for v in unseen_vertices :
914922 G .add_node (v )
915923
924+ if undirected_edges :
925+ mixed = True
916926 for u , v , attr_dict in undirected_edges :
917927 attr_dict = attr_dict or empty_dict
918928 G .add_edge (u , v , ** attr_dict )
@@ -931,7 +941,7 @@ def full_new_edge_properties(new_edge_style):
931941 n_undirected = len (undirected_edges ),
932942 )
933943
934- g = Graph (G )
944+ g = Graph (G , mixed = mixed )
935945 _process_graph_options (g , options )
936946 return g
937947
@@ -1209,6 +1219,10 @@ class DirectedEdge(Builtin):
12091219
12101220class DirectedGraphQ (_NetworkXBuiltin ):
12111221 """
1222+ <dl>
1223+ <dt>'DirectedGraphQ'[$graph$]
1224+ <dd>True if $graph$ is a 'Graph' and all the edges are directed.
1225+ </dl>
12121226 >> g = Graph[{1 -> 2, 2 -> 3}]; DirectedGraphQ[g]
12131227 = True
12141228
@@ -1226,8 +1240,7 @@ def eval(self, graph, expression, evaluation, options):
12261240 "%(name)s[graph_, OptionsPattern[%(name)s]]"
12271241 graph = self ._build_graph (graph , evaluation , options , expression , quiet = True )
12281242 if graph :
1229- directed = graph .G .is_directed () and not graph .is_mixed_graph ()
1230- return from_python (directed )
1243+ return from_python (graph .is_directed ())
12311244 else :
12321245 return SymbolFalse
12331246
@@ -1268,8 +1281,11 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
12681281
12691282class EdgeIndex (_NetworkXBuiltin ):
12701283 """
1271- >> EdgeIndex[{c <-> d, d <-> a, a -> e}, d <-> a]
1272- = 2
1284+ <dl>
1285+ <dt>'EdgeIndex['graph', 'edge']'
1286+ <dd>gives the position of the 'edge' in the list of edges associated \
1287+ to the graph.
1288+ </dl>
12731289 """
12741290
12751291 def eval (self , graph , v , expression , evaluation , options ):
@@ -1287,8 +1303,10 @@ def eval(self, graph, v, expression, evaluation, options):
12871303
12881304class EdgeList (_PatternList ):
12891305 """
1290- >> EdgeList[{1 -> 2, 2 <-> 3}]
1291- = {DirectedEdge[1, 2], UndirectedEdge[2, 3]}
1306+ <dl>
1307+ <dt>'EdgeList'[$g$]
1308+ <dd>gives the list of edges that defines $g$
1309+ </dl>
12921310 """
12931311
12941312 def _items (self , graph ):
@@ -1301,17 +1319,13 @@ class EdgeRules(_NetworkXBuiltin):
13011319 <dt>'EdgeRules'[$g$]
13021320 <dd> gives the list of edge rules for the graph $g$.
13031321 </dl>
1304-
1305- >> EdgeRules[{1 <-> 2, 2 -> 3, 3 <-> 4}]
1306- = {1 -> 2, 2 -> 3, 3 -> 4}
13071322 """
13081323 summary_text = "list the edge rules"
13091324
13101325 def eval (self , graph , expression , evaluation , options ):
13111326 "%(name)s[graph_, OptionsPattern[%(name)s]]"
13121327 graph = self ._build_graph (graph , evaluation , options , expression )
13131328 if graph :
1314-
13151329 def rules ():
13161330 for edge in graph .edges :
13171331 u , v = edge
@@ -1396,11 +1410,6 @@ class FindShortestPath(_NetworkXBuiltin):
13961410 = {}
13971411
13981412 >> g = Graph[{1 -> 2, 2 -> 3, 1 -> 3}, EdgeWeight -> {0.5, a, 3}];
1399- >> a = 0.5; FindShortestPath[g, 1, 3]
1400- = {1, 2, 3}
1401- >> a = 10; FindShortestPath[g, 1, 3]
1402- = {1, 3}
1403- >> a=.;
14041413
14051414 #> FindShortestPath[{}, 1, 2]
14061415 : The vertex at position 2 in FindShortestPath[{}, 1, 2] does not belong to the graph at position 1.
@@ -1519,14 +1528,6 @@ class GraphAtom(AtomBuiltin):
15191528 >> Graph[{{1 -> 2}}]
15201529 = Graph[{{1 -> 2}}]
15211530
1522- >> g = Graph[{1 -> 2, 2 -> 3}, DirectedEdges -> True];
1523- >> EdgeCount[g, _DirectedEdge]
1524- = 2
1525- >> g = Graph[{1 -> 2, 2 -> 3}, DirectedEdges -> False];
1526- >> EdgeCount[g, _DirectedEdge]
1527- = 0
1528- >> EdgeCount[g, _UndirectedEdge]
1529- = 2
15301531 """
15311532
15321533 # requires = ("networkx",)
@@ -1583,8 +1584,6 @@ class HITSCentrality(_Centrality):
15831584 the vertices in the graph $g$.
15841585 </dl>
15851586
1586- >> g = Graph[{a -> d, b -> c, d -> c, d -> a, e -> c}]; HITSCentrality[g]
1587- = {{0.292893, 0., 0., 0.707107, 0.}, {0., 1., 0.707107, 0., 0.707107}}
15881587 """
15891588
15901589 summary_text = "HITS centrality"
0 commit comments