I am having objective function with pre-decided objective value, but want to know the values of decision variable for that objective function.
from pulp import LpMaximize, LpProblem, LpStatus, lpSum, LpVariable, LpConstraint
constraints =['0 <= X1<= 150',
'0 <= X2= 1453',
'0 <= X3<= 12',
'0 <= X4<= 149',
,'X1+X2 <= 14'
,'X3+X4 <=1'
,'X1+ X3 <= 6'
,'X2 +X4 <= 9']
for i in range(4):
t = f'X{i+1} = LpVariable('X{i+1}' , cat= \'Integer\')'
exec(t)
model = LpProblem(name = "test" , sense = LpMaximize )
for i in range(0, len(constraints)):
model += (eval(constraints[i]), 'constraint'+str(i))
#objective function
model += lpsum([eval('X1+X2+X3+X4')]
status = model.solve()
for var in model.varibles():
print(f"{var.name}: {var.value()}")
The expected output : X1=6,X2=8,X3=0,X4=1 but getting output X1= -6,X2=20,X3=12,X4= -11, even though I have added the range constraint for decision variable.
can anybody help me on this , how can I get the expected output where variable values should not be negative.