pub struct Constant<V> { /* private fields */ }
Implementations§
source§impl<V> Constant<V>
impl<V> Constant<V>
sourcepub fn new(value: V) -> Constant<V>
pub fn new(value: V) -> Constant<V>
Examples found in repository?
src/libpcp/search/branch_and_bound.rs (line 70)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
fn enter(&mut self, mut current: Space<VStore, CStore, R>)
-> (<Space<VStore, CStore, R> as Freeze>::FrozenState, Status<Space<VStore, CStore, R>>)
{
if let Some(bound) = self.value.clone() {
let bound = Box::new(Constant::new(bound)) as Var<VStore>;
match self.mode {
Mode::Minimize => current.cstore.alloc(Box::new(XLessY::new(self.var.bclone(), bound.bclone()))),
Mode::Maximize => current.cstore.alloc(Box::new(x_greater_y(self.var.bclone(), bound.bclone()))),
};
}
let (mut immutable_state, status) = self.child.enter(current);
if status == Satisfiable {
let space = immutable_state.unfreeze();
self.value = Some(self.var.read(&space.vstore).lower());
immutable_state = space.freeze();
}
(immutable_state, status)
}
More examples
src/libpcp/search/branching/binary_split.rs (line 40)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn distribute(&mut self, space: Space<VStore, CStore, R>, var_idx: usize, val: Bound) ->
(<Space<VStore, CStore, R> as Freeze>::FrozenState, Vec<Branch<Space<VStore, CStore, R>>>)
{
// See notes in Enumerate::distribute.
Branch::distribute(space,
vec![
Box::new(move |space: &mut Space<VStore, CStore, R>| {
let x = Box::new(Identity::<Domain>::new(var_idx)) as Var<VStore>;
let v = Box::new(Constant::new(val)) as Var<VStore>;
let x_less_v = x_leq_y::<_,_,Bound>(x.bclone(), v.bclone());
space.cstore.alloc(Box::new(x_less_v));
}),
Box::new(move |space: &mut Space<VStore, CStore, R>| {
let x = Box::new(Identity::<Domain>::new(var_idx)) as Var<VStore>;
let v = Box::new(Constant::new(val)) as Var<VStore>;
let x_geq_v = x_greater_y(x, v);
space.cstore.alloc(Box::new(x_geq_v));
})
]
)
}
src/libpcp/search/branching/enumerate.rs (line 42)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn distribute(&mut self, space: Space<VStore, CStore, R>, var_idx: usize, val: Bound) ->
(<Space<VStore, CStore, R> as Freeze>::FrozenState, Vec<Branch<Space<VStore, CStore, R>>>)
{
// Note that `Copy` on `Bound` should not be mandatory.
// This is a problem generated by the Rust issue #28796, because we cannot box (and thus return) closures that contain moved values.
// This is also why we have redundant code in both branches, we can only pass value that can be copied to the closures (here `var_idx` and `val`).
Branch::distribute(space,
vec![
Box::new(move |space: &mut Space<VStore, CStore, R>| {
let x = Box::new(Identity::<Domain>::new(var_idx)) as Var<VStore>;
let v = Box::new(Constant::new(val)) as Var<VStore>;
let x_eq_v = XEqY::new(x.bclone(), v.bclone());
space.cstore.alloc(Box::new(x_eq_v));
}),
Box::new(move |space: &mut Space<VStore, CStore, R>| {
let x = Box::new(Identity::<Domain>::new(var_idx)) as Var<VStore>;
let v = Box::new(Constant::new(val)) as Var<VStore>;
let x_neq_v = XNeqY::new(x, v);
space.cstore.alloc(Box::new(x_neq_v));
})
]
)
}