gallandarakhneorg / afc

Arakhnê Foundation Classes
http://www.arakhne.org/afc/
Apache License 2.0
14 stars 8 forks source link

Error with function "solve" of RoadAStar #175

Closed beta-ray70 closed 6 years ago

beta-ray70 commented 6 years ago

When we call the function "solve" with two RoadConnection, we have this runtime error :

"java.lang.AssertionError at org.arakhne.afc.gis.road.path.astar.RoadAStar.translateCandidate(RoadAStar.java:201) at org.arakhne.afc.gis.road.path.astar.RoadAStar.translateCandidate(RoadAStar.java:1) at org.arakhne.afc.math.graph.astar.AStar.findPath(AStar.java:521) at org.arakhne.afc.math.graph.astar.AStar.solve(AStar.java:439) at org.arakhne.afc.math.graph.astar.AStar.solve(AStar.java:416) at ia51.project.trafficsimulation.agents.Environment.findPath(Environment.java:244) at ia51.project.trafficsimulation.agents.Environment.spawnCars(Environment.java:197) at ia51.project.trafficsimulation.agents.Environment.$behaviorUnit$Initialize$0(Environment.java:93) at ia51.project.trafficsimulation.agents.Environment.lambda$0(Environment.java:299) at io.janusproject.kernel.bic.internaleventdispatching.AgentInternalEventsDispatcher$1.run(AgentInternalEventsDispatcher.java:295) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)"

The code that causes this issue is :

def findPath(startingPoint : RoadConnection, goalPoint : RoadConnection): RoadPath{
        if (startingPoint != goalPoint) {
            var heuristic = new AStarHeuristic<RoadConnection>() {

                def evaluate(p1 : RoadConnection, p2 : RoadConnection) : double {
                    if (p1.isReallyCulDeSac() && p1 != p2) {
                        return Double.MAX_VALUE;
                    } else {
                        var point1 = p1.getPoint();
                        var point2 = p2.getPoint();
                        return Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2));
                    }
                }
            }

            var aStar = new RoadAStar(heuristic);
            return aStar.solve(startingPoint, goalPoint);   
        }
        return null;
    }
gallandarakhneorg commented 6 years ago

The Road A* utility is designed for finding a path from a segment to another segment, not from a connection to another connection. It is more close to the needs of the agents: find a sequence of segments.

I would recommend you to consider to call the other solve functions, which are written for the previously explained purpose.

Nevertheless, I will update the code of the API in order to let you find a path between two connections.

beta-ray70 commented 6 years ago

Hello,

Can you tell me the "solve" function that use the RoadSegment ? I only see "solve" function that use RoadConnection or Point2D<?,?>.

Thanks in advance,

Julien Barbier

gallandarakhneorg commented 6 years ago

The other solve functions takes a 2D position as input. There is no solve function that takes a segment as input. Nevertheless, commit bd22152 contains a patch for solve(RoadConnection, RoadConnection). It should be available on the Maven server.