繁体   English   中英

具有邻接表图的Dijkstra算法

[英]Dijkstra's Algorithm with adjacency list graph

我有一个实现为邻接表的无向加权图。 有一个哈希图,其中Node对象为键,Edge对象列表为值。 这些Edge对象的权重包括两个节点之间的边缘的权重。

我正在尝试编写Dijkstra的最短路径算法; 但是我担心我的图形结构太复杂,无法理解我能为Dijkstra找到的所有示例/伪代码。 任何人都可以提供任何帮助。 提前致谢。

如何使用Boost Graph Library ,还有python绑定。 我认为Dijkstra最短路径是其示例之一。

对于Java,有很多可用的。 JGraphT简单又不错。 Jung,JTS等。如果您是自己实现的,那么我宁愿使用LinkedHashSet,例如:

public abstract class Graphs<T, E> 
{
final LinkedHashSet<Vertex<? extends T>> allVertex;
 ...

顶点将是:

/**
 * E is of the type: the kind of vertex I want to make. For example String

 */
 public interface Vertice<E>
  {
  public void setAttribute(E ob);
  public E getAttribute();
  //      public Set<Edge<?>> getConnectedVertices();
  public Set<Edge<?>> getConnectedEdges();       
  public Edge<?> getPassageToVertice(Vertice<?> vertice);
  }

边缘为:

package Graph;

   public interface Edge<E> 
   {

/**
 * Returns the attribute Associated with the Edge
 * @return The Attribute associated with the Edge
 */
public E getAttribute();

public void setSource(Vertex<?> source);

public void setDestination(Vertex<?> dest);

/**
 * Sets the attribute of the edge
 * @param attr Sets the attribute of the Edge
 */
void setAttribute(E attr);

/**
 * Get the permission to access the destination from the source.
 * <p> For example:    
 * <li>A-------edge---------B </li>
 * here A is a vertex
 *      B is a vertex
 *      edge is the edge.
 * If the argument of the method is vertex A then it returns Vertex B, if it is
 * legal to return (for ex will return B if the edge is intended to be Undirected)
 * This method can be used to create different types of Edge's.</p>
 * <p> In case of a directed edge
 * <li>A----->----edge------>B</li>
 * on calling getPassage(B) it will return null.
 * </p>
 * @param source One end of the edge
 * @return The other end of the edge if the edge has access to. Or else return null;
 */
public Vertex<?> getPassage(Vertex<?> source);

public Vertex<?> getSource();

public Vertex<?> getDestination();

}

暂无
暂无

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

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