Python Forum

Full Version: regarding lpvariable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
How do I write the code for a dependent decision variable for linear programming?

I want to minimize the cost.
and I wrote: Lp_prob = p.LpProblem('Problem', p.LpMinimize)

For example,
A factory can produce up to 10 products in a month.
so: njan = LpVariable("n", lowBound = 0, upBound = 10)

A factory has an additional cost for $100 if more than 5 products are produced. ($100 regardless of how much more)
I tried using
if n >= 5:
addjan = 100,
else:
addjan = 0
after my objective function, but it won't work

Is there anyway I can let the objective function considers the if statement for decision variables?
Thank you. Sorry for poor English.