Skip to content

Commit

Permalink
[Concept][Store] Add concepts for VStore and CStore to simplify type …
Browse files Browse the repository at this point in the history
…bounds.
  • Loading branch information
ptal committed Dec 29, 2016
1 parent 7668d08 commit f612c13
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 53 deletions.
30 changes: 29 additions & 1 deletion src/libpcp/concept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

use gcollections::*;
use gcollections::ops::*;
use kernel::*;
use term::ops::*;
use variable::ops::*;
use propagation::events::*;
use propagation::concept::*;
use propagation::ops::*;
use interval::ops::Range;
use num::{Signed, Integer};
use std::ops::*;
use std::fmt::Debug;
use std::fmt::{Display, Debug};


pub trait IntBound:
Expand Down Expand Up @@ -70,3 +74,27 @@ impl<R, VStore> IntVariable<VStore> for R where
R: Clone + Debug,
VStore: Collection
{}

pub trait IntVStore:
AssociativeCollection + Alloc + Display + Cardinality<Size=usize> +
Freeze + Iterable + Index<usize> + MonotonicUpdate
{}

impl<R> IntVStore for R where
R: AssociativeCollection + Alloc + Display + Cardinality<Size=usize>,
R: Freeze + Iterable + Index<usize> + MonotonicUpdate
{}

pub trait IntCStore<VStore>:
Alloc + Empty + Clone + Freeze + Debug +
Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>> +
Consistency<VStore> +
PropagatorConcept<VStore, FDEvent> + Propagator<VStore>
{}

impl<R, VStore> IntCStore<VStore> for R where
R: Alloc + Empty + Clone + Freeze + Debug,
R: Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>>,
R: Consistency<VStore>,
R: PropagatorConcept<VStore, FDEvent> + Propagator<VStore>
{}
16 changes: 6 additions & 10 deletions src/libpcp/propagators/cumulative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
// limitations under the License.

use propagators::*;
use propagation::*;
use propagation::events::*;
use term::bool2int::*;
use gcollections::ops::*;
use gcollections::*;
use std::marker::PhantomData;
use concept::*;

Expand Down Expand Up @@ -48,12 +44,12 @@ impl<VS, VD, VR, VC, VStore> Cumulative<VS, VD, VR, VC, VStore>
}

impl<V, VS, VD, VR, VC, Bound, VStore, Dom> Cumulative<VS, VD, VR, VC, VStore> where
VStore: AssociativeCollection<Item=Dom, Location=V> + Alloc,
VStore: IntVStore<Item=Dom, Location=V>,
V: IntVariable<VStore> + 'static,
VS: IntVariable<VStore> + 'static,
VD: IntVariable<VStore> + 'static,
VR: IntVariable<VStore> + 'static,
VC: IntVariable<VStore> + 'static,
V: IntVariable<VStore> + 'static,
Dom: IntDomain<Item=Bound> + 'static,
Bound: IntBound + 'static,
{
Expand All @@ -62,8 +58,7 @@ impl<V, VS, VD, VR, VC, Bound, VStore, Dom> Cumulative<VS, VD, VR, VC, VStore> w
// c >= r[j] + sum( i in tasks where i != j ) (
// bool2int( s[i] <= s[j] /\ s[j] < s[i] + d[i] ) * r[i]));
pub fn join<CStore>(&self, vstore: &mut VStore, cstore: &mut CStore) where
CStore: Alloc + Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>>
+ Empty + Clone + PropagatorConcept<VStore, FDEvent> + Propagator<VStore> + 'static
CStore: IntCStore<VStore> + 'static
{
let tasks = self.starts.len();
// forall( j in tasks ) (...)
Expand Down Expand Up @@ -119,10 +114,11 @@ mod test {
use super::*;
use kernel::*;
use kernel::Trilean::*;
use interval::interval::*;
use interval::ops::Range;
use variable::VStoreCopy;
use propagation::CStoreFD;
use interval::interval::*;
use interval::ops::Range;
use gcollections::ops::*;

type VStoreFD = VStoreCopy<Interval<i32>>;

Expand Down
13 changes: 5 additions & 8 deletions src/libpcp/search/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use search::search_tree_visitor::*;
use search::search_tree_visitor::Status::*;
use term::*;
use propagators::cmp::*;
use propagation::concept::*;
use propagation::events::*;
use gcollections::ops::*;
use gcollections::*;
use concept::*;

pub enum Mode {
Expand Down Expand Up @@ -49,12 +45,12 @@ impl<V, Bound, C> BranchAndBound<V, Bound, C> {

impl<C, Bound, Dom, V, VStore, CStore, R> SearchTreeVisitor<Space<VStore, CStore, R>> for
BranchAndBound<V, Bound, C> where
VStore: Freeze + Collection<Item=Dom>,
V: IntVariable<VStore> + 'static,
CStore: Freeze + Alloc + Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>>,
C: SearchTreeVisitor<Space<VStore, CStore, R>>,
VStore: IntVStore<Item=Dom>,
CStore: IntCStore<VStore>,
Dom: IntDomain<Item=Bound> + 'static,
Bound: IntBound + 'static,
V: IntVariable<VStore> + 'static,
C: SearchTreeVisitor<Space<VStore, CStore, R>>,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
{
fn start(&mut self, root: &Space<VStore, CStore, R>) {
Expand Down Expand Up @@ -94,6 +90,7 @@ mod test {
use search::branching::middle_val::*;
use interval::interval_set::*;
use gcollections::VectorStack;
use gcollections::ops::*;

#[test]
fn simple_maximize_test() {
Expand Down
13 changes: 3 additions & 10 deletions src/libpcp/search/branching/binary_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,16 @@ use kernel::*;
use search::branching::*;
use search::branching::branch::*;
use search::space::*;
use variable::ops::*;
use term::*;
use propagators::cmp::*;
use propagation::concept::*;
use propagation::events::*;
use gcollections::ops::*;
use gcollections::*;
use std::ops::*;
use concept::*;

pub struct BinarySplit;

// See discussion about type bounds: https://github.com/ptal/pcp/issues/11
impl<VStore, CStore, R, Domain, Bound> Distributor<Space<VStore, CStore, R>, Bound> for BinarySplit where
VStore: Freeze + Iterable<Item=Domain> + Index<usize, Output=Domain> + MonotonicUpdate,
VStore: AssociativeCollection<Location=Identity<Domain>>,
CStore: Freeze,
CStore: Alloc + Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>>,
VStore: IntVStore<Item=Domain, Location=Identity<Domain>, Output=Domain>,
CStore: IntCStore<VStore>,
Domain: IntDomain<Item=Bound> + 'static,
Bound: IntBound + 'static,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
Expand Down Expand Up @@ -69,6 +61,7 @@ pub mod test {
use search::*;
use interval::interval_set::*;
use interval::ops::Range;
use gcollections::ops::*;

type Domain = IntervalSet<i32>;

Expand Down
8 changes: 2 additions & 6 deletions src/libpcp/search/branching/brancher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ use search::search_tree_visitor::*;
use kernel::*;
use search::branching::*;
use search::space::*;
use variable::ops::*;
use term::*;
use term::ops::*;
use gcollections::*;
use std::ops::*;
use concept::*;

pub struct Brancher<Var,Val,D>
Expand All @@ -43,10 +40,9 @@ impl<Var,Val,D> Brancher<Var,Val,D>
}

impl<Var, Val, D, VStore, CStore, R, Domain, Bound> SearchTreeVisitor<Space<VStore, CStore, R>> for Brancher<Var,Val,D> where
VStore: Freeze + Iterable<Item=Domain> + Index<usize, Output=Domain> + MonotonicUpdate,
VStore: AssociativeCollection<Location=Identity<Domain>>,
VStore: IntVStore<Item=Domain, Location=Identity<Domain>, Output=Domain>,
CStore: IntCStore<VStore>,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>,
CStore: Freeze,
Var: VarSelection<Space<VStore, CStore, R>>,
Val: ValSelection<Domain>,
Domain: IntDomain<Item=Bound>,
Expand Down
13 changes: 2 additions & 11 deletions src/libpcp/search/branching/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@ use kernel::*;
use search::branching::*;
use search::branching::branch::*;
use search::space::*;
use variable::ops::*;
use term::*;
use propagators::cmp::*;
use propagation::concept::*;
use propagation::events::*;
use gcollections::ops::*;
use gcollections::*;
use std::ops::*;
use concept::*;

pub struct Enumerate;

// See discussion about type bounds: https://github.com/ptal/pcp/issues/11
impl<VStore, CStore, R, Domain, Bound> Distributor<Space<VStore, CStore, R>, Bound> for Enumerate where
VStore: Freeze + Iterable<Item=Domain> + Index<usize, Output=Domain> + MonotonicUpdate,
VStore: AssociativeCollection<Location=Identity<Domain>>,
CStore: Freeze,
CStore: Alloc + Collection<Item=Box<PropagatorConcept<VStore, FDEvent>>>,
VStore: IntVStore<Item=Domain, Location=Identity<Domain>, Output=Domain>,
CStore: IntCStore<VStore>,
Domain: IntDomain<Item=Bound> + 'static,
Bound: IntBound + 'static,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
Expand Down
1 change: 0 additions & 1 deletion src/libpcp/search/branching/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub use search::branching::input_order::*;
pub use search::branching::middle_val::*;
pub use search::branching::min_val::*;


use search::branching::branch::*;
use gcollections::*;

Expand Down
7 changes: 3 additions & 4 deletions src/libpcp/search/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
// limitations under the License.

use kernel::*;
use variable::ops::*;
use gcollections::ops::*;
use search::space::*;
use search::search_tree_visitor::*;
use std::fmt::{Debug, Display};
use std::io::{self};
use concept::*;

pub struct Debugger<C> {
child: C
Expand All @@ -33,8 +32,8 @@ impl<C> Debugger<C> {
}

impl<VStore, CStore, Domain, R, C> SearchTreeVisitor<Space<VStore, CStore, R>> for Debugger<C> where
VStore: Freeze + Display + Iterable<Item=Domain> + Cardinality<Size=usize>,
CStore: Freeze + Consistency<VStore> + Debug,
VStore: IntVStore<Item=Domain>,
CStore: IntCStore<VStore>,
C: SearchTreeVisitor<Space<VStore, CStore, R>>,
Domain: IsSingleton,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
Expand Down
5 changes: 3 additions & 2 deletions src/libpcp/search/propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use kernel::*;
use kernel::Trilean::*;
use search::space::*;
use search::search_tree_visitor::*;
use concept::*;

pub struct Propagation<C> {
child: C
Expand All @@ -30,8 +31,8 @@ impl<C> Propagation<C> {
}

impl<VStore, CStore, R, C> SearchTreeVisitor<Space<VStore, CStore, R>> for Propagation<C> where
VStore: Freeze,
CStore: Freeze + Consistency<VStore>,
VStore: IntVStore,
CStore: IntCStore<VStore>,
C: SearchTreeVisitor<Space<VStore, CStore, R>>,
R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
{
Expand Down

0 comments on commit f612c13

Please sign in to comment.