src/bisection_tree/refine.rs

branch
dev
changeset 86
d5b0e496b72f
parent 55
7b2ee3e84c5f
equal deleted inserted replaced
76:99ad55974e62 86:d5b0e496b72f
1 1
2 use std::collections::BinaryHeap; 2 use std::collections::BinaryHeap;
3 use std::cmp::{PartialOrd, Ord, Ordering, Ordering::*, max}; 3 use std::cmp::{PartialOrd, Ord, Ordering, Ordering::*, max};
4 use std::marker::PhantomData; 4 use std::marker::PhantomData;
5 use std::sync::{Arc, Mutex, MutexGuard, Condvar}; 5 use std::sync::{Arc, Mutex, MutexGuard, Condvar};
6 use serde::{Serialize, Deserialize};
6 use crate::types::*; 7 use crate::types::*;
7 use crate::nanleast::NaNLeast; 8 use crate::nanleast::NaNLeast;
8 use crate::sets::Cube; 9 use crate::sets::Cube;
9 use crate::parallelism::{thread_pool_size, thread_pool}; 10 use crate::parallelism::{thread_pool_size, thread_pool};
10 use super::support::*; 11 use super::support::*;
33 } 34 }
34 35
35 /// An [`AggregatorSorting`] for [`Bounds`], using the upper/lower bound as the upper/lower key. 36 /// An [`AggregatorSorting`] for [`Bounds`], using the upper/lower bound as the upper/lower key.
36 /// 37 ///
37 /// See [`LowerBoundSorting`] for the opposite ordering. 38 /// See [`LowerBoundSorting`] for the opposite ordering.
38 pub struct UpperBoundSorting<F : Float>(PhantomData<F>); 39 #[derive(Debug, Clone, Serialize, Deserialize)]
40 pub struct UpperBoundSorting<F : Float>(
41 #[serde(skip)]
42 PhantomData<F>
43 );
39 44
40 /// An [`AggregatorSorting`] for [`Bounds`], using the upper/lower bound as the lower/upper key. 45 /// An [`AggregatorSorting`] for [`Bounds`], using the upper/lower bound as the lower/upper key.
41 /// 46 ///
42 /// See [`UpperBoundSorting`] for the opposite ordering. 47 /// See [`UpperBoundSorting`] for the opposite ordering.
43 pub struct LowerBoundSorting<F : Float>(PhantomData<F>); 48 #[derive(Debug, Clone, Serialize, Deserialize)]
49 pub struct LowerBoundSorting<F : Float>(
50 #[serde(skip)]
51 PhantomData<F>
52 );
44 53
45 impl<F : Float> AggregatorSorting for UpperBoundSorting<F> { 54 impl<F : Float> AggregatorSorting for UpperBoundSorting<F> {
46 type Agg = Bounds<F>; 55 type Agg = Bounds<F>;
47 type Sort = NaNLeast<F>; 56 type Sort = NaNLeast<F>;
48 57
134 /// Fuse two [`Self::Result`]s (needed in threaded refinement). 143 /// Fuse two [`Self::Result`]s (needed in threaded refinement).
135 fn fuse_results(r1 : &mut Self::Result, r2 : Self::Result); 144 fn fuse_results(r1 : &mut Self::Result, r2 : Self::Result);
136 } 145 }
137 146
138 /// Structure for tracking the refinement process in a [`BinaryHeap`]. 147 /// Structure for tracking the refinement process in a [`BinaryHeap`].
148 #[derive(Debug)]
139 struct RefinementInfo<'a, F, D, A, S, RResult, const N : usize, const P : usize> 149 struct RefinementInfo<'a, F, D, A, S, RResult, const N : usize, const P : usize>
140 where F : Float, 150 where F : Float,
141 D : 'static, 151 D : 'static,
142 A : Aggregator, 152 A : Aggregator,
143 S : AggregatorSorting<Agg = A> { 153 S : AggregatorSorting<Agg = A> {
226 } 236 }
227 237
228 /// This is a container for a [`BinaryHeap`] of [`RefinementInfo`]s together with tracking of 238 /// This is a container for a [`BinaryHeap`] of [`RefinementInfo`]s together with tracking of
229 /// the greatest lower bound of the [`Aggregator`]s of the [`Node`]s therein accroding to 239 /// the greatest lower bound of the [`Aggregator`]s of the [`Node`]s therein accroding to
230 /// chosen [`AggregatorSorting`]. 240 /// chosen [`AggregatorSorting`].
241 #[derive(Debug)]
231 struct HeapContainer<'a, F, D, A, S, RResult, const N : usize, const P : usize> 242 struct HeapContainer<'a, F, D, A, S, RResult, const N : usize, const P : usize>
232 where F : Float, 243 where F : Float,
233 D : 'static + Copy, 244 D : 'static + Copy,
234 Const<P> : BranchCount<N>, 245 Const<P> : BranchCount<N>,
235 A : Aggregator, 246 A : Aggregator,

mercurial