Changeset 3068


Ignore:
Timestamp:
Oct 3, 2010 11:56:20 AM (11 years ago)
Author:
wehart
Message:

Adding support for non-mutable parameters, which are now
the default. These are simply parameters that are stored as
dictionaries with float values rather than ParamValue? values.

There were many changes to the CUTE test examples to
use the value() function, which works with either mutable or
immutable Param objects. There were similar changes to other tests.
These changes allow us to make mutable or immutable the default
for Param objects without changing our tests.

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

Legend:

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

    r3067 r3068  
    5555
    5656        Block.__init__(self, ctype=Model)
    57         #
     57        #
    5858        # the _name_varmap and _name_conmap dictionarys are assigned when
    5959        # the problem definition file is written, i.e., via the write()
    6060        # command. intent is to map names that will be coming back from
    6161        # a solver into Pyomo variables. Values are of type _VarValue.
    62         #
     62        #
    6363        self._name_varmap={}
    6464        self._name_conmap={}
     
    7878        #
    7979        self.statistics = Container()
    80         #
     80        #
    8181        # We make the default behavior of has_capabilities to lie and return
    8282        # True. We do this to allow the richest output formats when no
     
    8686        # We define _tempTrue since using self.has_capability = lambda x: True
    8787        # causes pickling errors.
    88         #
     88        #
    8989        self.has_capability = _tempTrue
    9090
  • coopr.pyomo/trunk/coopr/pyomo/base/block.py

    r3041 r3068  
    251251        #
    252252        # We hard-code the order of the core Pyomo modeling
    253         # components, to ensure that the output follows the logical
    254         # expected by a user.
     253        # components, to ensure that the output follows the logical order
     254        # that expected by a user.
    255255        #
    256256        items = [Set, RangeSet, Param, Var, Objective, Constraint, Block]
  • coopr.pyomo/trunk/coopr/pyomo/base/param.py

    r3066 r3068  
    7676        self.doc         = kwd.pop('doc', None )
    7777        self.domain      = kwd.pop('within', Any )
     78        self.mutable     = kwd.pop('mutable', False )
    7879        self.name        = kwd.pop('name', 'unknown')
    7980        defaultval       = kwd.pop('default', None )
     
    107108           tmp.sort()
    108109           for key in tmp:
    109              val = self._paramval[key].value
     110             if self.mutable:
     111                val = self._paramval[key].value
     112             else:
     113                val = self._paramval[key]
    110114             print >>ostream, "\t"+str(key)+" : "+str(val)
    111115        if self._default.value is not None and not self._default.value is None:
     
    154158
    155159    def __setitem__(self,ndx,val):
    156 
    157160        if self._index_set is not None:
    158            # this is a "hack", in that we still need to check for legal
    159            # sub-components in the input index.
    160            if ndx in self._paramval:
    161                 self._paramval[ndx].value = val
    162            else:
    163                 self._paramval[ndx]= _ParamValue(
    164                   name   = create_name(self.name,ndx),
    165                   domain = self.domain,
    166                   value  = val
    167                 )
    168            return
    169 
     161            # this is a "hack", in that we still need to check for legal
     162            # sub-components in the input index.
     163            if self.mutable:
     164                if ndx in self._paramval:
     165                    self._paramval[ndx].value = val
     166                else:
     167                    self._paramval[ndx]= _ParamValue(
     168                        name   = create_name(self.name,ndx),
     169                        domain = self.domain,
     170                        value  = val
     171                        )
     172            else:
     173                self._paramval[ndx]= val
     174            return
     175        #
     176        if type(ndx) is tuple and len(ndx) == 1 and ndx[0] in self._index:
     177            ndx = ndx[0]
    170178        if (None in self._index) and (ndx is not None):
    171179            # allow for None indexing if this is truly a singleton
    172180            msg = "Cannot set an array value in the simple parameter '%s'"
    173181            raise KeyError, msg % self.name
    174 
     182        #
    175183        if ndx not in self._index:
    176184            msg = "Cannot set the value of array parameter '%s' with invalid" \
    177185                  "index '%s'"
    178186            raise KeyError, msg % ( self.name, str(ndx) )
    179 
    180         if ndx in self._paramval:
    181             self._paramval[ndx].value = val
    182         else:
    183             self._paramval[ndx]= _ParamValue(
    184               name   = create_name(self.name,ndx),
    185               domain = self.domain,
    186               value  = val
    187             )
    188 
     187        #
    189188        if not self._valid_indexed_value(val,ndx,False):
    190189            msg = "Invalid parameter value: %s[%s] = '%s'"
    191190            raise ValueError, msg % ( self.name, str(ndx), str(val) )
     191        #
     192        if self.mutable:
     193            if ndx in self._paramval:
     194                self._paramval[ndx].value = val
     195            else:
     196                self._paramval[ndx]= _ParamValue(
     197                    name   = create_name(self.name,ndx),
     198                    domain = self.domain,
     199                    value  = val
     200                    )
     201        else:
     202            self._paramval[ndx] = val
    192203
    193204    def construct(self, data=None):
     
    254265                        else:
    255266                            tmpkey=key
    256 
    257                         self._valid_indexed_value(data[key],key,True)
    258                         self._paramval[tmpkey] = _ParamValue(
    259                           name   = create_name(_name,key),
    260                           domain = _domain,
    261                           value  = data[key]
    262                         )
     267                        self.__setitem__(key, data[key])
    263268                #
    264269                # Initialize with initialization data.
     
    267272                    if type(self._initialize) is dict:
    268273                        for key in self._initialize:
    269                             self._paramval[key] = _ParamValue(
    270                               name   = create_name(_name,key),
    271                               domain = _domain,
    272                               value=self._initialize[key]
    273                             )
    274                             self._valid_indexed_value(
    275                               self._initialize[key],
    276                               key,
    277                               True
    278                             )
     274                            self.__setitem__(key, self._initialize[key])
    279275                    else:
    280276                        for key in self._index:
    281                             self._paramval[key] = _ParamValue(
    282                               name=create_name(_name,key),
    283                               domain=_domain,
    284                               value=self._initialize
    285                             )
    286                         for key in self._index:
    287                             self._valid_indexed_value(self._initialize,key,True)
    288                             # Only apply this test once
    289                             break
     277                            self.__setitem__(key, self._initialize)
    290278        #
    291279        # Construct using the rule
     
    316304                    tmp = tuple(tmp)
    317305                    tval = self._initialize(*tmp)
    318                     self._paramval[val] = _ParamValue(
    319                       name=tname,
    320                       domain=_domain,
    321                       value=tval
    322                     )
    323                     self._valid_indexed_value(tval,val,True)
     306                    self.__setitem__(val, tval)
    324307
    325308    def _valid_indexed_value(self,value,index, use_exception):
     
    360343        tmp = {}
    361344        for key in self.keys():
    362             tmp[key] = self._paramval[key].value
     345            if self.mutable:
     346                tmp[key] = self._paramval[key].value
     347            else:
     348                tmp[key] = self._paramval[key]
    363349        return tmp
    364350
     
    414400    def set_value(self, value):
    415401        for key in self._paramval:
    416             self._paramval[key].value = value
    417             self._valid_indexed_value(value,key,True)
    418             #self._valid_value(value,key,True)
     402            self.__setitem__(key,value)
    419403
    420404    def check_values(self):         #pragma:nocover
     
    422406        # Validate the values
    423407        #
    424         for val in self._paramval:
    425             if val not in self._index:
     408        for key in self._paramval:
     409            if key not in self._index:
    426410                msg = "Undefined value for parameter %s[%s]"
    427                 raise ValueError, msg % ( self.name, str(val) )
    428 
    429             if not self._valid_indexed_value(
    430                                       self._paramval[val].value, val, False ):
     411                raise ValueError, msg % ( self.name, str(key) )
     412
     413            if self.mutable:
     414                val = self._paramval[key].value
     415            else:
     416                val = self._paramval[key]
     417            if not self._valid_indexed_value( val, key, False ):
    431418                msg = "Parameter %s[%s] failed validation test.  Value: %s"
    432                 raise ValueError, msg % (
    433                         self.name, str(val), str(self._paramval[val].value) )
     419                raise ValueError, msg % ( self.name, str(key), str(tval) )
    434420
    435421    def reset(self):
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/aljazzaf_cute.py

    r2882 r3068  
    4040model.Biga = Param(initialize=100.0)
    4141def F_rule(model):
    42         return (model.Biga.value**2-1.0)/(model.N.value-1)
     42        return (value(model.Biga)**2-1.0)/(value(model.N)-1)
    4343model.F = Param(initialize=F_rule)
    4444def F2_rule(model):
    45         return (model.Biga.value**2-1.0)/(model.Biga.value*(model.N.value-1))
     45        return (value(model.Biga)**2-1.0)/(value(model.Biga)*(value(model.N)-1))
    4646model.F2 = Param(initialize=F2_rule)
    4747model.S = RangeSet(1,model.N)
    4848def A_rule(i,model):
    49         return model.Biga.value-(i-1)*model.F2.value
     49        return value(model.Biga)-(i-1)*value(model.F2)
    5050model.A = Param(model.S, initialize=A_rule)
    5151def B_rule(i,model):
    52         return (i-1)*model.F.value+1.0
     52        return (i-1)*value(model.F)+1.0
    5353model.B = Param(model.S, initialize=B_rule)
    5454
     
    5858model.SS2 = RangeSet(model.N1+1,model.N)
    5959def f(model):
    60         sum1 = sum ([model.A[i].value*(model.x[i]+1.0)**2 for i in model.SS1])
    61         sum2 = sum ([model.A[i].value*(model.x[i]-1.0)**2 for i in model.SS2])
    62         return model.A[1].value*(model.x[1]-0.5)**2 + sum1 + sum2
     60        sum1 = sum ([value(model.A[i])*(model.x[i]+1.0)**2 for i in model.SS1])
     61        sum2 = sum ([value(model.A[i])*(model.x[i]-1.0)**2 for i in model.SS2])
     62        return value(model.A[1])*(model.x[1]-0.5)**2 + sum1 + sum2
    6363model.f = Objective(rule=f,sense=minimize)
    6464
    6565def cons1(model):
    66         sum1 = sum ([model.B[i].value*(model.x[i]-0.0)**2 for i in model.SS1])
    67         sum2 = sum ([model.B[i].value*(model.x[i]-1.0)**2 for i in model.SS2])
    68         return -model.B[1].value*model.x[1]+model.B[1].value + sum1 + sum2 == 0
     66        sum1 = sum ([value(model.B[i])*(model.x[i]-0.0)**2 for i in model.SS1])
     67        sum2 = sum ([value(model.B[i])*(model.x[i]-1.0)**2 for i in model.SS2])
     68        return -value(model.B[1])*model.x[1]+value(model.B[1]) + sum1 + sum2 == 0
    6969model.cons1 = Constraint(rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/artif_cute.py

    r2882 r3068  
    4444model.x = Var(model.S, initialize=1.0)
    4545def fix1(i,model):
    46         if i == model.N.value+1 or i == 0:
     46        if i == value(model.N)+1 or i == 0:
    4747                model.x[i] = 0
    4848                model.x[i].fixed=True
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/arwhead_cute.py

    r2882 r3068  
    4242def f(model):
    4343        expsum1 = sum ([(-4*model.x[i]+3.0) for i in model.SS])
    44         expsum2 = sum ([(model.x[i]**2+model.x[model.N.value]**2)**2 for i in model.SS])
     44        expsum2 = sum ([(model.x[i]**2+model.x[value(model.N)]**2)**2 for i in model.SS])
    4545        return expsum1 + expsum2
    4646model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/bard_cute.py

    r2882 r3068  
    4949model.v = Param(model.S,initialize=v_rule)
    5050def w_rule(i,model):
    51         return min([model.u[i].value,model.v[i].value])
     51        return min([value(model.u[i]),value(model.v[i])])
    5252model.w = Param(model.S,initialize=w_rule)
    5353
     
    5656
    5757def f(model):
    58         return sum ([( model.y[i].value-(model.x[1]+model.u[i].value/(model.v[i].value*model.x[2]+model.w[i].value*model.x[3])) )**2 for i in model.S])
     58        return sum ([( value(model.y[i])-(model.x[1]+value(model.u[i])/(value(model.v[i])*model.x[2]+value(model.w[i])*model.x[3])) )**2 for i in model.S])
    5959model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/bdqrtic_cute.py

    r2882 r3068  
    4343def f(model):
    4444        expsum1 = sum ([(-4*model.x[i]+3.0)**2 for i in model.SS])
    45         expsum2 = sum ([(model.x[i]**2+2*model.x[i+1]**2+3*model.x[i+2]**2+4*model.x[i+3]**2+5*model.x[model.N.value]**2)**2 for i in model.SS])
     45        expsum2 = sum ([(model.x[i]**2+2*model.x[i+1]**2+3*model.x[i+2]**2+4*model.x[i+3]**2+5*model.x[value(model.N)]**2)**2 for i in model.SS])
    4646        return expsum1 + expsum2
    4747model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/biggs5_cute.py

    r2882 r3068  
    4242model.xinit = Param(model.S)
    4343def init1(i,model):
    44         return model.xinit[i].value
     44        return value(model.xinit[i])
    4545model.x = Var(model.S, initialize=init1)
    4646
     
    5151                - model.x[4]*exp(-0.1*i*model.x[2]) + model.x[6]*exp(-0.1*i*model.x[5]))**2
    5252        return sum1
    53         #return sum ([(-exp(-0.1*i)+5*exp(-i)-3*exp(-0.4*i)+ model.x[3].value*exp(-0.1*i*model.x[1].value)\
    54         #- model.x[4].value*exp(-0.1*i*model.x[2].value) + model.x[6].value*exp(-0.1*i*model.x[5].value))**2 for i in model.SS])
    5553model.f = Objective(rule=f,sense=minimize)
    5654
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/blockqp2_cute.py

    r2882 r3068  
    5757                sum_cexpr_2 += model.z[j]
    5858        cexp = sum_cexpr_1 + sum_cexpr_2
    59         return (model.b.value + 1, cexp, None)
     59        return (value(model.b)+ 1, cexp, None)
    6060model.cons1 = Constraint(rule=cons1)
    6161
     
    6464        for j in model.Sb:
    6565                csum += model.z[j]
    66         return model.x[i] - model.y[i] + csum == model.b.value
     66        return model.x[i] - model.y[i] + csum == value(model.b)
    6767model.cons2 = Constraint(model.Sn, rule=cons2)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/brownden_cute.py

    r2882 r3068  
    5353
    5454def f(model):
    55         expa = sum ([( (model.x[1]+model.t[i]*model.x[2]-exp(model.t[i].value))**2 \
    56         + (model.x[3]+model.x[4]*sin(model.t[i].value)-cos(model.t[i].value))**2 )**2 for i in model.St])
     55        expa = sum ([( (model.x[1]+model.t[i]*model.x[2]-exp(value(model.t[i])))**2 \
     56        + (model.x[3]+model.x[4]*sin(value(model.t[i]))-cos(value(model.t[i])))**2 )**2 for i in model.St])
    5757        return expa
    5858model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/bt13_cute.py

    r2882 r3068  
    4545model.x_init = Param(model.S)
    4646def xinit(i,model):
    47         return model.x_init[i].value
     47        return value(model.x_init[i])
    4848model.x = Var(model.S, initialize=xinit)
    4949
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/byrdsphr_cute.py

    r2882 r3068  
    3737model.xinit = Param(model.S)
    3838def xin(i,model):
    39         return model.xinit[i].value
     39        return value(model.xinit[i])
    4040model.x = Var(model.S, initialize=xin)
    4141
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/cantilvr_cute.py

    r2882 r3068  
    4444
    4545def cons1(model):
    46         see = sum ([model.num[i].value/model.x[i]**3 for i in model.S]) 
     46        see = sum ([value(model.num[i])/model.x[i]**3 for i in model.S]) 
    4747        return see - 1.0 <= 0
    4848model.cons1 = Constraint(rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/catena_cute.py

    r2882 r3068  
    4545
    4646def len_rule(model):
    47         return model.bl.value*(model.N.value+1)*model.fract.value
     47        return value(model.bl)*(value(model.N)+1)*value(model.fract)
    4848def mass_rule(model):
    49         return model.tmass.value/(model.N.value+1.0)
     49        return value(model.tmass)/(value(model.N)+1.0)
    5050def mg_rule(model):
    51         return model.mass.value*model.gamma.value
     51        return value(model.mass)*value(model.gamma)
    5252model.length = Param(initialize=len_rule)
    5353model.mass = Param(initialize=mass_rule)
     
    5959
    6060def x_rule(i,model):
    61         return i*model.length.value/(model.N.value+1.0)
     61        return i*value(model.length)/(value(model.N)+1.0)
    6262def y_rule(i,model):
    63         return -i*model.length.value/(model.N.value+1.0)
     63        return -i*value(model.length)/(value(model.N)+1.0)
    6464#def fix1(i,model):
    6565#       if i == 0:
     
    8282        obsum = 0
    8383        for i in model.So:
    84                 obsum += model.mg.value*model.y[i]
    85         obsum +=  model.mg.value*model.y[model.N.value+1]/2.0
    86         expr = model.mg.value*model.y[0]/2.0 + obsum
     84                obsum += value(model.mg)*model.y[i]
     85        obsum +=  value(model.mg)*model.y[value(model.N)+1]/2.0
     86        expr = value(model.mg)*model.y[0]/2.0 + obsum
    8787        return expr
    8888model.f = Objective(rule=f,sense=minimize)
     
    9090def cons1(i,model):
    9191        expr = (model.x[i]-model.x[i-1])**2 + (model.y[i]-model.y[i-1])**2 + (model.z[i]-model.z[i-1])**2
    92         return expr == model.bl.value**2
     92        return expr == value(model.bl)**2
    9393model.cons1 = Constraint(model.Sc, rule=cons1)
    9494
     
    100100        return model.z[0] == 0.0
    101101def fix4(model):
    102         return model.x[model.N.value+1] == model.length.value
     102        return model.x[value(model.N)+1] == value(model.length)
    103103model.xc = Constraint(rule=fix1)
    104104model.yc = Constraint(rule=fix2)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/chaconn1_cute.py

    r2882 r3068  
    3838model.xinit = Param(model.S)
    3939def xit(i,model):
    40         return model.xinit[i].value
     40        return value(model.xinit[i])
    4141model.x = Var(model.S,initialize=xit)
    4242model.u = Var()
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/chaconn2_cute.py

    r2882 r3068  
    3838model.xinit = Param(model.S)
    3939def xit(i,model):
    40         return model.xinit[i].value
     40        return value(model.xinit[i])
    4141model.x = Var(model.S,initialize=xit)
    4242model.u = Var()
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/chemrctb_cute.py

    r2882 r3068  
    4949model.h = Param(initialize=h_rule)
    5050def ct1_rule(model):
    51         return -model.h.value*model.pe.value
     51        return -value(model.h)*value(model.pe)
    5252model.ct1 = Param(initialize=ct1_rule)
    5353def cti1_rule(model):
    54         return 1/model.h.value + 1/((model.h.value**2)*model.pe.value)
     54        return 1/value(model.h) + 1/((value(model.h)**2)*value(model.pe))
    5555model.cti1 = Param(initialize=cti1_rule)
    5656def cti_rule(model):
    57         return -1/model.h.value-2/((model.h.value**2)*model.pe.value)
     57        return -1/value(model.h)-2/((value(model.h)**2)*value(model.pe))
    5858model.cti = Param(initialize=cti_rule)
    5959
     
    6666
    6767def cons1(model):
    68         return (model.ct1.value*model.t[2]-model.t[1]+model.h.value*model.pe.value) == 0
     68        return (value(model.ct1)*model.t[2]-model.t[1]+value(model.h)*value(model.pe)) == 0
    6969model.cons1 = Constraint(rule=cons1)
    7070
    7171model.SS = RangeSet(2,model.n-1)
    7272def cons2(i,model):
    73         return (model.d.value*(model.b.value+1-model.t[i])*exp(model.gamma.value-model.gamma.value/model.t[i])+model.cti1.value*model.t[i-1]\
    74         +model.cti.value*model.t[i]+model.t[i+1]/(model.h.value**2*model.pe.value)) == 0
     73        return (value(model.d)*(value(model.b)+1-model.t[i])*exp(value(model.gamma)-value(model.gamma)/model.t[i])+value(model.cti1)*model.t[i-1]\
     74        +value(model.cti)*model.t[i]+model.t[i+1]/(value(model.h)**2*value(model.pe))) == 0
    7575model.cons2 = Constraint(model.SS,rule=cons2)
    7676
    7777def cons3(model):
    78         return (model.t[model.n.value]-model.t[model.n.value-1]) == 0
     78        return (model.t[value(model.n)]-model.t[value(model.n)-1]) == 0
    7979model.cons3 = Constraint(rule=cons3)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/corkscrw_cute.py

    r2882 r3068  
    3939
    4040def h_rule(model):
    41         return model.xt.value/model.t.value
     41        return value(model.xt)/value(model.t)
    4242model.h = Param(initialize=h_rule)
    4343def w_rule(model):
    44         return model.xt.value*(model.t.value+1.0)/2.0
     44        return value(model.xt)*(value(model.t)+1.0)/2.0
    4545model.w = Param(initialize=w_rule)
    4646
    4747def fmax_rule(model):
    48         return model.xt.value/model.t.value
     48        return value(model.xt)/value(model.t)
    4949model.fmax = Param(initialize=fmax_rule)
    5050
     
    5353
    5454def x_rule(i,model):
    55         return i*model.h.value
     55        return i*value(model.h)
    5656def x_bound(i,model):
    5757        l = 0.0
    58         u = model.xt.value
     58        u = value(model.xt)
    5959        return (l,u)
    6060model.x = Var(model.S, bounds=x_bound, initialize=x_rule)
     
    6666
    6767def u_bound(i,model):
    68         l = -model.fmax.value
    69         u = model.fmax.value
     68        l = -value(model.fmax)
     69        u = value(model.fmax)
    7070        return (l,u)
    7171model.ux = Var(model.SS, bounds=u_bound)
     
    8585        model.vz[0] = 0.0
    8686        model.vz[0].fixed=True
    87         model.vx[model.t.value] = 0.0
    88         model.vx[model.t.value].fixed=True
    89         model.vy[model.t.value] = 0.0
    90         model.vy[model.t.value].fixed=True
    91         model.vz[model.t.value] = 0.0
    92         model.vz[model.t.value].fixed=True
     87        model.vx[value(model.t)] = 0.0
     88        model.vx[value(model.t)].fixed=True
     89        model.vy[value(model.t)] = 0.0
     90        model.vy[value(model.t)].fixed=True
     91        model.vz[value(model.t)] = 0.0
     92        model.vz[value(model.t)].fixed=True
    9393model.fixRules = Constraint(rule=fixRules)
    9494
    9595def f(model):
    96         return sum ([(i*model.h.value/model.w.value)*(model.x[i] - model.xt.value)**2 for i in model.SS])
     96        return sum ([(i*value(model.h)/value(model.w))*(model.x[i] - value(model.xt))**2 for i in model.SS])
    9797model.f = Objective(rule=f,sense=minimize)
    9898
    9999def acx(i,model):
    100         return model.mass.value*(model.vx[i]-model.vx[i-1])/model.h.value - model.ux[i] == 0
     100        return value(model.mass)*(model.vx[i]-model.vx[i-1])/value(model.h) - model.ux[i] == 0
    101101model.acx = Constraint(model.SS, rule=acx)
    102102def acy(i,model):
    103         return model.mass.value*(model.vy[i]-model.vy[i-1])/model.h.value - model.uy[i] == 0
     103        return value(model.mass)*(model.vy[i]-model.vy[i-1])/value(model.h) - model.uy[i] == 0
    104104model.acy = Constraint(model.SS, rule=acy)
    105105def acz(i,model):
    106         return model.mass.value*(model.vz[i]-model.vz[i-1])/model.h.value - model.uz[i] == 0
     106        return value(model.mass)*(model.vz[i]-model.vz[i-1])/value(model.h) - model.uz[i] == 0
    107107model.acz = Constraint(model.SS, rule=acz)
    108108def psx(i,model):
    109         return (model.x[i]-model.x[i-1])/model.h.value - model.vx[i] == 0
     109        return (model.x[i]-model.x[i-1])/value(model.h) - model.vx[i] == 0
    110110model.psx = Constraint(model.SS, rule=psx)
    111111def psy(i,model):
    112         return (model.y[i]-model.y[i-1])/model.h.value - model.vy[i] == 0
     112        return (model.y[i]-model.y[i-1])/value(model.h) - model.vy[i] == 0
    113113model.psy = Constraint(model.SS, rule=psy)
    114114def psz(i,model):
    115         return (model.z[i]-model.z[i-1])/model.h.value - model.vz[i] == 0
     115        return (model.z[i]-model.z[i-1])/value(model.h) - model.vz[i] == 0
    116116model.psz = Constraint(model.SS, rule=psz)
    117117def sc(i,model):
    118         return (model.y[i] - sin(model.x[i]))**2 + (model.z[i] - cos(model.x[i]))**2 - model.tol.value**2 <= 0
     118        return (model.y[i] - sin(model.x[i]))**2 + (model.z[i] - cos(model.x[i]))**2 - value(model.tol)**2 <= 0
    119119model.sc = Constraint(model.SS, rule=sc)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/cresc100_cute.py

    r2882 r3068  
    4747
    4848def cons1(i,model):
    49         exp1 = (model.v1+model.a*model.d*cos(model.t)-model.x[i].value)**2 + (model.w1+model.a*model.d*sin(model.t)-model.y[i].value)**2 - (model.d+model.r)**2
     49        exp1 = (model.v1+model.a*model.d*cos(model.t)-value(model.x[i]))**2 + (model.w1+model.a*model.d*sin(model.t)-value(model.y[i]))**2 - (model.d+model.r)**2
    5050        return exp1 <= 0.0
    5151model.cons1 = Constraint(model.S,rule=cons1)
    5252
    5353def cons2(i,model):
    54         exp2 = (model.v1-model.x[i].value)**2 + (model.w1-model.y[i].value)**2 - (model.a*model.d+model.r)**2
     54        exp2 = (model.v1-value(model.x[i]))**2 + (model.w1-value(model.y[i]))**2 - (model.a*model.d+model.r)**2
    5555        return exp2 >= 0.0
    5656model.cons2 = Constraint(model.S,rule=cons2)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/csfi2_cute.py

    r2882 r3068  
    4444
    4545def thick_bound(model):
    46         l = model.minthick.value
     46        l = value(model.minthick)
    4747        return (l,None)
    4848model.thick = Var(bounds=thick_bound, initialize=0.5)
     
    5050model.len = Var(bounds=(0.0,None), initialize=0.5)
    5151def tph_bound(model):
    52         l = model.mintph.value
     52        l = value(model.mintph)
    5353        return (l,None)
    5454model.tph = Var(bounds=tph_bound, initialize=0.5)
     
    6666model.cons2 = Constraint(rule=cons2)
    6767def cons3(model):
    68         return model.wid/model.thick <= model.maxaspr.value
     68        return model.wid/model.thick <= value(model.maxaspr)
    6969model.cons3 = Constraint(rule=cons3)
    7070def cons4(model):
    71         return 0.0 <= model.thick*model.wid - model.minarea.value <= model.maxarea.value-model.minarea.value
     71        return 0.0 <= model.thick*model.wid - value(model.minarea) <= value(model.maxarea) - value(model.minarea)
    7272model.cons4 = Constraint(rule=cons4)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/cvxqp3_cute.py

    r2882 r3068  
    3636
    3737def f(model):
    38         return sum ([(model.x[i]+model.x[((2*i-1) % model.N.value)+1]+model.x[((3*i-1) % model.N.value)+1])**2*i/2.0 for i in model.S])
     38        return sum ([(model.x[i]+model.x[((2*i-1) % value(model.N))+1]+model.x[((3*i-1) % value(model.N))+1])**2*i/2.0 for i in model.S])
    3939model.f = Objective(rule=f,sense=minimize)
    4040def cons1(i,model):
    41         return model.x[i]+2*model.x[((4*i-1) % model.N.value)+1] + 3*model.x[((5*i-1)   % model.N.value)+1] - 6.0 == 0
     41        return model.x[i]+2*model.x[((4*i-1) % value(model.N))+1] + 3*model.x[((5*i-1)  % value(model.N))+1] - 6.0 == 0
    4242model.cons1 = Constraint(model.SS, rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/demymalo_cute.py

    r2882 r3068  
    3838model.xinit = Param(model.S)
    3939def xit(i,model):
    40         return model.xinit[i].value
     40        return value(model.xinit[i])
    4141model.x = Var(model.S,initialize=xit)
    4242model.u = Var()
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/denschnc_cute.py

    r2882 r3068  
    3939model.xinit = Param(model.S)
    4040def xit(i,model):
    41         return model.xinit[i].value
     41        return value(model.xinit[i])
    4242model.x = Var(model.S, initialize=xit)
    4343
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/dixchlng_cute.py

    r2882 r3068  
    3636model.x_init = Param(model.S)
    3737def xit(i,model):
    38         return model.x_init[i].value
     38        return value(model.x_init[i])
    3939model.x = Var(model.S, initialize=xit)
    4040
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/dixmaana_cute.py

    r2882 r3068  
    5656
    5757def f(model):
    58         exp1 = sum ([model.alpha.value*model.x[i]**2*(i/model.N.value)**model.K[1].value for i in model.S2])
    59         exp2 = sum ([model.beta.value*model.x[i]**2*(model.x[i+1]+model.x[i+1]**2)**2*(i/model.N.value)**model.K[2].value for i in model.S3])
    60         exp3 = sum ([model.gamma.value*model.x[i]**2*model.x[i+model.M.value]**4*(i/model.N.value)**model.K[3].value for i in model.S4])
    61         exp4 = sum ([model.delta.value*model.x[i]*model.x[i+2*model.M.value]*(i/model.N.value)**model.K[4].value for i in model.S5])
     58        exp1 = sum ([value(model.alpha)*model.x[i]**2*(i/value(model.N))**value(model.K[1]) for i in model.S2])
     59        exp2 = sum ([value(model.beta)*model.x[i]**2*(model.x[i+1]+model.x[i+1]**2)**2*(i/value(model.N))**value(model.K[2]) for i in model.S3])
     60        exp3 = sum ([value(model.gamma)*model.x[i]**2*model.x[i+value(model.M)]**4*(i/value(model.N))**value(model.K[3]) for i in model.S4])
     61        exp4 = sum ([value(model.delta)*model.x[i]*model.x[i+2*value(model.M)]*(i/value(model.N))**value(model.K[4]) for i in model.S5])
    6262        return 1.0 + exp1 + exp2 + exp3 + exp4
    6363model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/dixmaanb_cute.py

    r2882 r3068  
    5656
    5757def f(model):
    58         exp1 = sum ([model.alpha.value*model.x[i]**2*(i/model.N.value)**model.K[1].value for i in model.S2])
    59         exp2 = sum ([model.beta.value*model.x[i]**2*(model.x[i+1]+model.x[i+1]**2)**2*(i/model.N.value)**model.K[2].value for i in model.S3])
    60         exp3 = sum ([model.gamma.value*model.x[i]**2*model.x[i+model.M.value]**4*(i/model.N.value)**model.K[3].value for i in model.S4])
    61         exp4 = sum ([model.delta.value*model.x[i]*model.x[i+2*model.M.value]*(i/model.N.value)**model.K[4].value for i in model.S5])
     58        exp1 = sum ([value(model.alpha)*model.x[i]**2*(i/value(model.N))**value(model.K[1]) for i in model.S2])
     59        exp2 = sum ([value(model.beta)*model.x[i]**2*(model.x[i+1]+model.x[i+1]**2)**2*(i/value(model.N))**value(model.K[2]) for i in model.S3])
     60        exp3 = sum ([value(model.gamma)*model.x[i]**2*model.x[i+value(model.M)]**4*(i/value(model.N))**value(model.K[3]) for i in model.S4])
     61        exp4 = sum ([value(model.delta)*model.x[i]*model.x[i+2*value(model.M)]*(i/value(model.N))**value(model.K[4]) for i in model.S5])
    6262        return 1.0 + exp1 + exp2 + exp3 + exp4
    6363model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/dixon3dq_cute.py

    r2882 r3068  
    4545def obj(model):
    4646        es = sum ([(model.x[j]-model.x[j+1])**2 for j in model.SS])
    47         return (model.x[1]-1.0)**2 + es + (model.x[model.n.value]-1.0)**2
     47        return (model.x[1]-1.0)**2 + es + (model.x[value(model.n)]-1.0)**2
    4848model.obj = Objective(rule=obj,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/drcav3lq_cute.py

    r2882 r3068  
    5656        return (20*model.y[i,j]-8*model.y[i-1,j]-8*model.y[i+1,j]\
    5757        -8*model.y[i,j-1]-8*model.y[i,j+1]+2*model.y[i-1,j+1]+2*model.y[i+1,j-1]+2*model.y[i-1,j-1]+2*model.y[i+1,j+1] +\
    58         model.y[i-2,j] + model.y[i+2,j] + model.y[i,j-2] + model.y[i,j+2] + (model.RE.value/4.0)*(model.y[i,j+1]-model.y[i,j-1])\
     58        model.y[i-2,j] + model.y[i+2,j] + model.y[i,j-2] + model.y[i,j+2] + (value(model.RE)/4.0)*(model.y[i,j+1]-model.y[i,j-1])\
    5959        *(model.y[i-2,j]+model.y[i-1,j-1]+model.y[i-1,j+1]-4*model.y[i-1,j]-4*model.y[i+1,j]-model.y[i+1,j-1] \
    60         -model.y[i+1,j+1] - model.y[i+2,j]) - (model.RE.value/4.0)*(model.y[i+1,j]-model.y[i-1,j])*\
     60        -model.y[i+1,j+1] - model.y[i+2,j]) - (value(model.RE)/4.0)*(model.y[i+1,j]-model.y[i-1,j])*\
    6161        (model.y[i,j-2]+model.y[i-1,j-1]+model.y[i+1,j-1]-4*model.y[i,j-1]-4*model.y[i,j+1]-model.y[i-1,j+1]-model.y[i+1,j+1] - model.y[i,j+2])) == 0
    6262model.cons = Constraint(model.S2,model.S2,rule=cons)
     
    7171                #model.y[0,j].fixed=True
    7272def fix3(j,model):
    73         return model.y[model.M.value+1,j] == -model.H.value/2.0
     73        return model.y[value(model.M)+1,j] == -value(model.H)/2.0
    7474model.fix3 = Constraint(model.S1,rule=fix3)
    75                 #model.y[model.M.value+1,j].fixed=True
    7675def fix4(j,model):
    77         return model.y[model.M.value+2,j] == model.H.value/2.0
     76        return model.y[value(model.M)+2,j] == value(model.H)/2.0
    7877model.fix4 = Constraint(model.S1,rule=fix4)
    79                 #model.y[model.M.value+2,j].fixed=True
    8078
    8179def fix5(i,model):
     
    8886                #model.y[i,0].fixed=True
    8987def fix7(i,model):
    90         return model.y[i,model.M.value+1] == 0.0
     88        return model.y[i,value(model.M)+1] == 0.0
    9189model.fix7 = Constraint(model.S2,rule=fix7)
    92                 #model.y[i,model.M.value+1].fixed=True
    9390def fix8(i,model):
    94         return model.y[i,model.M.value+2] == 0.0
     91        return model.y[i,value(model.M)+2] == 0.0
    9592model.fix8 = Constraint(model.S2,rule=fix8)
    96                 #model.y[i,model.M.value+2].fixed=True
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/dtoc1l_cute.py

    r2882 r3068  
    5353
    5454def cons1(t,model):
    55         sc1 = sum ([model.b[1,i].value*model.x[t,i] for i in model.S2])
     55        sc1 = sum ([value(model.b[1,i])*model.x[t,i] for i in model.S2])
    5656        return 0.5*model.y[t,1] + 0.25*model.y[t,2] - model.y[t+1,1] + sc1 == 0
    5757model.cons1 = Constraint(model.S3,rule=cons1)
    5858def cons2(t,j,model):
    59         sc2 = sum ([model.b[j,i].value*model.x[t,i] for i in model.S2])
     59        sc2 = sum ([value(model.b[j,i])*model.x[t,i] for i in model.S2])
    6060        return -model.y[t+1,j] + 0.5*model.y[t,j] - 0.25*model.y[t,j-1] + 0.25*model.y[t,j+1] + sc2 == 0
    6161model.cons2 = Constraint(model.S3,model.S5,rule=cons2)
    6262def cons3(t,model):
    63         sc3 = sum ([model.b[ny,i].value*model.x[t,i] for i in model.S2])
     63        sc3 = sum ([value(model.b[ny,i])*model.x[t,i] for i in model.S2])
    6464        return 0.5*model.y[t,ny] - 0.25*model.y[t,ny-1] - model.y[t+1,ny] + sc3 == 0
    6565model.cons3 = Constraint(model.S3,rule=cons3)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/eg2_cute.py

    r2882 r3068  
    4141
    4242def f(m):
    43         expr = sum([sin(m.x[1]+m.x[i]**2 - 1.0) for i in range(1,m.N.value)])
    44         expr += 0.5*sin(m.x[m.N.value]**2)
     43        expr = sum([sin(m.x[1]+m.x[i]**2 - 1.0) for i in range(1,value(m.N))])
     44        expr += 0.5*sin(m.x[value(m.N)]**2)
    4545        return expr
    4646
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/eg3_cute.py

    r2882 r3068  
    4646
    4747def f(m):
    48     expr = 0.5*( (m.x[1] - m.x[m.n.value]) * m.x[2] + m.y )**2
     48    expr = 0.5*( (m.x[1] - m.x[value(m.n)]) * m.x[2] + m.y )**2
    4949    return expr
    5050model.f = Objective(rule=f,sense=minimize)
    5151
    5252def consq(i,m):
    53     expr = m.y + m.x[1]*m.x[i+1] + (1+2/i)*m.x[i]*m.x[m.n.value]
     53    expr = m.y + m.x[1]*m.x[i+1] + (1+2/i)*m.x[i]*m.x[value(m.n)]
    5454    return (None,expr,0.0)
    5555model.consq = Constraint(RangeSet(1,model.n-1),rule=consq)
     
    6161
    6262def eq(m):
    63     return (1.0, (m.x[1]+m.x[m.n.value])**2)
     63    return (1.0, (m.x[1]+m.x[value(m.n)])**2)
    6464model.eq = Constraint(rule=eq)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/errinros_cute.py

    r2882 r3068  
    3939model.SS = RangeSet(2,model.N)
    4040def f(model):
    41         sum1 = sum ([(model.x[i-1]-16*model.alpha[i].value**2*model.x[i]**2)**2 for i in model.SS])
     41        sum1 = sum ([(model.x[i-1]-16*value(model.alpha[i])**2*model.x[i]**2)**2 for i in model.SS])
    4242        sum2 = sum ([(model.x[i]-1.0)**2 for i in model.SS])
    4343        return sum1 + sum2
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/expfit_cute.py

    r2882 r3068  
    4141model.S = RangeSet(1,model.p)
    4242def f(model):
    43         return sum ([(model.alpha*exp(i*model.h.value*model.beta)-i*model.h.value)**2 for i in model.S])
     43        return sum ([(model.alpha*exp(i*value(model.h)*model.beta)-i*value(model.h))**2 for i in model.S])
    4444model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/explin2_cute.py

    r2882 r3068  
    3636model.SS = RangeSet(1,model.m)
    3737def f(model):
    38         sum1 = sum ([exp(0.1*i*model.x[i]*model.x[i+1]/model.m.value)  for i in model.SS])
     38        sum1 = sum ([exp(0.1*i*model.x[i]*model.x[i+1]/value(model.m))  for i in model.SS])
    3939        sum2 = sum ([(-10.0*i*model.x[i]) for i in model.S])
    4040        return sum1 + sum2
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/expquad_cute.py

    r2882 r3068  
    3838
    3939def f(model):
    40         sum1 = sum ([exp(0.1*i*model.m.value*model.x[i]*model.x[i+1]) for i in model.SS])
    41         sum2 = sum ([(4.0*model.x[i]*model.x[i]+2.0*model.x[model.n.value]*model.x[model.n.value] + model.x[i]*model.x[model.n.value]) for i in model.SSS])
     40        sum1 = sum ([exp(0.1*i*value(model.m)*model.x[i]*model.x[i+1]) for i in model.SS])
     41        sum2 = sum ([(4.0*model.x[i]*model.x[i]+2.0*model.x[value(model.n)]*model.x[value(model.n)] + model.x[i]*model.x[value(model.n)]) for i in model.SSS])
    4242        sum3 = sum ([(-10.0*i*model.x[i]) for i in model.S])
    4343        return sum1 + sum2 + sum3
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/fccu_cute.py

    r2882 r3068  
    6060
    6161def f(model):
    62         return (model.Feed-model.m[1].value)**2/model.w[1].value\
    63         +(model.Effluent-model.m[2].value)**2/model.w[2].value\
    64         +(model.MF_ohd-model.m[3].value)**2/model.w[3].value\
    65         +(model.HCN-model.m[4].value)**2/model.w[4].value\
    66         +(model.LCO-model.m[5].value)**2/model.w[5].value\
    67         +(model.HCO-model.m[6].value)**2/model.w[6].value\
    68         +(model.MF_btms-model.m[7].value)**2/model.w[7].value\
    69         +(model.Decant-model.m[8].value)**2/model.w[8].value\
    70         +(model.Dec_recy-model.m[9].value)**2/model.w[9].value\
    71         +(model.Off_gas-model.m[10].value)**2/model.w[10].value\
    72         +(model.DC4_feed-model.m[11].value)**2/model.w[11].value\
    73         +(model.DC3_feed-model.m[12].value)**2/model.w[12].value\
    74         +(model.DC4_btms-model.m[13].value)**2/model.w[13].value\
    75         +(model.Lean_oil-model.m[14].value)**2/model.w[14].value\
    76         +(model.Propane-model.m[15].value)**2/model.w[15].value\
    77         +(model.Butane-model.m[16].value)**2/model.w[16].value\
    78         +(model.C8spl_fd-model.m[17].value)**2/model.w[17].value\
    79         +(model.LCN-model.m[18].value)**2/model.w[18].value\
    80         +(model.MCN-model.m[19].value)**2/model.w[19].value
     62        return (model.Feed-value(model.m[1]))**2/value(model.w[1])\
     63        +(model.Effluent-value(model.m[2]))**2/value(model.w[2])\
     64        +(model.MF_ohd-value(model.m[3]))**2/value(model.w[3])\
     65        +(model.HCN-value(model.m[4]))**2/value(model.w[4])\
     66        +(model.LCO-value(model.m[5]))**2/value(model.w[5])\
     67        +(model.HCO-value(model.m[6]))**2/value(model.w[6])\
     68        +(model.MF_btms-value(model.m[7]))**2/value(model.w[7])\
     69        +(model.Decant-value(model.m[8]))**2/value(model.w[8])\
     70        +(model.Dec_recy-value(model.m[9]))**2/value(model.w[9])\
     71        +(model.Off_gas-value(model.m[10]))**2/value(model.w[10])\
     72        +(model.DC4_feed-value(model.m[11]))**2/value(model.w[11])\
     73        +(model.DC3_feed-value(model.m[12]))**2/value(model.w[12])\
     74        +(model.DC4_btms-value(model.m[13]))**2/value(model.w[13])\
     75        +(model.Lean_oil-value(model.m[14]))**2/value(model.w[14])\
     76        +(model.Propane-value(model.m[15]))**2/value(model.w[15])\
     77        +(model.Butane-value(model.m[16]))**2/value(model.w[16])\
     78        +(model.C8spl_fd-value(model.m[17]))**2/value(model.w[17])\
     79        +(model.LCN-value(model.m[18]))**2/value(model.w[18])\
     80        +(model.MCN-value(model.m[19]))**2/value(model.w[19])
    8181model.f = Objective(rule=f,sense=minimize)
    8282
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/fletchbv_cute.py

    r2882 r3068  
    4242model.objscale = Param(initialize=1.0e0)
    4343def h_rule(model):
    44         return 1/(model.n.value+1.0)
     44        return 1/(value(model.n)+1.0)
    4545model.h = Param(initialize=h_rule)
    4646def p_rule(model):
    47         return 1/model.objscale.value
     47        return 1/value(model.objscale)
    4848model.p = Param(initialize=p_rule)
    4949
     
    5252
    5353def x_int(i,model):
    54         return i*model.h.value
     54        return i*value(model.h)
    5555model.x = Var(model.S, initialize=x_int)
    5656
    5757def f(model):
    58         exp1 = 0.5*model.p.value*(model.x[1])**2
    59         exp2 = 0.5*model.p.value*(model.x[model.n.value])**2
    60         sum1 = sum ([0.5*model.p.value*(model.x[i]-model.x[i+1])**2 for i in model.SS])
    61         sum2 = sum ([(model.p.value*(-1-2/model.h.value**2)*model.x[i]) for i in model.S])
    62         sum3 = sum ([(-model.kappa.value*model.p.value*cos(model.x[i])/model.h.value**2) for i in model.S])
     58        exp1 = 0.5*value(model.p)*(model.x[1])**2
     59        exp2 = 0.5*value(model.p)*(model.x[value(model.n)])**2
     60        sum1 = sum ([0.5*value(model.p)*(model.x[i]-model.x[i+1])**2 for i in model.SS])
     61        sum2 = sum ([(value(model.p)*(-1-2/value(model.h)**2)*model.x[i]) for i in model.S])
     62        sum3 = sum ([(-value(model.kappa)*value(model.p)*cos(model.x[i])/value(model.h)**2) for i in model.S])
    6363        return (exp1 + sum1 + exp2 + sum2 + sum3)
    6464model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/hager1_cute.py

    r2882 r3068  
    4848        sum_coefs = []
    4949        for i in m.Sy:
    50                 sum_exprs.append((m.u[i]**2)/(2*m.N.value))
     50                sum_exprs.append((m.u[i]**2)/(2*value(m.N)))
    5151                sum_coefs.append(1)
    52         expr = 0.5*m.x[m.N.value]**2 + _SumExpression(sum_exprs, sum_coefs)
     52        expr = 0.5*m.x[value(m.N)]**2 + _SumExpression(sum_exprs, sum_coefs)
    5353        return expr
    5454model.f = Objective(rule=f,sense=minimize)
    5555
    5656def cons1(i,m):
    57         expr = (m.N.value-0.5)*m.x[i] + (-m.N.value - 0.5)*m.x[i-1] - m.u[i]
     57        expr = (value(m.N)-0.5)*m.x[i] + (-value(m.N) - 0.5)*m.x[i-1] - m.u[i]
    5858        return (0,expr)
    5959model.cons1 = Constraint(model.Sy,rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/hager2_cute.py

    r2882 r3068  
    5454    sum_expr_2 = 0
    5555    for i in m.Su:
    56         sum_expr_1 += (m.h.value)*(m.x[i-1]**2 + m.x[i-1]*m.x[i] + m.x[i]**2)/6
    57         sum_expr_2 += ((m.h.value)*(m.u[i])**2)/4
     56        sum_expr_1 += (value(m.h))*(m.x[i-1]**2 + m.x[i-1]*m.x[i] + m.x[i]**2)/6
     57        sum_expr_2 += ((value(m.h))*(m.u[i])**2)/4
    5858    exp = sum_expr_1 + sum_expr_2
    5959    return exp
     
    6161
    6262def cons1(i,m):
    63     exp = (m.n.value-0.25)*m.x[i] - (m.n.value+0.25)*m.x[i-1] - m.u[i]
     63    exp = (value(m.n)-0.25)*m.x[i] - (value(m.n)+0.25)*m.x[i-1] - m.u[i]
    6464    return (0,exp)
    6565model.cons1 = Constraint(model.Su,rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/hager3_cute.py

    r2882 r3068  
    5454    sum_expr_2 = 0
    5555    for i in m.Su:
    56         sum_expr_1 += (m.h.value)*(0.625*(m.x[i-1]**2 + m.x[i-1]*m.x[i] + m.x[i]**2) + ((m.x[i-1]+m.x[i])*m.u[i]))/8
    57         sum_expr_2 += ((m.h.value)*(m.u[i])**2)/4
     56        sum_expr_1 += (value(m.h))*(0.625*(m.x[i-1]**2 + m.x[i-1]*m.x[i] + m.x[i]**2) + ((m.x[i-1]+m.x[i])*m.u[i]))/8
     57        sum_expr_2 += (value(m.h)*(m.u[i])**2)/4
    5858    exp = sum_expr_1 + sum_expr_2
    5959    return exp
     
    6161
    6262def cons1(i,m):
    63     exp = (m.n.value-0.25)*m.x[i] - (m.n.value+0.25)*m.x[i-1] - m.u[i]
     63    exp = (value(m.n)-0.25)*m.x[i] - (value(m.n)+0.25)*m.x[i-1] - m.u[i]
    6464    return (0,exp)
    6565model.cons1 = Constraint(model.Su,rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/hager4_cute.py

    r2882 r3068  
    3737
    3838def t_rule(i,m):               
    39     return i*m.h.value
     39    return i*value(m.h)
    4040def z_rule(i,m):
    41     return exp(-2*m.t[i].value)
     41    return exp(-2*value(m.t[i]))
    4242def a_rule(i,m):
    43     return -0.5*m.z[i].value
     43    return -0.5*value(m.z[i])
    4444def b_rule(i,m):
    45     return m.a[i].value*(m.t[i].value+0.5)
     45    return value(m.a[i])*(value(m.t[i])+0.5)
    4646def c_rule(i,m):
    47     return m.a[i].value*(m.t[i].value**2 + m.t[i].value + 0.5)
     47    return value(m.a[i])*(value(m.t[i])**2 + value(m.t[i])+ 0.5)
    4848def scda_rule(m):
    49     return (m.a[1].value-m.a[0].value)/2
     49    return (value(m.a[1])-value(m.a[0]))/2
    5050def scdb_rule(m):
    51     return (m.b[1].value - m.b[0].value)*m.n.value
     51    return (value(m.b[1])- value(m.b[0]))*value(m.n)
    5252def scdc_rule(m):
    53     return (m.c[1].value - m.c[0].value)*m.n.value*m.n.value*0.5
     53    return (value(m.c[1])- value(m.c[0]))*value(m.n)*value(m.n)*0.5
    5454def xx0_rule(m):
    55     return (1+3*m.e.value)/(2-2*m.e.value)
     55    return (1+3*value(m.e))/(2-2*value(m.e))
    5656
    5757model.n = Param(initialize=5000)
     
    9191    sum_expr_2 = 0
    9292    for i in m.Su:
    93         sum_expr_1 += (m.scda.value*m.z[i-1]*m.x[i]**2 + m.scdb.value*m.z[i-1]*m.x[i]*(m.x[i-1]-m.x[i]) + m.scdc.value*m.z[i-1]*(m.x[i-1]-m.x[i])**2)
    94         sum_expr_2 += ((m.h.value)*(m.u[i])**2)*0.5
     93        sum_expr_1 += (value(m.scda)*m.z[i-1]*m.x[i]**2 + value(m.scdb)*m.z[i-1]*m.x[i]*(m.x[i-1]-m.x[i]) + value(m.scdc)*m.z[i-1]*(m.x[i-1]-m.x[i])**2)
     94        sum_expr_2 += ((value(m.h))*(m.u[i])**2)*0.5
    9595    exp = sum_expr_1 + sum_expr_2
    9696    return exp
     
    9898
    9999def cons1(i,m):
    100     return (0,(m.n.value-1)*m.x[i] - m.n.value*m.x[i-1] - exp(m.t[i].value)*m.u[i])
     100    return (0,(value(m.n)-1)*m.x[i] - value(m.n)*m.x[i-1] - exp(value(m.t[i]))*m.u[i])
    101101model.cons1 = Constraint(model.Su,rule=cons1)
    102102
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/ncvxbqp1_cute.py

    r2882 r3068  
    2929model.N = Param(initialize=100)
    3030def M(model):
    31         return model.N.value/2.0
     31        return value(model.N)/2.0
    3232model.M = Param(initialize=M)
    3333def Nplus(model):
    34         return model.N.value/4.0
     34        return value(model.N)/4.0
    3535model.Nplus = Param(initialize=Nplus)
    3636
     
    4141model.Rsum2 = RangeSet(model.Nplus+1,model.N)
    4242def f(model):
    43         sum1 = sum([ 0.5*i*(model.x[i]+model.x[ ((2*i-1) % model.N.value) + 1] + model.x[ ((3*i-1) % model.N.value) +1 ] )**2 for i in model.Rsum1])
    44         sum2 = sum([ 0.5*i*(model.x[i]+model.x[ ((2*i-1) % model.N.value) + 1] + model.x[ ((3*i-1) % model.N.value) +1 ] )**2 for i in model.Rsum2])
     43        sum1 = sum([ 0.5*i*(model.x[i]+model.x[ ((2*i-1) % value(model.N)) + 1] + model.x[ ((3*i-1) % value(model.N)) +1 ] )**2 for i in model.Rsum1])
     44        sum2 = sum([ 0.5*i*(model.x[i]+model.x[ ((2*i-1) % value(model.N)) + 1] + model.x[ ((3*i-1) % value(model.N)) +1 ] )**2 for i in model.Rsum2])
    4545        return sum1-sum2
    4646model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/oet1_cute.py

    r2882 r3068  
    4040
    4141def d_rule(model):
    42                 return model.upper.value-model.lower.value
     42                return value(model.upper)-value(model.lower)
    4343model.diff = Param(rule=d_rule)
    4444def h_rule(model):
    45                 return model.diff.value/model.M.value
     45                return value(model.diff)/value(model.M)
    4646model.h = Param(rule=h_rule)
    4747#model.diff = Param(initialize=model.upper-model.lower)
     
    5858model.OP = RangeSet(0,model.M)
    5959def cons1(i,model):
    60         ex = model.u-(i*model.h.value+model.lower.value)*model.x[1]-exp(i*model.h.value+model.lower.value)*model.x[2] - (i*model.h.value+model.lower.value)**2
     60        ex = model.u-(i*value(model.h)+value(model.lower))*model.x[1]-exp(i*value(model.h)+value(model.lower))*model.x[2] - (i*value(model.h)+value(model.lower))**2
    6161        return ex >= 0
    6262model.cons1 = Constraint(model.OP,rule=cons1)
    6363def cons2(i,model):
    64         return model.u+(i*model.h.value+model.lower.value)*model.x[1]+exp(i*model.h.value+model.lower.value)*model.x[2] + (i*model.h.value+model.lower.value)**2 >= 0
     64        return model.u+(i*value(model.h)+value(model.lower))*model.x[1]+exp(i*value(model.h)+value(model.lower))*model.x[2] + (i*value(model.h)+value(model.lower))**2 >= 0
    6565model.cons2 = Constraint(model.OP,rule=cons2)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/palmer1_cute.py

    r2882 r3068  
    4444
    4545def palmer(model):
    46         return sum([(model.Y[m].value - (model.A*(model.X[m].value**2) + model.B / (model.C \
    47         + (model.X[m].value**2)/model.D)))**2 for m in model.M])
     46        return sum([(value(model.Y[m]) - (model.A*(value(model.X[m])**2) + model.B / (model.C \
     47        + (value(model.X[m])**2)/model.D)))**2 for m in model.M])
    4848model.palmer = Objective(rule=palmer,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/powell20_cute.py

    r2882 r3068  
    5858
    5959def cons2(model):
    60         exp1 = model.x[1]-model.x[model.N.value]
    61         exp2 = model.N.value - 0.5
     60        exp1 = model.x[1]-model.x[value(model.N)]
     61        exp2 = value(model.N) - 0.5
    6262        return exp1 >= exp2
    6363model.cons2 = Constraint(rule=cons2)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/sisser_cute.py

    r2882 r3068  
    4343
    4444def fa(i,model):
    45         return model.xinit[i].value
     45        return value(model.xinit[i])
    4646model.x = Var(model.N,initialize=fa)
    4747
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/testCUTE.py

    r2915 r3068  
    2424        os.chdir(currdir)
    2525#       t0= time.clock()
    26         output = main.run(list(args))
     26        output = main.run(['--debug=errors']+ list(args))
    2727#       t1 = time.clock() - t0 # t is CPU seconds elapsed (floating point)
    2828#       print "Seconds: " + str(t1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/tfi2_cute.py

    r2882 r3068  
    3737model.M = Param(initialize=1000)
    3838def h_rule(model):
    39         return 1.0/model.M.value
     39        return 1.0/value(model.M)
    4040model.h = Param(initialize=h_rule)
    4141
     
    4949model.Rc1 = RangeSet(0,model.M)
    5050def cons1(i,model):
    51         return -model.x[1]-i*model.h.value*model.x[2]-(i*model.h.value)**2*model.x[3]+tan(i*model.h.value) <= 0
     51        return -model.x[1]-i*value(model.h)*model.x[2]-(i*value(model.h))**2*model.x[3]+tan(i*value(model.h)) <= 0
    5252model.cons1 = Constraint(model.Rc1,rule=cons1)
  • coopr.pyomo/trunk/coopr/pyomo/tests/NL/CUTE/tridia_cute.py

    r2882 r3068  
    4848model.R2 = RangeSet(2,model.N)
    4949def f(model):
    50         ex = sum([ i*(-model.beta.value*model.x[i-1]+model.alpha.value*model.x[i])**2 for i in model.R2])
    51         return model.gamma.value*(model.x[1]*model.delta.value-1.0)**2 + ex
     50        ex = sum([ i*(-value(model.beta)*model.x[i-1]+value(model.alpha)*model.x[i])**2 for i in model.R2])
     51        return value(model.gamma)*(model.x[1]*value(model.delta)-1.0)**2 + ex
    5252model.f = Objective(rule=f,sense=minimize)
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/pmedian.py

    r2379 r3068  
    1515model.Customers = RangeSet(1,model.M)
    1616
     17# NOTE: the mutable flag is only used to ensure a consistent baseline.
    1718def d_rule(n, m, model):
    1819    return math.sin(n*2.33333+m*7.99999)
    19 model.d = Param(model.Locations, model.Customers, rule=d_rule, within=Reals)
     20model.d = Param(model.Locations, model.Customers, rule=d_rule, within=Reals, mutable=True)
    2021
    2122model.x = Var(model.Locations, model.Customers, bounds=(0.0,1.0))
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/test6.txt

    r2878 r3068  
    33Pyomo Model Components:
    44----------------------------------------------------------------
     5
     6 AbstractModel
     7    An abstract optimization model that defers construction of
     8    components.
    59
    610 Block
     
    2024
    2125 ConcreteModel
    22     Model with concrete expressions, which can be used as a
    23     component of other models.
     26    A concrete optimization model that does not defer
     27    construction of components.
    2428
    2529 Constraint
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_check.py

    r1176 r3068  
    2424
    2525def action1a_fn(model):
    26     return model.A.value == 3.3
     26    return value(model.A) == 3.3
    2727   
    2828def action1b_fn(model):
    29     return model.A.value != 3.3
     29    return value(model.A) != 3.3
    3030   
    3131def action2a_fn(i,model):
    3232    ans=True
    3333    if i in model.A:
    34         return (model.A[i].value == 1.3)
     34        return (value(model.A[i]) == 1.3)
    3535    return True
    3636   
    3737def action2b_fn(i,model):
    3838    if i in model.A:
    39         ans = (model.A[i].value == 1.3)
     39        ans = (value(model.A[i]) == 1.3)
    4040        #print "HERE",i,ans,not ans
    4141        return not ans
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_param.py

    r3019 r3068  
    186186        self.instance.A.value = 4.3
    187187        self.instance.A = 4.3
    188         self.instance.A[1].value = 4.3
    189         self.failUnlessEqual( type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
     188        if self.instance.A.mutable:
     189            self.instance.A[1].value = 4.3
     190            self.failUnlessEqual( type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
    190191        self.instance.A[1] = 4.3
    191         self.failUnlessEqual( type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
     192        if self.instance.A.mutable:
     193            self.failUnlessEqual( type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
     194        else:
     195            self.failUnlessEqual( type(self.instance.A[1]), float)
     196
    192197
    193198    def test_setitem(self):
     
    224229        else:
    225230          self.fail("test_getitem")
    226         self.failUnlessEqual(type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
     231        if self.instance.A.mutable:
     232            self.failUnlessEqual(type(self.instance.A[1]), coopr.pyomo.base.param._ParamValue)
     233        else:
     234            self.failUnlessEqual(type(self.instance.A[1]), float)
    227235        self.failUnlessEqual( self.instance.A[1], 1.3)
    228236        try:
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_util.py

    r2592 r3068  
    2020        model = Model()
    2121        model.A = Set(initialize=[1,2,3])
    22         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     22        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    2323        model.x = Var(model.A)
    2424        model.y = Var(model.A)
     
    3434        model = Model()
    3535        model.A = Set(initialize=[1,2,3])
    36         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     36        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    3737        model.x = Var(model.A)
    3838        model.y = Var(model.A)
     
    4848        model = Model()
    4949        model.A = Set(initialize=[1,2,3])
    50         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     50        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    5151        model.x = Var(model.A)
    5252        model.y = Var(model.A)
     
    6363        model = Model()
    6464        model.A = Set(initialize=[1,2,3])
    65         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     65        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    6666        model.x = Var(model.A)
    6767        model.y = Var(model.A)
     
    7979        model = Model()
    8080        model.A = Set(initialize=[1,2,3])
    81         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     81        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    8282        model.x = Var(model.A)
    8383        model.y = Var(model.A)
     
    9595        model = Model()
    9696        model.A = Set(initialize=[1,2,3])
    97         model.B = Param(model.A,initialize={1:100,2:200,3:300})
     97        model.B = Param(model.A,initialize={1:100,2:200,3:300}, mutable=True)
    9898        model.x = Var(model.A)
    9999        model.y = Var(model.A)
     
    116116        model = Model()
    117117        model.a = Set(initialize=[1,2,3])
    118         model.A = Param(initialize=1)
     118        model.A = Param(initialize=1, mutable=True)
    119119        model.B = Param(model.a)
    120120        model.x = Var(initialize=1,within=Reals)
Note: See TracChangeset for help on using the changeset viewer.