简体   繁体   中英

QuickGraph - How can I make A* to skip particular edges?

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 use double.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. The double type has an IsPositiveInfinity method to test.

So, try setting the impassible weight to infinity and test the final path length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM