Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions uc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import sys

## Grab instance file from first command line argument
if len(sys.argv) == 1:
print("uc_model.py <data-file> [<solver>]")
sys.exit(0)
data_file = sys.argv[1]
if len(sys.argv) == 3:
solver_name = sys.argv[2]
else:
solver_name = 'cbc'

print('loading data')
data = json.load(open(data_file, 'r'))
Expand Down Expand Up @@ -133,7 +140,7 @@
m.cost_select[g,t] = m.cg[g,t] == sum( (piece['cost'] - piece_cost1)*m.lg[g,l,t] for l,piece in enumerate(gen['piecewise_production'])) #(22)
m.on_select[g,t] = m.ug[g,t] == sum(m.lg[g,l,t] for l,_ in enumerate(gen['piecewise_production'])) #(23)

m.startup_allowed = Constraint(m.dg_index)
m.startup_allowed = Constraint(m.dg.index_set())
for g, gen in thermal_gens.items():
for s,_ in enumerate(gen['startup'][:-1]): ## all but last
for t in time_periods:
Expand All @@ -148,7 +155,9 @@
print("model setup complete")

from pyomo.opt import SolverFactory
cbc = SolverFactory('cbc')
solver = SolverFactory(solver_name)

print("solving")
cbc.solve(m, options={'ratioGap':0.01}, tee=True)
options = {'gurobi':{'ratioGap':0.01}, 'glpk':{'mipgap':0.01}, 'cbc':{'ratioGap':0.01}, 'scip':{'mipgap':0.01}}
solver.solve(m, options=options[solver_name], tee=True)