0

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.

  • Are you using the CPLEX Python API or docplex? You mention the former in the title, but it's not clear from the rest of your question whether that is really the case or not. See https://stackoverflow.com/questions/54891266 for more on the difference. – rkersh Nov 26 '19 at 16:54
  • I am using the Python API, sorry for the confusion. – Phylosofazo M Nov 26 '19 at 20:10

1 Answers1

1

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)
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15