-
Notifications
You must be signed in to change notification settings - Fork 15
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
Solution to find optimal number of vehicles (instead of given as input) #13
Comments
Currently, the number of vehicles need to be known from advance. The way this problem is solved in class VehicleKind(Enum):
KIND_A
KIND_B
KIND_C
# ...
@planning_entity
class Vehicle:
id: int
capacity: int
depot: Depot
kind: VehicleKind
customer_list: list[Customer]
def __init__(self, _id, kind, capacity, depot, customer_list=None):
self.id = _id
self.capacity = capacity
self.kind = kind
self.depot = depot
if customer_list is None:
self.customer_list = []
else:
self.customer_list = customer_list
@planning_list_variable(Customer, ['customer_range'])
def get_customer_list(self):
return self.customer_list
def set_customer_list(self, customer_list):
self.customer_list = customer_list
def get_cost(self):
if kind == KIND_A:
return calc_cost_a(...)
... Your def minimize_used_vehicles(constraint_factory):
return (
constraint_factory.for_each(Vehicle)
.filter(lambda vehicle: len(vehicle.customer_list) > 0)
.penalize('Minimize Used Vehicles', HardMediumSoftScore.ONE_MEDIUM)
) |
Thanks @Christopher-Chianelli - that was fast! I will try these suggestions and post back here. |
Hi again @Christopher-Chianelli -
And regarding the
where/how exactly do I call this function? I thought it would be called in the filter inside Thanks again |
You call the def total_cost(constraint_factory: ConstraintFactory):
return constraint_factory.for_each(Vehicle) \
.penalize("minimize cost", HardMediumSoftScore.ONE_SOFT,
lambda vehicle: vehicle.get_cost()) |
Thanks @Christopher-Chianelli - made it run, and seems to work! One more question regarding the cost functions Should these values be normalized? For instance, demands are in Kg and distance in meters, but the Sorry about these newby questions - trying to learn how to use this library. |
|
Understood thanks - testing out various combinations here. However, this
does not seems to influence the results - no matter how high (or low) I set the cost for a particular "kind" of vehicle. Any pointers on how I can debug this? Thanks again @Christopher-Chianelli |
Did you add it in the @constraint_provider
def vehicle_routing_constraints(constraint_factory: ConstraintFactory):
return [
vehicle_capacity(constraint_factory),
total_distance(constraint_factory),
total_cost(constraint_factory) # this line was added
] |
Yes I did |
Hello!
I have successfully ran the vehicle routing example. But my question is:
Is it possible to model the problem such as that the number of vehicles is not given as input?
Imagine that I need to find the optimal number of vehicles that minimizes a cost function that is related to "price per km" - so for instance, there are several types of vehicles (with different capacities, different fuel consumptions, etc) that can be "grabbed" from a pool.
Is this possible with
optapy
? If so, how would I model this?Thanks in advance!
The text was updated successfully, but these errors were encountered: