Class Equation

java.lang.Object
org.ojalgo.equation.Equation
All Implemented Interfaces:
Comparable<Equation>, Access1D<Double>, Mutate1D.Modifiable<Double>, Structure1D

public final class Equation extends Object implements Comparable<Equation>, Access1D<Double>, Mutate1D.Modifiable<Double>
  • Field Details

    • index

      public final int index
      The row index of the original body matrix, [A].
    • myBody

      private final BasicArray<?> myBody
      The (nonzero) elements of this equation/row
    • myPivot

      private double myPivot
    • myRHS

      private double myRHS
  • Constructor Details

    • Equation

      Equation(BasicArray<?> body, int pivot, double rhs)
  • Method Details

    • dense

      public static Equation dense(int pivot, int cols)
    • dense

      public static <N extends Comparable<N>> Equation dense(int pivot, int cols, DenseArray.Factory<N,?> factory)
    • denseSystem

      public static List<Equation> denseSystem(int rows, int cols)
    • denseSystem

      public static <N extends Comparable<N>> List<Equation> denseSystem(int rows, int cols, DenseArray.Factory<N,?> factory)
    • of

      public static Equation of(double rhs, int pivot, double... body)
    • sparse

      public static Equation sparse(int pivot, int cols)
    • sparse

      public static Equation sparse(int pivot, int cols, int numberOfNonzeros)
    • sparse

      public static <N extends Comparable<N>> Equation sparse(int pivot, int cols, PlainArray.Factory<N,?> factory)
    • sparse

      public static <N extends Comparable<N>> Equation sparse(int pivot, int cols, PlainArray.Factory<N,?> factory, int numberOfNonzeros)
    • sparseSystem

      public static List<Equation> sparseSystem(int rows, int cols)
    • sparseSystem

      public static List<Equation> sparseSystem(int rows, int cols, int numberOfNonzeros)
    • sparseSystem

      public static <N extends Comparable<N>> List<Equation> sparseSystem(int rows, int cols, PlainArray.Factory<N,?> factory)
    • sparseSystem

      public static <N extends Comparable<N>> List<Equation> sparseSystem(int rows, int cols, PlainArray.Factory<N,?> factory, int numberOfNonzeros)
    • wrap

      public static Equation wrap(BasicArray<?> body, int pivot, double rhs)
    • add

      public void add(int ind, double addend)
      Specified by:
      add in interface Mutate1D.Modifiable<Double>
    • add

      public void add(long ind, Comparable<?> addend)
      Specified by:
      add in interface Mutate1D.Modifiable<Double>
    • adjust

      public <T extends Access1D<Double> & Mutate1D.Modifiable<Double>> double adjust(T x, double relaxation)
      Will perform a (relaxed) GaussSeidel update.

      This call will not work if the pivot (the element at index) is zero!

      Parameters:
      x - The current solution (one element will be updated)
      relaxation - Typically 1.0 but could be anything (Most likely should be between 0.0 and 2.0).
      Returns:
      The error in this equation
    • compareTo

      public int compareTo(Equation other)
      Specified by:
      compareTo in interface Comparable<Equation>
    • count

      public long count()
      Description copied from interface: Structure1D
      The total number of elements in this structure.

      You only need to implement this method if the structure can contain more than Integer.MAX_VALUE elements.

      Specified by:
      count in interface Structure1D
    • dot

      public double dot(Access1D<?> vector)
      Description copied from interface: Access1D
      Will calculate and return the dot product of this 1D-structure and another input 1D-vector.
      Specified by:
      dot in interface Access1D<Double>
      Parameters:
      vector - Another 1D-structure
      Returns:
      The dot product
    • dotLower

      public double dotLower(Access1D<?> x)
      Efficiently compute sum_{j invalid input: '<' pivot} a_{ij} * x_j (excludes the pivot). Uses direct sparse iteration when available to avoid O(n) random access scans.
    • dotUpper

      public double dotUpper(Access1D<?> x)
      Efficiently compute sum_{j > pivot} a_{ij} * x_j (excludes the pivot). Uses direct sparse iteration when available to avoid O(n) random access scans.
    • doubleValue

      public double doubleValue(int ind)
      Specified by:
      doubleValue in interface Access1D<Double>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • get

      public Double get(long ind)
      Specified by:
      get in interface Access1D<Double>
    • getBody

      public BasicArray<?> getBody()
    • getCoefficients

      public double[] getCoefficients()
    • getPivot

      public double getPivot()
      Returns:
      The element at index
    • getRHS

      public double getRHS()
      Returns:
      The equation RHS
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • initialise

      public <T extends Access1D<Double> & Mutate1D.Modifiable<Double>> void initialise(T x)
      Initialises the solution vector's element at index to the value that would solve this equation if the RHS was zero and all other elements in the solution vector unchanged.
      Type Parameters:
      T - The solution vector type
      Parameters:
      x - The solution vector to be initialised
    • modifyOne

      public void modifyOne(long ind, UnaryFunction<Double> modifier)
      Specified by:
      modifyOne in interface Mutate1D.Modifiable<Double>
    • set

      public void set(long ind, Comparable<?> value)
    • set

      public void set(long ind, double value)
    • setRHS

      public void setRHS(double rhs)
    • size

      public int size()
      Description copied from interface: Structure1D
      The total number of elements in this structure.
      Specified by:
      size in interface Structure1D
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • calculate

      private <T extends Access1D<Double> & Mutate1D.Modifiable<Double>> double calculate(T x, double rhs, double relaxation)