Please refer to the dummy network created using networkX.
I have created a dummy network of 50 nodes (incomplete graph) in Python using the networkX package. The dummy network of nodes is represented by the above diagrams diagrams.
I have randomly chosen Nodes AJ, A, G, R as vehicle starting points/depots.
I have randomly chosen F, AQ, AA as the dumping zones.
Each edge has certain weights, which is a representation of the amount of waste a vehicle can collect from that node.
Each depot has fixed number of vehicles, and each vehicle have a fixed carrying capacity, beyond which it will dump the waste to the nearest dumping zone. After dumping the waste, the vehicle can return to the original start depot (if there's no more waste left to clean)
Here the fixed conditions are as follow:
- Network is fixed.
- Depot & Dumping zone locations are fixed.
- Number of vehicle in each dumping zone is fixed.
- Carrying capacity of each vehicle is fixed for now.
- Edge weight represents the amount/volume of waste present in a edge.
How to build this solution using OptaPy ?
EDIT:
Let's stay, a vehicle starts from Node R. Based on the waste accumulation, let's say it traverses this path -- R - Q - O - N - L - K - J. Let's say that at Node J, the vehicle capacity will max out, then it should check from J which is the nearest dumping zone. The vehicle will see that F is the nearest dumping zone, so it will go to F, dump the waste and re-start it's operation from F. Let's say from F, the vehicle takes another path -- F - G - U - V - W - X. Let's say that the same vehicles capacity is maxed out at X. Then it will see that the nearest dumping zone from Z is AA, hence it will go there and dump the waste. Now if there's no longer waste left to be cleaned, the vehicle can get back to its starting position which is R.


I would model the problem as below using OptaPy:
@problem_factwith graph_nodes ids (assuming str) and weight fields:@planning_entityis a vehicle, with a fixed depot and carrying capacity, and a@planning_list_variableofEdge:@problem_fact, which can be used to query dumping zones and get the full network:@planning_solutionwould store the NetworkInfo, Edge, Vehicle and the solution's score:You would create the initial planning problem like this:
You would put your constraints into a
@constraint_providerfunction:for example,
over_capacitywould be written like this:My guess is you also want to minimize distance. I will assume the distance function = shortest path between edges as given by networkx:
(note: this does not take into consideration the "Number of vehicle in each dumping zone is fixed." constraint. If you want the dumping zone to be a planning variable, you currently need to use a chained model (https://www.optapy.org/docs/latest/planner-configuration/planner-configuration.html#chainedPlanningVariable) until https://issues.redhat.com/browse/PLANNER-2755 is fixed). If you are doing overconstrained planning (i.e. not enough vehicles to pick up all the garbage in one run), you can change the score type to
HardMediumSoftScore, and add a new field to vehicleis_extra. If the fieldis_extrais True, the vehicle is ignored by theover_capacityandminimize_distanceconstraints, and you'll add a new constraint that penalize byHardMediumSoftScore.ONE_MEDIUMfor each edge in the extra vehicle's visited_edge_list.