Integer Programming (Section 5) Introduces a Nice (Big "em") Coding Trick
You have a decision variable that can take a range of natural number values - including 0.
It's the number of items you decide to produce. You want to maximize profit.
The catch is, there a fixed cost associated with the decision to produce an item at all. If you make 0 of it and make that decision, then you don't rent the machinery for it. Else, add a fixed cost.
How do you add this to your constraints and your objective (cost) function that you're trying to maximize?
Z = whatever + sum( Fi * yi)
And then, xi <= M*yi where M is just some large number - this introduces the coupling between x and y that you'd otherwise only get with an if statement..
Really?
y is (0,1) whole - only two possible values. What you are trying to do is ensure the optimizer doesn't set y to 0 by introducing the coupling. Now, with a non-zero xi, yi has to be 1.
Choosing Mi? Pick the largest value xi can attain - given the known parameter values.
here, we starting using domain = pyo.Integers, bounds = (0.M[i]) in the pyo.Var (later he removes the bounds..)
And y? domain = pyo.Binary
Use cplex_direct, not plain cplex. (Why? no clue)
Comments
Post a Comment