Changeset 2161


Ignore:
Timestamp:
Jan 14, 2010 12:38:15 AM (11 years ago)
Author:
jwatson
Message:

Cut the run-time of the PyomoModel? _load_solution method by 2/3 - it's still taking too long, but even this improvement is noticeable.

File:
1 edited

Legend:

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

    r2108 r2161  
    5757        self._declarations=[]
    5858        # the _name_varmap and _name_conmap dictionarys are assigned when
    59         # the problem definition
    60         # file is written, i.e., via the write() command. intent
    61         # is to map names that will be coming back from a solver
    62         # into Pyomo variables. Values are of type _VarValue.
     59        # the problem definition file is written, i.e., via the write()
     60        # command. intent is to map names that will be coming back from
     61        # a solver into Pyomo variables. Values are of type _VarValue.
    6362        self._name_varmap={}
    6463        self._name_conmap={}
     
    371370        # Load variable data
    372371        #
    373         for name in soln.variable:
     372        for name, entry in soln.variable.items():
    374373          #
    375374          # NOTE: the following is a hack, to handle the ONE_VAR_CONSTANT variable
     
    390389                raise TypeError, "Variable '"+name+"' in model '"+self.name+"' is currently fixed - new value is not expected in solution"
    391390
    392              #print "HERE",soln.variable[name].keys()
    393              for _key in soln.variable[name].keys():
     391             var_value = self._name_varmap[name]
     392             for _key in entry.keys():
    394393                key = _key[0].lower() + _key[1:]
    395394                if key == 'value':
    396                     self._name_varmap[name].value = soln.variable[name].value
     395                    var_value.value = entry.value
    397396                elif not key == 'id':
    398                     setattr(self._name_varmap[name], key, getattr(soln.variable[name], _key))
     397                    setattr(var_value, key, getattr(entry, _key))
    399398        #
    400399        # Load constraint data
    401400        #
    402         for name in soln.constraint:
     401        for name,entry in soln.constraint.items():
    403402             #
    404              # This is a hack
     403             # This is a hack - see above.
    405404             #
    406405             if name.endswith('ONE_VAR_CONSTANT'):
     
    414413             if name[0:2] == 'c_':
    415414                _name = name[4:-1]
    416              #print "HERE",_name
     415
    417416             if _name not in self._name_conmap:
    418417                names=""
     
    421420                raise TypeError, "Constraint '"+name+"' in model '"+self.name+"' is type "+str(type(self._name_conmap[_name]))
    422421
    423              #print "HERE",soln.constraint[name].keys()
    424              for _key in soln.constraint[name].keys():
     422             constraint_data = self._name_conmap[_name]
     423             for _key in entry.keys():
    425424                key = _key[0].lower() + _key[1:]
    426425                if key == 'value':
    427                     self._name_conmap[name].value = soln.constraint[name].value
     426                    constraint_data.value = entry.value
    428427                elif not key == 'id':
    429                     setattr(self._name_conmap[_name], key, getattr(soln.constraint[name], _key))
     428                    setattr(constraint_data, key, getattr(entry, _key))
    430429
    431430    def write(self,filename=None,format=ProblemFormat.cpxlp):
Note: See TracChangeset for help on using the changeset viewer.