Skip to content

Commit

Permalink
feat!: remove RepulsiveSystem type
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Nov 13, 2023
1 parent 69b037a commit bc35ea2
Showing 1 changed file with 2 additions and 77 deletions.
79 changes: 2 additions & 77 deletions src/core/system.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use nalgebra::{
allocator::Allocator,
storage::{Storage, StorageMut},
DefaultAllocator, Dynamic, IsContiguous, OVector, Vector,
Dynamic, IsContiguous, Vector,
};

use super::{base::Problem, domain::Domain};
use super::base::Problem;

/// The trait for defining equations systems.
///
Expand Down Expand Up @@ -75,77 +74,3 @@ pub trait System: Problem {
fx.norm()
}
}

/// A wrapper type for systems that implements a standard mechanism for
/// repulsing solvers from solutions that have been already found and stored in
/// the archive.
///
/// **WARNING:** This is currently noop as the repulsion mechanism has not been
/// determined yet. But the technique is mentioned in [A Decomposition-based
/// Differential Evolution with Reinitialization for Nonlinear Equations
/// Systems](https://www.sciencedirect.com/science/article/abs/pii/S0950705119305933)
/// or [Testing Nelder-Mead Based Repulsion Algorithms for Multiple Roots of
/// Nonlinear Systems via a Two-Level Factorial Design of
/// Experiments](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0121844),
/// for example.
pub struct RepulsiveSystem<'f, F: System> {
f: &'f F,
archive: Vec<OVector<F::Field, Dynamic>>,
}

impl<'f, F: System> RepulsiveSystem<'f, F> {
/// Initializes the repulsive system by wrapping the original system.
pub fn new(f: &'f F) -> Self {
Self {
f,
archive: Vec::new(),
}
}

/// Add a found solution to the archive.
pub fn push(&mut self, root: OVector<F::Field, Dynamic>) {
self.archive.push(root);
}

/// Get the size of the archive.
pub fn len(&self) -> usize {
self.archive.len()
}

/// Determine whether the archive is empty.
pub fn is_empty(&self) -> bool {
self.archive.is_empty()
}

/// Unpack the archive which contains all solutions found.
pub fn unpack(self) -> Vec<OVector<F::Field, Dynamic>> {
self.archive
}
}

impl<'f, F: System> Problem for RepulsiveSystem<'f, F> {
type Field = F::Field;

fn domain(&self) -> Domain<Self::Field> {
self.f.domain()
}
}

impl<'f, F: System> System for RepulsiveSystem<'f, F>
where
DefaultAllocator: Allocator<F::Field, Dynamic>,
{
fn eval<Sx, Sfx>(
&self,
x: &Vector<Self::Field, Dynamic, Sx>,
fx: &mut Vector<Self::Field, Dynamic, Sfx>,
) where
Sx: Storage<Self::Field, Dynamic> + IsContiguous,
Sfx: StorageMut<Self::Field, Dynamic>,
{
// TODO: RepulsiveSystem should adjust the residuals of the inner system
// such that solvers tend to go away from the roots stored in the
// archive.
self.f.eval(x, fx)
}
}

0 comments on commit bc35ea2

Please sign in to comment.