1

I'm fairly new to this, so I'm just going to shoot and hope I'm as precise as possible and you'll think it warrants an answer.

I'm trying to optimize (minimize) a cost/quantity model, where both are continuous variables. Global cost should be minimized, but is dependent on total quantity, which is dependent on specific cost.

My code looks like this so far:

# create model
m = Model('Szenario1')

# create variables 
X_WP = {}
X_IWP = {}

P_WP = {}
P_IWP = {}

for year in df1.index:
    X_WP[year] = m.addVar(vtype=GRB.CONTINUOUS, name="Wärmepumpe%d" % year)
    X_IWP[year] = m.addVar(vtype=GRB.CONTINUOUS, name="Industrielle Wärmepumpe%d" % year)

    #Price in year i =  Base.price * ((Sum of newly installed capacity + sum of historical capacity)^(math.log(LearningRate)/math.log(2)))
    P_WP[year] = P_WP0 * (quicksum(X_WP[year] for year in df1.index) ** (learning_factor)
    P_IWP[year] = m.addVar(vtype=GRB.CONTINUOUS, name="Preis Industrielle Wärmepumpe%d" % year)

X_WP[2016] = 0
X_IWP[2016] = 0

# Constraints and Objectives 
for year in df1.index:
    m.addConstr((X_WP[year]*VLST_WP+X_IWP[year]*VLST_IWP == Wärmemenge[year]), name="Demand(%d)" % year)
    obj = quicksum(
    ((X_WP[year]-X_WP[year-1])*P_WP[year]+X_WP[year]*Strompreis_WP*VLST_WP)+
    ((X_IWP[year]-X_IWP[year-])*P_IWP[year]+X_IWP[year]*Strompreis_EHK*VLST_IWP)
    for year in Wärmemenge.index)

 m.setObjective(obj, GRB.MINIMIZE)
 m.update()
 m.optimize()

X is quantity and P is price. WP and IWP are two different technologies (more will be added later). Since X and P are multiplied the problem is nonlinear, now I haven't found a solution so far as to feed gurobi an objective, that it can handle.

My research online and on stackoverflow basically let me to the conclusion that I can either linearize and solve with gurobi, find another solver that can solve this MINLP or formulate my objective in a way that Gurobi can solve. Since I've already made myself familiar with Gurobi, that would be my prefered choice.

Any advice on what's best at this point? Would be highly appreciated!

Takko
  • 11
  • 3

1 Answers1

-1

I'd suggest rewriting your Python code using Pyomo.

This is a general-purpose optimization modeling framework for Python which can construct valid inputs for Gurobi as well as a number of other optimization tools.

In particular, it will allow you to use Ipopt as a backend, which does solve (at least some) nonlinear problems. Even if Ipopt cannot solve your nonlinear problem, using Pyomo will allow you to test that quickly and then easily move back to a linearized representation in Gurobi if things don't work out.

Richard
  • 56,349
  • 34
  • 180
  • 251
  • I wish the downvoters had provided the reasoning behind their downvotes. – Richard Feb 09 '18 at 22:22
  • 1
    In addition: Pyomo also supports a number of MINLP solvers. – Erwin Kalvelagen Feb 10 '18 at 07:16
  • Thanks for the advice! I'll have a look at Pyomo and see if I can make it work for me. – Takko Feb 10 '18 at 18:06
  • @Takko: Glad to help! Since you're new here, I'll point out that if this answer was helpful you can upvote it with the nearby arrows. If it's the most helpful answer you can accept with the checkmark. You can also wait for other answers as long as you'd like! – Richard Feb 10 '18 at 18:14