C # Path Planning (Shortest Path) Algorithm

Source: Internet
Author: User

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 =
Related Article

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.