public class QuadraticOptimizer
extends java.lang.Object
| Constructor and Description |
|---|
QuadraticOptimizer(int variableCount)
The constructor creates a zero function with no constraints.
|
| 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. |
public QuadraticOptimizer(int variableCount)
variableCount - the number of variables in the function this QuadraticOptimizer
will optimizepublic void setVariable(int i,
double value)
value.i - the index of the variable whose value to setvalue - the new value of the variablepublic void addQuadraticDifference(int i,
int j,
double weight)
weight*(xi-xj)2. Use this method to minimize
the distance between two objects.i - the first variable of the termj - the second variable of the termweight - the weight of this termpublic void addQuadraticConstantDifference(int i,
double value,
double weight)
weight*(xi-value)2. Use this method to minimize the drift
of an object.i - the variable of the termvalue - the value to keep the variable close toweight - the weight of this termpublic void addLinearDifference(int i,
int j,
double weight)
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.i - the first variable of the termj - the second variable of the termweight - the weight of this termpublic void addMeanDifference(int i,
int j,
double value,
double weight)
weight*((xi+xj)/2-value)2. Use this method to
minimize the drift of the mass center of two objects.i - the first variable of the termj - the second variable of the termvalue - the value to keep the mass center of the two objects close toweight - the weight of this termpublic void addDoubleMeanDifference(int i1,
int j1,
int i2,
int j2,
double weight)
weight*((xi1+xj1)/2-(xi2+xj2)/2)2.
Use this method to minimize the distance between the mass centers of two object pairs.i1 - the first variable of the first pairj1 - the second variable of the first pairi2 - the first variable of the second pairj2 - the second variable of the second pairweight - the weight of this termpublic void addDoubleMeanConstantDifference(int i1,
int j1,
int i2,
int j2,
double value,
double weight)
weight*((xi1+xj1)/2-(xi2+xj2)/2-value)2.
Use this method to minimize the drift between the mass centers of two object pairs.i1 - the first variable of the first pairj1 - the second variable of the first pairi2 - the first variable of the second pairj2 - the second variable of the second pairvalue - the value to keep the distance between the two mass centers atweight - the weight of this termpublic void addMeanVariableDifference(int i,
int j,
int k,
double weight)
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.i - the first variable of the pairj - the second variable of the pairk - the solitary objectweight - the weight of this termpublic void addInequality(int i,
int j,
double distance)
xj-xi≥distance.i - the second variable of the inequalityj - the first variable of the inequalitydistance - the minimum distance between the two variablespublic void addEquality(int i,
int j,
double distance)
xj-xi=distance.i - the second variable of the equalityj - the first variable of the equalitydistance - the distance between the two variablespublic void addQuadraticTerm(int i,
double coefficient)
coefficient*xi2 to the function.i - the index of the variable whose quadratic term to altercoefficient - the coefficient of the added quadratic termpublic void addLinearTerm(int i,
double coefficient)
coefficient*xi to the function.i - the index of the variable whose linear term to altercoefficient - the coefficient of the added linear termpublic void addCombinedTerm(int i,
int j,
double coefficient)
coefficient*xi*xj to the function.i - the index of the first variable of the combined termj - the index of the second variable of the combined termcoefficient - the coefficient of the added combined termpublic void setEpsilon(double epsilon)
epsilon - the new precisionpublic double[] performOptimization()