Re: CostOfPath

• To: mathgroup at smc.vnet.net
• Subject: [mg62651] Re: [mg62481] CostOfPath
• From: <bsyehuda at gmail.com>
• Date: Wed, 30 Nov 2005 00:07:06 -0500 (EST)
• References: <200511250725.CAA18026@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Bart,
I decided to fix it for you
you may use this code (put it in the Combinatorica.m file) to replace the
original buggy implementation.

enjoy
yehuda

CostOfPath[g_Graph, p_List] :=
Block[{w = GetEdgeWeights[g],
pos = Map[Position[Edges[g], #]&,
If[EdgeDirection /. Options[g],
Partition[p,2,1],Map[Sort, Partition[p, 2,
1]]]
]
},
If[MemberQ[pos, {}],
Infinity,
Apply[Plus, w[[ Map[#[[1, 1]]&, pos] ]]
]
]
]

On 11/25/05, Bart De Vylder <bart.de.vylder at pandora.be> wrote:
>
> I run Windows XP and Mathematica 5.2 (student version).
>
> Can anybody explain the following?
>
> << DiscreteMath`Combinatorica`;
> gr = FromOrderedPairs[{{2, 1}}];
> CostOfPath[gr, {2, 1}]
>
> Out[]= ∞ (infinity)
>
> I would expect 1 as answer.
>
> Thanks,
> Bart
>
>
>

```

• References:
• CostOfPath
• From: "Bart De Vylder" <bart.de.vylder@pandora.be>
• Prev by Date: International Mathematica Symposium 2006
• Next by Date: Re: Re: Re: Package development
• Previous by thread: CostOfPath
• Next by thread: Re: CostOfPath