I used to use the path planning algorithm implemented by C # When I was idle. I posted it today to see if there is any better implementation solution. For more information about Path Planning (Shortest Path) algorithms, see C ++ algorithm-graph algorithm.
This graph algorithm describes a scenario where a graph consists of nodes and edges with directions. Each edge has a corresponding weight and Path Planning (Shortest Path) the algorithm is to find the path with the minimum cumulative weight from node A to Node B.
First, we can abstract the "directed Edge" into an Edge class:
Public class Edge
{
Public string StartNodeID;
Public string EndNodeID;
Public double Weight; // Weight, cost
}
A Node is abstracted as a Node class. A Node is hung with an "outbound" table starting from this Node.
Public class Node
{
Private string iD;
Private ArrayList edgeList; // Edge set -- Edge table
Public Node (string id)
{
This. iD = id;
This. edgeList = new ArrayList ();
}
Property # region property
Public string ID
{
Get
{
Return this. iD;
}
}
Public ArrayList EdgeList
{
Get
{
Return this. edgeList;
}
}
# Endregion
}
In the calculation process, we need to record the path that reaches the minimum weight of each node. This abstraction can be expressed using the PassedPath class:
/// <Summary>
/// PassedPath is used to cache the path with the minimum weight of a node during computing.
/// </Summary>
Public class PassedPath
{
Private string curNodeID;
Private bool beProcessed; // whether it has been processed
Private double weight; // the cumulative weight.
Private ArrayList passedIDList; // path
Public PassedPath (string ID)
{
This. curNodeID = ID;
This. weight =