Changeset 1918


Ignore:
Timestamp:
Nov 20, 2009 5:27:31 PM (10 years ago)
Author:
wehart
Message:

Rework of the SolverResults? object, to provide for a more explicit
definition of solver results, and to support loading of
solver results from YAML-formated data.

Location:
coopr.opt/trunk/coopr/opt
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/trunk/coopr/opt/base/solver.py

    r1900 r1918  
    171171        if self._results_format is None:
    172172           self._results_format= self._default_results_format(self._problem_format)
    173         if self._results_format not in self._valid_result_formats[self._problem_format]:
    174            raise ValueError, "Results format `"+str(self._results_format)+"' cannot be used with problem format `"+str(self._problem_format)+"' in solver "+self.name
     173        #
     174        # Disabling this check for now.  A solver doesn't have just _one_ results format.
     175        #
     176        #if self._results_format not in self._valid_result_formats[self._problem_format]:
     177        #   raise ValueError, "Results format `"+str(self._results_format)+"' cannot be used with problem format `"+str(self._problem_format)+"' in solver "+self.name
    175178        if self._results_format == ResultsFormat.log:
    176179            self.results_reader = None
  • coopr.opt/trunk/coopr/opt/colin/ps.py

    r1657 r1918  
    99#  _________________________________________________________________________
    1010
    11 from coopr.opt import SolverResults, ProblemSense, SolverStatus, SolutionStatus
     11from coopr.opt import SolverResults, ProblemSense, SolverStatus, SolutionStatus, TerminationStatus
    1212import solver
    1313import problem
     
    7575        ndim=len(x)
    7676        curr_iter=0
     77        tstatus = TerminationStatus.maxIterations
     78        tmsg=None
    7779        while curr_iter < self.max_iterations:
    7880            #
     
    8587            #   
    8688            if best <= self.min_function_value:
     89                tstatus = TerminationStatus.minFunctionValue
     90                tmsg = "%s < %s" % (best,self.min_function_value)
    8791                break
    8892            if self.delta <= self.min_delta:
     93                tstatus = TerminationStatus.minStepLength
     94                tmsg = "%s < %s" % (self.delta,self.min_delta)
    8995                break
    9096            #
     
    142148        results = SolverResults()
    143149        #
    144         results.solver.curr_iteration = curr_iter
    145         results.solver.final_delta = self.delta
     150        results.solver.number_of_iterations = curr_iter
     151        results.solver.final_step_length = self.delta
    146152        results.solver.status = SolverStatus.ok
     153        results.solver.termination_condition = tstatus
     154        results.solver.termination_message = tmsg
    147155        #
    148         results.problem.num_objectives=1
    149         results.problem.num_constraints=0
     156        results.problem.number_of_objectives=1
     157        results.problem.number_of_constraints=0
     158        results.problem.number_of_variables=ndim
    150159        results.problem.sense=ProblemSense.minimize
    151160        results.problem.upper_bound=best
    152161        #
    153         soln = results.solution.create()
    154         soln.value=best
     162        soln = results.solution.add()
     163        soln.objective['f']=best
    155164        soln.status = SolutionStatus.bestSoFar
    156165        for i in range(0,ndim):
    157           soln.variable.add(str(i),x[i])
     166          soln.variable[i] = x[i]
    158167        #
    159168        # Return final results
  • coopr.opt/trunk/coopr/opt/reader/OS.py

    r1900 r1918  
    316316from coopr.opt.base import results
    317317from coopr.opt.base.formats import *
    318 from coopr.opt import SolverResults, Solution
     318from coopr.opt import SolverResults
    319319
    320320class ResultsReader_osrl(results.AbstractResultsReader):
     
    353353          # The solution object is managed by the SolverResults instance
    354354          #
    355           solution = res.solution.create()
     355          solution = res.solution.add()
    356356          solution.status = SolutionStatus(soln.status_type)
    357357          solution.status_description = soln.status_description
    358358          solution.message = soln.message
    359359          for key in soln.variable:
    360             solution.variable.add(key, soln.variable[key])
     360            solution.variable[key] = soln.variable[key]
    361361          for key in soln.dual:
    362             solution.dual.add(key, soln.dual[key])
    363           solution.value = soln.objective
     362            solution.constraint[key].dual = soln.dual[key]
     363          i=0
     364          for key in soln.objective:
     365            solution.objective['f'+str(i)] = soln.objective[key]
     366            solution.objective['f'+str(i)].id = key
     367            i=i+1
    364368          solution.other=soln.other
    365           res.problem.num_constraints = len(soln.dual)
    366           res.problem.num_variables = len(soln.variable)
    367           res.problem.num_objectives = len(soln.objective)
     369          res.problem.number_of_constraints = len(soln.dual)
     370          res.problem.number_of_variables = len(soln.variable)
     371          res.problem.number_of_objectives = len(soln.objective)
    368372        return res
    369373
  • coopr.opt/trunk/coopr/opt/reader/res.py

    r1900 r1918  
    1919from coopr.opt.base import results
    2020from coopr.opt.base.formats import *
    21 from coopr.opt import SolverResults, Solution
     21from coopr.opt import SolverResults
    2222
    2323
  • coopr.opt/trunk/coopr/opt/reader/sol.py

    r1907 r1918  
    1919from coopr.opt.base import results
    2020from coopr.opt.base.formats import *
    21 from coopr.opt import SolverResults, Solution
     21from coopr.opt import SolverResults
    2222
    2323class ResultsReader_sol(results.AbstractResultsReader):
     
    9191        ##res.problem.name = osrl.header.instanceName
    9292        if soln is None:
    93             soln = res.solution.create()
     93            soln = res.solution.add()
    9494        ##soln.status = Solution.SolutionStatus(soln.status_type)
    9595        ##soln.status_description = soln.status_description
     
    9898        for i in range(0,len(x)):
    9999            #soln.variable.add("_svar["+str(i)+"]", x[i])
    100             soln.variable.add("v"+str(i), x[i])
     100            soln.variable["v"+str(i)].value = x[i]
    101101        for i in range(0,len(y)):
    102102            #soln.dual.add("_scon["+str(i)+"]", y[i])
    103             soln.dual.add("c"+str(i), y[i])
    104         #soln.value = objno[0]
    105         try:
    106             #
    107             # This is a bit of a hack to accommodate PICO.  If
    108             # the PICO parser has parsed the # of constraints, then
    109             # don't try to read it in from the *.sol file.  The reason
    110             # is that these may be inconsistent values!
    111             #
    112             res.problem.num_constraints
    113         except AttributeError:
    114             res.problem.num_constraints = m
    115         if res.problem.num_constraints is None:
    116             res.problem.num_constraints = m
    117         res.problem.num_variables = n
    118         #res.problem.num_objectives = len(objno)
    119         res.problem.num_objectives = 1
     103            soln.constraint["c"+str(i)].dual = y[i]
     104        #
     105        # This is a bit of a hack to accommodate PICO.  If
     106        # the PICO parser has parsed the # of constraints, then
     107        # don't try to read it in from the *.sol file.  The reason
     108        # is that these may be inconsistent values!
     109        #
     110        #print "HERE", res.problem.number_of_constraints, type(res.problem.number_of_constraints)
     111        if res.problem.number_of_constraints == 0:
     112            res.problem.number_of_constraints = m
     113        res.problem.number_of_variables = n
     114        res.problem.number_of_objectives = 1
    120115        return res
    121116
  • coopr.opt/trunk/coopr/opt/results/__init__.py

    r1905 r1918  
    1 from old_results import *
    2 #from results import *
    3 #from solver import SolverStatus, TerminationStatus
    4 #from problem import ProblemSense
    5 #from solution import SolutionStatus
     1#from old_results import *
     2from results import *
     3from solver import SolverStatus, TerminationStatus
     4from problem import ProblemSense
     5from solution import SolutionStatus, Solution
  • coopr.opt/trunk/coopr/opt/results/container.py

    r1915 r1918  
    11
    2 __all__ = ['UndefinedData', 'undefined', 'ignore', 'ScalarData', 'ListContainer', 'MapContainer', 'default_print_options']
     2__all__ = ['UndefinedData', 'undefined', 'ignore', 'ScalarData', 'ListContainer', 'MapContainer', 'default_print_options', 'ScalarType']
    33
    44from pyutilib.misc import Bunch
    5 from pyutilib.enum import EnumValue
    6 import yaml
     5from pyutilib.enum import EnumValue, Enum
    76import StringIO
    87
    9 default_print_options = Bunch(schema=False, sparse=True, num_solutions=None)
     8ScalarType = Enum('int', 'time', 'string', 'float', 'enum', 'undefined')
     9
     10default_print_options = Bunch(schema=False, ignore_time=False)
    1011
    1112strict=False
     
    2324class ScalarData(object):
    2425
    25     def __init__(self, value=undefined, description=None, units=None, scalar_description=None, scalar_type=None, required=False):
     26    def __init__(self, value=undefined, description=None, units=None, scalar_description=None, type=ScalarType.undefined, required=False):
    2627        self.value = value
    2728        self.description = description
    2829        self.units = units
    2930        self.scalar_description = scalar_description
    30         self.scalar_type = scalar_type
     31        self.scalar_type = type
    3132        self._required=required
    3233
    3334    def _repn_(self, option):
    3435        if not option.schema and not self._required and self.value is undefined:
     36            return ignore
     37        if option.ignore_time and str(self.scalar_type) == str(ScalarType.time):
    3538            return ignore
    3639        if type(self.value) is EnumValue:
     
    4851            if not self.scalar_description is None:
    4952                tmp['description'] = self.scalar_description
    50             if not self.scalar_type is None:
     53            if not self.scalar_type is ScalarType.undefined:
    5154                tmp['type'] = self.scalar_type
    5255            return tmp
     
    6366        if not option.schema and not self._required and self.value is undefined:
    6467            return ignore
     68        if option.ignore_time and str(self.scalar_type) == str(ScalarType.time):
     69            return ignore
    6570        if type(self.value) is EnumValue:
    66             value = str(self.value)
     71            value = self.yaml_fix(str(self.value))
    6772        elif type(self.value) is UndefinedData:
    6873            value = '<undefined>'
    6974        else:
    70             value = self.value
     75            value = self.yaml_fix(self.value)
    7176        if not option.schema and self.description is None and self.units is None:
    7277            print >>ostream, value
     
    7681            if not option.schema:
    7782                if not self.description is None:
    78                     print >>ostream, prefix+'Description:',self.description
     83                    print >>ostream, prefix+'Description:',self.yaml_fix(self.description)
    7984                if not self.units is None:
    8085                    print >>ostream, prefix+'Units:',self.units
    8186            else:
    8287                if not self.scalar_description is None:
    83                     print >>ostream, prefix+'Description:',self.scalar_description
    84                 if not self.scalar_type is None:
    85                     print >>ostream, prefix+'Type:',self.scalar_type
     88                    print >>ostream, prefix+'Description:',self.yaml_fix(self.scalar_description)
     89                if not self.scalar_type is ScalarType.undefined:
     90                    print >>ostream, prefix+'Type:',self.yaml_fix(self.scalar_type)
     91
     92    def yaml_fix(self, val):
     93        if not isinstance(val,basestring):
     94            return val
     95        return val.replace(':','\\x3a')
     96           
     97    def load(self, repn):
     98        if type(repn) is dict:
     99            for key in repn:
     100                setattr(self, key, repn[key])
     101        else:
     102            self.value = repn
    86103
    87104
     
    111128        except:
    112129            pass
    113         if len(self) > 0:
    114             return getattr(self._list[0], name)
    115         raise AttributeError, "Unknown attribute `"+str(name)+"' for object with type "+str(type(self))
     130        if len(self) == 0:
     131            self.add()
     132        return getattr(self._list[0], name)
    116133
    117134    def __setattr__(self,name,val):
     
    126143        setattr(self._list[0], name, val)
    127144
     145    def insert(self, obj):
     146        self._active=True
     147        self._list.append( obj )
     148
    128149    def add(self):
    129150        self._active=True
     
    151172            print >>ostream, prefix+'-',
    152173            item.pprint(ostream, option, from_list=True, prefix=prefix+"  ", repn=repn[i])
    153             #if type(item) is MapContainer:
    154                 #item.pprint(ostream, option, from_list=True, prefix=prefix+"  ", repn=repn[i])
    155             #else:
    156                 #item.pprint(ostream, option, prefix=prefix+"  ", repn=repn[i])
     174
     175    def load(self, repn):
     176        for data in repn:
     177            item = self.add()
     178            item.load(data)
    157179
    158180
     
    171193        self._ordered=ordered
    172194        self._order=[]
     195        self._option=default_print_options
    173196
    174197    def keys(self):
     
    181204            pass
    182205        try:
     206            self._active=True
    183207            return self[self._convert(name)]
    184208        except Exception, err:
    185             print "IGNORING EXCEPTION: ",str(err)
     209            if name[0] != '_':
     210                print "EXCEPTION: ",str(err),name
    186211            pass
    187212        raise AttributeError, "Unknown attribute `"+str(name)+"' for object with type "+str(type(self))
     
    199224            if strict:
    200225                raise AttributeError, "Unknown attribute `"+str(name)+"' for object with type "+str(type(self))
     226            #else:
     227                #print "WARNING: creating attribute '"+str(name)+"' for object with type "+str(type(self))
    201228            #print "DECL1"
    202229            self.declare(tmp)
     
    209236            if strict:
    210237                raise AttributeError, "Unknown attribute `"+str(name)+"' for object with type "+str(type(self))
     238            #else:
     239                #print "WARNING: creating attribute '"+str(name)+"' for object with type "+str(type(self))
    211240            #print "DECL1"
    212241            self.declare(tmp)
     
    271300
    272301    def __repr__(self):
    273         return str(self._repn_(default_print_options))
     302        return str(self._repn_(self._options))
    274303
    275304    def __str__(self):
    276305        ostream = StringIO.StringIO()
    277306        option=default_print_options
    278         self.pprint(ostream, option, repn=self._repn_(option))
     307        self.pprint(ostream, self._option, repn=self._repn_(self._option))
    279308        return ostream.getvalue()
    280309
     
    295324            else:
    296325                item.pprint(ostream, option, prefix=_prefix+"  ", repn=repn[key])
     326
     327    def load(self, repn):
     328        for key in repn:
     329            tmp = self._convert(key)
     330            if tmp not in self:
     331                self.declare(tmp)
     332            item = dict.__getitem__(self,tmp)
     333            item.load(repn[key])
    297334
    298335
  • coopr.opt/trunk/coopr/opt/results/problem.py

    r1905 r1918  
    2020    def __init__(self):
    2121        MapContainer.__init__(self)
    22         self.declare('lower_bound')
    23         self.declare('upper_bound')
    2422        self.declare('name')
     23        self.declare('lower_bound', value=float('-inf'))
     24        self.declare('upper_bound', value=float('inf'))
     25        self.declare('number_of_objectives', value=1, required=True)
    2526        self.declare('number_of_constraints', value=0)
    2627        self.declare('number_of_variables', value=0)
    2728        self.declare('number_of_nonzeros')
    28         self.declare('number_of_objectives', value=1, required=True)
    2929        self.declare('sense', value=ProblemSense.unknown, required=True)
    3030       
  • coopr.opt/trunk/coopr/opt/results/results.py

    r1915 r1918  
    1212
    1313import sys
    14 import yaml
    1514from container import *
    1615from pyutilib.enum import Enum
    1716from pyutilib.misc import Bunch
     17import copy
    1818
    1919import problem
     
    2222
    2323
     24try:
     25    import yaml
     26    yaml_available=True
     27except ImportError:
     28    yaml_available=False
     29
     30
    2431class SolverResults(MapContainer):
     32
     33    undefined = undefined
     34    default_print_options = solution.default_print_options
    2535
    2636    def __init__(self):
     
    4151        if not option.schema and not self._active and not self._required:
    4252            return ignore
    43         tmp = []
     53        tmp = {}
    4454        for key in self._sections:
    4555            rep = dict.__getitem__(self, key)._repn_(option)
    4656            if not rep == ignore:
    47                 tmp.append( {key:rep} )
     57                tmp[key] = rep
    4858        return tmp
    4959
     
    6272            return
    6373
    64         option = copy.copy(default_print_options)
     74        option = copy.copy(solution.default_print_options)
    6575        for key in kwds:
    6676            setattr(option,key,kwds[key])
     
    92102            return
    93103
    94         if not 'schema' in kwds:
    95             kwds['schema']=False
    96         if not 'sparse' in kwds:
    97             kwds['sparse']=True
    98         if not 'num_solutions' in kwds:
    99             kwds['num_solutions']=None
    100         option = Bunch(**kwds)
     104        option = copy.copy(SolverResults.default_print_options)
     105        for key in kwds:
     106            setattr(option,key,kwds[key])
     107
    101108        repn = self._repn_(option)
    102         print "HERE",repn,len(repn)
     109        #print "HERE",repn,len(repn)
    103110        print >>ostream, "# =========================================================="
    104111        print >>ostream, "# = Solver Results                                         ="
     
    109116                continue
    110117            item = dict.__getitem__(self,key)
    111             #if isinstance(item, ScalarData) and type(item.value) is UndefinedData:
    112                 #if not option.schema:
    113                     #continue
    114118            print >>ostream, ""
    115119            print >>ostream, "# ----------------------------------------------------------"
     
    118122            print >>ostream, key+":",
    119123            if isinstance(item, ListContainer):
    120                 #print >>ostream, "HERE",key,repr(repn[i][key])
    121                 item.pprint(ostream, option, prefix="", repn=repn[i][key])
     124                item.pprint(ostream, option, prefix="", repn=repn[key])
    122125            else:
    123                 item.pprint(ostream, option, prefix="  ", repn=repn[i][key])
     126                item.pprint(ostream, option, prefix="  ", repn=repn[key])
    124127
    125         #for key in self._sections:
    126             #print >>ostream, key+":"
    127             #for item in dict.__getitem__(self, key):
    128                 #key = item.keys()[0]
    129             ##print repr(item)
    130             #yaml.dump(item, ostream, default_flow_style=False)
    131             #item.pprint(ostream, option)
     128    def read(self, **kwds):
     129        if not yaml_available:
     130            print "Aborting SolverResults.read() because PyYAML is not installed!"
     131            return
     132
     133        if 'istream' in kwds:
     134            istream = kwds['istream']
     135            del kwds['istream']
     136        else:
     137            ostream = sys.stdin
     138        if 'filename' in kwds:
     139            INPUT=open(kwds['filename'],"r")
     140            del kwds['filename']
     141            kwds['istream']=INPUT
     142            self.read(**kwds)
     143            INPUT.close()
     144            return
     145
     146        repn = yaml.load(istream, Loader=yaml.SafeLoader)
     147        for i in range(0,len(self._order)):
     148            key = self._order[i]
     149            if not key in repn:
     150                continue
     151            item = dict.__getitem__(self,key)
     152            item.load(repn[key])
     153       
     154    def __repr__(self):
     155        return str(self._repn_(default_print_options))
     156
     157    def __str__(self):
     158        ostream = StringIO.StringIO()
     159        option=default_print_options
     160        self.pprint(ostream, option, repn=self._repn_(option))
     161        return ostream.getvalue()
     162
     163 
     164
     165       
    132166
    133167
  • coopr.opt/trunk/coopr/opt/results/solution.py

    r1915 r1918  
    1212import math
    1313from container import *
     14from pyutilib.misc import Bunch
    1415from pyutilib.enum import Enum
    1516from pyutilib.math import as_number
     17
     18default_print_options = Bunch(schema=False, sparse=True, num_solutions=None, ignore_time=False)
    1619
    1720SolutionStatus = Enum('globallyOptimal', 'locallyOptimal',
     
    2730        self._names = {}
    2831        self._prefix='x'
     32        self._option = default_print_options
    2933
    3034    def __getitem__(self, name):
     
    4246        return item.value
    4347
    44     def foo(self, name):
    45         tmp=self._convert(name)
    46         return dict.__getitem__(self, tmp)
    47 
    4848    def _set_value(self, name, val):
    4949        #print "_set_value",name,val
     
    6060        self.declare_item(name)
    6161
    62     def declare_item(self, name):
     62    def declare_item(self, name, id=None):
    6363        self._active=True
    6464        if name in self:
     
    7171                name = self._prefix+str(name)
    7272        else:
    73             id = len(self._names)
     73            if id is None:
     74                id = len(self._names)
    7475        if name in self:
    7576            return
    7677        #print "DECL3",name
    7778        MapContainer.declare(self, name, value=MapContainer())
    78         dict.__getitem__(self, name).id = len(self._names)
     79        dict.__getitem__(self, name).id = id
    7980        self._names[id] = name
    8081        #
     
    154155                            trep[tkey] = rep[tkey]
    155156                            continue
    156                         if not type(rep[tkey]) is float or math.fabs(rep[tkey]) > 1e-16:
     157                        if not type(rep[tkey]) in (float,int,long) or math.fabs(rep[tkey]) > 1e-16:
    157158                            trep[tkey] = rep[tkey]
    158159                    if len(trep.keys()) > 1:
     
    160161                else:
    161162                    tmp[key] = rep
    162         #if tmp == {}:
    163         #    return "No nonzero values"
     163        if tmp == {}:
     164            return "No nonzero values"
    164165        return tmp
    165166
    166167    def pprint(self, ostream, option, from_list=False, prefix="", repn=None):
    167         if repn == {}:
    168             print prefix+"  No nonzero values"
     168        if isinstance(repn,basestring):
     169            print >>ostream, repn
    169170        else:
    170171            MapContainer.pprint(self, ostream, option, from_list=from_list, prefix=prefix, repn=repn)
     172
     173    def load(self, repn):
     174        if isinstance(repn, basestring):
     175            return
     176        index = {}
     177        for key in repn:
     178            index[repn[key]['Id']] = key
     179        keys = index.keys()
     180        keys.sort()
     181        for key in keys:
     182            self.declare_item(index[key], id=key)
     183            for elt in repn[index[key]]:
     184                if elt == 'Id':
     185                    continue
     186                dict.__getitem__(self, index[key])[elt] = repn[index[key]][elt]
    171187
    172188
     
    184200        self.declare('constraint', value=SolutionMap(), active=False)
    185201
     202        self._option = default_print_options
     203
    186204
    187205class SolutionSet(ListContainer):
     
    189207    def __init__(self):
    190208        ListContainer.__init__(self,Solution)
     209        self._option = default_print_options
    191210
    192211    def _repn_(self, option):
     
    194213            return ignore
    195214        if option.schema and len(self) == 0:
    196             #print "SCHEMA",option
    197215            self.add()
    198216            self.add()
     
    224242            print >>ostream, prefix+'-',
    225243            item.pprint(ostream, option, from_list=True, prefix=prefix+"  ", repn=repn[i+1])
    226             #if isinstance(item,MapContainer):
    227             #    item.pprint(ostream, option, from_list=True, prefix=prefix+"..", repn=repn[i+1])
    228             #else:
    229             #    item.pprint(ostream, option, prefix=prefix+"  ", repn=repn[i+1])
    230 
    231 
     244
     245    def load(self, repn):
     246        #
     247        # Note: we ignore the first element of the repn list, since
     248        # it was generated on the fly by the SolutionSet object.
     249        #
     250        for data in repn[1:]:
     251            item = self.add()
     252            item.load(data)
     253
  • coopr.opt/trunk/coopr/opt/results/solver.py

    r1915 r1918  
    5555        self.declare('return_code')
    5656        self.declare('message')
    57         self.declare('user_time')
    58         self.declare('system_time')
     57        self.declare('user_time', type=ScalarType.time)
     58        self.declare('system_time', type=ScalarType.time)
    5959        self.declare('termination_condition', value=TerminationStatus.unsure)
    6060        self.declare('termination_message')
  • coopr.opt/trunk/coopr/opt/tests/base/soln_pprint2.txt

    r1244 r1918  
    1 ----------------------------------------------------------
    2 ------  Solution 1
    3 ----------------------------------------------------------
    4   gap: None
    5   status: unsure
    6   value: None
    7   Primal Variables
    8         No nonzero values
    9   Primal Variables
    10         No nonzero values
     1
     2Status: unknown
     3Variable: No nonzero values
     4
     5No nonzero values
     6
  • coopr.opt/trunk/coopr/opt/tests/base/test1.txt

    r1072 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name:
    9   num_constraints: 3
    10   num_objectives: 2
    11   num_variables: 3
    12   sense: unknown
    13   upper_bound: None
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   id: 0
    18   instanceName:
    19   message:
    20   serviceName:
    21   serviceURI:
    22   status: ok
    23   systime: 0.0
    24   usrtime: None
    25   num_solutions: 1
    26 ----------------------------------------------------------
    27 ------  Solution 1
    28 ----------------------------------------------------------
    29   gap: None
    30   message: None
    31   other: {}
    32   status: unsure
    33   status_description:
    34   Objectives
    35         -1      1.2
    36         -2      1.2
    37   Primal Variables
    38         0       1.2
    39         1       1.2
    40         3       1.2
    41   Dual Variables
    42         0       1.2
    43         1       1.2
    44         3       1.2
    45 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4
     5# ----------------------------------------------------------
     6#   Problem Information
     7# ----------------------------------------------------------
     8Problem:
     9- Name:
     10  Lower bound: -inf
     11  Upper bound: inf
     12  Number of objectives: 2
     13  Number of constraints: 3
     14  Number of variables: 3
     15  Sense: unknown
     16
     17# ----------------------------------------------------------
     18#   Solver Information
     19# ----------------------------------------------------------
     20Solver:
     21- Status: ok
     22  Message:
     23  Termination condition: unsure
     24  ServiceURI:
     25  ServiceName:
     26  InstanceName:
     27  Systime: 0.0
     28  Id: 0
     29
     30# ----------------------------------------------------------
     31#   Solution Information
     32# ----------------------------------------------------------
     33Solution:
     34- number of solutions: 1
     35  number of solutions displayed: 1
     36- Status: unsure
     37  Message: None
     38  Objective:
     39    f0:
     40      Id: -1
     41      Value: 1.2
     42    f1:
     43      Id: -2
     44      Value: 1.2
     45  Variable:
     46    x0:
     47      Id: 0
     48      Value: 1.2
     49    x1:
     50      Id: 1
     51      Value: 1.2
     52    x3:
     53      Id: 3
     54      Value: 1.2
     55  Constraint:
     56    x0:
     57      Id: 0
     58      Dual: 1.2
     59    x1:
     60      Id: 1
     61      Dual: 1.2
     62    x3:
     63      Id: 3
     64      Dual: 1.2
     65  Status description:
     66  Other: {}
  • coopr.opt/trunk/coopr/opt/tests/base/test1_soln.txt

    r1072 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: None
    10   num_objectives: None
    11   num_variables: None
    12   sense: unknown
    13   upper_bound: None
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   status: ok
    18   systime: None
    19   usrtime: None
    20   num_solutions: 1
    21 ----------------------------------------------------------
    22 ------  Solution 1
    23 ----------------------------------------------------------
    24   gap: None
    25   status: unsure
    26   value: None
    27 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4# ----------------------------------------------------------
     5#   Solution Information
     6# ----------------------------------------------------------
     7Solution:
     8- number of solutions: 1
     9  number of solutions displayed: 1
     10- Status: unknown
     11  Variable: No nonzero values
  • coopr.opt/trunk/coopr/opt/tests/base/test2_soln.txt

    r1248 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: None
    10   num_objectives: None
    11   num_variables: None
    12   sense: unknown
    13   upper_bound: None
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   status: ok
    18   systime: None
    19   usrtime: None
    20   num_solutions to display: 0
    21 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4# ----------------------------------------------------------
     5#   Solution Information
     6# ----------------------------------------------------------
     7Solution:
     8- number of solutions: 1
     9  number of solutions displayed: 1
     10- Status: unknown
     11  Variable: No nonzero values
  • coopr.opt/trunk/coopr/opt/tests/base/test3_soln.txt

    r1072 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: None
    10   num_objectives: None
    11   num_variables: None
    12   sense: unknown
    13   upper_bound: None
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   status: ok
    18   systime: None
    19   usrtime: None
    20   num_solutions: 1
    21 ----------------------------------------------------------
    22 ------  Solution 1
    23 ----------------------------------------------------------
    24   gap: None
    25   status: unsure
    26   value: None
    27   Primal Variables
    28         No nonzero values
    29 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4# ----------------------------------------------------------
     5#   Solution Information
     6# ----------------------------------------------------------
     7Solution:
     8- number of solutions: 1
     9  number of solutions displayed: 1
     10- Status: unknown
     11  Variable: No nonzero values
  • coopr.opt/trunk/coopr/opt/tests/base/test4_sol.txt

    r1794 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: 24
    10   num_objectives: 1
    11   num_variables: 32
    12   sense: unknown
    13   upper_bound: None
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   id: 0
    18   message: PICO Solver: final f = 88.200000
    19   status: ok
    20   systime: None
    21   usrtime: None
    22   num_solutions: 1
    23 ----------------------------------------------------------
    24 ------  Solution 1
    25 ----------------------------------------------------------
    26   gap: None
    27   message: PICO Solver: final f = 88.200000
    28   status: unsure
    29   value: None
    30   Primal Variables
    31         v4      46.6666666667
    32         v11     933.333333333
    33         v12     10000.0
    34         v13     10000.0
    35         v14     10000.0
    36         v15     10000.0
    37         v17     100.0
    38         v19     100.0
    39         v21     100.0
    40         v23     100.0
    41         v24     46.6666666667
    42         v25     53.3333333333
    43         v27     100.0
    44         v29     100.0
    45         v31     100.0
    46   Dual Variables
    47         c2      0.126
    48 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4
     5# ----------------------------------------------------------
     6#   Problem Information
     7# ----------------------------------------------------------
     8Problem:
     9- Lower bound: -inf
     10  Upper bound: inf
     11  Number of objectives: 1
     12  Number of constraints: 24
     13  Number of variables: 32
     14  Sense: unknown
     15
     16# ----------------------------------------------------------
     17#   Solver Information
     18# ----------------------------------------------------------
     19Solver:
     20- Status: ok
     21  Message: PICO Solver\x3a final f = 88.200000
     22  Termination condition: unsure
     23  Id: 0
     24
     25# ----------------------------------------------------------
     26#   Solution Information
     27# ----------------------------------------------------------
     28Solution:
     29- number of solutions: 1
     30  number of solutions displayed: 1
     31- Status: unknown
     32  Message: PICO Solver\x3a final f = 88.200000
     33  Variable:
     34    v4:
     35      Id: 4
     36      Value: 46.6666666667
     37    v11:
     38      Id: 11
     39      Value: 933.333333333
     40    v12:
     41      Id: 12
     42      Value: 10000.0
     43    v13:
     44      Id: 13
     45      Value: 10000.0
     46    v14:
     47      Id: 14
     48      Value: 10000.0
     49    v15:
     50      Id: 15
     51      Value: 10000.0
     52    v17:
     53      Id: 17
     54      Value: 100.0
     55    v19:
     56      Id: 19
     57      Value: 100.0
     58    v21:
     59      Id: 21
     60      Value: 100.0
     61    v23:
     62      Id: 23
     63      Value: 100.0
     64    v24:
     65      Id: 24
     66      Value: 46.6666666667
     67    v25:
     68      Id: 25
     69      Value: 53.3333333333
     70    v27:
     71      Id: 27
     72      Value: 100.0
     73    v29:
     74      Id: 29
     75      Value: 100.0
     76    v31:
     77      Id: 31
     78      Value: 100.0
     79  Constraint:
     80    c2:
     81      Id: 2
     82      Dual: 0.126
  • coopr.opt/trunk/coopr/opt/tests/base/test_os.py

    r1768 r1918  
    2121pyutilib.services.TempfileManager.tempdir = currdir
    2222
    23 class OptOSDebug(pyutilib.th.TestCase):
     23class Test(pyutilib.th.TestCase):
    2424
    2525    def setUp(self):
     
    134134        reader = coopr.opt.ReaderFactory("osrl")
    135135        soln = reader(currdir+"test1.OSrL.xml")
    136         soln.write(currdir+"test_os.txt")
     136        soln.write(filename=currdir+"test_os.txt")
    137137        #
    138138        # Compare with baseline
  • coopr.opt/trunk/coopr/opt/tests/base/test_sol.py

    r1768 r1918  
    2020
    2121
    22 class OptSolDebug(pyutilib.th.TestCase):
     22class Test(pyutilib.th.TestCase):
    2323
    2424    def setUp(self):
     
    3636        reader = coopr.opt.ReaderFactory("sol")
    3737        soln = reader(currdir+"test4_sol.sol")
    38         soln.write(currdir+"factory.txt")
     38        soln.write(filename=currdir+"factory.txt")
    3939        self.failUnlessFileEqualsBaseline(currdir+"factory.txt", currdir+"test4_sol.txt")
    4040       
  • coopr.opt/trunk/coopr/opt/tests/base/test_soln.py

    r1768 r1918  
    2020import xml
    2121
    22 class OptSolnDebug(pyutilib.th.TestCase):
     22class Test(pyutilib.th.TestCase):
    2323
    2424    def setUp(self):
    2525        pyutilib.services.TempfileManager.tempdir = currdir
    2626        self.results = coopr.opt.SolverResults()
    27         self.soln = self.results.solution.create()
    28 
    29     def tmp(self):
     27        self.soln = self.results.solution.add()
    3028        self.soln.variable[0]=0.0
    3129        self.soln.variable[1]=0.0
     
    5048        self.failUnlessFileEqualsBaseline(currdir+"write_solution2.txt", currdir+"test2_soln.txt")
    5149
    52     def test_delete_solution(self):
     50    def test_read_solution1(self):
     51        """ Read a SolverResults Object"""
     52        self.results = coopr.opt.SolverResults()
     53        self.results.read(filename=currdir+"test4_sol.txt")
     54        self.results.write(filename=currdir+"read_solution1.out")
     55        if not os.path.exists(currdir+"read_solution1.out"):
     56           self.fail("test_read_solution1 - failed to write read_solution1.out")
     57        self.failUnlessFileEqualsBaseline(currdir+"read_solution1.out", currdir+"test4_sol.txt")
     58
     59    #
     60    # deleting is not supported right now
     61    #
     62    def Xtest_delete_solution(self):
    5363        """ Delete a solution from a SolverResults object """
    5464        self.results.solution.delete(0)
     
    7181           pass
    7282
    73     def test_set_solution_attr_error(self):
     83    #
     84    # This is currently allowed, although soln.variable = True is equivalent to
     85    #   soln.variable.value = True
     86    #
     87    def Xtest_set_solution_attr_error(self):
    7488        """ Create an error with a solution suffix """
    7589        try:
    7690           self.soln.variable = True
    77            self.fail("Expected attribute error failure for 'var'")
     91           self.fail("Expected attribute error failure for 'variable'")
    7892        except AttributeError:
    7993           pass
     
    8195    def test_soln_pprint1(self):
    8296        """ Write a solution with only zero values, using the results 'write()' method """
    83         self.soln.variable.add(0,0.0)
    84         self.soln.variable.add(1,0.0)
    85         self.soln.variable.add(3,0.0)
     97        self.soln.variable[0]=0.0
     98        self.soln.variable[1]=0.0
     99        self.soln.variable[3]=0.0
    86100        self.results.write(filename=currdir+"soln_pprint.txt")
    87101        if not os.path.exists(currdir+"soln_pprint.txt"):
     
    91105    def test_soln_pprint2(self):
    92106        """ Write a solution with only zero values, using the Solution.pprint() method """
    93         self.soln.variable.add(0,0.0)
    94         self.soln.variable.add(1,0.0)
    95         self.soln.variable.add(3,0.0)
     107        self.soln.variable[0]=0.0
     108        self.soln.variable[1]=0.0
     109        self.soln.variable[3]=0.0
    96110        pyutilib.misc.setup_redirect(currdir+"soln_pprint2.out")
    97         self.soln.pprint()
    98         self.soln._variable.pprint()
     111        print self.soln
     112        print self.soln.variable
    99113        pyutilib.misc.reset_redirect()
    100114        self.failUnlessFileEqualsBaseline(currdir+"soln_pprint2.out", currdir+"soln_pprint2.txt")
     
    102116    def test_soln_suffix_iter(self):
    103117        """ Test a suffix iterator """
    104         self.soln.variable.add(0,0.0)
    105         self.soln.variable.add(1,0.1)
    106         self.soln.variable.add(3,0.3)
     118        self.soln.variable[0]=0.0
     119        self.soln.variable[1]=0.1
     120        self.soln.variable[3]=0.3
    107121        i=0
    108         for val in self.soln.variable:
     122        for key in self.soln.variable:
    109123          i=i+1
    110           self.failUnlessEqual(val[1], val[0]/10.0)
     124          self.failUnlessEqual(self.soln.variable[key].value, self.soln.variable[key].id/10.0)
    111125        self.failUnlessEqual(i,len(self.soln.variable))
    112126
    113127    def test_soln_suffix_getiter(self):
    114         self.soln.variable.add("x0",0.0)
    115         self.soln.variable.add(1,0.1)
    116         self.soln.variable.add("x3",0.3)
    117         #print "HERE", self.soln.variable._index.keys()
    118         self.failUnlessEqual(self.soln.variable["x3"],0.3)
    119         self.failUnlessEqual(self.soln.variable[1],0.1)
     128        self.soln.variable["x0"]=0.0
     129        self.soln.variable[1]=0.1
     130        self.soln.variable["x3"]=0.3
     131        self.failUnlessEqual(self.soln.variable["x3"].value,0.3)
     132        #print "HERE",self.soln.variable._names
     133        self.failUnlessEqual(self.soln.variable[1].value,0.1)
    120134
    121135    def test_soln_suffix_setattr(self):
    122         self.soln.variable.add("x(0)",0.0)
    123         self.soln.variable.add("x3",0.3)
    124         self.soln.variable.add("y[1,ab]",0.5)
     136        self.soln.variable["x(0)"] = 0.0
     137        self.soln.variable["x3"]=0.3
     138        self.soln.variable["x3"].slack=0.4
     139        self.soln.variable["y[1,ab]"]=0.5
     140        #self.soln.variable.z[0,'a']=2.0
     141        #print "HERE",self.soln.variable._names
     142        #print "HERE",self.soln.variable.__dict__.keys()
     143        #print "HERE",self.soln.variable.keys()
     144        #print "HERE",self.soln.variable.__getitem__('y[1,ab]')
     145        #print "HERE",repr(self.soln.variable.x)
     146        #print "HERE",repr(self.soln.variable.x[0])
     147        #print "HERE",repr(self.soln.variable.y)
     148        #print "HERE",repr(self.soln.variable.y[1,'ab'])
     149        #print "HERE",repr(self.soln.variable.z)
     150        #print "HERE",repr(self.soln.variable.z[0,'a'])
     151        #print "HERE",repr(self.soln.variable.foo('x(0)'))
    125152        #self.soln.pprint()
    126153        #print "HERE", self.soln.variable._index.keys()
    127154        self.failUnlessEqual(self.soln.variable.x.keys(),[0])
    128         self.failUnlessEqual(self.soln.variable.x[0],0.0)
    129         self.failUnlessEqual(self.soln.variable.x3,0.3)
     155        self.failUnlessEqual(self.soln.variable.x[0].value,0.0)
     156        self.failUnlessEqual(self.soln.variable.x3.value,0.3)
     157        self.failUnlessEqual(self.soln.variable.x3.slack,0.4)
    130158        self.failUnlessEqual(self.soln.variable.y.keys(),[(1,'ab')])
    131         self.failUnlessEqual(self.soln.variable.y[1,'ab'],0.5)
    132 
     159        self.failUnlessEqual(self.soln.variable.y[1,'ab'].value,0.5)
    133160
    134161
    135162if __name__ == "__main__":
    136    unittest.main()
     163    import pyutilib.misc
     164    #sys.settrace(pyutilib.misc.traceit)
     165    unittest.main()
  • coopr.opt/trunk/coopr/opt/tests/colin/test1_ps.txt

    r1254 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: 0
    10   num_objectives: 1
    11   num_variables: None
    12   sense: minimize
    13   upper_bound: 1.92623278941e-7
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   curr_iteration: 71
    18   final_delta: 8.24113785813e-6
    19   status: ok
    20   num_solutions: 1
    21 ----------------------------------------------------------
    22 ------  Solution 1
    23 ----------------------------------------------------------
    24   gap: None
    25   status: bestSoFar
    26   value: 1.92623278941e-7
    27   Primal Variables
    28         1       -1.92622619169e-7
    29         2       1.50000081226
    30         3       -1.99999209991
    31 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4
     5# ----------------------------------------------------------
     6#   Problem Information
     7# ----------------------------------------------------------
     8Problem:
     9- Lower bound: -inf
     10  Upper bound: 1.92623278941e-07
     11  Number of objectives: 1
     12  Number of constraints: 0
     13  Number of variables: 4
     14  Sense: minimize
     15
     16# ----------------------------------------------------------
     17#   Solver Information
     18# ----------------------------------------------------------
     19Solver:
     20- Status: ok
     21  Termination condition: minStepLength
     22  Termination message: 8.24113785813e-06 < 1e-05
     23  Number of iterations: 71
     24  Final step length: 8.24113785813e-06
     25
     26# ----------------------------------------------------------
     27#   Solution Information
     28# ----------------------------------------------------------
     29Solution:
     30- number of solutions: 1
     31  number of solutions displayed: 1
     32- Status: bestSoFar
     33  Objective:
     34    f:
     35      Id: 0
     36      Value: 1.92623278941e-07
     37  Variable:
     38    x1:
     39      Id: 1
     40      Value: -1.92622619169e-07
     41    x2:
     42      Id: 2
     43      Value: 1.50000081226
     44    x3:
     45      Id: 3
     46      Value: -1.99999209991
  • coopr.opt/trunk/coopr/opt/tests/colin/test2_ps.txt

    r1254 r1918  
    1 ==========================================================
    2 ---  Solver Results                                    ---
    3 ==========================================================
    4 ----------------------------------------------------------
    5 ------  Problem Information                         ------
    6 ----------------------------------------------------------
    7   lower_bound: None
    8   name: None
    9   num_constraints: 0
    10   num_objectives: 1
    11   num_variables: None
    12   sense: minimize
    13   upper_bound: 0.0708829578448
    14 ----------------------------------------------------------
    15 ------  Solver Information                          ------
    16 ----------------------------------------------------------
    17   curr_iteration: 9
    18   final_delta: 2.37037037037
    19   status: ok
    20   num_solutions: 1
    21 ----------------------------------------------------------
    22 ------  Solution 1
    23 ----------------------------------------------------------
    24   gap: None
    25   status: bestSoFar
    26   value: 0.0708829578448
    27   Primal Variables
    28         1       -0.0333333333333
    29         2       1.6
    30         3       -1.59259259259
    31 ----------------------------------------------------------
     1# ==========================================================
     2# = Solver Results                                         =
     3# ==========================================================
     4
     5# ----------------------------------------------------------
     6#   Problem Information
     7# ----------------------------------------------------------
     8Problem:
     9- Lower bound: -inf
     10  Upper bound: 0.0708829578448
     11  Number of objectives: 1
     12  Number of constraints: 0
     13  Number of variables: 4
     14  Sense: minimize
     15
     16# ----------------------------------------------------------
     17#   Solver Information
     18# ----------------------------------------------------------
     19Solver:
     20- Status: ok
     21  Termination condition: minFunctionValue
     22  Termination message: 0.0708829578448 < 0.1
     23  Number of iterations: 9
     24  Final step length: 2.37037037037
     25
     26# ----------------------------------------------------------
     27#   Solution Information
     28# ----------------------------------------------------------
     29Solution:
     30- number of solutions: 1
     31  number of solutions displayed: 1
     32- Status: bestSoFar
     33  Objective:
     34    f:
     35      Id: 0
     36      Value: 0.0708829578448
     37  Variable:
     38    x1:
     39      Id: 1
     40      Value: -0.0333333333333
     41    x2:
     42      Id: 2
     43      Value: 1.6
     44    x3:
     45      Id: 3
     46      Value: -1.59259259259
  • coopr.opt/trunk/coopr/opt/tests/colin/test_parallel.py

    r1794 r1918  
    131131        self.ps.reset()
    132132        results = self.ps.solve(logfile=currdir+"test_solve1.log")
    133         results.write(currdir+"test_solve1.txt",times=False)
     133        results.write(filename=currdir+"test_solve1.txt",times=False)
    134134        self.failUnlessFileEqualsBaseline(currdir+"test_solve1.txt", currdir+"test1_ps.txt")
    135135        if os.path.exists(currdir+"test_solve1.log"):
     
    144144        mngr = coopr.opt.parallel.SolverManagerFactory("serial")
    145145        results = mngr.solve(opt=self.ps, logfile=currdir+"test_solve2.log")
    146         results.write(currdir+"test_solve2.txt",times=False)
     146        results.write(filename=currdir+"test_solve2.txt",times=False)
    147147        self.failUnlessFileEqualsBaseline(currdir+"test_solve2.txt", currdir+"test1_ps.txt")
    148148        if os.path.exists(currdir+"test_solve2.log"):
     
    216216        mngr = SolverManager_DelayedSerial()
    217217        results = mngr.solve(opt=self.ps, logfile=currdir+"test_solve4.log")
    218         results.write(currdir+"test_solve4.txt",times=False)
     218        results.write(filename=currdir+"test_solve4.txt",times=False)
    219219        self.failUnlessFileEqualsBaseline(currdir+"test_solve4.txt", currdir+
    220220"test1_ps.txt")
  • coopr.opt/trunk/coopr/opt/tests/colin/test_ps.py

    r1768 r1918  
    5656        self.ps.reset()
    5757        results = self.ps.solve(logfile=currdir+"test_solve1.log")
    58         results.write(currdir+"test_solve1.txt",times=False)
     58        results.write(filename=currdir+"test_solve1.txt",times=False)
    5959        self.failUnlessFileEqualsBaseline(currdir+"test_solve1.txt", currdir+"test1_ps.txt")
    6060        if os.path.exists(currdir+"test_solve1.log"):
     
    6969        self.ps.min_function_value = 1e-1
    7070        results = self.ps.solve(logfile=currdir+"test_solve2.log")
    71         results.write(currdir+"test_solve2.txt",times=False)
     71        results.write(filename=currdir+"test_solve2.txt",times=False)
    7272        self.failUnlessFileEqualsBaseline(currdir+"test_solve2.txt", currdir+"test2_ps.txt")
    7373        if os.path.exists(currdir+"test_solve2.log"):
Note: See TracChangeset for help on using the changeset viewer.