Search code examples
anylogic

Differentiate Rail routes that exist and not found in anylogic


I'm trying to simulate routes from the retailer to the customer in the US in Anylogic and wanted to know what routes could be done by rail. But, if a rail route does not exist I get an error, and the simulation stops. I want the simulation to run and if the route does not exist, it saves in a variable (like a boolean variable, if the route exists it's true and if not is false). Thanks for the help!


Solution

  • You should have a map object that has the road type set to rail and one that has the road type set to rail

    enter image description here

    Then with some simple code, you can check if there is a rail that exists and if not do something else.

    
    try {
        GISRoute route = map.getRoute(fromLatitude, fromLongitude, toLatitude, 
        toLatitude);
    } catch (Exception e) {
        traceln("Error - no route found - from " + fromLatitude) + ", " + 
        fromLongitude + " to " + toLatitude + ", " + toLongitude);
        traceln("Exception " + e);
        // Maybe look for a road route?
     }