In here I couldn't get calculations of y1,y2 and y3 when I try my code y1,y2 and y3 was not calculated. how can I fix this
from pulp import *
model = LpProblem("LineBalancing",LpMinimize)
x11 = LpVariable('x11', lowBound = 0, upBound = 1, cat = 'Integer')
x12 = LpVariable('x12', lowBound = 0, upBound = 1, cat = 'Integer')
x13 = LpVariable('x13', lowBound = 0, upBound = 1, cat = 'Integer')
x21 = LpVariable('x21', lowBound = 0, upBound = 1, cat = 'Integer')
x22 = LpVariable('x22', lowBound = 0, upBound = 1, cat = 'Integer')
x23 = LpVariable('x23', lowBound = 0, upBound = 1, cat = 'Integer')
x31 = LpVariable('x31', lowBound = 0, upBound = 1, cat = 'Integer')
x32 = LpVariable('x32', lowBound = 0, upBound = 1, cat = 'Integer')
x33 = LpVariable('x33', lowBound = 0, upBound = 1, cat = 'Integer')
x41 = LpVariable('x41', lowBound = 0, upBound = 1, cat = 'Integer')
x42 = LpVariable('x42', lowBound = 0, upBound = 1, cat = 'Integer')
x43 = LpVariable('x43', lowBound = 0, upBound = 1, cat = 'Integer')
x51 = LpVariable('x51', lowBound = 0, upBound = 1, cat = 'Integer')
x52 = LpVariable('x52', lowBound = 0, upBound = 1, cat = 'Integer')
x53 = LpVariable('x53', lowBound = 0, upBound = 1, cat = 'Integer')
x61 = LpVariable('x61', lowBound = 0, upBound = 1, cat = 'Integer')
x62 = LpVariable('x62', lowBound = 0, upBound = 1, cat = 'Integer')
x63 = LpVariable('x63', lowBound = 0, upBound = 1, cat = 'Integer')
Z = LpVariable('Z', lowBound = 0, upBound = None, cat = 'Integer')
t1 = 20
t2 = 15
t3 = 35
t4 = 55
t5 = 40
t6 = 5
y1 = (x11 * t1) + (x21 * t2) + (x31 * t3) + (x41 * t4) + (x51 * t5) + (x61 * t6)
y2 = (x12 * t1) + (x22 * t2) + (x32 * t3) + (x42 * t4) + (x52 * t5) + (x62 * t6)
y3 = (x13 * t1) + (x23 * t2) + (x33 * t3) + (x43 * t4) + (x53 * t5) + (x63 * t6)
model += Z
model += 1 <= x11 + x12 + x13 <= 1
model += 1 <= x21 + x22 + x23 <= 1
model += 1 <= x31 + x32 + x33 <= 1
model += 1 <= x41 + x42 + x43 <= 1
model += 1 <= x51 + x52 + x53 <= 1
model += 1 <= x61 + x62 + x63 <= 1
model += x11 >= x41
model += x11 + x12 >= x41 + x42
model += x11 + x12 + x13 >= x41 + x42 + x43
model += Z >= y1
model += Z >= y2
model += Z >= y3
status = model.solve()
print(f"minumum hat süresi {Z.varValue}")
print(status)
print(y1)
print(LpStatus[status])
print(f"minumum hat süresi {Z.varValue}")
----------When I try this code I will get this output(I paste it shortly).-----------------
minumum hat süresi 0.0 1 20x11 + 15x21 + 35x31 + 55x41 + 40x51 + 5x61 Optimal minumum hat süresi 0.0
so, I printed the y1 and it gives me this (20x11 + 15x21 + 35x31 + 55x41 + 40x51 + 5x61). I must be get some integer value to minimize my Z.
Try this:
Output:
Notes
In your model, you define the following constraints, like so:
A constraint like
1 <= f(x) <= 1is the same thing asf(x) == 1. When you set these constraints the way you did, they translate to the following equation:x11 + x12 + x13 - 1 <= 0->x11 + x12 + x13 <= 1This means that the sum of x11, x12 and x13 can be either 0 or 1. Since you're defining a minimization problem, the values of x11, x12 and x13 that return the smallest value possible, is when all of them equal 0.
When you define the constraint as
model += x11 + x12 + x13 == 1instead, PuLP defines the constraint as:x11 + x12 + x13 - 1 == 0->x11 + x12 + x13 == 1Therefore it forces one of x11, x12 or x13 to be equal to 1 and the rest equal to 0.