lv.lumii.layoutengine.funcmin

## Class QuadraticOptimizer

- java.lang.Object
- - lv.lumii.layoutengine.funcmin.QuadraticOptimizer

- Direct Known Subclasses:
    ExtendedQuadraticOptimizer

      public class QuadraticOptimizer
      extends java.lang.Object

  Contains methods to create the function and constraints used in Funcmin, as well as call Funcmin and return the results.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `QuadraticOptimizer(int variableCount)` The constructor creates a zero function with no constraints.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCombinedTerm(int i, int j, double coefficient)` Adds the combined term `coefficient*xi*xj to the function.`
    `void` | `addDoubleMeanConstantDifference(int i1, int j1, int i2, int j2, double value, double weight)` Add a new term in the form of `weight*((xi1+xj1)/2-(xi2+xj2)/2-value)2`.
    `void` | `addDoubleMeanDifference(int i1, int j1, int i2, int j2, double weight)` Add a new term in the form of `weight*((xi1+xj1)/2-(xi2+xj2)/2)2`.
    `void` | `addEquality(int i, int j, double distance)` Adds an equality constraint in the form of `xj-xi=distance`.
    `void` | `addInequality(int i, int j, double distance)` Adds an inequality constraint in the form of `xj-xi≥distance`.
    `void` | `addLinearDifference(int i, int j, double weight)` Add a new term in the form of `weight*(xj-xi)`.
    `void` | `addLinearTerm(int i, double coefficient)` Adds the linear term `coefficient*xi to the function.`
    `void` | `addMeanDifference(int i, int j, double value, double weight)` Add a new term in the form of `weight*((xi+xj)/2-value)2`.
    `void` | `addMeanVariableDifference(int i, int j, int k, double weight)` Add a new term in the form of `weight*((xi+xj)/2-xk)2`.
    `void` | `addQuadraticConstantDifference(int i, double value, double weight)` Add a new term in the form of `weight*(xi-value)2`.
    `void` | `addQuadraticDifference(int i, int j, double weight)` Add a new term in the form of `weight*(xi-xj)2`.
    `void` | `addQuadraticTerm(int i, double coefficient)` Adds the quadratic term `coefficient*xi2 to the function.`
    `double[]` | `performOptimization()` Performs the function minimization using the given terms and constraints.
    `void` | `setEpsilon(double epsilon)` Sets the precision of the minimization, used both for constraints and the function's value.
    `void` | `setVariable(int i, double value)` Sets the initial value of the ith variable to `value`.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### QuadraticOptimizer

          public QuadraticOptimizer(int variableCount)

      The constructor creates a zero function with no constraints.
      Parameters:
        `variableCount` - the number of variables in the function this `QuadraticOptimizer` will optimize

  - ### Method Detail

    - #### setVariable

          public void setVariable(int i,
                                  double value)

      Sets the initial value of the ith variable to `value`.
      Parameters:
        `i` - the index of the variable whose value to set
        `value` - the new value of the variable

    - #### addQuadraticDifference

          public void addQuadraticDifference(int i,
                                             int j,
                                             double weight)

      Add a new term in the form of `weight*(xi-xj)2`. Use this method to minimize the distance between two objects.
      Parameters:
        `i` - the first variable of the term
        `j` - the second variable of the term
        `weight` - the weight of this term

    - #### addQuadraticConstantDifference

          public void addQuadraticConstantDifference(int i,
                                                     double value,
                                                     double weight)

      Add a new term in the form of `weight*(xi-value)2`. Use this method to minimize the drift of an object.
      Parameters:
        `i` - the variable of the term
        `value` - the value to keep the variable close to
        `weight` - the weight of this term

    - #### addLinearDifference

          public void addLinearDifference(int i,
                                          int j,
                                          double weight)

      Add a new term in the form of `weight*(xj-xi)`. Use this method to minimize the distance between two objects. This term does not have a minimum, therefore it should be constrained.
      Parameters:
        `i` - the first variable of the term
        `j` - the second variable of the term
        `weight` - the weight of this term

    - #### addMeanDifference

          public void addMeanDifference(int i,
                                        int j,
                                        double value,
                                        double weight)

      Add a new term in the form of `weight*((xi+xj)/2-value)2`. Use this method to minimize the drift of the mass center of two objects.
      Parameters:
        `i` - the first variable of the term
        `j` - the second variable of the term
        `value` - the value to keep the mass center of the two objects close to
        `weight` - the weight of this term

    - #### addDoubleMeanDifference

          public void addDoubleMeanDifference(int i1,
                                              int j1,
                                              int i2,
                                              int j2,
                                              double weight)

      Add a new term in the form of
      `weight*((xi1+xj1)/2-(xi2+xj2)/2)2`. Use this method to minimize the distance between the mass centers of two object pairs.
      Parameters:
        `i1` - the first variable of the first pair
        `j1` - the second variable of the first pair
        `i2` - the first variable of the second pair
        `j2` - the second variable of the second pair
        `weight` - the weight of this term

    - #### addDoubleMeanConstantDifference

          public void addDoubleMeanConstantDifference(int i1,
                                                      int j1,
                                                      int i2,
                                                      int j2,
                                                      double value,
                                                      double weight)

      Add a new term in the form of
      `weight*((xi1+xj1)/2-(xi2+xj2)/2-value)2`. Use this method to minimize the drift between the mass centers of two object pairs.
      Parameters:
        `i1` - the first variable of the first pair
        `j1` - the second variable of the first pair
        `i2` - the first variable of the second pair
        `j2` - the second variable of the second pair
        `value` - the value to keep the distance between the two mass centers at
        `weight` - the weight of this term

    - #### addMeanVariableDifference

          public void addMeanVariableDifference(int i,
                                                int j,
                                                int k,
                                                double weight)

      Add a new term in the form of
      `weight*((xi+xj)/2-xk)2`. Use this method to minimize the distance between the mass center of the (i, j) object pair and object k.
      Parameters:
        `i` - the first variable of the pair
        `j` - the second variable of the pair
        `k` - the solitary object
        `weight` - the weight of this term

    - #### addInequality

          public void addInequality(int i,
                                    int j,
                                    double distance)

      Adds an inequality constraint in the form of `xj-xi≥distance`.
      Parameters:
        `i` - the second variable of the inequality
        `j` - the first variable of the inequality
        `distance` - the minimum distance between the two variables

    - #### addEquality

          public void addEquality(int i,
                                  int j,
                                  double distance)

      Adds an equality constraint in the form of `xj-xi=distance`.
      Parameters:
        `i` - the second variable of the equality
        `j` - the first variable of the equality
        `distance` - the distance between the two variables

    - #### addQuadraticTerm

          public void addQuadraticTerm(int i,
                                       double coefficient)

      Adds the quadratic term `coefficient*xi2 to the function.`
      Parameters:
        `i` - the index of the variable whose quadratic term to alter
        `coefficient` - the coefficient of the added quadratic term

    - #### addLinearTerm

          public void addLinearTerm(int i,
                                    double coefficient)

      Adds the linear term `coefficient*xi to the function.`
      Parameters:
        `i` - the index of the variable whose linear term to alter
        `coefficient` - the coefficient of the added linear term

    - #### addCombinedTerm

          public void addCombinedTerm(int i,
                                      int j,
                                      double coefficient)

      Adds the combined term `coefficient*xi*xj to the function.`
      Parameters:
        `i` - the index of the first variable of the combined term
        `j` - the index of the second variable of the combined term
        `coefficient` - the coefficient of the added combined term

    - #### setEpsilon

          public void setEpsilon(double epsilon)

      Sets the precision of the minimization, used both for constraints and the function's value.
      Parameters:
        `epsilon` - the new precision

    - #### performOptimization

          public double[] performOptimization()

      Performs the function minimization using the given terms and constraints.
      Returns:
        an array of the new values of the function variables.