Previously idle time with C # implementation of the path planning algorithm, today posted it out to see if we have a better implementation of the scheme. About the path planning (shortest path) algorithm background knowledge, we can refer to the "C + + algorithm-graph algorithm," a book.
The graph algorithm describes this scenario: the graph is composed of nodes and directional edges, each side has corresponding weights, and path planning (shortest path) algorithm is to find the path from Node A to Node B with the least cumulative weights.
First, we can abstract the "forward edge" to the Edge class:
Code
[Copy to Clipboard]
CODE:
public class Edge
{
public string StartNodeID ;
public string EndNodeID ;
public double Weight ; //权值,代价
}
Nodes are abstracted into node classes, and a node is hung with an "out side" table with this node as its starting point.
Code
[Copy to Clipboard]
CODE:
public class Node
{
private string iD ;
private ArrayList edgeList ;//Edge的集合--出边表
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
}