Class IterativeSolverTask
java.lang.Object
org.ojalgo.matrix.task.iterative.IterativeSolverTask
- All Implemented Interfaces:
MatrixTask<Double>, SolverTask<Double>
- Direct Known Subclasses:
ConjugateGradientSolver, GaussSeidelSolver, JacobiSolver, MINRESSolver, ParallelGaussSeidelSolver, QMRSolver
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 ClassesNested classes/interfaces inherited from interface SolverTask
SolverTask.Factory<N> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final NumberContextprivate NumberContextprivate IterativeSolverTask.Configuratorprivate BasicLoggerprivate intprivate Preconditionerprivate double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidprotected final NumberContextprotected final intprotected final Preconditionerprotected final doubleprotected final booleanfinal PhysicalStore<Double> preallocate(int nbEquations, int nbVariables, int nbSolutions) abstract doubleresolve(List<Equation> equations, PhysicalStore<Double> solution) final doubleprotected final voidsetAccuracyContext(NumberContext accuracyContext) protected final voidsetDebugPrinter(BasicLogger debugPrinter) protected final voidsetIterationsLimit(int iterationsLimit) protected final voidsetPreconditioner(Preconditioner preconditioner) protected final voidsetRelaxationFactor(double relaxation) final Optional<MatrixStore<Double>> solve(MatrixStore<Double> body, MatrixStore<Double> rhs) final MatrixStore<Double> solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<Double> preallocated) Exactly how (if at all) a specific implementation makes use ofpreallocatedis not specified by this interface.toListOfRows(Access2D<?> body, Access2D<?> rhs) (package private) static R064StoreMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SolverTask
preallocate, solve, toSolutionProvider
-
Field Details
-
DEFAULT
-
myAccuracyContext
-
myConfigurator
-
myDebugPrinter
-
myIterationsLimit
private int myIterationsLimit -
myRelaxationFactor
private double myRelaxationFactor -
myPreconditioner
-
-
Constructor Details
-
IterativeSolverTask
IterativeSolverTask()
-
-
Method Details
-
toListOfRows
-
worker
-
configurator
-
preallocate
- Specified by:
preallocatein interfaceSolverTask<Double>
-
resolve
-
resolve
public final double resolve(List<Equation> equations, PhysicalStore<Double> solution, Access1D<?> rhs) -
solve
public final MatrixStore<Double> solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<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<Double>- Parameters:
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
-
debug
-
getAccuracyContext
-
getIterationsLimit
protected final int getIterationsLimit() -
getPreconditioner
-
getRelaxationFactor
protected final double getRelaxationFactor() -
isDebugPrinterSet
protected final boolean isDebugPrinterSet() -
setAccuracyContext
-
setDebugPrinter
-
setIterationsLimit
protected final void setIterationsLimit(int iterationsLimit) -
setPreconditioner
-
setRelaxationFactor
protected final void setRelaxationFactor(double relaxation)
-