简体   繁体   中英

CPLEX Python API how to multiply a decision variable with a dummy in the objective function?

I am trying to add a multiplication of variables to the objective function. I have x_t which is an integer and I have a binary variable w_t_1. I want to have in the objective function -1200 * w_t_1 * x_t. How can I do it? I couldn't find anything in the IBM documentation.

let me give you a very simple example out of the zoo example

mdl.maximize(nbbus40*500*option1+nbbus30*400*option2 )

in

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')

mdl.parameters.optimalitytarget=3


mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')

mdl.minimize(nbbus40*500 + nbbus30*400)

mdl.solve()

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

print()
print("with more constraints")

option1=mdl.binary_var(name='option1')
option2=mdl.binary_var(name='option2')

mdl.add(nbbus40<=10)
mdl.add(nbbus30<=10)
mdl.add(option1==(nbbus40<=3))
mdl.add(option2==(nbbus40>=7))

mdl.add_constraint(option1+option2>=1)

mdl.maximize(nbbus40*500*option1+nbbus30*400*option2 )

mdl.solve()

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM