Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to force a fixed number of vehicles #239

Closed
matthewrudy opened this issue May 17, 2016 · 9 comments
Closed

A way to force a fixed number of vehicles #239

matthewrudy opened this issue May 17, 2016 · 9 comments
Labels

Comments

@matthewrudy
Copy link

We are looking for a way to force the number of vehicles.

Namely, we have 20 waypoints, and 5 vehicles,
we want to optimise the routes to use all of the 5 vehicles.

I think given the existing library, the best way to do this is to have a negative fixed cost for each vehicle.

ie. it should increase the cost function to not use all vehicles.

But currently that function isn't supported,

if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero")

and forking the library to remove this line doesn't seem to work correctly.

(I guess negative fixedCosts are ignored somewhere internally?)

@oblonski
Copy link
Member

oblonski commented May 24, 2016

You need to redefine the objective function. It is a min-max problem where you want to reduce the overall makespan by employing all your available resources. Unfortunately, this is not open source yet. What you can try is to implement a two step approach. In the first step, you would try to reduce the operation time of your drivers so that you can just serve all your jobs. Given the max operation time of the drivers, you would redefine your problem incorporating this max time. Then you would minimize transport costs.

@matthewrudy
Copy link
Author

matthewrudy commented May 25, 2016

Thanks @oblonski we managed to hack it by doing the following

we add a massive negative fixed cost for each vehicle
(we had to fork the repo to allow this)

val vehicleType = VehicleTypeImpl.Builder.newInstance("vehicle")
  .setFixedCost(-1000000.0) //Workaround to force using all vehicles
  .setMaxVelocity(13.0) //~ 50km/h
  .build()

Then we make sure it uses the fixed cost

val algorithm = Jsprit.Builder.newInstance(problem)
  .setProperty(Jsprit.Parameter.FAST_REGRET, "true")
  .setProperty(Jsprit.Parameter.THREADS, "5")
  .setProperty(Jsprit.Parameter.FIXED_COST_PARAM, "1.") //Increase weight of the fixed cost to enable the force all vehicle workaround
  .buildAlgorithm()

@roganjoshp
Copy link

Hi @matthewrudy I am interested in this feature. I have made the changes you have suggested and removed the error. However, with 4 available vehicles and 23 jobs, it's only assigning two drivers. All vehicles start in the same location and could all carry the items. The route cost is correctly reflecting the disproportionate negative cost. Does this implementation really work for you consistently or is there something else going on to keep vehicle numbers down?

@roganjoshp
Copy link

roganjoshp commented Jun 9, 2016

Actually, it seems the setup of the algorithm is important. By ensuring there is regret in the Strategy, it will then use all of the vehicles as you suggested. It is hacky though and it shows; the extra two vehicles are simply grabbing one item each (closest to the warehouse) after which they become an unnecessary additional cost. I can't think of a reasonable way to define the problem to make them behave more naturally without fundamental changes to the objective function.

I suppose this could be because the warehouse in this case is not located centrally in the service catchment area, they're all heading in the same direction initially. Perhaps if you have something more evenly distributed then you get better solutions.

@matthewrudy
Copy link
Author

@mcrnotts it will depend on how the algorithm generates new solutions, yes.

Our business requirement is give the customer the exact number of vehicles they request
even if it would be more efficient and cheaper not to.

But... that's business requirements for you
:)

@PGWelch
Copy link
Contributor

PGWelch commented Jun 10, 2016

It may be more reliable to actually modify the insertion and ruin heuristics a bit. Assuming you want n vehicles, for the initial solution construction, randomly choose n jobs, assigning one per vehicle and then apply cheapest or regret based construction to assign all other jobs and finish building the first solution. For subsequent ruin-and-recreate iterations, use a modified ruin which leaves at least a single job in place on each route (where the job is randomly chosen each time).

This kind of strategy would force the algorithm to always use n vehicles, but still allow it to optimise them.

@atmikev
Copy link

atmikev commented Feb 21, 2017

Was this functionality ever added into the master branch?

@lfreneda
Copy link

lfreneda commented Mar 1, 2017

Same question: Was this functionality ever added into the master branch?

@nkaragiannis
Copy link

nkaragiannis commented Oct 27, 2021

It may be more reliable to actually modify the insertion and ruin heuristics a bit. Assuming you want n vehicles, for the initial solution construction, randomly choose n jobs, assigning one per vehicle and then apply cheapest or regret based construction to assign all other jobs and finish building the first solution. For subsequent ruin-and-recreate iterations, use a modified ruin which leaves at least a single job in place on each route (where the job is randomly chosen each time).

This kind of strategy would force the algorithm to always use n vehicles, but still allow it to optimise them.

Hi! Can you please help me to code the above strategy?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants