22# Pull-in Pybind11 wrappers
33#
44from io import StringIO
5- from pycoek_pybind11 import variable_ , parameter_ , variable_array
5+ from pycoek_pybind11 import create_variable_ , create_parameter_ , variable_array
66from pycoek_pybind11 import *
77from .func import quicksum , prod , seq
88
@@ -18,38 +18,30 @@ class _DummyConcreteSet(object):
1818
1919class data (object ):
2020 def __new__ (cls , * args , ** kwds ):
21- #p = parameter_single(*args)
22- #if value is not None:
23- # p.value = value
24- #return p
2521 if len (args ) == 0 or args [0 ] == 1 or type (args [0 ]) == str :
26- return data_ (** kwds )
22+ return create_data_ (** kwds )
2723 if len (args ) == 1 :
28- return data_ (args [0 ], ** kwds )
24+ return create_data_indexed_ (args [0 ], ** kwds )
2925 else :
30- raise RuntimeError ("Data values only have one argument" )
26+ raise RuntimeError ("Data objects only have one argument" )
3127
3228
3329class parameter (object ):
3430 def __new__ (cls , * args , ** kwds ):
35- #p = parameter_single(*args)
36- #if value is not None:
37- # p.value = value
38- #return p
3931 if len (args ) == 0 or args [0 ] == 1 or type (args [0 ]) == str :
40- return parameter_ (** kwds )
32+ return create_parameter_ (** kwds )
4133 if len (args ) == 1 :
42- return parameter_ (args [0 ], ** kwds )
34+ return create_parameter_indexed_ (args [0 ], ** kwds )
4335 else :
4436 raise RuntimeError ("Parameters only have one argument" )
4537
4638
4739class variable (object ):
4840 def __new__ (cls , * args , ** kwds ):
4941 if len (args ) == 0 or args [0 ] == 1 or type (args [0 ]) == str :
50- return variable_ (** kwds )
42+ return create_variable_ (** kwds )
5143 if len (args ) == 1 :
52- return variable_ (args [0 ], ** kwds )
44+ return create_variable_indexed_ (args [0 ], ** kwds )
5345 else :
5446 raise RuntimeError ("Variables only have one argument" )
5547
@@ -58,20 +50,20 @@ def model_variable(self, *args, **kwds):
5850 if len (args ) == 0 or args [0 ] == 1 or type (args [0 ]) == str :
5951 if "index" in kwds :
6052 _index = list (kwds .pop ("index" ))
61- v = variable_ (len (_index ), ** kwds )
53+ v = create_variable_indexed_ (len (_index ), ** kwds )
6254 self .add_variable_ (v )
6355 ans = {}
6456 for i , key in enumerate (_index ):
6557 ans [key ] = v [i ]
6658 return ans
6759 else :
68- v = variable_ (** kwds )
60+ v = create_variable_ (** kwds )
6961 self .add_variable_ (v )
7062 return v
7163 elif args [0 ].__class__ == variable_array :
7264 self .add_variable_ (args [0 ])
7365 else :
74- v = variable_ (args [0 ], ** kwds )
66+ v = create_variable_indexed_ (args [0 ], ** kwds )
7567 self .add_variable_ (v )
7668 return v
7769
@@ -82,24 +74,29 @@ def model_variable(self, *args, **kwds):
8274except :
8375 pass
8476
77+
8578def print_equations (self , ostream = None ):
8679 if ostream is None :
8780 self .print_equations_ ()
8881 else :
89- ostream .write ( self .print_equations_ (0 ) );
82+ ostream .write (self .print_equations_ (0 ))
9083 return ostream
9184
85+
9286setattr (model , "print_equations" , print_equations )
9387
88+
9489def print_values (self , ostream = None ):
9590 if ostream is None :
9691 self .print_values_ ()
9792 else :
98- ostream .write ( self .print_values_ (0 ) );
93+ ostream .write (self .print_values_ (0 ))
9994 return ostream
10095
96+
10197setattr (model , "print_values" , print_values )
10298
99+
103100def constraint_is_numeric_type (self , * args , ** kwds ):
104101 return True
105102
0 commit comments