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