MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: CostOfPath


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



  • Prev by Date: International Mathematica Symposium 2006
  • Next by Date: Re: Re: Re: Package development
  • Previous by thread: CostOfPath
  • Next by thread: Re: CostOfPath