-1

I calculated a machine scheduling problem using docplex in python. I obtained one of the decision variable as:

yib solution
y_0_1 1
y_1_2 1
y_2_1 1
y_3_1 1
y_4_1 1

Since I wanted to use this values in another calculation I used this code:

ySol = [y[i,b].solution_value for i in range(0,J) for b in range(1,B)]

Then, I tried to use ySol in my constraints.

***my first question is, this code is true code to take the decision variable?

after I added ySol in the second calculation I took this error:

"TypeError: list indices must be integers or slices, not tuple"

I tried some alternative ways but I've not solved the tuple problem yet.

***my second question is, how can I solve this error?

thank you in advance!

Melissa
  • 9
  • 3

1 Answers1

0

you can either use warmstart

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)

warmstart=mdl.new_solution()
warmstart.add_var_value(nbbus40,8)
warmstart.add_var_value(nbbus30,0)
mdl.add_mip_start(warmstart)


sol=mdl.solve(log_output=True)

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

or fixed start

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)

#Fixed start nbBus40 should be 5
nbbus40.lb=5
nbbus40.ub=5

mdl.solve()


for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you for your reply. You took the integer values. Is it same for binary variables too? I turned it to "for v in mdl.iter_binary_vars(): print(v," = ",v.solution_value)" but it isn't work. What is your suggestion? (for a little reminder, I added my codes in question section after your reply) – Melissa Feb 25 '22 at 11:56