本文整理汇总了Java中org.apache.commons.math3.optim.linear.SimplexSolver类的典型用法代码示例。如果您正苦于以下问题:Java SimplexSolver类的具体用法?Java SimplexSolver怎么用?Java SimplexSolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimplexSolver类属于org.apache.commons.math3.optim.linear包,在下文中一共展示了SimplexSolver类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: calculatePrimal
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
public PointValuePair calculatePrimal() {
SimplexSolver solver = new SimplexSolver();
//All variables are nonnegative
NonNegativeConstraint nonneg = new NonNegativeConstraint(true);
//objective function is of the form MAX w+ - w- (+0x1,etc)
LinearObjectiveFunction objective = new LinearObjectiveFunction(new double[] {1.0, -1.0, 0.0,0.0,0.0}, 0.0);
ArrayList<LinearConstraint> constraints = new ArrayList<>();
//probabilities must sum to 1.0
double[] probabilityConstraint = new double[values.length + 2];
probabilityConstraint[0] = probabilityConstraint[1] = 0.0;
for(int i=2; i<probabilityConstraint.length; i++)
probabilityConstraint[i]=1.0;
constraints.add(new LinearConstraint(probabilityConstraint, Relationship.EQ, 1.0));
//input game parameters
//constraints supports two-sided equation
double[] wConstraint = new double[values.length + 2];
wConstraint[0] = 1.0;
wConstraint[1] = -1.0;
for(int i=0; i<values.length; i++) {
double[] constr = new double[values.length+2];
for(int j=2; j<constr.length; j++)
constr[j]=values[i][j-2];
constraints.add(new LinearConstraint(wConstraint, 0.0, Relationship.LEQ, constr, 0.0));
}
LinearConstraintSet constraintSet = new LinearConstraintSet(constraints);
PointValuePair optimal = solver.optimize(objective, nonneg, constraintSet, GoalType.MAXIMIZE);
return optimal;
}
开发者ID:matthewjwolff,项目名称:MatrixGameTool,代码行数:29,代码来源:PayoffMatrix.java
示例2: calculateDual
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
public PointValuePair calculateDual() {
SimplexSolver solver = new SimplexSolver();
//All variables are nonnegative
NonNegativeConstraint nonneg = new NonNegativeConstraint(true);
//objective function is of the form MAX w+ - w- (+0x1,etc)
LinearObjectiveFunction objective = new LinearObjectiveFunction(new double[] {1.0, -1.0, 0.0,0.0,0.0}, 0.0);
ArrayList<LinearConstraint> constraints = new ArrayList<>();
//probabilities must sum to 1.0
double[] probabilityConstraint = new double[values.length + 2];
probabilityConstraint[0] = probabilityConstraint[1] = 0.0;
for(int i=2; i<probabilityConstraint.length; i++)
probabilityConstraint[i]=1.0;
constraints.add(new LinearConstraint(probabilityConstraint, Relationship.EQ, 1.0));
//input game parameters
//constraints supports two-sided equation
double[] wConstraint = new double[values.length +2];
wConstraint[0] = 1.0;
wConstraint[1] = -1.0;
for(int i=0; i<values.length; i++) {
double[] constr = new double[values.length+2];
for(int j=2; j<constr.length; j++)
constr[j]=values[j-2][i];
constraints.add(new LinearConstraint(wConstraint, 0.0, Relationship.GEQ, constr, 0.0));
}
// constraints.add(new LinearConstraint(new double[] {1.0,-1.0,0.0,0.0,0.0}, 0.0, Relationship.GEQ, new double[] {0.0,0.0,values[0][0],values[1][0],values[2][0]}, 0.0));
// constraints.add(new LinearConstraint(new double[] {1.0,-1.0,0.0,0.0,0.0}, 0.0, Relationship.GEQ, new double[] {0.0,0.0,values[0][1],values[1][1],values[2][1]}, 0.0));
// constraints.add(new LinearConstraint(new double[] {1.0,-1.0,0.0,0.0,0.0}, 0.0, Relationship.GEQ, new double[] {0.0,0.0,values[0][2],values[1][2],values[2][2]}, 0.0));
LinearConstraintSet constraintSet = new LinearConstraintSet(constraints);
PointValuePair optimal = solver.optimize(objective, nonneg, constraintSet, GoalType.MINIMIZE);
return optimal;
}
开发者ID:matthewjwolff,项目名称:MatrixGameTool,代码行数:32,代码来源:PayoffMatrix.java
示例3: computeFitnessValue
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
private void computeFitnessValue()
{
fitnessValueSolution = new SimplexSolver()
.optimize(new MaxIter(500),
f,
new LinearConstraintSet(getConstraints()),
GoalType.MINIMIZE,
new NonNegativeConstraint(true));
}
开发者ID:Polytech-AdrienCastex,项目名称:2D-Cutting-Stock-Problem-with-Setup-Cost,代码行数:10,代码来源:Solution.java
示例4: simplexDouble
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
/**
*
* @param A ресурсы на выпуск всех товаров (юнитов) [номер ресурса][номер юнита]
* @param b предел ресурсов (ограничение)
* @param c выгода
* @param x out кол-во выпуска (план выпуска, ответ)
* @return суммарная выгода плана x
*/
public static double simplexDouble(double[][] A, double[] b, double[] c, double[] x) {
// return justOneMaximize(A,b,c, x); // maybe fast, but not precission
// - - -
LinearObjectiveFunction f = new LinearObjectiveFunction(c, 0); // !!!
ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
for(int i=0; i<A.length; i++) { // Ограничения
constraints.add( new LinearConstraint(A[i], Relationship.LEQ, b[i]) ); // _c[i]*x[i]<=V_Res[i]
double[] zeroV = new double[A[i].length];
Arrays.fill(zeroV, 0);
constraints.add( new LinearConstraint(zeroV, Relationship.GEQ, 0) ); // _c[i]*x[i]<=V_Res[i]
}
// TODO при переработке энергии в металл можно учесть с помощью двух переменных и ограничения!!!
// FIXME precission - do not use between 0.00001 and 1.0, only 1,2,3...
SimplexSolver solver = new SimplexSolver();
PointValuePair optSolution = solver.optimize(new MaxIter(1000), f,
new LinearConstraintSet(constraints),
GoalType.MAXIMIZE,
new NonNegativeConstraint(true));
//double[] solution = optSolution.getPoint();
double[] x_=optSolution.getPointRef(); // TODO it is bad fix for n*1.0. To do iteration.
for (int i=0;i<x_.length;i++) if (x_[i]>0) x_[i]=Math.round(x_[i]-0.5);
System.arraycopy(x_, 0, x, 0, x.length);
return optSolution.getValue();
// - - -
}
开发者ID:playerO1,项目名称:FieldBOT,代码行数:40,代码来源:MathOptimizationMethods.java
示例5: configure
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
public void configure(final SimplexSolver solver, final Options options) {
// TODO Auto-generated method stub
}
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:4,代码来源:SolverCommonsMath.java
示例6: solve
import org.apache.commons.math3.optim.linear.SimplexSolver; //导入依赖的package包/类
public Optimisation.Result solve(final Result kickStarter) {
// final InitialGuess guess = new InitialGuess(kickStarter.toRawCopy1D());
//
// myModelData.add(guess);
Optimisation.State state = Optimisation.State.FAILED;
double value = Double.NaN;
Access1D<?> solution = kickStarter;
try {
final SimplexSolver solver = new SimplexSolver();
DEFAULT.configure(solver, myOptions);
final Optional<Configurator> optional = myOptions.getConfigurator(Configurator.class);
if (optional.isPresent()) {
optional.get().configure(solver, myOptions);
}
final PointValuePair solutionAndValue = solver.optimize(myModelData.toArray(new OptimizationData[myModelData.size()]));
state = Optimisation.State.OPTIMAL;
value = solutionAndValue.getValue();
solution = Access1D.wrap(solutionAndValue.getPoint());
} catch (final NoFeasibleSolutionException infeasible) {
state = Optimisation.State.INFEASIBLE;
} catch (final UnboundedSolutionException unbounded) {
state = Optimisation.State.UNBOUNDED;
}
final Optimisation.Result result = new Optimisation.Result(state, value, solution);
return result;
}
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:40,代码来源:SolverCommonsMath.java
注:本文中的org.apache.commons.math3.optim.linear.SimplexSolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论