cc.redberry.core.solver.frobenius
Class FrobeniusSolver
- java.lang.Object
-
- cc.redberry.core.solver.frobenius.FrobeniusSolver
-
- All Implemented Interfaces:
- OutputPort<int[]>
public final class FrobeniusSolver extends java.lang.Object implements OutputPort<int[]>
Solves system of Frobenius equations.Example: This gives all solutions of the system of Frobenius equations { 12 x + 16 y + 20 z + 27 t = 123, x + 3 z = 12}:
This class calculates solutions iteratively: methodint[][] equations = {{12, 16, 20, 27, 123}, {1, 0, 3, 0, 12}}; FrobeniusSolver solver = new FrobeniusSolver(equations); int[] solution; while ((solution = solver.take()) != null) System.out.println(Arrays.toString(solution));take()calculates and returns the next solution or null, if no more solutions exist. So next solution will be calculated only on the invocation oftake().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cc.redberry.core.utils.OutputPort
OutputPort.PortIterable<T>, OutputPort.PortIterator<T>, OutputPort.Singleton<T>
-
-
Constructor Summary
Constructors Constructor and Description FrobeniusSolver(int[]... equations)Constructs solver from the given system of equations (see class documentation for example).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int[]take()Calculates and returns the next solution ornullif no more solutions exist.
-
-
-
Constructor Detail
-
FrobeniusSolver
public FrobeniusSolver(int[]... equations)
Constructs solver from the given system of equations (see class documentation for example).- Parameters:
equations- system of Frobenius equations- Throws:
java.lang.IllegalArgumentException- ifequationshave different lengthsjava.lang.IllegalArgumentException- if some coefficient is negative
-
-
Method Detail
-
take
public int[] take()
Calculates and returns the next solution ornullif no more solutions exist.- Specified by:
takein interfaceOutputPort<int[]>- Returns:
- the next solution or
nullif no more solutions exist
-
-
DataMelt 3.0 © DataMelt by jWork.ORG