本文整理匯總了Java中scpsolver.lpsolver.SolverFactory類的典型用法代碼示例。如果您正苦於以下問題:Java SolverFactory類的具體用法?Java SolverFactory怎麽用?Java SolverFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SolverFactory類屬於scpsolver.lpsolver包,在下文中一共展示了SolverFactory類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runLPAndGetJointActionProbs
import scpsolver.lpsolver.SolverFactory; //導入依賴的package包/類
/**
* Helper method for running the linear program optimization (after its constraints have already been set) and returning
* the result in the form of the 2D double matrix joint strategy.
* @param lp the linear program to be optimized
* @param nRows the number of rows in the bimatrix (number of player 1 actions)
* @param nCols the number of columns in the bimatrix (number of player 2 actions)
* @return a 2D double representing the joint strategy for the given linear program correlated equilibrium problem.
*/
protected static double [][] runLPAndGetJointActionProbs(LinearProgram lp, int nRows, int nCols){
int nn = nRows*nCols;
lp.setMinProblem(false);
LinearProgramSolver solver = SolverFactory.newDefault();
double[] sol = solver.solve(lp);
double [][] jointActionProbs = new double[nRows][nCols];
for(int i = 0; i < nn; i++){
int [] rc = rowCol(i, nCols);
jointActionProbs[rc[0]][rc[1]] = sol[i];
}
return jointActionProbs;
}
示例2: getColPlayersStrategy
import scpsolver.lpsolver.SolverFactory; //導入依賴的package包/類
/**
* Computes the minmax strategy for the column player of the given payoff matrix.
* The entries of the payoff matrix are assumed to be the payouts for the *column* player.
* @param payoffMatrix payoffs for column player.
* @return strategy of the column player.
*/
public static double [] getColPlayersStrategy(double [][] payoffMatrix){
//get positive matrix (finds the minimum value and adds -min + 1 to all elements)
double [][] G = GeneralBimatrixSolverTools.getPositiveMatrix(payoffMatrix);
LinearProgram lp = new LinearProgram(GeneralBimatrixSolverTools.constantDoubleArray(1., G[0].length));
int cCount = 0;
//add payoff matrix constraints
for(int i = 0; i < G.length; i++){
lp.addConstraint(new LinearBiggerThanEqualsConstraint(G[i], 1., "c" + cCount));
cCount++;
}
//add lower bound constraints
for(int i = 0; i < G[0].length; i++){
lp.addConstraint(new LinearBiggerThanEqualsConstraint(GeneralBimatrixSolverTools.zero1Array(i, G[0].length), 0., "c" + cCount));
cCount++;
}
//solve it
lp.setMinProblem(true);
LinearProgramSolver solver = SolverFactory.newDefault();
double[] sol = solver.solve(lp);
//convert LP solution into probability vector.
double z = 0.;
for(double d : sol){
z += d;
}
double v = 1/z;
for(int i = 0; i < sol.length; i++){
sol[i] *= v;
}
return sol;
}