Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: GraphPath With Edge Weights
Replies: 2   Last Post: May 30, 2012 4:11 AM

 Messages: [ Previous | Next ]
 Ralph Dratman Posts: 62 Registered: 5/13/11
Re: GraphPath With Edge Weights
Posted: May 30, 2012 4:11 AM

Dana, do you mean, you hope Wolfram consolidates the graph-handling
routines? If so, I sure agree. Many routines don't seem to work
properly, and bringing in Combinatorica has been catastrophic every
time I've tried it.

Ralph

On Tue, May 29, 2012 at 5:45 AM, Dana DeLouis <dana01@me.com> wrote:
> = = = = = = = = = =
> I hope they consolidate Graphics in the next release
> HTH :>)
> Dana DeLouis
> Mac & Math 8
> = = = = = = = = = =

>> . . if I compute GraphPath[graph, 1, 3] it returns
>> the unweighted shortest path {1, 3}.

>
> My opinion is that graphics are so confusing now with multiple overlaps between packages, Combinatorica, and new built in functions in version 8.
>
> The use of WeightedAdjacencyMatrix appears to solve this problem.
> Not sure if it's the best solution.
>
> Needs["GraphUtilities`"]
>
> graph=Graph[{UndirectedEdge[1,2],UndirectedEdge[2,3],UndirectedEdge[3,1]},EdgeWeight->{1,2,9}];
>
> GraphDistance[graph,1,3]
> 3.
>
> GraphPath[graph,1,3]
> {1,3}
>
> // Workaround:
>
> {1,2,3}
>
> Here is a slightly larger graph (4 points)
>
> // Setup:
>
> g=CompleteGraph[4];
>
> // Graph
>
> g=CompleteGraph[4,
> Rule[VertexShapeFunction,List["Name"]],
> EdgeWeight->wgts,
> EdgeLabels->wgts,
> EdgeLabelStyle->Directive[Blue,Italic,20]
> ]
>
> GraphDistance[g,2,4]
> 4.
>
> {2,1,4}
>
> {2,1,3}
>
> {3,1,4}
>
> = = = = = = = = = =
> I hope they consolidate Graphics in the next release
> HTH :>)
> Dana DeLouis
> Mac & Math 8
> = = = = = = = = = =
>
>
>
>
> On May 28, 5:14 am, Ben <ben...@gmail.com> wrote:

>> I can't figure out how to compute a shortest path using GraphPath with
>> edge weights. I first define a graph as follows.
>>
>> graph = Graph[{UndirectedEdge[1,2], UndirectedEdge[2,3],
>> UndirectedEdge[3,1]}, EdgeWeight->{1, 2, 9}]
>>
>> it correctly returns the shortest path distance of 3 corresponding to
>> the path {1, 2, 3}. But if I compute GraphPath[graph, 1, 3] it
>> returns the unweighted shortest path {1, 3}. Even if I use
>> GraphPath[graph, 1, 3, Weighted->True] it still returns the same
>> answer of {1, 3}. (Weighted is supposed be True by default anyway.)
>> What am I doing wrong?
>>
>> Thanks.

>
>
>

Date Subject Author
5/30/12 Ralph Dratman
5/30/12 Ralph Dratman