Added a helper function to remove a variable from the model
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use crate::{ffi, proto};
|
use crate::{ffi, proto};
|
||||||
use proto::constraint_proto::Constraint as CstEnum;
|
use proto::constraint_proto::Constraint as CstEnum;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use crate::proto::LinearArgumentProto;
|
||||||
|
|
||||||
/// A builder for CP SAT.
|
/// A builder for CP SAT.
|
||||||
///
|
///
|
||||||
@@ -98,6 +99,27 @@ impl CpModelBuilder {
|
|||||||
self.new_int_var_with_name(domain, "")
|
self.new_int_var_with_name(domain, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes the [IntVar] whose name matches the given name from the model.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use cp_sat::builder::{CpModelBuilder, IntVar};
|
||||||
|
/// let mut model = CpModelBuilder::default();
|
||||||
|
/// let x = model.new_int_var_with_name([(0, 1)], "some cool name");
|
||||||
|
/// assert!(!model.proto().variables.is_empty());
|
||||||
|
/// let name = model.remove_int_var("some cool name");
|
||||||
|
/// assert!(model.proto().variables.is_empty());
|
||||||
|
pub fn remove_int_var(&mut self, name: &str) {
|
||||||
|
let position = self
|
||||||
|
.proto
|
||||||
|
.variables
|
||||||
|
.iter()
|
||||||
|
.position(|variable| variable.name == name)
|
||||||
|
.unwrap();
|
||||||
|
self.proto.variables.remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new integer variable with a name, and returns the
|
/// Creates a new integer variable with a name, and returns the
|
||||||
/// [IntVar] indentifier.
|
/// [IntVar] indentifier.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user