Skip to content

Commit bba0e78

Browse files
committed
Adding add_parameter logic
This mimics the logic used for add_variable
1 parent f2275e3 commit bba0e78

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: lib/poek/poek/poek_pybind11.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Pull-in Pybind11 wrappers
33
#
44
from io import StringIO
5-
from pycoek_pybind11 import variable_, parameter_single, variable_array
5+
from pycoek_pybind11 import variable_, parameter_, variable_array
66
from pycoek_pybind11 import *
77
from .func import quicksum, prod, seq
88

@@ -17,11 +17,17 @@ class _DummyConcreteSet(object):
1717

1818

1919
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")
2531

2632

2733
class variable(object):
@@ -57,6 +63,7 @@ def model_variable(self, *args, **kwds):
5763

5864

5965
setattr(model, "add_variable", model_variable)
66+
setattr(compact_model, "add_variable", model_variable)
6067

6168
def print_equations(self, ostream=None):
6269
if ostream is None:

0 commit comments

Comments
 (0)