Class Path
- Namespace
- OpenMEPSandbox.Graph
- Assembly
- OpenMEPSandbox.dll
public class Path
- Inheritance
-
Path
- Inherited Members
Methods
FindShortestPathBellman(int, int, List<int>, List<int>, List<int>)
Get shortest path and distance from start node to end node By Bellman-Ford algorithm
[MultiReturn(new string[] { "shortestPath", "distance" })]
public static Dictionary<string, object> FindShortestPathBellman(int startNode, int endNode, List<int> sources, List<int> destinations, List<int> weights)
Parameters
startNode
intfirst location of node
endNode
intend location of node
sources
List<int>A list of source vertices for each edge.
destinations
List<int>A list of destinations vertices for each edge.
weights
List<int>A list of weights for each edge.
Returns
- Dictionary<string, object>
the shortest path
Examples
Path.FindShortestPathBellman.dyn
Exceptions
FindShortestPathDijkstra(int, int, List<int>, List<int>, List<int>)
Finds the shortest path between two nodes in a graph using Dijkstra's algorithm. The graph is represented as a list of edges, where each edge is a triple (source, destination, weight). The startNode and endNode parameters specify the source and destination nodes, respectively. The sources, destinations, and weights parameters contain the lists of source nodes, destination nodes, and edge weights, respectively, that make up the graph. Returns an array of node IDs that form the shortest path from the start node to the end node. If no path exists, returns an empty array.
[MultiReturn(new string[] { "shortestPath", "distance" })]
public static Dictionary<string, object> FindShortestPathDijkstra(int startNode, int endNode, List<int> sources, List<int> destinations, List<int> weights)
Parameters
startNode
intThe ID of the start node.
endNode
intThe ID of the end node.
sources
List<int>The list of source nodes for each edge in the graph.
destinations
List<int>The list of destination nodes for each edge in the graph.
weights
List<int>The list of edge weights for each edge in the graph.
Returns
- Dictionary<string, object>
the shortest path
Examples
Path.FindShortestPathDijkstra.dyn
GetDistancesPathFromNode(int, List<int>, List<int>, List<int>)
Finds the shortest path from each source vertex to every other vertex in the graph using the Bellman-Ford algorithm,
and returns an array of tuples containing the distance and path to each vertex.
The v
and e
parameters specify the number of vertices and edges in the graph, respectively.
The sources
, targets
, and weights
lists define the source, destination, and weight of each edge, respectively.
[MultiReturn(new string[] { "path", "distance" })]
public static Dictionary<string, object> GetDistancesPathFromNode(int from, List<int> sources, List<int> destinations, List<int> weights)
Parameters
from
intvalue of node want start check
sources
List<int>A list of source vertices for each edge.
destinations
List<int>A list of target vertices for each edge.
weights
List<int>A list of weights for each edge.
Returns
- Dictionary<string, object>
An array of tuples, where each tuple contains the distance and path from a source vertex to every other vertex in the graph. If there is no path from a source to a destination vertex, or if there is a negative weight cycle in the graph, the distance for that tuple will be
double.MaxValue
and the path will be an empty array.