Skip to content

Commit

Permalink
back to knitro
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinRigoni committed Feb 21, 2020
1 parent f88284a commit d5d3f66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions MAIN_Unbalanced_OPF_RUN.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ def range1(start, end, step): # like range but inlcuding the ending value

#### Choose a NLP solver - make sure its installed - some solvers won't be able to find a feasible or optimal solution - NOTE: with IPOPT as default, I've disabled "PV operational limits" constraint... you need another solver when including that
# IPOPT
optimizer = pyo.SolverFactory('ipopt')
optimizer.options["max_iter"] = 100000
optimizer.options["linear_solver"] = 'mumps'
#optimizer = pyo.SolverFactory('ipopt')
#optimizer.options["max_iter"] = 100000
#optimizer.options["linear_solver"] = 'mumps'

# KNITRO
#optimizer = pyo.SolverFactory('knitroampl')
#optimizer.options["par_numthreads"] = 5
#optimizer.options["algorithm"] = 0 # Indicates which algorithm to use to solve the problem - 0 is auto [0-5]
#optimizer.options["presolve"] = 1 # Determine whether or not to use the Knitro presolver to try to simplify the model by removing variables or constraints.
optimizer = pyo.SolverFactory('knitroampl')
optimizer.options["par_numthreads"] = 1
optimizer.options["algorithm"] = 0 # Indicates which algorithm to use to solve the problem - 0 is auto [0-5]
optimizer.options["presolve"] = 1 # Determine whether or not to use the Knitro presolver to try to simplify the model by removing variables or constraints.

print('Solving OPF model...')
Problem = optimizer.solve(instance,tee=True)
Expand Down
4 changes: 2 additions & 2 deletions Main_packages/OPF_model_creator_v01.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def Q_flow_receiving_rule(model, l, s, t): # Q receiving flow
return -1.0 *(model.Vim[model.Lines_i[l],s,t] * model.Iflow_re[l,s,t] - model.Vre[model.Lines_i[l],s,t] * model.Iflow_im[l,s,t])
model.Q_flow_receiving = pyo.Expression(model.Lines,model.Phases_abc,model.time, rule=Q_flow_receiving_rule)
# Losses
if 1==1:
if 1==0: # Only model the variables that you are using in the optimization problem (in objective function or constraints)
# Losses for this time step per line and phase
def P_losses_rule(model, l, s, t): # Active power losses Watts!
return model.P_flow_sending[l,s,t] + model.P_flow_receiving[l,s,t]
Expand Down Expand Up @@ -233,7 +233,7 @@ def Transformer_limit_rule(model, t):
model.Transformer_limit_con = pyo.Constraint(model.time, rule=Transformer_limit_rule)

# PV operational limits
if 1==0: # I recommend using a different NLP solver than IPOPT if incorporating this constraint (e.g. knitro or modifiying IPOPT options) - otherwise, relax the constraint
if 1==1: # I recommend using a different NLP solver than IPOPT if incorporating this constraint (e.g. knitro or modifiying IPOPT options) - otherwise, relax the constraint
def PV_inverter_limit_rule(model, pv, t):
max_P = PV_Gen_data[pv,'Profile'].loc[t]
max_S = (max_P**2+ (max_P*math.tan(math.acos(min_Cosphi)))**2)**0.5
Expand Down

0 comments on commit d5d3f66

Please sign in to comment.