Adding overlapping non-weighted, directed edges to a weighted, undirected graph

The name of the pictureThe name of the pictureThe name of the pictureClash 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:



Small weighted graph example



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.










share|improve this question









New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 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














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:



Small weighted graph example



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.










share|improve this question









New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 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












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:



Small weighted graph example



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.










share|improve this question









New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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:



Small weighted graph example



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






share|improve this question









New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 4 hours ago









kglr

163k8188387




163k8188387






New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









Jordan MacLachlan

203




203




New contributor




Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Jordan MacLachlan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 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




    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










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]


enter image description here



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]


enter image description here






share|improve this answer






















  • 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's IGraph/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










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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]


enter image description here



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]


enter image description here






share|improve this answer






















  • 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's IGraph/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














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]


enter image description here



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]


enter image description here






share|improve this answer






















  • 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's IGraph/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












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]


enter image description here



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]


enter image description here






share|improve this answer














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]


enter image description here



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]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








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's IGraph/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






  • 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







  • 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










Jordan MacLachlan is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery