1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use core::Card;
use rand::Rng;
use std::fmt::Debug;
use std::ops::Range;
pub trait Space {
type Value: Debug + Clone;
fn dim(&self) -> usize;
fn card(&self) -> Card;
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::Value;
}
impl<D: Space> Space for Box<D> {
type Value = D::Value;
fn dim(&self) -> usize { (**self).dim() }
fn card(&self) -> Card { (**self).card() }
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::Value {
(**self).sample(rng)
}
}
impl<'a, D: Space> Space for &'a D {
type Value = D::Value;
fn dim(&self) -> usize { (**self).dim() }
fn card(&self) -> Card { (**self).card() }
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::Value {
(**self).sample(rng)
}
}
pub trait BoundedSpace: Space
where Self::Value: PartialOrd
{
type BoundValue: PartialOrd + Copy;
fn inf(&self) -> Option<Self::BoundValue>;
fn sup(&self) -> Option<Self::BoundValue>;
fn contains(&self, val: Self::BoundValue) -> bool;
}
pub trait FiniteSpace: BoundedSpace
where Self::Value: PartialOrd
{
fn range(&self) -> Range<Self::Value>;
}