Skip to content

Commit 4e2d87a

Browse files
committed
NFC: add/update comments
1 parent 0bc65e1 commit 4e2d87a

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

pyomo/core/base/constraint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,13 @@ def template_expr(self):
552552
return self._expr
553553

554554
def set_value(self, expr):
555+
# Setting a value will convert this instance from a templatized
556+
# type to the original Data type (and call the original set_value()).
557+
#
558+
# Note: We assume that the templatized type is created by
559+
# inheriting (TemplateDataMixin, <original data class>), and
560+
# that this instance doesn't have additional multiple
561+
# inheritance that could re-order the MRO.
555562
self.__class__ = self.__class__.__mro__[
556563
self.__class__.__mro__.index(TemplateDataMixin) + 1
557564
]

pyomo/core/base/objective.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ def template_expr(self):
180180
return self._args_
181181

182182
def set_value(self, expr):
183+
# Setting a value will convert this instance from a templatized
184+
# type to the original Data type (and call the original set_value()).
185+
#
186+
# Note: We assume that the templatized type is created by
187+
# inheriting (TemplateDataMixin, <original data class>), and
188+
# that this instance doesn't have additional multiple
189+
# inheritance that could re-order the MRO.
183190
self.__class__ = self.__class__.__mro__[
184191
self.__class__.__mro__.index(TemplateDataMixin) + 1
185192
]

pyomo/repn/linear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def append(self, other):
181181
# change). Omitting the assertion for efficiency.
182182
# assert self.multiplier == 1
183183
_type, other = other
184-
if _type <= _FIXED:
184+
if _type <= _FIXED: # Note: catching _FIXED and _CONSTANT
185185
self.constant += other
186186
return
187187

@@ -234,7 +234,7 @@ def append(self, other):
234234

235235

236236
def to_expression(visitor, arg):
237-
if arg[0] <= _VARIABLE:
237+
if arg[0] <= _VARIABLE: # Note: catching _VARIABLE, _FIXED, and _CONSTANT
238238
return arg[1]
239239
else:
240240
return arg[1].to_expression(visitor)
@@ -916,7 +916,7 @@ def finalizeResult(self, result):
916916
ans = result[1]
917917
if ans.__class__ is not self.Result:
918918
ans = self.Result()
919-
assert result[0] <= _FIXED
919+
assert result[0] <= _FIXED # Note: allowing _FIXED or _CONSTANT
920920
ans.constant = result[1]
921921
return ans
922922

pyomo/repn/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767

6868

6969
class ExprType(enums.IntEnum):
70+
# Note that the ordering is meaningful, and we will compare
71+
# instances using relational operators. In particular, we assume
72+
# that the Enum values increase in polynomial degree, starting at
73+
# CONSTANT and endine at GENERAL (nonlinear).
7074
CONSTANT = 0
7175
FIXED = 3
7276
VARIABLE = 5

0 commit comments

Comments
 (0)