Added a helper function to remove a variable from the model

This commit is contained in:
hamilcarBarca17
2023-03-08 16:40:46 -07:00
parent 7ecf0c3fc2
commit 9d38c4acb9
+22
View File
@@ -1,6 +1,7 @@
use crate::{ffi, proto};
use proto::constraint_proto::Constraint as CstEnum;
use smallvec::SmallVec;
use crate::proto::LinearArgumentProto;
/// A builder for CP SAT.
///
@@ -98,6 +99,27 @@ impl CpModelBuilder {
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
/// [IntVar] indentifier.
///