Changeset 3707


Ignore:
Timestamp:
Feb 23, 2011 10:23:36 PM (9 years ago)
Author:
wehart
Message:

Reverting changes from r3704.

Adding a future import for integer division, which
internally resolves how integers are used in Pyomo expressions.

File:
1 edited

Legend:

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

    r3704 r3707  
    88#  For more information, see the Coopr README.txt file.
    99#  _________________________________________________________________________
     10
     11from __future__ import division
    1012
    1113__all__ = ['Expression', '_LessThanExpression', '_LessThanOrEqualExpression',
     
    290292        self._denominator = []
    291293        self._numerator = []
    292         self.coef = 1.0
     294        self.coef = 1
    293295
    294296    def __getstate__(self):
     
    343345              print >>ostream, 1,
    344346           print >>ostream, ")",
    345            if self._denominator:
     347           if len(self._denominator) > 0:
    346348              print >>ostream, ", denom=(",
    347349              first=True
     
    413415        _LinearExpression.__init__(self, 'sum', None, [])
    414416        self._coef = []
    415         self._const = 0.0
     417        self._const = 0
    416418
    417419    def __getstate__(self):
     
    436438
    437439    def negate(self):
    438         self.scale(-1.0)
     440        self.scale(-1)
    439441
    440442    def pprint(self, ostream=None, nested=True, eol_flag=True):
     
    502504        else:
    503505            etype = 'rmul'
    504             other = NumericConstant(value=-1.0)
     506            other = NumericConstant(value=-1)
    505507    elif etype == 'abs':
    506508        return _AbsExpression([_self])
     
    535537    # Some binary operators are special cases of other operators
    536538    #
    537     multiplier = 1.0
     539    multiplier = 1
    538540    if etype == 'sub':
    539         multiplier = -1.0
     541        multiplier = -1
    540542        etype = 'add'
    541543
     
    580582                else:
    581583                    other._args.append(_self)
    582                     other._coef.append(1.0)
     584                    other._coef.append(1)
    583585                ans = other
    584586            else:
     
    593595                else:
    594596                    ans._args.append(_self)
    595                     ans._coef.append(1.0)
     597                    ans._coef.append(1)
    596598                if other_type is NumericConstant:
    597599                    ans._const += multiplier * other()
     
    646648        # Special cases for simplifying expressions
    647649        if ans.coef == 0:
    648             return NumericConstant(value=0.0)
     650            return NumericConstant(value=0)
    649651        if ans.coef == 1 and len(ans._numerator) == 1 and not ans._denominator:
    650652            return ans._numerator[0]
     
    688690        # Special cases for simplifying expressions
    689691        if ans.coef == 0:
    690             return NumericConstant(value=0.0)
     692            return NumericConstant(value=0)
    691693        if ans.coef == 1 and len(ans._numerator) == 1 and not ans._denominator:
    692694            return ans._numerator[0]
Note: See TracChangeset for help on using the changeset viewer.