Changeset 2360


Ignore:
Timestamp:
Feb 16, 2010 9:51:19 AM (10 years ago)
Author:
wehart
Message:

Merged revisions 2315-2359 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pyomo/trunk

........

r2330 | wehart | 2010-02-14 13:47:44 -0700 (Sun, 14 Feb 2010) | 7 lines


Setting directory properties to ignore *.pyc files.


Reworking parser management for data command files, to
directly manage the generation of the parsetab.py file.
This file is not called parse_table_datacmds.py, and it is
committed to the coopr.pyomo repository.

........

r2344 | wehart | 2010-02-15 13:44:18 -0700 (Mon, 15 Feb 2010) | 2 lines


Extending definition of svn:ignore to include *.egg-info files.

........

r2350 | wehart | 2010-02-15 15:17:53 -0700 (Mon, 15 Feb 2010) | 3 lines


Unfortunately, this file is being regenerated with path information.
For now, I'm going to delete this from the subversion repository.

........

r2359 | wehart | 2010-02-15 20:26:44 -0700 (Mon, 15 Feb 2010) | 30 lines


  1. Renaming the 'presolve' phase in Pyomo to 'preprocess'. We'll

eventually want an explicit presolve phase, but that will be applied
as a transformation, right before the problem is written and sent
to the solver. Currently, this preprocess phase collects data about
the model and computes the canonical representations for expressions.


  1. Created the ability to support the construction of concrete models.

The concrete_mode() method for Model objects enables this mode.
When in the concrete mode, each component added to the model has
its construct() method called immediately after the component is
added to the model. The symbolic_mode() method for Model objects
can be called to switch back to a symbolic mode (which defers the
execution of construct().


Bad things might happen if you switch back and forth between these
modes. Notably, if you ever generate components in symbolic mode,
then you need to switch back to symbolic mode before calling create().


Note that the Model.create() method is still called when the model
construction is 'done', even when done completely in concrete mode.
This basically calls the preprocessing steps, and this method returns
the current model (i.e. no cloning is done when building a concrete
model).


  1. Created an example directory for concrete models. Note that these

can still be solved with the Pyomo command line. In this
instance, the command line simply executes the script and applies
a solver.

........

Location:
coopr.pyomo/stable/2.3
Files:
1 deleted
44 edited
12 copied

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/stable/2.3

  • coopr.pyomo/stable/2.3/coopr

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/__init__.py

    r2315 r2360  
    2020import io
    2121from components import *
    22 import presolve
     22import preprocess
    2323import coopr.opt
    2424import transform
  • coopr.pyomo/stable/2.3/coopr/pyomo/base

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/PyomoModel.py

    r2226 r2360  
    3939    """
    4040
    41     presolver_ep = pyutilib.component.core.ExtensionPoint(IPyomoPresolver)
     41    preprocessor_ep = pyutilib.component.core.ExtensionPoint(IPyomoPresolver)
    4242
    4343
     
    4545        """Constructor"""
    4646        Component.__init__(self, ctype=Model)
     47        self._defer_construction=True
    4748        #
    4849        # Define component dictionary: component type -> instance
     
    6667        self.tmpctr=0
    6768        self._varctr=0
    68         self._presolvers = ["simple_presolver"]
     69        self._preprocessors = ["simple_preprocessor"]
    6970        #
    7071        # Dictionaries that map from id to Variable/Constraints
     
    7778        #
    7879        self.statistics = Container()
     80
     81    def concrete_mode(self):
     82        self._defer_construction=False
     83
     84    def symbolic_mode(self):
     85        self._defer_construction=True
    7986
    8087    def components(self, ctype=None):
     
    203210        if not val.type() is Model:
    204211            val.model=self
     212        if not self._defer_construction:
     213            val.construct(None)
    205214
    206215    def __setattr__(self,name,val):
     
    235244        read in from a file.
    236245        """
    237         instance = self.clone()
    238         instance.load(filename)
    239         instance.presolve()
     246        if self._defer_construction:
     247            instance = self.clone()
     248            instance.load(filename)
     249        else:
     250            instance = self
     251        instance.preprocess()
    240252        if not name is None:
    241253            instance.name=name
     
    260272
    261273
    262     def presolve(self):
    263         """Apply the presolvers defined by the user"""
    264         for item in self._presolvers:
    265             self = Model.presolver_ep.service(item).presolve(self)
     274    def preprocess(self):
     275        """Apply the preprocess plugins defined by the user"""
     276        for item in self._preprocessors:
     277            self = Model.preprocessor_ep.service(item).preprocess(self)
    266278       
    267279
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/component.py

    r2025 r2360  
    55        self.active=True
    66        self._type=ctype
     7        self._constructed=False
    78        self.model=None
    89
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/constraint.py

    r2170 r2360  
    7272          elif key == "sense":
    7373             tmpsense = kwd[key]
     74          elif key == "expr":
     75             tmprule = kwd[key]
    7476          else:
    7577             raise ValueError, "Objective constructor: unknown keyword - "+key
     
    130132
    131133    def construct(self, data=None):
    132         if self.rule is not None:
     134        if self._constructed:
     135            return
     136        self._constructed=True
     137        #
     138        if isinstance(self.rule,Expression):
     139            if None in self._index or len(self._index) == 0:
     140                self._data[None].expr = self.rule
     141            else:
     142                raise IndexError, "Cannot define multiple indices in an objective with a single expression"
     143        #
     144        elif self.rule is not None:
    133145           if self._ndim==0:
    134146              tmp = self._apply_rule((self.model,),None)
     
    232244          elif key == "doc":
    233245             self.doc=kwd[key]
    234           elif key == "rule":
     246          elif key == "rule" or key == 'expr':
    235247             tmprule = kwd[key]
    236248          else:
     
    282294
    283295    def construct(self, data=None):
    284 
    285296        if pyomo.debug("verbose") or pyomo.debug("normal"):     #pragma:nocover
    286297           print "Construcing constraint "+self.name
    287298        if self.rule is None:
    288299           return
     300        if self._constructed:
     301            return
     302        self._constructed=True
    289303        #
    290304        # Local variables for code optimization
     
    292306        _self_rule = self.rule
    293307        #
    294         if not None in self._index and len(self._index) > 0 and _self_rule.func_code.co_argcount == 1:
     308        if isinstance(_self_rule,Expression):
     309            if not None in self._index:
     310                raise IndexError, "Cannot define multiple indices in a constraint with a single expression"
     311            self.add(None, _self_rule)
     312        elif not None in self._index and len(self._index) > 0 and _self_rule.func_code.co_argcount == 1:
    295313            if pyomo.debug("verbose"):                            #pragma:nocover
    296314                print "   Constructing constraint indices with rule that returns a dictionary"
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/indexed_component.py

    r2128 r2360  
    22from component import Component
    33from sets import _BaseSet, Set, set_options
    4 
    5 def set_options(**kwds):
    6     def decorator(func):
    7         func.set_options = kwds
    8         return func
    9     return decorator
    104
    115
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/param.py

    r2315 r2360  
    174174        if pyomo.debug("verbose"):      #pragma:nocover
    175175           print "Constructing Param, name="+self.name+", from data="+`data`
     176        if self._constructed:
     177            return
     178        self._constructed=True
    176179        #
    177180        # Code optimization with local variables
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/rangeset.py

    r2025 r2360  
    5656
    5757    def construct(self, values=None):
     58        if self._constructed:
     59            return
     60        self._constructed=True
    5861        if isinstance(self._start,expr.Expression):
    5962           self._start_val = self._start()
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/sets.py

    r2201 r2360  
    188188        """ Apply the rule to construct values in this set """
    189189        log.debug("Constructing _SetContainer, name="+self.name+", from data="+repr(values))
     190        if self._constructed:
     191            return
     192        self._constructed=True
    190193        #
    191194        # Construct using the values list
     
    717720        """ Apply the rule to construct values in each set"""
    718721        log.debug("Constructing _SetArray, name="+self.name+", from data="+repr(values))
     722        if self._constructed:
     723            return
     724        self._constructed=True
    719725        if self.virtual:                                #pragma:nocover
    720726           raise TypeError, "It doesn't make sense to create a virtual set array"
     
    852858        """ Apply the rule to construct values in this set """
    853859        log.debug("Constructing _ProductSet, name="+self.name+", from data="+repr(values))
     860        if self._constructed:
     861            return
     862        self._constructed=True
    854863        if self.virtual:
    855864           if len(self.set_tuple) == 0:
  • coopr.pyomo/stable/2.3/coopr/pyomo/base/var.py

    r2129 r2360  
    237237
    238238    def construct(self, data=None):
     239        if self._constructed:
     240            return
     241        self._constructed=True
    239242        #
    240243        # Construct _VarValue() objects for all index values
  • coopr.pyomo/stable/2.3/coopr/pyomo/components

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/components/action.py

    r2025 r2360  
    5353        """ Apply the rule to construct values in this set """
    5454        if pyomo.debug("verbose"):      #pragma:nocover
    55            print "Constructing Param, name="+self._name+", from data="+`data`
     55           print "Constructing Action, name="+self._name+", from data="+`data`
     56        if self._constructed:
     57            return
     58        self._constructed=True
    5659        #
    5760        # Update the index set dimension
  • coopr.pyomo/stable/2.3/coopr/pyomo/components/check.py

    r2025 r2360  
    5353        """ Apply the rule to construct values in this set """
    5454        if pyomo.debug("verbose"):      #pragma:nocover
    55            print "Constructing Param, name="+self._name+", from data="+`data`
     55           print "Constructing Check, name="+self._name+", from data="+`data`
     56        if self._constructed:
     57            return
     58        self._constructed=True
    5659        #
    5760        # Update the index set dimension
  • coopr.pyomo/stable/2.3/coopr/pyomo/data

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/data/parse_datacmds.py

    r2315 r2360  
    1414import re
    1515import os
     16import os.path
    1617import ply.lex as lex
    1718import ply.yacc as yacc
     
    1920from pyutilib.ply import t_newline, t_ignore, _find_column, p_error, ply_init
    2021
     22tabmodule = 'parse_table_datacmds'
     23outputdir = os.path.dirname(os.path.abspath(__file__))+os.sep
    2124
    2225## -----------------------------------------------------------
     
    340343    # Build yaccer
    341344    #
    342     yacc.yacc(debug=debug)
     345    yacc.yacc(debug=debug, tabmodule=tabmodule, outputdir=outputdir)
    343346    #
    344347    # Parse the file
  • coopr.pyomo/stable/2.3/coopr/pyomo/expr

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/io

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/scripting

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/examples

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/examples/test_pyomo.py

    r2148 r2360  
    8686        output = self.pyomo('--instance-only pmedian.py pmedian.dat', file=currdir+'test8.out')
    8787        self.failUnlessEqual(type(output.instance), Model)
     88        os.remove(currdir+'test8.out')
    8889
    8990    def test9(self):
    9091        """Run pyomo with --disable-gc option"""
    9192        output = self.pyomo('--disable-gc pmedian.py pmedian.dat', file=currdir+'test9.out')
     93        self.failUnlessEqual(type(output.instance), Model)
     94        os.remove(currdir+'test9.out')
    9295
    9396    def test10(self):
     
    108111        self.pyomo('--debug=errors --logfile=%s pmedian.py pmedian.dat' % (currdir+'test12.log'), file=currdir+'test12.out')
    109112        self.failUnlessFileEqualsBaseline(currdir+"test12.log", currdir+"test12.txt")
     113        os.remove(currdir+'test12.out')
    110114
    111115
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/expr

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/expr/test_canonical.py

    r2214 r2360  
    1515import pyutilib.th
    1616import pyutilib.services
    17 from coopr.pyomo.presolve.simple_presolver import SimplePresolver
     17from coopr.pyomo.preprocess.simple_preprocessor import SimplePreprocessor
    1818from pyutilib.component.core import PluginGlobals
    1919
     
    4444        TestBase.setUp(self)
    4545        #PluginGlobals.pprint()
    46         self.plugin = SimplePresolver()
     46        self.plugin = SimplePreprocessor()
    4747        self.plugin.deactivate_action("compute_canonical_repn")
    4848
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/unit

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/unit/test_preprocess.py

    r1768 r2360  
    2424        model.y = Var(model.A)
    2525        instance=model.create()
    26         instance.presolve()
     26        instance.preprocess()
    2727        self.failUnlessEqual(instance.num_used_variables(),0)
    2828
     
    3535        model.obj = Objective(rule=lambda inst: inst.x[1])
    3636        instance=model.create()
    37         instance.presolve()
     37        instance.preprocess()
    3838        self.failUnlessEqual(instance.num_used_variables(),1)
    3939        self.failUnlessEqual(instance.x[1].label,"x[1]")
  • coopr.pyomo/stable/2.3/coopr/pyomo/tests/unit/test_set.py

    r2128 r2360  
    23722372        except KeyError:
    23732373            pass
     2374        b._constructed=False
    23742375        try:
    23752376            b.construct()
  • coopr.pyomo/stable/2.3/coopr/pyomo/transform

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/doc

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/doc/pyomo

    • Property svn:ignore
      •  

        old new  
        1 *.aux
        2 *.blg
        3 *.toc
        4 *.bbl
        5 *.log
         1*.pyc
         2*.pyo
         3*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/amplbook2

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/benders

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/diet

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/draft

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/p-median

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/stoch

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/tutorials

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/tutorials/csv

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
  • coopr.pyomo/stable/2.3/examples/pyomo/tutorials/tab

    • Property svn:ignore
      •  

        old new  
        22*.pyo
        33*.cover
         4*.egg-info
  • coopr.pyomo/stable/2.3/scripts

    • Property svn:ignore set to
      *.pyc
      *.pyo
      *.cover
      *.egg-info
Note: See TracChangeset for help on using the changeset viewer.