1

This is my sample network and idea of trying how to make a new routing instead of just the shortest path (the path i want to follow is via the pink arrows)

What am I missing here to make my predefined function work?

enter image description here

1 Answers1

0

Fixing the basics

As explained here, you can't instantiate a Java List, because it is an interface. You can however instantiate any implementing Class of a List, for example an ArrayList.

With this in mind your code will look like this:

List<Path> myPath = new ArrayList<Path>();

   myPath.add(path14);
   myPath.add(path8);
   myPath.add(path);
   myPath.add(path1);
   myPath.add(path4);
   myPath.add(path13);

return myPath;

So far for the basics.

Where to go from here

To get it to consider your actual source and destination for the route planning, define both as input parameters of type ILocation in the properties of the function.

Now comes the really tricky part: writing your own or importing a routing algorithm that can give you that list of paths automatically based on criteria that you define. This is however a topic too broad for this question. The basic steps will be:

  • Create a graph that represents your AnyLogic path network
  • Solve the graph routing problem with a solving algorithm (eg. Dijkstra Algorithm), using the graph, the startpoint and the endpoint
  • Convert the solution you get from the solver back again to an ArrayList that you can work with in AnyLogic

You can do these steps on your own, eg. by implementing the Dijkstra Algorithm yourself, or you import into AnyLogic one of the available graph solving Java packages like JUNG or Graphhopper. In this article I explain step by step how to do so with JUNG.

Florian
  • 962
  • 1
  • 5
  • 17