當前位置: 首頁>>代碼示例>>Java>>正文


Java SolverFactory類代碼示例

本文整理匯總了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;
}
 
開發者ID:f-leno,項目名稱:DOO-Q_BRACIS2016,代碼行數:26,代碼來源:CorrelatedEquilibriumSolver.java

示例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;
}
 
開發者ID:f-leno,項目名稱:DOO-Q_BRACIS2016,代碼行數:49,代碼來源:MinMaxSolver.java


注:本文中的scpsolver.lpsolver.SolverFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。