Both VRP and Transportation Problem

Might take some time before somebody replies, and my answer might not be optimal since i am still learning jsprit.

There is something in jsprit called ‘statemanager’ that holds the state and updates it for each iteration that jsprit does.

So you can use various interfaces to intercept an action such as ‘visited location’

You have the SoftActivityConstraint interface and a state-manipulator class called ‘stateupdater’.

In stateupdate, you can update the goods being retrieved from a depot with their costs and then in softactivityconstraints calculate the ‘softscore’ of unloading of goods to another client.

So if the lowest price for apples is 1 dollar, and you unload 1 apple that originally costs 2 dollar, then you have to apply a positive softscore ( positive means bad score and negative good ) with the softactivityconstraints.

Now the tricky part is to know how much is each kilometer/time waited doing nothing in dollars for each vehicle, so you can match the costs. ie, a vehicle traveling 10 kilometers is not worth if it delivered 2 apples each worth 10 dollars less or soemthing of tha nature.

Here is an example of mine that you can inspire yourself and it is the latest version ( note that most examples on the internet dont work as they use an older version, so inspire yourself from my example to update the examples on the internet on latest version if you will. )

Here is another example you can learn how jsprit works geared for your situation

https://github.com/graphhopper/jsprit/blob/master/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/MultipleProductsWithLoadConstraintExample.java

Take a cup of coffee and understand these examples 100 per cent, once you do you will probably be able to figure out your problem.

1 Like