# Can mathematica's GraphDistance handle complex weights? Or unknown parameters eg. 'x'?

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'.

• 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). Jul 19, 2016 at 10:42
• 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. Jul 19, 2016 at 10:43
• 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. Jul 19, 2016 at 10:45
• It sounds like you are looking for the weight of a single edge, which is a different concept from the distance of two nodes. Jul 19, 2016 at 10:45
• 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. Jul 19, 2016 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.