Tue, 04 Aug 2026 19:24:55 -0500
Added greedy insertion option, but does and actually really should not too much
| 89 | 1 | /*! |
| 2 | Definition of an admissible domain. | |
| 3 | */ | |
| 4 | ||
| 5 | use alg_tools::instance::{Instance, Space}; | |
| 6 | use alg_tools::loc::Loc; | |
| 7 | use alg_tools::sets::{Cube, Set}; | |
| 8 | use alg_tools::types::Num; | |
| 9 | use rand::distr::Uniform; | |
| 10 | use rand::prelude::{Rng, StdRng}; | |
| 11 | ||
| 12 | /// Admissible domain | |
| 13 | pub trait AdmissibleDomain<Point: Space>: Set<Point> { | |
| 14 | // Generate a random point in the domain | |
| 15 | fn random_point(&mut self) -> Option<Point> { | |
| 16 | None | |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | impl<F: Num + PartialOrd + Sized, const N: usize> AdmissibleDomain<Loc<N, F>> for Cube<N, F> {} | |
| 21 | ||
| 22 | /// | |
| 23 | pub struct FullSpace; | |
| 24 | ||
| 25 | impl<A: Space> Set<A> for FullSpace { | |
| 26 | fn contains<I: Instance<A>>(&self, _: I) -> bool { | |
| 27 | true | |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 31 | impl<F: Num + PartialOrd + Sized, const N: usize> AdmissibleDomain<Loc<N, F>> for FullSpace {} | |
| 32 | ||
| 33 | pub struct UniformRandom<S, R: Rng = StdRng>(pub S, pub R); | |
| 34 | ||
| 35 | impl<A: Space, S: Set<A>, R: Rng> Set<A> for UniformRandom<S, R> { | |
| 36 | fn contains<I: Instance<A>>(&self, item: I) -> bool { | |
| 37 | self.0.contains(item) | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | impl<const N: usize, R: Rng> AdmissibleDomain<Loc<N, f64>> for UniformRandom<Cube<N, f64>, R> { | |
| 42 | fn random_point(&mut self) -> Option<Loc<N, f64>> { | |
| 43 | let UniformRandom(ref cube, ref mut rng) = *self; | |
| 44 | Some(Loc(cube.map(|a, b| rng.sample(Uniform::new(a, b).unwrap())))) | |
| 45 | } | |
| 46 | } |