Skip to content

Commit

Permalink
Merge pull request #85 from ojdo/drop-coopr-support
Browse files Browse the repository at this point in the history
drop coopr (Pyomo 3) support. Closes #84.
  • Loading branch information
ojdo authored Aug 18, 2016
2 parents cb0b0ea + a28f162 commit 984fe46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
16 changes: 2 additions & 14 deletions runme.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
try:
import pyomo.environ
from pyomo.opt.base import SolverFactory
PYOMO3 = False
except ImportError:
import coopr.environ
from coopr.opt.base import SolverFactory
PYOMO3 = True
import os
import pyomo.environ
import shutil
import urbs
from datetime import datetime
from pyomo.opt.base import SolverFactory

# SCENARIOS
def scenario_base(data):
Expand Down Expand Up @@ -100,8 +94,6 @@ def run_scenario(input_file, timesteps, scenario, result_dir, plot_periods={}):

# create model
prob = urbs.create_model(data, timesteps)
if PYOMO3:
prob = prob.create()

# refresh time stamp string and create filename for logfile
now = prob.created
Expand All @@ -111,10 +103,6 @@ def run_scenario(input_file, timesteps, scenario, result_dir, plot_periods={}):
optim = SolverFactory('glpk') # cplex, glpk, gurobi, ...
optim = setup_solver(optim, logfile=log_filename)
result = optim.solve(prob, tee=True)
if PYOMO3:
prob.load(result)
else:
prob.solutions.load_from(result)

# copy input file in result directory
cdir = os.getcwd()
Expand Down
29 changes: 10 additions & 19 deletions urbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@
commodities.
"""
import warnings
try:
import pyomo.core as pyomo
except ImportError:
import coopr.pyomo as pyomo
warnings.warn("Support for Pyomo 3.x is now deprecated and will be removed"
"removed with the next release. Please upgrade to Pyomo 4.",
FutureWarning, stacklevel=2)

import math
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import pandas as pd
import pyomo.core as pyomo
import warnings
from datetime import datetime
from operator import itemgetter
from random import random
Expand Down Expand Up @@ -1274,7 +1268,7 @@ def split_columns(columns, sep='.'):
Example:
>>> split_columns(['DE.Elec', 'MA.Elec', 'NO.Wind'])
MultiIndex(levels=[[u'DE', u'MA', u'NO'], [u'Elec', u'Wind']],
MultiIndex(levels=[['DE', 'MA', 'NO'], ['Elec', 'Wind']],
labels=[[0, 1, 2], [0, 0, 1]])
"""
Expand Down Expand Up @@ -1348,7 +1342,7 @@ def commodity_subset(com_tuples, type_name):
return set(com for sit, com, com_type in com_tuples
if com_type == type_name)
else:
# type(type_name) is a class 'coopr.pyomo.base.sets.SimpleSet'
# type(type_name) is a class 'pyomo.base.sets.SimpleSet'
# type_name: ('Buy')=>('Elec buy', 'Heat buy')
return set((sit, com, com_type) for sit, com, com_type in com_tuples
if com in type_name)
Expand Down Expand Up @@ -1700,21 +1694,18 @@ def get_constants(instance):
(costs, cpro, ctra, csto) tuple
Example:
>>> import coopr.environ
>>> from coopr.opt.base import SolverFactory
>>> import pyomo.environ
>>> from pyomo.opt.base import SolverFactory
>>> data = read_excel('mimo-example.xlsx')
>>> model = create_model(data, range(1,25))
>>> prob = model.create()
>>> prob = create_model(data, range(1,25))
>>> optim = SolverFactory('glpk')
>>> result = optim.solve(prob)
>>> prob.load(result)
True
>>> cap_pro = get_constants(prob)[1]['Total']
>>> cap_pro.xs('Wind park', level='Process').apply(int)
Site
Mid 13000
North 27271
South 2674
North 23258
South 0
Name: Total, dtype: int64
"""
costs = get_entity(instance, 'costs')
Expand Down

0 comments on commit 984fe46

Please sign in to comment.