Greetings,
I'm trying to implement a model using the python cplex python module. My program has a number of constraints and the objective is to maximize w.r.t two parameters, revenue and priority.
My question is, how can I specify multiple objectives for my model? Currently I am doing this:
import docplex.mp.model as cpx
... specify a bunch of constraints ...
# objective 1:
revenues = []
for k in break_labels:
for i, nums in enumerate(snums):
for j in range(nums):
revenues.append(placed_ijk[i, j, k] * price[i])
revenue_sum = model.sum(revenues)
# objective 2:
priorities = []
for k in labels:
for i, nums in enumerate(snums):
for j in range(nums):
revenues.append(placed_ijk[i, j, k] * priority[i])
# maximize objective #1
objective = model.maximize(revenue_sum)
# solve
solution = model.solve()
Is there a way to optimize with respect to two objectives in cplex?
Answer by RyanKersh (296) | Jun 21 at 11:35 AM
You can use the set_multi_objective method to specify multiple objectives (requires CPLEX 12.9). There is an example of using this method here.
In your case, you might use something like the following:
model.set_multi_objective(
ObjectiveSense.Maximize,
[revenue_sum, priority_sum],
priorities=[2, 1])
Cplex docplex Python API: infeasible solution for 1millions variables 3 Answers
Ending a CPLEX solve via a callback using Python and `docplex` 3 Answers
IloIntervalVar which are part of IloIntervalSequenceVar 2 Answers
How to implement constraint relaxation in Docplex with the python API? 2 Answers
Docplex constraint causing unboundedness 2 Answers