Changeset 2098


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

Allow expressions to be generated from a dictionary variable-id -> _VarValue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/expr/canonical_repn.py

    r2057 r2098  
    99#  _________________________________________________________________________
    1010
    11 __all__ = ['generate_canonical_repn']
     11__all__ = ['generate_canonical_repn', 'as_expr']
    1212
    1313import pyutilib.plugin.core
    14 from coopr.pyomo.base import IPyomoPresolver, IPyomoPresolveAction
     14from coopr.pyomo.base import IPyomoPresolver, IPyomoPresolveAction, Model
    1515from coopr.pyomo.base import expr
    1616from coopr.pyomo.base.var import _VarValue
     
    2828def as_expr(rep, model, ignore_other=False):
    2929    """ Convert a canonical representation into an expression. """
     30    if isinstance(model, Model):
     31        vars = model._var
     32    else:
     33        vars = model
    3034    expr = 0.0
    3135    for d in rep:
     
    4145            for id in v:
    4246                for i in range(v[id]):
    43                     e *= model.variable(id)
     47                    e *= vars[id]
    4448            expr += e
    4549    return expr
Note: See TracChangeset for help on using the changeset viewer.