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

How to implement piecewise linear costs? #94

Open
prince4249 opened this issue Jun 1, 2021 · 6 comments
Open

How to implement piecewise linear costs? #94

prince4249 opened this issue Jun 1, 2021 · 6 comments

Comments

@prince4249
Copy link

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
Copy link
Owner

Kuifje02 commented Jun 1, 2021

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

@prince4249
Copy link
Author

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

@Kuifje02
Copy link
Owner

Kuifje02 commented Jun 1, 2021

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

@tomatoes-prog
Copy link

tomatoes-prog commented Jun 3, 2021

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
Copy link
Owner

Kuifje02 commented Jun 3, 2021

Yes, this is equivalent to using the fixed_cost argument. In fact this is exactly what is done :

vrpy/vrpy/vrp.py

Lines 929 to 933 in fb9adea

def _add_fixed_costs(self):
"""Adds fixed cost on each outgoing edge from Source."""
for v in self.G.successors("Source"):
for k in range(self._vehicle_types):
self.G.edges["Source", v]["cost"][k] += self.fixed_cost[k]

@Kuifje02 Kuifje02 changed the title How to Implement fixed cost + variable cost for each vehicle? How to implement piecewise linear costs? Jun 5, 2021
@Kuifje02
Copy link
Owner

Kuifje02 commented Jun 5, 2021

#90

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

No branches or pull requests

3 participants