Problem formulation for to satisfy the demand for a list of products
AnsweredI would like to introduce a penalty connected with the number of parcels sent from one location to another.
Something like:
- if the number of parcels sent is < 15 then the penalty is 0
- [15, 20) penalty is 10
- [20, 30) penalty is 50
- [30, infinity) penalty is 1000000
I have a variable the counts number of packages sent from one location to another count_parcels[(loc_from, loc_to)] how to create the penalty?
-
Official comment
You can use the method model.setPWLObj(), so I suggest to read the associated documentation, as well as the section Objectives of our reference manual.
-
Ok, and what if I want it to be a part of a variable?
something like this codefor loc_a in locations:
for loc_b in locations:
if loc_a != loc_b:
m.addConstr(total_value[loc_a, loc_b] == quicksum(x[loc_a, loc_b, p]*price[p] for p in products))
if total_value[loc_a, loc_b] < 1500 and total_value[loc_a, loc_b] > 1000:
m.addConstr(value_penalty[loc_a, loc_b] = 1500 - total_value[loc_a, loc_b])
else:
m.addConstr(value_penalty[loc_a, loc_b] = 2*(1500 - total_value[loc_a, loc_b]))0 -
And then I want to sum-up all the penalties and add it to a objective function.
0 -
Hi Krzysztof,
I would suggest that you proceed in the way suggested by Juan.
Perhaps the following code snippet will be an inspiration for you:
for loc_a in locations:
for loc_b in locations:
if loc_a != loc_b:
m.setPWLObj(total_value[loc_a, loc_b], [0, 15, 20, 30], [0, 10, 50, 1000000])It should generally do everything you are after: define a piecewise-linear penalty for your variables and include them in your objective function.
Hope this helps.
Best regards
Jonasz0
Please sign in to leave a comment.
Comments
4 comments