Adding overlapping non-weighted, directed edges to a weighted, undirected graph
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have the following Mathematica code based on the GDB1 instance from the CARP literature:
HighlightGraph[
Graph[1 [UndirectedEdge] 2, 1 [UndirectedEdge] 4,
1 [UndirectedEdge] 7, 1 [UndirectedEdge] 10,
1 [UndirectedEdge] 12 , 2 [UndirectedEdge] 3,
2 [UndirectedEdge] 4, 2 [UndirectedEdge] 9,
3 [UndirectedEdge] 4, 3 [UndirectedEdge] 5,
5 [UndirectedEdge] 6, 5 [UndirectedEdge] 11,
5 [UndirectedEdge] 12, 6 [UndirectedEdge] 7,
6 [UndirectedEdge] 12, 7 [UndirectedEdge] 8,
7 [UndirectedEdge] 12, 8 [UndirectedEdge] 10,
8 [UndirectedEdge] 11, 9 [UndirectedEdge] 10,
9 [UndirectedEdge] 11, 10 [UndirectedEdge] 11,
EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
VertexLabels -> Table[i -> Placed[i, Center], i, 12],
VertexLabelStyle -> Directive[White, Bold, 15], VertexSize -> 0.6,
GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
"EdgeWeighted" -> True], 1, Red]
Which outputs the following weighted graph:
On which I would like to display multiple manually entered directed routes starting and ending at the highlighted vertex 1. These routes can overlap, traversing each edge multiple times, requiring multiple distinct directed arcs between nodes. However, they cannot also be introduced as weighted edges or they will distort the topology of the graph.
I will discern different routes with different coloured edges, so being able to make a single class of different edges between nodes will suffice.
I'm stumped. Any thoughts on how to do this would be fantastic.
graphs-and-networks style
New contributor
 |Â
show 1 more comment
up vote
2
down vote
favorite
I have the following Mathematica code based on the GDB1 instance from the CARP literature:
HighlightGraph[
Graph[1 [UndirectedEdge] 2, 1 [UndirectedEdge] 4,
1 [UndirectedEdge] 7, 1 [UndirectedEdge] 10,
1 [UndirectedEdge] 12 , 2 [UndirectedEdge] 3,
2 [UndirectedEdge] 4, 2 [UndirectedEdge] 9,
3 [UndirectedEdge] 4, 3 [UndirectedEdge] 5,
5 [UndirectedEdge] 6, 5 [UndirectedEdge] 11,
5 [UndirectedEdge] 12, 6 [UndirectedEdge] 7,
6 [UndirectedEdge] 12, 7 [UndirectedEdge] 8,
7 [UndirectedEdge] 12, 8 [UndirectedEdge] 10,
8 [UndirectedEdge] 11, 9 [UndirectedEdge] 10,
9 [UndirectedEdge] 11, 10 [UndirectedEdge] 11,
EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
VertexLabels -> Table[i -> Placed[i, Center], i, 12],
VertexLabelStyle -> Directive[White, Bold, 15], VertexSize -> 0.6,
GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
"EdgeWeighted" -> True], 1, Red]
Which outputs the following weighted graph:
On which I would like to display multiple manually entered directed routes starting and ending at the highlighted vertex 1. These routes can overlap, traversing each edge multiple times, requiring multiple distinct directed arcs between nodes. However, they cannot also be introduced as weighted edges or they will distort the topology of the graph.
I will discern different routes with different coloured edges, so being able to make a single class of different edges between nodes will suffice.
I'm stumped. Any thoughts on how to do this would be fantastic.
graphs-and-networks style
New contributor
1
does this give something close to what you need:path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?
â kglr
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago
 |Â
show 1 more comment
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have the following Mathematica code based on the GDB1 instance from the CARP literature:
HighlightGraph[
Graph[1 [UndirectedEdge] 2, 1 [UndirectedEdge] 4,
1 [UndirectedEdge] 7, 1 [UndirectedEdge] 10,
1 [UndirectedEdge] 12 , 2 [UndirectedEdge] 3,
2 [UndirectedEdge] 4, 2 [UndirectedEdge] 9,
3 [UndirectedEdge] 4, 3 [UndirectedEdge] 5,
5 [UndirectedEdge] 6, 5 [UndirectedEdge] 11,
5 [UndirectedEdge] 12, 6 [UndirectedEdge] 7,
6 [UndirectedEdge] 12, 7 [UndirectedEdge] 8,
7 [UndirectedEdge] 12, 8 [UndirectedEdge] 10,
8 [UndirectedEdge] 11, 9 [UndirectedEdge] 10,
9 [UndirectedEdge] 11, 10 [UndirectedEdge] 11,
EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
VertexLabels -> Table[i -> Placed[i, Center], i, 12],
VertexLabelStyle -> Directive[White, Bold, 15], VertexSize -> 0.6,
GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
"EdgeWeighted" -> True], 1, Red]
Which outputs the following weighted graph:
On which I would like to display multiple manually entered directed routes starting and ending at the highlighted vertex 1. These routes can overlap, traversing each edge multiple times, requiring multiple distinct directed arcs between nodes. However, they cannot also be introduced as weighted edges or they will distort the topology of the graph.
I will discern different routes with different coloured edges, so being able to make a single class of different edges between nodes will suffice.
I'm stumped. Any thoughts on how to do this would be fantastic.
graphs-and-networks style
New contributor
I have the following Mathematica code based on the GDB1 instance from the CARP literature:
HighlightGraph[
Graph[1 [UndirectedEdge] 2, 1 [UndirectedEdge] 4,
1 [UndirectedEdge] 7, 1 [UndirectedEdge] 10,
1 [UndirectedEdge] 12 , 2 [UndirectedEdge] 3,
2 [UndirectedEdge] 4, 2 [UndirectedEdge] 9,
3 [UndirectedEdge] 4, 3 [UndirectedEdge] 5,
5 [UndirectedEdge] 6, 5 [UndirectedEdge] 11,
5 [UndirectedEdge] 12, 6 [UndirectedEdge] 7,
6 [UndirectedEdge] 12, 7 [UndirectedEdge] 8,
7 [UndirectedEdge] 12, 8 [UndirectedEdge] 10,
8 [UndirectedEdge] 11, 9 [UndirectedEdge] 10,
9 [UndirectedEdge] 11, 10 [UndirectedEdge] 11,
EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
VertexLabels -> Table[i -> Placed[i, Center], i, 12],
VertexLabelStyle -> Directive[White, Bold, 15], VertexSize -> 0.6,
GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
"EdgeWeighted" -> True], 1, Red]
Which outputs the following weighted graph:
On which I would like to display multiple manually entered directed routes starting and ending at the highlighted vertex 1. These routes can overlap, traversing each edge multiple times, requiring multiple distinct directed arcs between nodes. However, they cannot also be introduced as weighted edges or they will distort the topology of the graph.
I will discern different routes with different coloured edges, so being able to make a single class of different edges between nodes will suffice.
I'm stumped. Any thoughts on how to do this would be fantastic.
graphs-and-networks style
graphs-and-networks style
New contributor
New contributor
edited 4 hours ago
kglr
163k8188387
163k8188387
New contributor
asked 4 hours ago
Jordan MacLachlan
203
203
New contributor
New contributor
1
does this give something close to what you need:path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?
â kglr
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago
 |Â
show 1 more comment
1
does this give something close to what you need:path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?
â kglr
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago
1
1
does this give something close to what you need:
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?â kglr
4 hours ago
does this give something close to what you need:
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?â kglr
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
g1 = Graph[1 <-> 2, 1 <-> 4,ÃÂ 1 <-> 7, 1 <-> 10, 1 <-> 12 , 2 <-> 3,
ÃÂ ÃÂ ÃÂ 2 <-> 4, 2 <-> 9, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 11,ÃÂ ÃÂ 5 <-> 12, 6 <-> 7,
ÃÂ ÃÂ ÃÂ 6 <-> 12, 7 <-> 8, 7 <-> 12, 8 <-> 10, 8 <-> 11, 9 <-> 10, ÃÂ 9 <-> 11, 10 <-> 11,
ÃÂ ÃÂ EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
ÃÂ ÃÂ ÃÂ ÃÂ 8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
ÃÂ ÃÂ VertexLabels -> Table[i -> Placed[i, Center], i, 12],
ÃÂ ÃÂ VertexLabelStyle -> Directive[White, Bold, 15],
VertexSize -> 1,
ÃÂ ÃÂ GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ "EdgeWeighted" -> True] ;
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
newedges = DirectedEdge @@@ Partition[path, 2, 1];
g2 = SetProperty[EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1],
VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges -> Orange]
Update: for multiple paths
path1 = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
path2 = 1, 7, 8, 7, 8, 7, 8, 10, 8, 10, 1, 10, 1, 10, 1;
newedges1 = DirectedEdge @@@ Partition[path1, 2, 1];
newedges2 = DirectedEdge @@@ Partition[path2, 2, 1];
g3 = SetProperty[EdgeAdd[g1, Join[newedges1, newedges2]],
VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges1 -> Orange, Alternatives @@ newedges2 -> Green]
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs'sIGraph/M
useful: How can I conveniently call igraph from Mathematica?.
â kglr
2 hours ago
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
g1 = Graph[1 <-> 2, 1 <-> 4,ÃÂ 1 <-> 7, 1 <-> 10, 1 <-> 12 , 2 <-> 3,
ÃÂ ÃÂ ÃÂ 2 <-> 4, 2 <-> 9, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 11,ÃÂ ÃÂ 5 <-> 12, 6 <-> 7,
ÃÂ ÃÂ ÃÂ 6 <-> 12, 7 <-> 8, 7 <-> 12, 8 <-> 10, 8 <-> 11, 9 <-> 10, ÃÂ 9 <-> 11, 10 <-> 11,
ÃÂ ÃÂ EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
ÃÂ ÃÂ ÃÂ ÃÂ 8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
ÃÂ ÃÂ VertexLabels -> Table[i -> Placed[i, Center], i, 12],
ÃÂ ÃÂ VertexLabelStyle -> Directive[White, Bold, 15],
VertexSize -> 1,
ÃÂ ÃÂ GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ "EdgeWeighted" -> True] ;
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
newedges = DirectedEdge @@@ Partition[path, 2, 1];
g2 = SetProperty[EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1],
VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges -> Orange]
Update: for multiple paths
path1 = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
path2 = 1, 7, 8, 7, 8, 7, 8, 10, 8, 10, 1, 10, 1, 10, 1;
newedges1 = DirectedEdge @@@ Partition[path1, 2, 1];
newedges2 = DirectedEdge @@@ Partition[path2, 2, 1];
g3 = SetProperty[EdgeAdd[g1, Join[newedges1, newedges2]],
VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges1 -> Orange, Alternatives @@ newedges2 -> Green]
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs'sIGraph/M
useful: How can I conveniently call igraph from Mathematica?.
â kglr
2 hours ago
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
add a comment |Â
up vote
3
down vote
accepted
g1 = Graph[1 <-> 2, 1 <-> 4,ÃÂ 1 <-> 7, 1 <-> 10, 1 <-> 12 , 2 <-> 3,
ÃÂ ÃÂ ÃÂ 2 <-> 4, 2 <-> 9, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 11,ÃÂ ÃÂ 5 <-> 12, 6 <-> 7,
ÃÂ ÃÂ ÃÂ 6 <-> 12, 7 <-> 8, 7 <-> 12, 8 <-> 10, 8 <-> 11, 9 <-> 10, ÃÂ 9 <-> 11, 10 <-> 11,
ÃÂ ÃÂ EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
ÃÂ ÃÂ ÃÂ ÃÂ 8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
ÃÂ ÃÂ VertexLabels -> Table[i -> Placed[i, Center], i, 12],
ÃÂ ÃÂ VertexLabelStyle -> Directive[White, Bold, 15],
VertexSize -> 1,
ÃÂ ÃÂ GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ "EdgeWeighted" -> True] ;
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
newedges = DirectedEdge @@@ Partition[path, 2, 1];
g2 = SetProperty[EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1],
VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges -> Orange]
Update: for multiple paths
path1 = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
path2 = 1, 7, 8, 7, 8, 7, 8, 10, 8, 10, 1, 10, 1, 10, 1;
newedges1 = DirectedEdge @@@ Partition[path1, 2, 1];
newedges2 = DirectedEdge @@@ Partition[path2, 2, 1];
g3 = SetProperty[EdgeAdd[g1, Join[newedges1, newedges2]],
VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges1 -> Orange, Alternatives @@ newedges2 -> Green]
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs'sIGraph/M
useful: How can I conveniently call igraph from Mathematica?.
â kglr
2 hours ago
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
g1 = Graph[1 <-> 2, 1 <-> 4,ÃÂ 1 <-> 7, 1 <-> 10, 1 <-> 12 , 2 <-> 3,
ÃÂ ÃÂ ÃÂ 2 <-> 4, 2 <-> 9, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 11,ÃÂ ÃÂ 5 <-> 12, 6 <-> 7,
ÃÂ ÃÂ ÃÂ 6 <-> 12, 7 <-> 8, 7 <-> 12, 8 <-> 10, 8 <-> 11, 9 <-> 10, ÃÂ 9 <-> 11, 10 <-> 11,
ÃÂ ÃÂ EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
ÃÂ ÃÂ ÃÂ ÃÂ 8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
ÃÂ ÃÂ VertexLabels -> Table[i -> Placed[i, Center], i, 12],
ÃÂ ÃÂ VertexLabelStyle -> Directive[White, Bold, 15],
VertexSize -> 1,
ÃÂ ÃÂ GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ "EdgeWeighted" -> True] ;
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
newedges = DirectedEdge @@@ Partition[path, 2, 1];
g2 = SetProperty[EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1],
VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges -> Orange]
Update: for multiple paths
path1 = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
path2 = 1, 7, 8, 7, 8, 7, 8, 10, 8, 10, 1, 10, 1, 10, 1;
newedges1 = DirectedEdge @@@ Partition[path1, 2, 1];
newedges2 = DirectedEdge @@@ Partition[path2, 2, 1];
g3 = SetProperty[EdgeAdd[g1, Join[newedges1, newedges2]],
VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges1 -> Orange, Alternatives @@ newedges2 -> Green]
g1 = Graph[1 <-> 2, 1 <-> 4,ÃÂ 1 <-> 7, 1 <-> 10, 1 <-> 12 , 2 <-> 3,
ÃÂ ÃÂ ÃÂ 2 <-> 4, 2 <-> 9, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 11,ÃÂ ÃÂ 5 <-> 12, 6 <-> 7,
ÃÂ ÃÂ ÃÂ 6 <-> 12, 7 <-> 8, 7 <-> 12, 8 <-> 10, 8 <-> 11, 9 <-> 10, ÃÂ 9 <-> 11, 10 <-> 11,
ÃÂ ÃÂ EdgeWeight -> 13, 17, 19, 19, 4, 18, 9, 2, 20, 5, 7, 20, 11, 4, 3,
ÃÂ ÃÂ ÃÂ ÃÂ 8, 18, 3, 10, 16, 14, 12, EdgeStyle -> Thick,
ÃÂ ÃÂ VertexLabels -> Table[i -> Placed[i, Center], i, 12],
ÃÂ ÃÂ VertexLabelStyle -> Directive[White, Bold, 15],
VertexSize -> 1,
ÃÂ ÃÂ GraphLayout -> "VertexLayout" -> "SpringElectricalEmbedding",
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ "EdgeWeighted" -> True] ;
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
newedges = DirectedEdge @@@ Partition[path, 2, 1];
g2 = SetProperty[EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1],
VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges -> Orange]
Update: for multiple paths
path1 = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1;
path2 = 1, 7, 8, 7, 8, 7, 8, 10, 8, 10, 1, 10, 1, 10, 1;
newedges1 = DirectedEdge @@@ Partition[path1, 2, 1];
newedges2 = DirectedEdge @@@ Partition[path2, 2, 1];
g3 = SetProperty[EdgeAdd[g1, Join[newedges1, newedges2]],
VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red,
EdgeStyle -> Alternatives @@ newedges1 -> Orange, Alternatives @@ newedges2 -> Green]
edited 3 hours ago
answered 3 hours ago
kglr
163k8188387
163k8188387
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs'sIGraph/M
useful: How can I conveniently call igraph from Mathematica?.
â kglr
2 hours ago
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
add a comment |Â
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs'sIGraph/M
useful: How can I conveniently call igraph from Mathematica?.
â kglr
2 hours ago
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
Apologies, another sub-question. With the (original) implementation above, I'm having the same question as the link below, where arcs between the same nodes are being considered the same and therefore are being formatted the same. i.e. the latter format definition is overwriting the prior. Ideas as to how to avoid this? mathematica.stackexchange.com/questions/91947/â¦
â Jordan MacLachlan
2 hours ago
1
1
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs's
IGraph/M
useful: How can I conveniently call igraph from Mathematica?.â kglr
2 hours ago
@JordanMacLachlan, that's a challenging issue with multiedges. See Graph: Coloring parallel edges individually. You might find Szabolcs's
IGraph/M
useful: How can I conveniently call igraph from Mathematica?.â kglr
2 hours ago
1
1
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
Thanks mate - appreciate it. After no success myself I've asked another question about this here for future reference: mathematica.stackexchange.com/questions/183086/â¦
â Jordan MacLachlan
29 mins ago
add a comment |Â
Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.
Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.
Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.
Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183066%2fadding-overlapping-non-weighted-directed-edges-to-a-weighted-undirected-graph%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
does this give something close to what you need:
path = 1, 2, 3, 4, 2, 4, 2, 1, 2, 1, 2, 1; newedges = DirectedEdge @@@ Partition[path, 2, 1]; g2 = SetProperty[ EdgeAdd[g1, newedges], VertexCoordinates -> GraphEmbedding[g1], VertexStyle -> 1 -> Red, EdgeStyle -> Alternatives @@ newedges -> Orange]
?â kglr
4 hours ago
Bang on. Thank you very much.
â Jordan MacLachlan
4 hours ago
Jordan, posted the comment as an answer.
â kglr
3 hours ago
Apologies, I believe this fails to stack multiple routes. For example, how could you add two different 'path' and 'newedges' to a single 'g2'? Either by way of passing a g2 to another g3 (which I've tried and doesn't seem to be working) or by manipulating the EdgeAdd method to accept more arguments?
â Jordan MacLachlan
3 hours ago
please see the update re multiple routes.
â kglr
3 hours ago