简体   繁体   English

树节点之间的路径,边之间的成本在遍历方向上有所不同

[英]Path beween tree nodes, cost between edges differs in direction of traversal

I have a shortest-path problem and not sure what the right approach would be. 我有一条最短路径的问题,不确定是否正确的方法。

Given a tree, I would like to find the path and the path cost between two nodes, where the cost differs depending on the direction of traversal. 给定一棵树,我想找到两个节点之间的路径和路径成本,其中成本根据遍历的方向而有所不同。

For example if A is a child node of B, A->B could have a cost of 3 and B->A has a cost of 4. 例如,如果A是B的子节点,则A-> B的成本为3,而B-> A的成本为4。

Is there a Java library where I can model this problem by setting up a graph with nodes and path costs in different directions as defined above, and have a way to get the path and path cost between two nodes? 是否存在一个Java库,可以通过设置一个图来对这个问题进行建模,该图的节点和路径成本如上所述,并且方向不同,并且有一种方法可以获取两个节点之间的路径和路径成本?

There is a single path between each pair of nodes in a tree. 树中每对节点之间只有一条路径。 Thus it doesn't really matter if prizes differ in the two directions - find the single path and then compute its prize in the two directions. 因此,奖品在两个方向上是否不同并不重要-找到单个路径,然后在两个方向上计算其奖赏。 Note that what you have is not a shortest path problem - you have a single path . 请注意,您拥有的并不是最短路径问题-您只有一条路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM