- java.lang.Object
-
- org.ojalgo.matrix.task.iterative.MutableSolver
-
- All Implemented Interfaces:
MatrixTask<java.lang.Double>,SolverTask<java.lang.Double>
- Direct Known Subclasses:
IterativeASS.SchurComplementSolver
public abstract class MutableSolver extends java.lang.Object implements SolverTask<java.lang.Double>
Lightweight mutable wrapper around a list ofEquationrows that delegates solving to anIterativeSolverTask.Purpose
- Build and update an equation system incrementally by adding/removing
Equationrows. - Reuse an iterative solver across solves without rebuilding matrices.
- Support workflows where the active rows/columns change between iterations.
- Subclass to define the problem size and to provide the delegate iterative solver.
- Call
add(Equation)andremove(Equation)to maintain the active set of rows. Rows are kept sorted by theirEquation.index. - Call
resolve(PhysicalStore)(orresolve(PhysicalStore, Access1D)) to solve [A][x]=[b] using the current rows and right-hand sides stored in eachEquation. - All methods that solve or preallocate simply forward to the delegate.
- Every added
Equationmust haveEquation.size()equal to the problem size passed to the constructor; otherwise anIllegalArgumentExceptionis thrown. - The provided
solutionvector represents the active variable subspace; residuals are formed against that vector and the current row bodies only. - Thread-safety: instances are not thread-safe; do not mutate the row set while solving.
- A subclass can also implement
MatrixStoreand dynamically assemble a Schur-complement-style system by adding/removing rows, and then callresolve(PhysicalStore)to compute the unknowns.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.task.SolverTask
SolverTask.Factory<N extends java.lang.Comparable<N>>
-
-
Field Summary
Fields Modifier and Type Field Description private IterativeSolverTaskmyDelegateprivate java.util.List<Equation>myRowsprivate intmySize
-
Constructor Summary
Constructors Modifier Constructor Description protectedMutableSolver(IterativeSolverTask delegate, int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Equation row)voidclear()protected doubledoubleValue(int row, int col)protected java.util.stream.Stream<Equation>equations()protected IterativeSolverTaskgetDelegate()PhysicalStore<java.lang.Double>preallocate(int nbEquations, int nbVariables, int nbSolutions)booleanremove(Equation row)doubleresolve(PhysicalStore<java.lang.Double> solution)A variation of solve(Access2D, Access2D, PhysicalStore) where the system body has already been set up usingadd(Equation).doubleresolve(PhysicalStore<java.lang.Double> solution, Access1D<?> rhs)Same asresolve(PhysicalStore)but replaces the RHS values before solving.MatrixStore<java.lang.Double>solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> current)Exactly how (if at all) a specific implementation makes use ofpreallocatedis not specified by this interface.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ojalgo.matrix.task.SolverTask
preallocate, solve, toSolutionProvider
-
-
-
-
Field Detail
-
myDelegate
private final IterativeSolverTask myDelegate
-
myRows
private final java.util.List<Equation> myRows
-
mySize
private final int mySize
-
-
Constructor Detail
-
MutableSolver
protected MutableSolver(IterativeSolverTask delegate, int size)
-
-
Method Detail
-
add
public boolean add(Equation row)
-
clear
public void clear()
-
preallocate
public PhysicalStore<java.lang.Double> preallocate(int nbEquations, int nbVariables, int nbSolutions)
- Specified by:
preallocatein interfaceSolverTask<java.lang.Double>
-
remove
public boolean remove(Equation row)
-
resolve
public double resolve(PhysicalStore<java.lang.Double> solution)
A variation of solve(Access2D, Access2D, PhysicalStore) where the system body has already been set up usingadd(Equation). Solves the current [A][x]=[b] using the delegate iterative solver.
-
resolve
public double resolve(PhysicalStore<java.lang.Double> solution, Access1D<?> rhs)
Same asresolve(PhysicalStore)but replaces the RHS values before solving.
-
solve
public MatrixStore<java.lang.Double> solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> current) throws RecoverableCondition
Description copied from interface:SolverTaskExactly how (if at all) a specific implementation makes use of
preallocatedis not specified by this interface. It must be documented for each implementation.Should produce the same results as calling
SolverTask.solve(Access2D, Access2D).Use
SolverTask.preallocate(Structure2D, Structure2D)to obtain a suitbalepreallocated.- Specified by:
solvein interfaceSolverTask<java.lang.Double>rhs- The Right Hand Side, wont be modfiedcurrent- Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/ /correct solution.- Returns:
- The solution
- Throws:
RecoverableCondition
-
doubleValue
protected double doubleValue(int row, int col)
-
equations
protected java.util.stream.Stream<Equation> equations()
-
getDelegate
protected final IterativeSolverTask getDelegate()
-
-