The EdgeWeight property states that the EdgeWeight can be any expression and the GraphDistance function states that in a weighted graph, it will return the minimum of the sum of the weights.

So if I do:

g = Graph[{ob1 \[DirectedEdge] ob2}];
PropertyValue[{g, ob1 \[DirectedEdge] ob2}, EdgeWeight] = 1/4 ;
GraphDistance[g, ob1, ob2]

I get 0.25 as expected, but

g = Graph[{ob1 \[DirectedEdge] ob2}];
PropertyValue[{g, ob1 \[DirectedEdge] ob2}, EdgeWeight] = I/4 ;
GraphDistance[g, ob1, ob2]

is returned unevaluated. The same thing happens if I try to use an edge weight containing a variable such as 'x'.

  • 1
    $\begingroup$ Can you explain how you define distance at all with complex numbers? For this function, the "distance" of two nodes is the smallest possible sum of weights along any path connecting the nodes. "Smallest" makes no sense with complex numbers. Neither is such a thing computable in a reasonably useful way if one of the weights is an unknown quantity (parameter). $\endgroup$ – Szabolcs Jul 19 '16 at 10:42
  • $\begingroup$ Even just having negative weights causes trouble because one can construct networks where moving around a cycle multiple times can accumulate an arbitrarily large negative total weights. $\endgroup$ – Szabolcs Jul 19 '16 at 10:43
  • $\begingroup$ Yeh ok that's a good point. I was hoping that since there were only two points in the example, that is there is a unique path, then it is by default the smallest and could be safely returned as the answer. $\endgroup$ – Se314en Jul 19 '16 at 10:45
  • $\begingroup$ It sounds like you are looking for the weight of a single edge, which is a different concept from the distance of two nodes. $\endgroup$ – Szabolcs Jul 19 '16 at 10:45
  • $\begingroup$ I was hoping to use a graph to store linear dependence relations for some vector space, so all paths would be of consistent length and I was really only wanting to use GraphDistance to find whether such a path existed. $\endgroup$ – Se314en Jul 19 '16 at 10:47

As pointed out by @Szabolcs in the comments to the question, I was trying to do something stupid. I figured I should write it up in case anyone else comes across this.

GraphDistance tries to find the minimal sum of weights of edges between two points for a weighted graph. Therefore it doesn't make sense to use complex weights, as mathematica will not be able to compare them to find the smallest. The same is obviously true for weights involving an unknown parameter.

I really only needed to know whether any such path existed (which I why I didn't think about the comparison problem) and would be better using the FindPath function, which will return a path I can then find the weights for:

g = Graph[{ob1 \[DirectedEdge] ob2}];
PropertyValue[{g, ob1 \[DirectedEdge] ob2}, EdgeWeight] = (I u)/4 ;
FindPath[g, ob1, ob2];
PropertyValue[{g, ob1 \[DirectedEdge] ob2}, EdgeWeight]

returns (I u)/4 as required.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.