Reputation: 125
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
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!
Upvotes: 0
Views: 159
Reputation: 1636
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.
Upvotes: 1