I conduct a path finding library. QuickGraph, open graph library, fits all my requirements but I have met one problem. I need the shortest path algorithms to skip edges which are impassable by the current moving agent. What I want is something like this:
Func<SEquatableEdge<VectorD3>, double> cityDistances = delegate(SEquatableEdge<VectorD3> edge)
{
if(edge.IsPassableBy(agent))
return edgeWeight; // Edge is passable, return its weight
else
return -1; // Edge is impassable, return -1, which means, that path finder should skip it
};
Func<VectorD3, double> heuristic = ...;
TryFunc<VectorD3, IEnumerable<SEquatableEdge<VectorD3>>> tryGetPath = graph2.ShortestPathsAStar(cityDistances, heuristic, sourceCity);
I could imagine solving this problem by creating a copy of graph and deleting the impassable edges, but it is unnecessary waste of computer's resources. Could one, please, hint me on how to solve this problem? Or is there no solution and I should update the source?
Given your weights are of
double
type, you should be able to usedouble.PositiveInfinity
for the weight of an impassible edge.As Eric Lippert says, the failure case of a high weight is a complete path, however any addition or subtraction from
double.PositiveInfinity
should still be infinity. Thedouble
type has anIsPositiveInfinity
method to test.So, try setting the impassible weight to infinity and test the final path length.