@@ -6044,7 +6044,7 @@ cdef class Model:
60446044 Parameters
60456045 ----------
60466046 cons : ExprCons
6047- The expression constraint that is not yet an actual constraint
6047+ the constraint expression to add to the model (e.g., x + y <= 5)
60486048 name : str, optional
60496049 the name of the constraint, generic name if empty (Default value = "")
60506050 initial : bool, optional
@@ -6692,43 +6692,131 @@ cdef class Model:
66926692 else :
66936693 raise NotImplementedError (" Adding coefficients to %s constraints is not implemented." % constype)
66946694
6695- def addConsNode (self , Node node , Constraint cons , Node validnode = None ):
6695+ def addConsNode (self , Node node , ExprCons cons , Node validnode = None , name = ' ' ,
6696+ initial = True , separate = True , enforce = True , check = True ,
6697+ propagate = True , local = True , dynamic = False , removable = True ,
6698+ stickingatnode = True ):
66966699 """
66976700 Add a constraint to the given node.
66986701
66996702 Parameters
67006703 ----------
67016704 node : Node
67026705 node at which the constraint will be added
6703- cons : Constraint
6704- the constraint to add to the node
6706+ cons : ExprCons
6707+ the constraint expression to add to the node (e.g., x + y <= 5)
67056708 validnode : Node or None, optional
67066709 more global node where cons is also valid. (Default=None)
6710+ name : str, optional
6711+ name of the constraint (Default value = '')
6712+ initial : bool, optional
6713+ should the LP relaxation of constraint be in the initial LP? (Default value = True)
6714+ separate : bool, optional
6715+ should the constraint be separated during LP processing? (Default value = True)
6716+ enforce : bool, optional
6717+ should the constraint be enforced during node processing? (Default value = True)
6718+ check : bool, optional
6719+ should the constraint be checked for feasibility? (Default value = True)
6720+ propagate : bool, optional
6721+ should the constraint be propagated during node processing? (Default value = True)
6722+ local : bool, optional
6723+ is the constraint only valid locally? (Default value = True)
6724+ dynamic : bool, optional
6725+ is the constraint subject to aging? (Default value = False)
6726+ removable : bool, optional
6727+ should the relaxation be removed from the LP due to aging or cleanup? (Default value = True)
6728+ stickingatnode : bool, optional
6729+ should the constraint always be kept at the node where it was added? (Default value = True)
6730+
6731+ Returns
6732+ -------
6733+ Constraint
6734+ The added Constraint object.
67076735
67086736 """
6737+ assert isinstance (cons, ExprCons), " given constraint is not ExprCons but %s " % cons.__class__ .__name__
6738+
6739+ cdef SCIP_CONS* scip_cons
6740+
6741+ kwargs = dict (name = name, initial = initial, separate = separate,
6742+ enforce = enforce, check = check, propagate = propagate,
6743+ local = local, modifiable = False , dynamic = dynamic,
6744+ removable = removable, stickingatnode = stickingatnode)
6745+ pycons_initial = self .createConsFromExpr(cons, ** kwargs)
6746+ scip_cons = (< Constraint> pycons_initial).scip_cons
6747+
67096748 if isinstance (validnode, Node):
6710- PY_SCIP_CALL(SCIPaddConsNode(self ._scip, node.scip_node, cons. scip_cons, validnode.scip_node))
6749+ PY_SCIP_CALL(SCIPaddConsNode(self ._scip, node.scip_node, scip_cons, validnode.scip_node))
67116750 else :
6712- PY_SCIP_CALL(SCIPaddConsNode(self ._scip, node.scip_node, cons.scip_cons, NULL ))
6713- Py_INCREF(cons)
6751+ PY_SCIP_CALL(SCIPaddConsNode(self ._scip, node.scip_node, scip_cons, NULL ))
6752+
6753+ pycons = Constraint.create(scip_cons)
6754+ pycons.data = (< Constraint> pycons_initial).data
6755+ PY_SCIP_CALL(SCIPreleaseCons(self ._scip, & scip_cons))
6756+
6757+ return pycons
67146758
6715- def addConsLocal (self , Constraint cons , Node validnode = None ):
6759+ def addConsLocal (self , ExprCons cons , Node validnode = None , name = ' ' ,
6760+ initial = True , separate = True , enforce = True , check = True ,
6761+ propagate = True , local = True , dynamic = False , removable = True ,
6762+ stickingatnode = True ):
67166763 """
67176764 Add a constraint to the current node.
67186765
67196766 Parameters
67206767 ----------
6721- cons : Constraint
6722- the constraint to add to the current node
6768+ cons : ExprCons
6769+ the constraint expression to add to the current node (e.g., x + y <= 5)
67236770 validnode : Node or None, optional
67246771 more global node where cons is also valid. (Default=None)
6772+ name : str, optional
6773+ name of the constraint (Default value = '')
6774+ initial : bool, optional
6775+ should the LP relaxation of constraint be in the initial LP? (Default value = True)
6776+ separate : bool, optional
6777+ should the constraint be separated during LP processing? (Default value = True)
6778+ enforce : bool, optional
6779+ should the constraint be enforced during node processing? (Default value = True)
6780+ check : bool, optional
6781+ should the constraint be checked for feasibility? (Default value = True)
6782+ propagate : bool, optional
6783+ should the constraint be propagated during node processing? (Default value = True)
6784+ local : bool, optional
6785+ is the constraint only valid locally? (Default value = True)
6786+ dynamic : bool, optional
6787+ is the constraint subject to aging? (Default value = False)
6788+ removable : bool, optional
6789+ should the relaxation be removed from the LP due to aging or cleanup? (Default value = True)
6790+ stickingatnode : bool, optional
6791+ should the constraint always be kept at the node where it was added? (Default value = True)
6792+
6793+ Returns
6794+ -------
6795+ Constraint
6796+ The added Constraint object.
67256797
67266798 """
6799+ assert isinstance (cons, ExprCons), " given constraint is not ExprCons but %s " % cons.__class__ .__name__
6800+
6801+ cdef SCIP_CONS* scip_cons
6802+
6803+ kwargs = dict (name = name, initial = initial, separate = separate,
6804+ enforce = enforce, check = check, propagate = propagate,
6805+ local = local, modifiable = False , dynamic = dynamic,
6806+ removable = removable, stickingatnode = stickingatnode)
6807+ pycons_initial = self .createConsFromExpr(cons, ** kwargs)
6808+ scip_cons = (< Constraint> pycons_initial).scip_cons
6809+
67276810 if isinstance (validnode, Node):
6728- PY_SCIP_CALL(SCIPaddConsLocal(self ._scip, cons. scip_cons, validnode.scip_node))
6811+ PY_SCIP_CALL(SCIPaddConsLocal(self ._scip, scip_cons, validnode.scip_node))
67296812 else :
6730- PY_SCIP_CALL(SCIPaddConsLocal(self ._scip, cons.scip_cons, NULL ))
6731- Py_INCREF(cons)
6813+ PY_SCIP_CALL(SCIPaddConsLocal(self ._scip, scip_cons, NULL ))
6814+
6815+ pycons = Constraint.create(scip_cons)
6816+ pycons.data = (< Constraint> pycons_initial).data
6817+ PY_SCIP_CALL(SCIPreleaseCons(self ._scip, & scip_cons))
6818+
6819+ return pycons
67326820
67336821 def addConsKnapsack (self , vars , weights , capacity , name = " " ,
67346822 initial = True , separate = True , enforce = True , check = True ,
0 commit comments