| 90 /// |
90 /// |
| 91 /// The search is performed by [`BTSearch::search_and_refine`]. |
91 /// The search is performed by [`BTSearch::search_and_refine`]. |
| 92 /// The `Refiner` is used to determine whether an [`Aggregator`] `A` stored in the [`BT`] is |
92 /// The `Refiner` is used to determine whether an [`Aggregator`] `A` stored in the [`BT`] is |
| 93 /// sufficiently refined within a [`Cube`], and in such a case, produce a desired result (e.g. |
93 /// sufficiently refined within a [`Cube`], and in such a case, produce a desired result (e.g. |
| 94 /// a maximum value of a function). |
94 /// a maximum value of a function). |
| 95 pub trait Refiner<F : Float, A, G, const N : usize> : Sync + Send + 'static |
95 pub trait Refiner<A, G, const N : usize> : Sync + Send + 'static |
| 96 where F : Num, |
96 where A : Aggregator, |
| 97 A : Aggregator, |
97 G : SupportGenerator<N> { |
| 98 G : SupportGenerator<F, N> { |
|
| 99 |
98 |
| 100 /// The result type of the refiner |
99 /// The result type of the refiner |
| 101 type Result : std::fmt::Debug + Sync + Send + 'static; |
100 type Result : std::fmt::Debug + Sync + Send + 'static; |
| 102 /// The sorting to be employed by [`BTSearch::search_and_refine`] on node aggregators |
101 /// The sorting to be employed by [`BTSearch::search_and_refine`] on node aggregators |
| 103 /// to detemrine node priority. |
102 /// to detemrine node priority. |
| 321 refiner : &R, |
320 refiner : &R, |
| 322 generator : &G, |
321 generator : &G, |
| 323 container_arc : &'c Arc<Mutex<HeapContainer<'a, F, D, A, R::Sorting, R::Result, N, P>>>, |
322 container_arc : &'c Arc<Mutex<HeapContainer<'a, F, D, A, R::Sorting, R::Result, N, P>>>, |
| 324 step : usize |
323 step : usize |
| 325 ) -> Result<R::Result, MutexGuard<'c, HeapContainer<'a, F, D, A, R::Sorting, R::Result, N, P>>> |
324 ) -> Result<R::Result, MutexGuard<'c, HeapContainer<'a, F, D, A, R::Sorting, R::Result, N, P>>> |
| 326 where R : Refiner<F, A, G, N>, |
325 where R : Refiner<A, G, N>, |
| 327 G : SupportGenerator<F, N, Id=D>, |
326 G : SupportGenerator<N, Id=D, RealField = F>, |
| 328 G::SupportType : LocalAnalysis<F, A, N> { |
327 G::SupportType : LocalAnalysis<A, Cube<F, N>> { |
| 329 |
328 |
| 330 //drop(container); |
329 //drop(container); |
| 331 |
330 |
| 332 // Refine a leaf. |
331 // Refine a leaf. |
| 333 let res = match self.data { |
332 let res = match self.data { |
| 433 fn search_and_refine<'b, R, G>( |
432 fn search_and_refine<'b, R, G>( |
| 434 &'b mut self, |
433 &'b mut self, |
| 435 refiner : R, |
434 refiner : R, |
| 436 generator : &Arc<G>, |
435 generator : &Arc<G>, |
| 437 ) -> Option<R::Result> |
436 ) -> Option<R::Result> |
| 438 where R : Refiner<F, Self::Agg, G, N> + Sync + Send + 'static, |
437 where R : Refiner<Self::Agg, G, N> + Sync + Send + 'static, |
| 439 G : SupportGenerator<F, N, Id=Self::Data> + Sync + Send + 'static, |
438 G : SupportGenerator<N, Id=Self::Data, RealField = F> + Sync + Send + 'static, |
| 440 G::SupportType : LocalAnalysis<F, Self::Agg, N>; |
439 G::SupportType : LocalAnalysis<Self::Agg, Cube<F, N>>; |
| 441 } |
440 } |
| 442 |
441 |
| 443 fn refinement_loop<F : Float, D, A, R, G, const N : usize, const P : usize> ( |
442 fn refinement_loop<F : Float, D, A, R, G, const N : usize, const P : usize> ( |
| 444 wakeup : Option<Arc<Condvar>>, |
443 wakeup : Option<Arc<Condvar>>, |
| 445 refiner : &R, |
444 refiner : &R, |
| 446 generator_arc : &Arc<G>, |
445 generator_arc : &Arc<G>, |
| 447 container_arc : &Arc<Mutex<HeapContainer<F, D, A, R::Sorting, R::Result, N, P>>>, |
446 container_arc : &Arc<Mutex<HeapContainer<F, D, A, R::Sorting, R::Result, N, P>>>, |
| 448 ) where A : Aggregator, |
447 ) where A : Aggregator, |
| 449 R : Refiner<F, A, G, N>, |
448 R : Refiner<A, G, N>, |
| 450 G : SupportGenerator<F, N, Id=D>, |
449 G : SupportGenerator<N, Id=D, RealField = F>, |
| 451 G::SupportType : LocalAnalysis<F, A, N>, |
450 G::SupportType : LocalAnalysis<A, Cube<F, N>>, |
| 452 Const<P> : BranchCount<N>, |
451 Const<P> : BranchCount<N>, |
| 453 D : 'static + Copy + Sync + Send + std::fmt::Debug { |
452 D : 'static + Copy + Sync + Send + std::fmt::Debug { |
| 454 |
453 |
| 455 let mut did_park = true; |
454 let mut did_park = true; |
| 456 let mut container = container_arc.lock().unwrap(); |
455 let mut container = container_arc.lock().unwrap(); |
| 563 fn search_and_refine<'b, R, G>( |
562 fn search_and_refine<'b, R, G>( |
| 564 &'b mut self, |
563 &'b mut self, |
| 565 refiner : R, |
564 refiner : R, |
| 566 generator : &Arc<G>, |
565 generator : &Arc<G>, |
| 567 ) -> Option<R::Result> |
566 ) -> Option<R::Result> |
| 568 where R : Refiner<F, A, G, $n>, |
567 where R : Refiner<A, G, $n>, |
| 569 G : SupportGenerator<F, $n, Id=D>, |
568 G : SupportGenerator<$n, Id=D, RealField = F>, |
| 570 G::SupportType : LocalAnalysis<F, A, $n> { |
569 G::SupportType : LocalAnalysis<A, Cube<F, $n>> { |
| 571 let mut init_container = HeapContainer { |
570 let mut init_container = HeapContainer { |
| 572 heap : BinaryHeap::new(), |
571 heap : BinaryHeap::new(), |
| 573 glb : R::Sorting::bottom(), |
572 glb : R::Sorting::bottom(), |
| 574 insert_counter : 0, |
573 insert_counter : 0, |
| 575 result : None, |
574 result : None, |