C # Implementation Path planning (shortest path) algorithm

Source: Internet
Author: User

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
   }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.