Changeset 2064


Ignore:
Timestamp:
Dec 29, 2009 5:16:16 PM (10 years ago)
Author:
wehart
Message:

Misc rework of variable presolving. Now, model
statistics are stored in a more obvious location, and using more
verbose names.

Location:
coopr.pyomo/trunk/coopr/pyomo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/PyomoModel.py

    r2053 r2064  
    1818import pyutilib.plugin.core
    1919from pyutilib.math import *
    20 from pyutilib.misc import quote_split, tuplize
     20from pyutilib.misc import quote_split, tuplize, Container
    2121
    2222from coopr.opt import ProblemFormat, ResultsFormat, guess_format
     
    7474        self._con = {}
    7575        self._obj = {}
     76        #
     77        # Model statistics
     78        #
     79        self.statistics = Container()
    7680
    7781    def components(self, ctype=None):
     
    8387
    8488    def nvariables(self):
    85         return len(self._var)
     89        return self.statistics.number_of_variables
    8690
    8791    def variable(self, name):
     
    9599
    96100    def nconstraints(self):
    97         return len(self._con)
     101        return self.statistics.number_of_constraints
    98102
    99103    def constraint(self, name):
     
    107111
    108112    def nobjectives(self):
    109         return len(self._obj)
     113        return self.statistics.number_of_objectives
    110114
    111115    def objective(self, name):
  • coopr.pyomo/trunk/coopr/pyomo/base/var.py

    r2025 r2064  
    8686            return True
    8787        return False
     88
     89    def is_binary(self):
     90        return self.var.is_binary()
     91
     92    def is_integer(self):
     93        return self.var.is_integer()
     94
     95    def is_continuous(self):
     96        return self.var.is_continuous()
    8897
    8998    def simplify(self, model):
     
    214223        except KeyError:
    215224            raise KeyError, "Unknown index " + str(ndx) + " in variable " + self.name
     225
     226    def is_binary(self):
     227        return isinstance(self.domain, BooleanSet)
     228
     229    def is_integer(self):
     230        return isinstance(self.domain, IntegerSet)
     231
     232    def is_continuous(self):
     233        return not (self.is_binary() or self.is_integer())
    216234
    217235    def simplify(self, model):
  • coopr.pyomo/trunk/coopr/pyomo/io/ampl.py

    r1992 r2064  
    128128        # LINE 2
    129129        #
    130         print >>OUTPUT, " " + str(model.vnum), nc, no, nrange, str(neqn) +\
     130        print >>OUTPUT, " " + str(model.statistics.number_of_variables), nc, no, nrange, str(neqn) +\
    131131                "\t# vars, constraints, objectives, ranges, eqns"
    132132        #
     
    165165        # LINE 8
    166166        #
    167         nsno = model.vnum
     167        nsno = model.statistics.number_of_variables
    168168        ngc = ngo = 0
    169169        for key in Obj:
     
    294294        # "k" lines
    295295        #
    296         n1 = model.vnum - 1
     296        n1 = model.statistics.number_of_variables - 1
    297297        print >>OUTPUT, "k" + str(n1)
    298298        ktot = 0
  • coopr.pyomo/trunk/coopr/pyomo/presolve/identify_vars.py

    r1993 r2064  
    7070                tmp.id = self.vnum
    7171                model._var[self.vnum] = tmp
     72            if model._var[self.vnum].is_binary():
     73                model.statistics.number_of_binary_variables += 1
     74            elif model._var[self.vnum].is_integer():
     75                model.statistics.number_of_integer_variables += 1
     76            else:
     77                model.statistics.number_of_continuous_variables +=1
    7278            self.vnum += 1
    7379        #
     
    8894        self.cnum=0
    8995        self.onum=0
     96        model.statistics.number_of_binary_variables = 0
     97        model.statistics.number_of_integer_variables = 0
     98        model.statistics.number_of_continuous_variables = 0
    9099        #
    91100        # Indicate that all variables are unused
     
    122131                model._con[self.cnum] = C._data[cndx]
    123132                self.cnum += 1
    124         model.vnum=self.vnum
    125         model.cnum=self.cnum
    126         model.onum=self.onum
     133        model.statistics.number_of_variables=self.vnum
     134        model.statistics.number_of_constraints=self.cnum
     135        model.statistics.number_of_objectives=self.onum
    127136        return model
    128137
Note: See TracChangeset for help on using the changeset viewer.