|
23 | 23 | from pyomo.common.modeling import NOTSET
|
24 | 24 | from pyomo.common.numeric_types import native_types, value as expr_value
|
25 | 25 | from pyomo.common.timing import ConstructionTimer
|
| 26 | +from pyomo.core.expr.expr_common import _type_check_exception_arg |
26 | 27 | from pyomo.core.expr.numvalue import NumericValue
|
27 | 28 | from pyomo.core.base.component import ComponentData, ModelComponentFactory
|
28 | 29 | from pyomo.core.base.global_set import UnindexedComponent_index
|
@@ -201,10 +202,12 @@ def set_value(self, value, idx=NOTSET):
|
201 | 202 | self._value = old_value
|
202 | 203 | raise
|
203 | 204 |
|
204 |
| - def __call__(self, exception=True): |
| 205 | + def __call__(self, exception=NOTSET): |
205 | 206 | """
|
206 | 207 | Return the value of this object.
|
207 | 208 | """
|
| 209 | + exception = _type_check_exception_arg(self, exception) |
| 210 | + |
208 | 211 | if self._value is Param.NoValue:
|
209 | 212 | if exception:
|
210 | 213 | raise ValueError(
|
@@ -929,10 +932,12 @@ def __init__(self, *args, **kwds):
|
929 | 932 | # up both the Component and Data base classes.
|
930 | 933 | #
|
931 | 934 |
|
932 |
| - def __call__(self, exception=True): |
| 935 | + def __call__(self, exception=NOTSET): |
933 | 936 | """
|
934 | 937 | Return the value of this parameter.
|
935 | 938 | """
|
| 939 | + exception = _type_check_exception_arg(self, exception) |
| 940 | + |
936 | 941 | if self._constructed:
|
937 | 942 | if not self._data:
|
938 | 943 | if self._mutable:
|
@@ -976,13 +981,6 @@ class SimpleParam(metaclass=RenamedClass):
|
976 | 981 |
|
977 | 982 |
|
978 | 983 | class IndexedParam(Param):
|
979 |
| - def __call__(self, exception=True): |
980 |
| - """Compute the value of the parameter""" |
981 |
| - if exception: |
982 |
| - raise TypeError( |
983 |
| - 'Cannot compute the value of an indexed Param (%s)' % (self.name,) |
984 |
| - ) |
985 |
| - |
986 | 984 | # Because IndexedParam can use a non-standard data store (i.e., the
|
987 | 985 | # values in the _data dict may not be ComponentData objects), we
|
988 | 986 | # need to override the normal scheme for pre-allocating
|
|
0 commit comments