Skip to content

Commit 0a51bd7

Browse files
committed
Add add_cons_local
1 parent 0f1ef58 commit 0a51bd7

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/model.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,26 @@ pub trait ProblemOrSolving {
862862
rhs: f64,
863863
name: &str,
864864
) -> Constraint;
865+
866+
/// Adds the given constraint to the model at the given node and its children.
867+
///
868+
/// # Arguments
869+
///
870+
/// * `cons` - The constraint to add.
871+
/// * `validnode` - The node at which the constraint is valid.
872+
///
873+
/// # Returns
874+
///
875+
/// A reference-counted pointer to the new constraint.
876+
///
877+
/// # Panics
878+
///
879+
/// This method panics if the constraint cannot be created in the current state.
880+
fn add_cons_local(
881+
&mut self,
882+
cons: Constraint,
883+
validnode: Node,
884+
) -> Constraint;
865885
}
866886

867887
/// A trait for model stages that have a problem or are during solving.
@@ -1182,6 +1202,34 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
11821202
scip: self.scip.clone(),
11831203
}
11841204
}
1205+
1206+
/// Adds the given constraint to the model at the given node and its children.
1207+
///
1208+
/// # Arguments
1209+
///
1210+
/// * `cons` - The constraint to add.
1211+
/// * `validnode` - The node at which the constraint is valid.
1212+
///
1213+
/// # Returns
1214+
///
1215+
/// A reference-counted pointer to the new constraint.
1216+
///
1217+
/// # Panics
1218+
///
1219+
/// This method panics if the constraint cannot be created in the current state.
1220+
fn add_cons_local(
1221+
&mut self,
1222+
cons: Constraint,
1223+
validnode: Node,
1224+
) -> Constraint {
1225+
let result = self
1226+
.scip
1227+
.add_cons_local(&cons, &validnode)
1228+
.expect("Failed to create constraint in state ProblemCreated");
1229+
1230+
cons
1231+
}
1232+
11851233
}
11861234

11871235
/// A trait for optimization models with any state that might have solutions.

src/scip.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::branchrule::{BranchRule, BranchingCandidate};
2+
use crate::node::Node;
23
use crate::pricer::{Pricer, PricerResultState};
34
use crate::{
45
ffi, scip_call_panic, BranchingResult, Conshdlr, Constraint, Event, Eventhdlr, HeurResult,
@@ -544,6 +545,7 @@ impl ScipPtr {
544545
Some(var)
545546
}
546547
}
548+
547549
pub(crate) fn create_cons_indicator(
548550
&self,
549551
bin_var: &Variable,
@@ -574,6 +576,18 @@ impl ScipPtr {
574576
Ok(scip_cons)
575577
}
576578

579+
pub(crate) fn add_cons_local(
580+
&self,
581+
cons: &Constraint,
582+
validnode: &Node,
583+
) -> Result<*mut SCIP_Cons, Retcode> {
584+
let cons_ptr = MaybeUninit::uninit();
585+
scip_call! { ffi::SCIPaddConsLocal(self.raw, cons.raw, validnode.raw) };
586+
let cons_ptr = unsafe { cons_ptr.assume_init() };
587+
Ok(cons_ptr)
588+
}
589+
590+
577591
/// Create solution
578592
pub(crate) fn create_sol(&self, original: bool) -> Result<*mut SCIP_SOL, Retcode> {
579593
let mut sol = MaybeUninit::uninit();

0 commit comments

Comments
 (0)