Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regarding lpvariable
#1
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020