2
2
# Pull-in Pybind11 wrappers
3
3
#
4
4
from io import StringIO
5
- from pycoek_pybind11 import variable_ , parameter_single , variable_array
5
+ from pycoek_pybind11 import variable_ , parameter_ , variable_array
6
6
from pycoek_pybind11 import *
7
7
from .func import quicksum , prod , seq
8
8
@@ -17,11 +17,17 @@ class _DummyConcreteSet(object):
17
17
18
18
19
19
class parameter (object ):
20
- def __new__ (cls , * args , value = None ):
21
- p = parameter_single (* args )
22
- if value is not None :
23
- p .value = value
24
- return p
20
+ def __new__ (cls , * args , ** kwds ):
21
+ #p = parameter_single(*args)
22
+ #if value is not None:
23
+ # p.value = value
24
+ #return p
25
+ if len (args ) == 0 or args [0 ] == 1 or type (args [0 ]) == str :
26
+ return parameter_ (** kwds )
27
+ if len (args ) == 1 :
28
+ return parameter_ (args [0 ], ** kwds )
29
+ else :
30
+ raise RuntimeError ("Variables only have one argument" )
25
31
26
32
27
33
class variable (object ):
@@ -57,6 +63,7 @@ def model_variable(self, *args, **kwds):
57
63
58
64
59
65
setattr (model , "add_variable" , model_variable )
66
+ setattr (compact_model , "add_variable" , model_variable )
60
67
61
68
def print_equations (self , ostream = None ):
62
69
if ostream is None :
0 commit comments