Kuifje02 / vrpy

A python framework for solving the VRP and its variants with column generation.
MIT License
179 stars 43 forks source link

How to implement piecewise linear costs? #94

Open prince4249 opened 3 years ago

prince4249 commented 3 years ago

I am currently working on a project where we want the cost of the first 'z' Km to be fixed and after that 'x' unit per km for each vehicle. How can we implement this in your library?

Kuifje02 commented 3 years ago

If z=0, you can use the fixed_cost argument : https://vrpy.readthedocs.io/en/latest/vrp_variants.html#fixed-costs.

prince4249 commented 3 years ago

ok but in my project z has some positive value. Is it not possible to implement it?

Kuifje02 commented 3 years ago

Unfortunately this is not possible generically. But you can obtain an approximation by computing the cost once you have the routes.

tomatoes-prog commented 3 years ago

What I do is to add the Fixed cost to every node between the Source and the node i.e for i in N: cost = c[0,i]+ fixed_cost G.add_edge("Source", str(i), time=t[0, i], cost=cost)

Kuifje02 commented 3 years ago

Yes, this is equivalent to using the fixed_cost argument. In fact this is exactly what is done : https://github.com/Kuifje02/vrpy/blob/fb9adea8d8f89f07e7074c4de3c56d7f05007243/vrpy/vrp.py#L929-L933

Kuifje02 commented 3 years ago

90