- java.lang.Object
-
- org.ojalgo.matrix.task.iterative.IterativeSolverTask
-
- All Implemented Interfaces:
MatrixTask<java.lang.Double>,SolverTask<java.lang.Double>
- Direct Known Subclasses:
ConjugateGradientSolver,GaussSeidelSolver,JacobiSolver,MINRESSolver,ParallelGaussSeidelSolver,QMRSolver
public abstract class IterativeSolverTask extends java.lang.Object implements SolverTask<java.lang.Double>
Base class for iterative solvers of large linear systems [A][x]=[b]. Subclasses provide concrete stationary or Krylov algorithms while sharing input conversion, configuration, and stopping logic. Characteristics- Accepts both sparse and dense inputs by converting the system to a
List<Equation>where rows can be iterated efficiently without assuming dense, contiguous storage. - Minimises allocations in hot loops by reusing buffers and operating directly on
PhysicalStoreandR064Storevectors. - Provides a common configuration and termination policy via
NumberContextand an iteration limit.
- Implementations must work when the effective system is a selected or reordered subset of the original problem. The equation list may represent only some rows, and column indices may need to be remapped or compacted.
- Do not assume a dense, contiguous column space. Always form row products using
Equation.dot(org.ojalgo.structure.Access1D)and access the diagonal throughEquation.getPivot(). - The provided
solutionvector defines the active variable subspace; form residuals against that vector and the current row bodies only. - RHS values are carried by each
Equation; useresolve(List, PhysicalStore, org.ojalgo.structure.Access1D)to update RHS between solves.
- Left-preconditioned Krylov methods may apply the configured
Preconditioneron residuals or intermediate vectors. The preconditioner should be symmetric positive-definite when the algorithm assumes this (e.g., for SPD problems). - Right-preconditioned Krylov methods may call both
Preconditioner.apply(org.ojalgo.structure.Access1D, PhysicalStore)andPreconditioner.applyTranspose(org.ojalgo.structure.Access1D, PhysicalStore). If the preconditioner is not symmetric, override the transpose variant. - Stationary (fixed-point) methods typically ignore preconditioners; use the relaxation factor to control convergence.
- Subclasses should measure a residual norm and stop when
NumberContext.isSmall(double, double)deems it small relative to the RHS norm (or absolutely small when the RHS is zero), or when the iteration limit is reached.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIterativeSolverTask.Configurator-
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 (package private) static NumberContextDEFAULTprivate NumberContextmyAccuracyContextprivate IterativeSolverTask.ConfiguratormyConfiguratorprivate BasicLoggermyDebugPrinterprivate intmyIterationsLimitprivate PreconditionermyPreconditionerprivate doublemyRelaxationFactor
-
Constructor Summary
Constructors Constructor Description IterativeSolverTask()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IterativeSolverTask.Configuratorconfigurator()protected voiddebug(int iteration, double error, Access1D<?> current)protected NumberContextgetAccuracyContext()protected intgetIterationsLimit()protected PreconditionergetPreconditioner()protected doublegetRelaxationFactor()protected booleanisDebugPrinterSet()PhysicalStore<java.lang.Double>preallocate(int nbEquations, int nbVariables, int nbSolutions)abstract doubleresolve(java.util.List<Equation> equations, PhysicalStore<java.lang.Double> solution)doubleresolve(java.util.List<Equation> equations, PhysicalStore<java.lang.Double> solution, Access1D<?> rhs)protected voidsetAccuracyContext(NumberContext accuracyContext)protected voidsetDebugPrinter(BasicLogger debugPrinter)protected voidsetIterationsLimit(int iterationsLimit)protected voidsetPreconditioner(Preconditioner preconditioner)protected voidsetRelaxationFactor(double relaxation)java.util.Optional<MatrixStore<java.lang.Double>>solve(MatrixStore<java.lang.Double> body, MatrixStore<java.lang.Double> rhs)MatrixStore<java.lang.Double>solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> preallocated)Exactly how (if at all) a specific implementation makes use ofpreallocatedis not specified by this interface.(package private) static java.util.List<Equation>toListOfRows(Access2D<?> body, Access2D<?> rhs)(package private) static R064Storeworker(R064Store vector, int size)-
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
-
DEFAULT
static final NumberContext DEFAULT
-
myAccuracyContext
private NumberContext myAccuracyContext
-
myConfigurator
private transient IterativeSolverTask.Configurator myConfigurator
-
myDebugPrinter
private BasicLogger myDebugPrinter
-
myIterationsLimit
private int myIterationsLimit
-
myRelaxationFactor
private double myRelaxationFactor
-
myPreconditioner
private Preconditioner myPreconditioner
-
-
Method Detail
-
configurator
public final IterativeSolverTask.Configurator configurator()
-
preallocate
public final PhysicalStore<java.lang.Double> preallocate(int nbEquations, int nbVariables, int nbSolutions)
- Specified by:
preallocatein interfaceSolverTask<java.lang.Double>
-
resolve
public abstract double resolve(java.util.List<Equation> equations, PhysicalStore<java.lang.Double> solution)
-
resolve
public final double resolve(java.util.List<Equation> equations, PhysicalStore<java.lang.Double> solution, Access1D<?> rhs)
-
solve
public final MatrixStore<java.lang.Double> solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> preallocated) 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 modfiedpreallocated- 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
-
solve
public final java.util.Optional<MatrixStore<java.lang.Double>> solve(MatrixStore<java.lang.Double> body, MatrixStore<java.lang.Double> rhs)
-
debug
protected final void debug(int iteration, double error, Access1D<?> current)
-
getAccuracyContext
protected final NumberContext getAccuracyContext()
-
getIterationsLimit
protected final int getIterationsLimit()
-
getPreconditioner
protected final Preconditioner getPreconditioner()
-
getRelaxationFactor
protected final double getRelaxationFactor()
-
isDebugPrinterSet
protected final boolean isDebugPrinterSet()
-
setAccuracyContext
protected final void setAccuracyContext(NumberContext accuracyContext)
-
setDebugPrinter
protected final void setDebugPrinter(BasicLogger debugPrinter)
-
setIterationsLimit
protected final void setIterationsLimit(int iterationsLimit)
-
setPreconditioner
protected final void setPreconditioner(Preconditioner preconditioner)
-
setRelaxationFactor
protected final void setRelaxationFactor(double relaxation)
-
-