src/bisection_tree/btfn.rs

branch
dev
changeset 86
d5b0e496b72f
parent 63
f7b87d84864d
equal deleted inserted replaced
76:99ad55974e62 86:d5b0e496b72f
1 1
2 use numeric_literals::replace_float_literals; 2 use numeric_literals::replace_float_literals;
3 use serde::{Serialize, Deserialize};
3 use std::iter::Sum; 4 use std::iter::Sum;
4 use std::marker::PhantomData; 5 use std::marker::PhantomData;
5 use std::sync::Arc; 6 use std::sync::Arc;
6 use crate::types::Float; 7 use crate::types::Float;
7 use crate::mapping::{ 8 use crate::mapping::{
28 /// 29 ///
29 /// The `generator` lists the component functions that have to implement [`Support`]. 30 /// The `generator` lists the component functions that have to implement [`Support`].
30 /// Identifiers of the components ([`SupportGenerator::Id`], usually `usize`) are stored stored 31 /// Identifiers of the components ([`SupportGenerator::Id`], usually `usize`) are stored stored
31 /// in a [bisection tree][BTImpl], when one is provided as `bt`. However `bt` may also be `()` 32 /// in a [bisection tree][BTImpl], when one is provided as `bt`. However `bt` may also be `()`
32 /// for a [`PreBTFN`] that is only useful for vector space operations with a full [`BTFN`]. 33 /// for a [`PreBTFN`] that is only useful for vector space operations with a full [`BTFN`].
33 #[derive(Clone,Debug)] 34 #[derive(Clone,Debug,Serialize,Deserialize)]
34 pub struct BTFN< 35 pub struct BTFN<
35 F : Float, 36 F : Float,
36 G : SupportGenerator<F, N>, 37 G : SupportGenerator<F, N>,
37 BT /*: BTImpl<F, N>*/, 38 BT /*: BTImpl<F, N>*/,
38 const N : usize 39 const N : usize
39 > /*where G::SupportType : LocalAnalysis<F, A, N>*/ { 40 > /*where G::SupportType : LocalAnalysis<F, A, N>*/ {
40 bt : BT, 41 bt : BT,
41 generator : Arc<G>, 42 generator : Arc<G>,
43 #[serde(skip)]
42 _phantoms : PhantomData<F>, 44 _phantoms : PhantomData<F>,
43 } 45 }
44 46
45 impl<F : Float, G, BT, const N : usize> 47 impl<F : Float, G, BT, const N : usize>
46 Space for BTFN<F, G, BT, N> 48 Space for BTFN<F, G, BT, N>
585 } 587 }
586 } 588 }
587 } 589 }
588 590
589 /// Helper type to use [`P2Refiner`] for maximisation. 591 /// Helper type to use [`P2Refiner`] for maximisation.
592 #[derive(Debug, Clone, Serialize, Deserialize)]
590 struct RefineMax; 593 struct RefineMax;
591 594
592 /// Helper type to use [`P2Refiner`] for minimisation. 595 /// Helper type to use [`P2Refiner`] for minimisation.
596 #[derive(Debug, Clone, Serialize, Deserialize)]
593 struct RefineMin; 597 struct RefineMin;
594 598
595 /// A bisection tree [`Refiner`] for maximising or minimising a [`BTFN`]. 599 /// A bisection tree [`Refiner`] for maximising or minimising a [`BTFN`].
596 /// 600 ///
597 /// The type parameter `T` should be either [`RefineMax`] or [`RefineMin`]. 601 /// The type parameter `T` should be either [`RefineMax`] or [`RefineMin`].
602 #[derive(Debug, Clone, Serialize, Deserialize)]
598 struct P2Refiner<F : Float, T> { 603 struct P2Refiner<F : Float, T> {
599 /// The maximum / minimum should be above / below this threshold. 604 /// The maximum / minimum should be above / below this threshold.
600 /// If the threshold cannot be satisfied, the refiner will return `None`. 605 /// If the threshold cannot be satisfied, the refiner will return `None`.
601 bound : Option<F>, 606 bound : Option<F>,
602 /// Tolerance for function value estimation. 607 /// Tolerance for function value estimation.
731 //// upper or lower bound. 736 //// upper or lower bound.
732 /// 737 ///
733 /// The type parameter `T` should be either [`RefineMax`] for upper bound or [`RefineMin`] 738 /// The type parameter `T` should be either [`RefineMax`] for upper bound or [`RefineMin`]
734 /// for lower bound. 739 /// for lower bound.
735 740
741 #[derive(Debug, Clone, Serialize, Deserialize)]
736 struct BoundRefiner<F : Float, T> { 742 struct BoundRefiner<F : Float, T> {
737 /// The upper/lower bound to check for 743 /// The upper/lower bound to check for
738 bound : F, 744 bound : F,
739 /// Tolerance for function value estimation. 745 /// Tolerance for function value estimation.
740 tolerance : F, 746 tolerance : F,

mercurial