Changeset 2108


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

Changes to make the API for Model() functions/attributes by
1-based indexing. This wound up having very little impact on the
Pyomo code base, though it has a bigger impact on my implementation of the FDT
heuristic.

NOTE: one other API that needs to be changed is the indexing of solver
results in coopr.opt. I'm going to defer that until tomorrow, when I'm more awake...

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

Legend:

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

    r2099 r2108  
    9393            return self._name_varmap[name]
    9494        else:
    95             return self._var[name]
     95            return self._var[name-1]
    9696
    9797    def variables(self):
     
    105105            return self._name_conmap[name]
    106106        else:
    107             return self._con[name]
     107            return self._con[name-1]
    108108
    109109    def constraints(self):
     
    117117            return self._name_objmap[name]
    118118        else:
    119             return self._obj[name]
     119            return self._obj[name-1]
    120120
    121121    def objectives(self):
  • coopr.pyomo/trunk/coopr/pyomo/expr/canonical_repn.py

    r2098 r2108  
    3030    if isinstance(model, Model):
    3131        vars = model._var
     32        id_offset=0
    3233    else:
    3334        vars = model
     35        id_offset=1
    3436    expr = 0.0
    3537    for d in rep:
     
    4446            e = rep[d][v]
    4547            for id in v:
    46                 for i in range(v[id]):
    47                     e *= vars[id]
     48                for i in xrange(v[id]):
     49                    e *= vars[id+id_offset]
    4850            expr += e
    4951    return expr
  • coopr.pyomo/trunk/coopr/pyomo/transform/eliminate_fixed_vars.py

    r2097 r2108  
    1212from coopr.pyomo import Constraint, Objective, NumericConstant, Expression
    1313from coopr.pyomo.base.var import _VarBase, _VarValue
     14from coopr.pyomo.base.util import xsequence
    1415
    1516
     
    4344        #
    4445        ctr = 0
    45         for i in range(len(M.variables())):
     46        for i in xsequence(M.nvariables()):
    4647            var = M.variable(i)
    47             del M._var[ i ]
     48            del M._var[ i-1 ]
    4849            if var.fixed:
    4950                if var.is_binary():
Note: See TracChangeset for help on using the changeset viewer.