Skip to content

Commit

Permalink
change rule->expr to get pyomo4 working
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgreenhall committed May 10, 2015
1 parent a073a30 commit 8bb1df9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion minpower/experiments/ed_sweep.py
Expand Up @@ -42,7 +42,7 @@ def main(args):

results.ix[load_val, 'committed'] = statuses.sum()
results.ix[load_val, 'last_committed'] = \
statuses[statuses == 1].index.diff(committed_gen_names)
statuses[statuses == 1].index.difference(committed_gen_names)
committed_gen_names = statuses[statuses == 1].index

if (load_values[-1] == 0.99 * gen_data.pmax.sum()) and \
Expand Down
2 changes: 1 addition & 1 deletion minpower/generators.py
@@ -1,7 +1,7 @@
import pandas as pd
import logging
from config import user_config
from commonscripts import update_attributes, bool_to_int, set_trace
from commonscripts import update_attributes, bool_to_int

from optimization import value, OptimizationObject
from schedule import is_init
Expand Down
2 changes: 1 addition & 1 deletion minpower/get_data.py
Expand Up @@ -286,7 +286,7 @@ def build_class_list(data, model, times=None, timeseries=None):
valid_fields = pd.Index(fields[model.__name__] + ['schedulename'])
if is_generator:
valid_fields = valid_fields.union(pd.Index(gen_extra_fields))
invalid_fields = row.index.diff(valid_fields)
invalid_fields = row.index.difference(valid_fields)
if len(invalid_fields) > 0:
raise ValueError('invalid fields in model:: {}'.format(
invalid_fields.tolist()))
Expand Down
18 changes: 6 additions & 12 deletions minpower/optimization.py
Expand Up @@ -149,13 +149,11 @@ def add_parameter(self, name, index=None, values=None, mutable=True, default=Non
def add_constraint(self, name, time, expression):
'''Create a new constraint and add it to the object's constraints and the model's constraints.'''
cname = self._t_id(name, time)
self._parent_problem().add_component_to_problem(
pyomo.Constraint(name=cname, rule=expression))
self._parent_problem().add_component_to_problem(pyomo.Constraint(name=cname, expr=expression))

def add_constraint_set(self, name, index, expression):
cname = self._id(name)
self._parent_problem().add_component_to_problem(
pyomo.Constraint(index, name=cname, rule=expression))
self._parent_problem().add_component_to_problem(pyomo.Constraint(index, name=cname, rule=expression))

def get_dual(self, cname, time=None):
'''get the dual of a constraint of an LP problem'''
Expand Down Expand Up @@ -287,13 +285,11 @@ def add_component_to_problem(self, component):

def add_objective(self, expression, sense=pyomo.minimize):
'''add an objective to the problem'''
self._model.objective = pyomo.Objective(
name='objective', rule=expression, sense=sense)
self._model.objective = pyomo.Objective(name='objective', expr=expression, sense=sense)

def add_set(self, name, items, ordered=False):
'''add a :class:`pyomo.Set` to the problem'''
self._model.add_component(name,
pyomo.Set(initialize=items, name=name, ordered=ordered))
self._model.add_component(name, pyomo.Set(initialize=items, name=name, ordered=ordered))

def add_variable(self, name, **kwargs):
'''create a new variable and add it to the root problem'''
Expand All @@ -304,12 +300,10 @@ def map_args(kind='Continuous', low=None, high=None):

def add_constraint(self, name, expression, time=None):
cname = self._t_id(name, time) if time is not None else name
self._model.add_component(cname,
pyomo.Constraint(name=name, rule=expression))
self._model.add_component(cname, pyomo.Constraint(name=name, expr=expression))

def add_suffix(self, name):
self._model.add_component(name,
pyomo.Suffix(direction=pyomo.Suffix.IMPORT))
self._model.add_component(name, pyomo.Suffix(direction=pyomo.Suffix.IMPORT))

def get_component(self, name, scenario=None):
'''Get an optimization component'''
Expand Down
4 changes: 2 additions & 2 deletions minpower/solve.py
Expand Up @@ -15,7 +15,7 @@
import pdb

from config import user_config, parse_command_line_config
from commonscripts import joindir, StreamToLogger, set_trace
from commonscripts import joindir, StreamToLogger
import powersystems
import get_data
import stochastic
Expand Down Expand Up @@ -263,7 +263,7 @@ def _setup_logging(pid=None):
and not user_config.debugger:
kwds['filename'] = joindir(user_config.directory,
'{}.log'.format(pid))
if (user_config.logging_level > 10) and (not 'filename' in kwds):
if (user_config.logging_level > 10) and ('filename' not in kwds):
# don't log the time if debugging isn't turned on
kwds['format'] = '%(levelname)s: %(message)s'
logging.basicConfig(**kwds)
Expand Down
3 changes: 0 additions & 3 deletions minpower/tests/memory_leak_check.py
@@ -1,9 +1,6 @@
'''Test for memory leaks'''
from minpower import powersystems, solve
from test_utils import solve_problem, make_loads_times
from coopr import pyomo


import objgraph
import inspect

Expand Down

0 comments on commit 8bb1df9

Please sign in to comment.