Changeset 2109


Ignore:
Timestamp:
Jan 2, 2010 2:45:21 AM (10 years ago)
Author:
wehart
Message:

Changing the API of the SolutionSet? object. Now, all variables, constraints, etc
can be indexed with 1-based integer indices (rather than 0-based). This change
makes this object consistent with the 1-based indexing API supported by Pyomo.

Location:
coopr.opt/trunk/coopr/opt
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/trunk/coopr/opt/colin/ps.py

    r2095 r2109  
    163163        soln.objective['f']=best
    164164        soln.status = SolutionStatus.bestSoFar
    165         for i in range(0,ndim):
    166           soln.variable[i] = x[i]
     165        for i in xrange(ndim):
     166            soln.variable[i+1] = x[i]
    167167        #
    168168        # Return final results
  • coopr.opt/trunk/coopr/opt/reader/OS.py

    r1918 r2109  
    358358          solution.message = soln.message
    359359          for key in soln.variable:
    360             solution.variable[key] = soln.variable[key]
     360            solution.variable[key+1] = soln.variable[key]
    361361          for key in soln.dual:
    362             solution.constraint[key].dual = soln.dual[key]
     362            solution.constraint[key+1].dual = soln.dual[key]
    363363          i=0
    364364          for key in soln.objective:
  • coopr.opt/trunk/coopr/opt/results/container.py

    r2047 r2109  
    171171        print >>ostream, ""
    172172        i=0
    173         for i in range(0, len(self._list)):
     173        for i in xrange(len(self._list)):
    174174            item = self._list[i]
    175175            print >>ostream, prefix+'-',
  • coopr.opt/trunk/coopr/opt/results/results.py

    r2095 r2109  
    113113        print >>ostream, "# = Solver Results                                         ="
    114114        print >>ostream, "# =========================================================="
    115         for i in range(0,len(self._order)):
     115        for i in xrange(len(self._order)):
    116116            key = self._order[i]
    117117            if not key in repn:
     
    146146
    147147        repn = yaml.load(istream, Loader=yaml.SafeLoader)
    148         for i in range(0,len(self._order)):
     148        for i in xrange(len(self._order)):
    149149            key = self._order[i]
    150150            if not key in repn:
  • coopr.opt/trunk/coopr/opt/results/solution.py

    r2003 r2109  
    3838        except:
    3939            pass
    40         self.declare_item(tmp)
     40        if type(name) in (int,long):
     41            self.declare_item(tmp-1)
     42        else:
     43            self.declare_item(tmp)
    4144        if type(tmp) is int:
    42             tmp = self._names[tmp]
     45            tmp = self._names[tmp-1]
    4346        item = dict.__getitem__(self, tmp)
    4447        if isinstance(item,ListContainer) or isinstance(item,MapContainer):
     
    4851    def _set_value(self, name, val):
    4952        #print "_set_value",name,val
    50         if isinstance(name,basestring) or type(name) is int:
     53        if isinstance(name,basestring):
    5154            self.declare_item(name)
     55        elif type(name) is int:
     56            self.declare_item(name-1)
    5257        if type(name) is int:
    53             name = self._names[name]
     58            name = self._names[name-1]
    5459        dict.__getitem__(self, name).value = as_number(val)
    5560        #print "_set_value",dict.__getitem__(self, name).value
     
    231236        return len(self._list)
    232237
    233     def __call__(self, i=0):
    234         return self._list[i]
     238    def __call__(self, i=1):
     239        return self._list[i-1]
    235240
    236241    def pprint(self, ostream, option, prefix="", repn=None):
     
    244249            spaces="  "
    245250        i=0
    246         for i in range(0, len(self._list)):
     251        for i in xrange(len(self._list)):
    247252            item = self._list[i]
    248253            print >>ostream, prefix+'-',
  • coopr.opt/trunk/coopr/opt/tests/base/test_soln.py

    r1937 r2109  
    3434        self.results = coopr.opt.SolverResults()
    3535        self.soln = self.results.solution.add()
    36         self.soln.variable[0]=0.0
    3736        self.soln.variable[1]=0.0
    38         self.soln.variable[3]=0.0
     37        self.soln.variable[2]=0.0
     38        self.soln.variable[4]=0.0
    3939        pyutilib.services.TempfileManager.clear_tempfiles()
    4040
     
    118118    def test_soln_pprint1(self):
    119119        """ Write a solution with only zero values, using the results 'write()' method """
    120         self.soln.variable[0]=0.0
    121120        self.soln.variable[1]=0.0
    122         self.soln.variable[3]=0.0
     121        self.soln.variable[2]=0.0
     122        self.soln.variable[4]=0.0
    123123        self.results.write(filename=currdir+"soln_pprint.txt")
    124124        if not os.path.exists(currdir+"soln_pprint.txt"):
     
    128128    def test_soln_pprint2(self):
    129129        """ Write a solution with only zero values, using the Solution.pprint() method """
    130         self.soln.variable[0]=0.0
    131130        self.soln.variable[1]=0.0
    132         self.soln.variable[3]=0.0
     131        self.soln.variable[2]=0.0
     132        self.soln.variable[4]=0.0
    133133        pyutilib.misc.setup_redirect(currdir+"soln_pprint2.out")
    134134        print self.soln
     
    139139    def test_soln_suffix_iter(self):
    140140        """ Test a suffix iterator """
    141         self.soln.variable[0]=0.0
    142         self.soln.variable[1]=0.1
    143         self.soln.variable[3]=0.3
     141        self.soln.variable[1]=0.0
     142        self.soln.variable[2]=0.1
     143        self.soln.variable[4]=0.3
    144144        i=0
    145145        for key in self.soln.variable:
     
    150150    def test_soln_suffix_getiter(self):
    151151        self.soln.variable["x0"]=0.0
    152         self.soln.variable[1]=0.1
     152        self.soln.variable[2]=0.1
    153153        self.soln.variable["x3"]=0.3
    154154        self.failUnlessEqual(self.soln.variable["x3"].value,0.3)
    155155        #print "HERE",self.soln.variable._names
    156         self.failUnlessEqual(self.soln.variable[1].value,0.1)
     156        self.failUnlessEqual(self.soln.variable[2].value,0.1)
    157157
    158158    def test_soln_suffix_setattr(self):
Note: See TracChangeset for help on using the changeset viewer.