Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: CostOfPath

  • To: mathgroup at
  • Subject: [mg62491] Re: [mg62481] CostOfPath
  • From: Andrzej Kozlowski <akoz at>
  • Date: Sat, 26 Nov 2005 02:46:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 25 Nov 2005, at 16:25, Bart De Vylder wrote:

> Can anybody explain the following?
> << DiscreteMath`Combinatorica`;
> gr = FromOrderedPairs[{{2, 1}}];
> CostOfPath[gr, {2, 1}]
> Out[]= ° (infinity)
> I would expect 1 as answer.

CostOfPath seems to give correct answers only for undirected graphs.  

gr = FromOrderedPairs[{{2, 1}},Type->Undirected];
CostOfPath[gr, {2, 1}]


It will give the same answer  in the case of a "bi-directed" graph, e.g.

hr = FromOrderedPairs[{{2, 1},{1,2}}];
CostOfPath[hr, {2, 1}]


It seems that edges with only one direction are counted as  
"impassable", and hence the answer Infinity.

I don't have my copy of Pemmaraju and Skiena book within reach (it is  
currently on a different continent and my reach is not that long ;-))  
so I can't guarantee that my explanation is completely correct, but I  
think it is not far off.

Andrzej Kozlowski

  • Prev by Date: Re: CostOfPath
  • Next by Date: Problem in Exporting Mathematica graphics What service do we have to run?
  • Previous by thread: Re: CostOfPath
  • Next by thread: SugarCube