Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Anylogic: How to add the choice of route and time of day (based on route costs)?

In my Anylogic model I added a Java class MyRoute and a function that reads route costs from a database:

GISRoute route = main.map.getRoute(
(double) selectFrom(odcosts)
    .where(odcosts.origin.eq(order.terminal.name))
    .uniqueResult(odcosts.latitudeorigin),
(double) selectFrom(odcosts)
    .where(odcosts.origin.eq(order.terminal.name))
    .uniqueResult(odcosts.longitudeorigin),
(double) selectFrom(odcosts)
    .where(odcosts.destination.eq(order.customer.name))
    .uniqueResult(odcosts.latitudedestination),
(double) selectFrom(odcosts)
    .where(odcosts.destination.eq(order.customer.name))
    .uniqueResult(odcosts.longitudedestination), true);
MyRoute myRoute = new MyRoute();
myRoute.route = route;
myRoute.cost = (double) selectFrom(odcosts)
    .where(odcosts.origin.eq(order.terminal.name))
    .where(odcosts.destination.eq(order.customer.name))
    .uniqueResult(odcosts.cost);

How can I now add the choice of trucks (when they receive an order) to use:

A) Direct route between origin and destination at day time

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

B) Route via hub (origin -> hub at night & hub -> destination at day time)

How do I tell the truck agent population to look at the routes and the costs and make the decision?

Thanks a lot in advance!

>Solution :

I usually write this information into 1D or 2D Arraylists, depending on the dimension of the input information:
ArrayList<ArrayList<Float>> routes=new ArrayList<ArrayList<Float>>();.
You can remove the lanes that do not meet certain criteria like this:
routes.removeIf(s -> s.get(0) != "myCustomer");

Then iterate through the OD information and add the cost of each into an arrayList.

List <Float> costs=new ArrayList<Float>();
for (int route_no=0;route_no<routes.size();route_no++) {
            cost=routes.get(route_no);
            costs.add(cost);    
            }

Then finding the index of the minimum cost like this:

        int indexMin=0;

        for (int i2=0; i2<costs.size(); ++i2) {
            if (min > costs.get(i2)) {
                    min = costs.get(i2);
                    indexMin = i2;
                        }
                }

Now you know that the cheapest option’s index is indexMin. Then you can do whatever you want with this information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading