src/bisection_tree/btfn.rs

branch
dev
changeset 150
c4e394a9c84c
parent 125
25b6c8b20d1b
child 152
dab30b331f49
child 162
bea0c3841ced
--- a/src/bisection_tree/btfn.rs	Mon Sep 01 00:04:22 2025 -0500
+++ b/src/bisection_tree/btfn.rs	Mon Sep 01 13:51:03 2025 -0500
@@ -1,6 +1,5 @@
-use crate::mapping::{
-    BasicDecomposition, DifferentiableImpl, DifferentiableMapping, Instance, Mapping, Space,
-};
+use crate::instance::{ClosedSpace, Instance, Ownable, Space};
+use crate::mapping::{BasicDecomposition, DifferentiableImpl, DifferentiableMapping, Mapping};
 use crate::types::Float;
 use numeric_literals::replace_float_literals;
 use std::iter::Sum;
@@ -37,12 +36,31 @@
     _phantoms: PhantomData<F>,
 }
 
+impl<F: Float, G, BT, const N: usize> Ownable for BTFN<F, G, BT, N>
+where
+    G: SupportGenerator<N, F, Id = BT::Data>,
+    G::SupportType: LocalAnalysis<F, BT::Agg, N>,
+    BT: BTImpl<N, F>,
+{
+    type OwnedVariant = Self;
+
+    fn into_owned(self) -> Self::OwnedVariant {
+        self
+    }
+
+    /// Returns an owned instance of a reference.
+    fn clone_owned(&self) -> Self::OwnedVariant {
+        self.clone()
+    }
+}
+
 impl<F: Float, G, BT, const N: usize> Space for BTFN<F, G, BT, N>
 where
     G: SupportGenerator<N, F, Id = BT::Data>,
     G::SupportType: LocalAnalysis<F, BT::Agg, N>,
     BT: BTImpl<N, F>,
 {
+    type OwnedSpace = Self;
     type Decomp = BasicDecomposition;
 }
 
@@ -64,11 +82,7 @@
     }
 
     fn new_arc(bt: BT, generator: Arc<G>) -> Self {
-        BTFN {
-            bt: bt,
-            generator: generator,
-            _phantoms: std::marker::PhantomData,
-        }
+        BTFN { bt, generator, _phantoms: std::marker::PhantomData }
     }
 
     /// Create a new BTFN support generator and a pre-initialised bisection tree,
@@ -161,11 +175,7 @@
 {
     /// Create a new [`PreBTFN`] with no bisection tree.
     pub fn new_pre(generator: G) -> Self {
-        BTFN {
-            bt: (),
-            generator: Arc::new(generator),
-            _phantoms: std::marker::PhantomData,
-        }
+        BTFN { bt: (), generator: Arc::new(generator), _phantoms: std::marker::PhantomData }
     }
 }
 
@@ -188,11 +198,7 @@
             bt.insert(d, &support);
         }
 
-        BTFN {
-            bt: bt,
-            generator: Arc::new(both),
-            _phantoms: std::marker::PhantomData,
-        }
+        BTFN { bt: bt, generator: Arc::new(both), _phantoms: std::marker::PhantomData }
     }
 }
 
@@ -411,7 +417,7 @@
     BT: BTImpl<N, F>,
     G: SupportGenerator<N, F, Id = BT::Data>,
     G::SupportType: LocalAnalysis<F, BT::Agg, N> + Mapping<Loc<N, F>, Codomain = V>,
-    V: Sum + Space,
+    V: Sum + ClosedSpace,
 {
     type Codomain = V;
 
@@ -430,7 +436,7 @@
     G: SupportGenerator<N, F, Id = BT::Data>,
     G::SupportType:
         LocalAnalysis<F, BT::Agg, N> + DifferentiableMapping<Loc<N, F>, DerivativeDomain = V>,
-    V: Sum + Space,
+    V: Sum + ClosedSpace,
 {
     type Derivative = V;
 
@@ -846,12 +852,7 @@
     Cube<N, F>: P2Minimise<Loc<N, F>, F>,
 {
     fn maximise(&mut self, tolerance: F, max_steps: usize) -> (Loc<N, F>, F) {
-        let refiner = P2Refiner {
-            tolerance,
-            max_steps,
-            how: RefineMax,
-            bound: None,
-        };
+        let refiner = P2Refiner { tolerance, max_steps, how: RefineMax, bound: None };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")
@@ -864,24 +865,14 @@
         tolerance: F,
         max_steps: usize,
     ) -> Option<(Loc<N, F>, F)> {
-        let refiner = P2Refiner {
-            tolerance,
-            max_steps,
-            how: RefineMax,
-            bound: Some(bound),
-        };
+        let refiner = P2Refiner { tolerance, max_steps, how: RefineMax, bound: Some(bound) };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")
     }
 
     fn minimise(&mut self, tolerance: F, max_steps: usize) -> (Loc<N, F>, F) {
-        let refiner = P2Refiner {
-            tolerance,
-            max_steps,
-            how: RefineMin,
-            bound: None,
-        };
+        let refiner = P2Refiner { tolerance, max_steps, how: RefineMin, bound: None };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")
@@ -894,36 +885,21 @@
         tolerance: F,
         max_steps: usize,
     ) -> Option<(Loc<N, F>, F)> {
-        let refiner = P2Refiner {
-            tolerance,
-            max_steps,
-            how: RefineMin,
-            bound: Some(bound),
-        };
+        let refiner = P2Refiner { tolerance, max_steps, how: RefineMin, bound: Some(bound) };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")
     }
 
     fn has_upper_bound(&mut self, bound: F, tolerance: F, max_steps: usize) -> bool {
-        let refiner = BoundRefiner {
-            bound,
-            tolerance,
-            max_steps,
-            how: RefineMax,
-        };
+        let refiner = BoundRefiner { bound, tolerance, max_steps, how: RefineMax };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")
     }
 
     fn has_lower_bound(&mut self, bound: F, tolerance: F, max_steps: usize) -> bool {
-        let refiner = BoundRefiner {
-            bound,
-            tolerance,
-            max_steps,
-            how: RefineMin,
-        };
+        let refiner = BoundRefiner { bound, tolerance, max_steps, how: RefineMin };
         self.bt
             .search_and_refine(refiner, &self.generator)
             .expect("Refiner failure.")

mercurial