• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IloLinearNumExpr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中ilog.concert.IloLinearNumExpr的典型用法代码示例。如果您正苦于以下问题:Java IloLinearNumExpr类的具体用法?Java IloLinearNumExpr怎么用?Java IloLinearNumExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IloLinearNumExpr类属于ilog.concert包,在下文中一共展示了IloLinearNumExpr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addConstraint

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
@Override
public void addConstraint(ArrayList<ILPVariable> lhs, ILPOperator operator, double rhs) throws ILPException
{
    try {
        IloLinearNumExpr constraint = cplex.linearNumExpr();
        for(ILPVariable var : lhs) {
            if(!variables.containsKey(var.getName())) {
                this.addVariable(var.getName(), 0d, 0d, 1d, false, var.isZVar());
            }
            constraint.addTerm(var.getValue(), variables.get(var.getName()));
        }

        switch(operator) {
            case LEQ:
                cplex.addLe(constraint, rhs);
            break;
            case GEQ:
                cplex.addGe(constraint, rhs);
            break;
            default:
            break;
        }
    } catch(IloException e) {
        throw new ILPException(e.getMessage());
    }
}
 
开发者ID:jnoessner,项目名称:rockIt,代码行数:27,代码来源:CplexConnector.java


示例2: addObjective

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void addObjective() throws IloException {

		// one binary variable per concept
		if (DEBUG) {
			String[] names = new String[this.concepts.size()];
			for (int i = 0; i < names.length; i++)
				names[i] = "c" + i;
			this.conceptVars = this.problem.boolVarArray(this.concepts.size(), names);
		} else {
			this.conceptVars = this.problem.boolVarArray(this.concepts.size());
		}

		// sum of weights of selected concepts
		IloLinearNumExpr obj = this.problem.linearNumExpr();
		for (int i = 0; i < this.conceptVars.length; i++)
			obj.addTerm(this.conceptVars[i], this.concepts.get(i).weight);
		this.problem.addMaximize(obj);

	}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:20,代码来源:SubgraphILP.java


示例3: addObjectiveCostSecondRoll

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void addObjectiveCostSecondRoll() throws IloException {
	for (int firstRoll1 = 1; firstRoll1 <= numSides; firstRoll1++) {
	for (int secondRoll1 = 1; secondRoll1 <= numSides; secondRoll1++) {
	for (int firstRoll2 = 1; firstRoll2 <= numSides; firstRoll2++) {
	for (int secondRoll2 = 1; secondRoll2 <= numSides; secondRoll2++) {
		double cost = computeCostOfAbstractingSecondRollPair(firstRoll1, firstRoll2, secondRoll1, secondRoll2);
		for (int bucket = 0; bucket < numAbstractionInformationSets; bucket++) {
		
			//objective.addTerm(cost, secondRollAbstractionVariables[firstRoll1][secondRoll1][bucket]);
			IloLinearNumExpr expr = cplex.linearNumExpr();
			expr.addTerm(cost, secondRollAbstractionVariables[firstRoll1][secondRoll1][bucket]);
			expr.addTerm(cost, secondRollAbstractionVariables[firstRoll2][secondRoll2][bucket]);
			expr.setConstant(-cost);
			cplex.addLe(expr, costVariablesSecondRoll[firstRoll1][secondRoll1]);
			cplex.addLe(expr, costVariablesSecondRoll[firstRoll2][secondRoll2]);
		}
	}}}}		
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:19,代码来源:DieRollPokerAbstractor.java


示例4: createObjective

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
public IloLinearNumExpr createObjective() throws IloException {
  double cycleBonus = kepInstance.getCycleBonus();
  IloLinearNumExpr obj = this.edgeVariables.doubleSum(edgeVariables,
      kepInstance.getEdgeWeights());
  // int negativeCount = 0;gm
  // int nonNeg = 0;
  // for (E edge : this.getEdgeVariables()) {
  // if (kepInstance.getEdgeWeights().apply(edge).doubleValue() < 0) {
  // negativeCount++;
  // } else {
  // nonNeg++;
  // }
  // }
  // System.out.println("negative count: " + negativeCount
  // + ", positive count: " + nonNeg);
  Function<EdgeCycle<E>, Double> cycleWeights = kepInstance.makeCycleWeight(
      kepInstance.getEdgeWeights(), 1 + cycleBonus);
  obj.add(this.cycleVariables.doubleSum(cycleVariables, cycleWeights));
  return obj;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:21,代码来源:CycleChainPackingPolytope.java


示例5: addLinear

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
static void addLinear(final Expression source, final IloLinearNumExpr destination, final ExpressionsBasedModel model, final List<IloNumVar> variables)
        throws IloException {

    for (final IntIndex key : source.getLinearKeySet()) {

        final int freeInd = model.indexOfFreeVariable(key.index);

        if (freeInd >= 0) {
            destination.addTerm(source.getAdjustedLinearFactor(key), variables.get(freeInd));
        }
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:13,代码来源:SolverCPLEX.java


示例6: addObjective

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void addObjective() throws IloException
{
    IloLinearNumExpr expr = cplex.linearNumExpr();
    for(String var : objective.keySet()) {
        expr.addTerm(objective.get(var), variables.get(var));
    }
    if(cplex.getObjective() == null) {
        cplex.addMaximize(expr);
    } else {
        cplex.getObjective().setExpr(expr);
    }
}
 
开发者ID:jnoessner,项目名称:rockIt,代码行数:13,代码来源:CplexConnector.java


示例7: addCut

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * If a violated inequality has been found add it to the master problem.
 * @param subtourInequality subtour inequality
 */
private void addCut(SubtourInequality subtourInequality){
	if(masterData.subtourInequalities.containsKey(subtourInequality))
		throw new RuntimeException("Error, duplicate subtour cut is being generated! This cut should already exist in the master problem: "+subtourInequality);
	//Create the inequality in cplex
	try {
		IloLinearNumExpr expr=masterData.cplex.linearNumExpr();
		//Register the columns with this constraint.
		for(PricingProblemByColor pricingProblem : masterData.pricingProblems){
			for(Matching matching: masterData.getColumnsForPricingProblemAsList(pricingProblem)){
				//Test how many edges in the matching enter/leave the cutSet (edges with exactly one endpoint in the cutSet)
				int crossings=0;
				for(DefaultWeightedEdge edge: matching.edges){
					if(subtourInequality.cutSet.contains(dataModel.getEdgeSource(edge)) ^ subtourInequality.cutSet.contains(dataModel.getEdgeTarget(edge)))
						crossings++;
				}
				if(crossings>0){
					IloNumVar var=masterData.getVar(pricingProblem,matching);
					expr.addTerm(crossings, var);
				}
			}
		}
		IloRange subtourConstraint = masterData.cplex.addGe(expr, 2, "subtour");
		masterData.subtourInequalities.put(subtourInequality, subtourConstraint);
	} catch (IloException e) {
		e.printStackTrace();
	}
}
 
开发者ID:coin-or,项目名称:jorlib,代码行数:32,代码来源:SubtourInequalityGenerator.java


示例8: setObjective

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * Update the objective function of the pricing problem with the new pricing information (modified costs).
 * The modified costs are stored in the pricing problem.
 */
@Override
protected void setObjective() {
	try {
		IloIntVar[] edgeVarsArray=vars.getValuesAsArray(new IloIntVar[vars.size()]);
		IloLinearNumExpr objExpr=cplex.scalProd(pricingProblem.dualCosts, edgeVarsArray);
		obj.setExpr(objExpr);
	} catch (IloException e) {
		e.printStackTrace();
	}
}
 
开发者ID:coin-or,项目名称:jorlib,代码行数:15,代码来源:ExactPricingProblemSolver.java


示例9: createSecondRollAbstractionVars

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void createSecondRollAbstractionVars() throws IloException {
	for (int firstRoll = 1; firstRoll <= numSides; firstRoll++) {
	for (int secondRoll = 1; secondRoll <= numSides; secondRoll++) {
		IloLinearNumExpr expr = cplex.linearNumExpr();
		for (int bucket = 0; bucket < numAbstractionInformationSets; bucket++) {
			secondRollAbstractionVariables[firstRoll][secondRoll][bucket] = cplex.boolVar("B("+firstRoll+";"+secondRoll+";"+bucket+")");
			// Ensure that the variable is only added to one bucket
			expr.addTerm(1, secondRollAbstractionVariables[firstRoll][secondRoll][bucket]);
			//addBucketLevelSwitchConstraint(secondRollAbstractionVariables[firstRoll][secondRoll][bucket], bucket, true);
		}
		cplex.addEq(expr, 1);
	}}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:14,代码来源:DieRollPokerAbstractor.java


示例10: createTieBreakingConstraints

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void createTieBreakingConstraints() throws IloException{
	for (int firstRoll = 1; firstRoll <= numSides; firstRoll++) {
	for (int secondRoll = 2; secondRoll <= numSides; secondRoll++) { // start at 2 so previous roll exists
		for (int bucket = 1; bucket < numAbstractionInformationSets; bucket++) { // only constrain second bucket and higher
			IloLinearNumExpr expr = cplex.linearNumExpr();
			expr.addTerm(1, secondRollAbstractionVariables[firstRoll][secondRoll][bucket]);
			for (int previousFirstRoll = 1; previousFirstRoll < firstRoll; previousFirstRoll++) {
			for (int previousSecondRoll = 1; previousSecondRoll < secondRoll; previousSecondRoll++) {
				expr.addTerm(-1, secondRollAbstractionVariables[previousFirstRoll][previousSecondRoll][bucket-1]);
			}}
			cplex.addLe(expr, 0);
		}
	}}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:15,代码来源:DieRollPokerAbstractor.java


示例11: addDualConstraintRemoval

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void addDualConstraintRemoval() throws IloException {
	// Start at 1, we do not want to deactivate the empty sequence
	for (int sequenceId = 1; sequenceId < numDualSequences; sequenceId++) {
		// expr represents the term (-maxPayoff * sequenceDeactivationsVars[sequenceId])
		IloLinearNumExpr expr = cplex.linearNumExpr();
		double biggestDifferential = maxPayoff - minPayoff;
		expr.addTerm(biggestDifferential, sequenceDeactivationVars[sequenceId]);
		// adds the term to the existing dual constraint representing the sequence
		cplex.addToExpr(dualConstraints.get(sequenceId), expr);
	}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:12,代码来源:LimitedLookAheadOpponentSolver.java


示例12: getDominatedActionExpression

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * Using dynamic programming, this method computes an expression representing the value of a given action not chosen to be made optimal. This is done by creating an expression whose value is the sum of the value of descendant information sets under the action, according to the evaulation function and strategy for the rational player
 * @param informationSetId
 * @param dominatedAction the action to compute a value expression for
 * @param dominatedActionExpressionTable dynamic programming table
 * @return expression that represents the value of the action
 * @throws IloException
 */
private IloLinearNumExpr getDominatedActionExpression(int informationSetId, Action dominatedAction, HashMap<Action,IloLinearNumExpr> dominatedActionExpressionTable) throws IloException {
	if (dominatedActionExpressionTable.containsKey(dominatedAction)) {
		return dominatedActionExpressionTable.get(dominatedAction);
	} else {
		// this expression represents the value of dominatedAction
		IloLinearNumExpr expr = cplex.linearNumExpr();
		//TIntObjectMap<IloNumVar> informationSetToVariableMap = new TIntObjectHashMap<IloNumVar>();
		TIntObjectMap<HashMap<String, IloRange>> rangeMap = new TIntObjectHashMap<HashMap<String, IloRange>>();
		IloNumVar actionValueVar = cplex.numVar(-Double.MAX_VALUE, Double.MAX_VALUE, "DomActionValue;"+Integer.toString(informationSetId) + dominatedAction.getName());
		expr.addTerm(1, actionValueVar);
		IloRange range = cplex.addGe(actionValueVar, 0, actionValueVar.getName());
		// Iterate over nodes in information set and add value of each node for dominatedAction
		TIntArrayList informationSet = game.getInformationSet(playerNotToSolveFor, informationSetId);
		for (int i = 0; i < informationSet.size(); i++) {
			Node node = game.getNodeById(informationSet.get(i));
			// we need to locate the action that corresponds to dominatedAction at the current node, so that we can pull the correct childId
			Action dominatedActionForNode = node.getActions()[0];
			for (Action action : node.getActions()) {
				if (action.getName().equals(dominatedAction.getName())) dominatedActionForNode = action;
			}

			// find the descendant information sets and add their values to the expression
			//fillDominatedActionExpr(expr, dominatedActionForNode.getChildId(), informationSetToVariableMap, exprMap, 1, Integer.toString(informationSetId) + dominatedAction.getName());
			fillDominatedActionRange(range, dominatedActionForNode.getChildId(), rangeMap, 1, Integer.toString(informationSetId) + dominatedAction.getName());
		}
		// remember the expression for future method calls
		dominatedActionExpressionTable.put(dominatedAction, expr);
		
		return expr;
	}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:40,代码来源:LimitedLookAheadOpponentSolver.java


示例13: getIncentivizedActionExpression

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private IloLinearNumExpr getIncentivizedActionExpression(int informationSetId, Action incentivizedAction) throws IloException {
	IloLinearNumExpr actionExpr = cplex.linearNumExpr(); 
	int sequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, incentivizedAction.getName());
	
	// Iterate over nodes in information set
	double maxHeuristicAtNode = 0;
	TIntObjectMap<HashMap<String, IloNumVar>> exprMap = new TIntObjectHashMap<HashMap<String, IloNumVar>>();
	TIntArrayList informationSet = game.getInformationSet(playerNotToSolveFor, informationSetId);
	
	//IloNumVar actionValueVar = cplex.numVar(-Double.MAX_VALUE, Double.MAX_VALUE, "IncActionValue;"+Integer.toString(informationSetId) + incentivizedAction.getName());
	//actionExpr.addTerm(1, actionValueVar);

	for (int i = 0; i < informationSet.size(); i++) {
		Node node = game.getNodeById(informationSet.get(i));
		// ensure that we are using the correct Action at the node, so we can pull the correct childId
		Action incentiveActionForNode = node.getActions()[0];
		for (Action action : node.getActions()) {
			if (action.getName().equals(incentivizedAction.getName())) incentiveActionForNode = action;
		}
		IloNumVar actionActiveVar = cplex.boolVar("ActionActive" + Integer.toString(informationSetId) + incentivizedAction.getName());
		IloLinearNumExpr notDeactivatedExpr = cplex.linearNumExpr();
		notDeactivatedExpr.addTerm(-1, sequenceDeactivationVars[sequenceId]);
		notDeactivatedExpr.setConstant(1);
		cplex.addEq(actionActiveVar, notDeactivatedExpr, "NotDeactivated");
		fillIncentivizedActionExpression(actionExpr, actionActiveVar, incentiveActionForNode.getChildId(), exprMap, 1, Integer.toString(informationSetId) + incentivizedAction.getName());
		if (maxEvaluationValueForSequence[sequenceId] > maxHeuristicAtNode) {
			maxHeuristicAtNode = maxEvaluationValueForSequence[sequenceId];
		}
	}
	
	return actionExpr;
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:33,代码来源:LimitedLookAheadOpponentSolver.java


示例14: addDualConstraintRemoval

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private void addDualConstraintRemoval() throws IloException {
    // Start at 1, we do not want to deactivate the empty sequence
    for (int sequenceId = 1; sequenceId < numDualSequences; sequenceId++) {
        // expr represents the term (-maxPayoff * sequenceDeactivationsVars[sequenceId])
        IloLinearNumExpr expr = cplex.linearNumExpr();
        double biggestDifferential = maxPayoff - minPayoff;
        expr.addTerm(biggestDifferential, sequenceDeactivationVars[sequenceId]);
        // adds the term to the existing dual constraint representing the sequence
        cplex.addToExpr(dualConstraints.get(sequenceId), expr);
    }
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:12,代码来源:LimitedLookaheadUncertaintySolver.java


示例15: getDominatedActionExpression

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * Using dynamic programming, this method computes an expression representing the value of a given action not chosen to be made optimal. This is done by creating an expression whose value is the sum of the value of descendant information sets under the action, according to the evaulation function and strategy for the rational player
 * @param informationSetId
 * @param dominatedAction the action to compute a value expression for
 * @param dominatedActionExpressionTable dynamic programming table
 * @return expression that represents the value of the action
 * @throws IloException
 */
private IloLinearNumExpr getDominatedActionExpression(int informationSetId, Action dominatedAction, HashMap<Action,IloLinearNumExpr> dominatedActionExpressionTable) throws IloException {
    if (dominatedActionExpressionTable.containsKey(dominatedAction)) {
        return dominatedActionExpressionTable.get(dominatedAction);
    } else {
        // this expression represents the value of dominatedAction
        IloLinearNumExpr expr = cplex.linearNumExpr();
        //TIntObjectMap<IloNumVar> informationSetToVariableMap = new TIntObjectHashMap<IloNumVar>();
        TIntObjectMap<HashMap<String, IloRange>> rangeMap = new TIntObjectHashMap<HashMap<String, IloRange>>();
        IloNumVar actionValueVar = cplex.numVar(-Double.MAX_VALUE, Double.MAX_VALUE, "DomActionValue;"+Integer.toString(informationSetId) + dominatedAction.getName());
        expr.addTerm(1, actionValueVar);
        IloRange range = cplex.addGe(actionValueVar, 0, actionValueVar.getName());
        // Iterate over nodes in information set and add value of each node for dominatedAction
        TIntArrayList informationSet = game.getInformationSet(playerNotToSolveFor, informationSetId);
        for (int i = 0; i < informationSet.size(); i++) {
            Node node = game.getNodeById(informationSet.get(i));
            // we need to locate the action that corresponds to dominatedAction at the current node, so that we can pull the correct childId
            Action dominatedActionForNode = node.getActions()[0];
            for (Action action : node.getActions()) {
                if (action.getName().equals(dominatedAction.getName())) dominatedActionForNode = action;
            }

            // find the descendant information sets and add their values to the expression
            //fillDominatedActionExpr(expr, dominatedActionForNode.getChildId(), informationSetToVariableMap, exprMap, 1, Integer.toString(informationSetId) + dominatedAction.getName());
            fillDominatedActionRange(range, dominatedActionForNode.getChildId(), rangeMap, 1, Integer.toString(informationSetId) + dominatedAction.getName());
        }
        // remember the expression for future method calls
        dominatedActionExpressionTable.put(dominatedAction, expr);

        return expr;
    }
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:40,代码来源:LimitedLookaheadUncertaintySolver.java


示例16: getIncentivizedActionExpression

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
private IloLinearNumExpr getIncentivizedActionExpression(int informationSetId, Action incentivizedAction) throws IloException {
    IloLinearNumExpr actionExpr = cplex.linearNumExpr();
    int sequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, incentivizedAction.getName());

    // Iterate over nodes in information set
    double maxHeuristicAtNode = 0;
    TIntObjectMap<HashMap<String, IloNumVar>> exprMap = new TIntObjectHashMap<HashMap<String, IloNumVar>>();
    TIntArrayList informationSet = game.getInformationSet(playerNotToSolveFor, informationSetId);

    //IloNumVar actionValueVar = cplex.numVar(-Double.MAX_VALUE, Double.MAX_VALUE, "IncActionValue;"+Integer.toString(informationSetId) + incentivizedAction.getName());
    //actionExpr.addTerm(1, actionValueVar);

    for (int i = 0; i < informationSet.size(); i++) {
        Node node = game.getNodeById(informationSet.get(i));
        // ensure that we are using the correct Action at the node, so we can pull the correct childId
        Action incentiveActionForNode = node.getActions()[0];
        for (Action action : node.getActions()) {
            if (action.getName().equals(incentivizedAction.getName())) incentiveActionForNode = action;
        }
        IloNumVar actionActiveVar = cplex.boolVar("ActionActive" + Integer.toString(informationSetId) + incentivizedAction.getName());
        IloLinearNumExpr notDeactivatedExpr = cplex.linearNumExpr();
        notDeactivatedExpr.addTerm(-1, sequenceDeactivationVars[sequenceId]);
        notDeactivatedExpr.setConstant(1);
        cplex.addEq(actionActiveVar, notDeactivatedExpr, "NotDeactivated");
        fillIncentivizedActionExpression(actionExpr, actionActiveVar, incentiveActionForNode.getChildId(), exprMap, 1, Integer.toString(informationSetId) + incentivizedAction.getName());
        if (maxEvaluationValueForSequence[sequenceId] > maxHeuristicAtNode) {
            maxHeuristicAtNode = maxEvaluationValueForSequence[sequenceId];
        }
    }

    return actionExpr;
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:33,代码来源:LimitedLookaheadUncertaintySolver.java


示例17: rescale

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
public static void rescale(IloLinearNumExpr sum, double multiplier) {
  IloLinearNumExprIterator it = sum.linearIterator();
  while (it.hasNext()) {
    it.nextNumVar();
    it.setValue(it.getValue() * multiplier);
  }
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:8,代码来源:CplexUtil.java


示例18: doubleSum

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
public IloLinearNumExpr doubleSum(Iterable<T> set, 
		Function<? super T,? extends Number> coefficients) throws IloException{
	IloLinearNumExpr sum = cplex.linearNumExpr();
	for(T t: set){
		sum.addTerm(getVarMap().get(t), coefficients.apply(t).doubleValue());
	}
	return sum;
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:9,代码来源:VariableSet.java


示例19: addPrimalIncentiveConstraints

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * Outer method that loops over all informationSetIds and action pairs for the limited look-ahead player.
 * @throws IloException
 */
private void addPrimalIncentiveConstraints() throws IloException {
	for (int informationSetId = game.getSmallestInformationSetId(playerNotToSolveFor); informationSetId < (numDualInformationSets + game.getSmallestInformationSetId(playerNotToSolveFor)); informationSetId++) {
		// We need to access the set of actions available at the information set. To do this, we loop over node.actions on the (arbitrarily picked) first node in the information set.
		int idOfFirstNodeInSet = game.getInformationSet(playerNotToSolveFor, informationSetId).get(0);
		Node firstNodeInSet = game.getNodeById(idOfFirstNodeInSet);
		// Dynamic programming table for expressions representing dominated actions
		HashMap<Action, IloLinearNumExpr> dominatedActionExpressionTable = new HashMap<Action, IloLinearNumExpr>();
		for (Action incentivizedAction : firstNodeInSet.getActions()) {
			// get expr representing value of chosen action
			IloLinearNumExpr incentiveExpr = getIncentivizedActionExpression(informationSetId, incentivizedAction);
			
			IloLinearNumExpr incentiveConstraintLHS = cplex.linearNumExpr();
			incentiveConstraintLHS.add(incentiveExpr);
			
			int incentiveSequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, incentivizedAction.getName());
			// ensure that expression is only active if the sequence is chosen
			//incentiveConstraintLHS.addTerm(maxEvaluationValueForSequence[incentiveSequenceId]+this.epsilon, sequenceDeactivationVars[incentiveSequenceId]);
	
			
			for (Action dominatedAction : firstNodeInSet.getActions()) {
				if (!incentivizedAction.equals(dominatedAction)) {
					// get expr representing value of dominated action
					IloLinearNumExpr dominatedExpr = getDominatedActionExpression(informationSetId, dominatedAction, dominatedActionExpressionTable);
					IloLinearNumExpr incentiveConstraintRHS = cplex.linearNumExpr();
					incentiveConstraintRHS.add(dominatedExpr);
					
					int dominatedSequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, dominatedAction.getName());
					// ensure that expression is only active is the sequence is deactivated
					incentiveConstraintRHS.addTerm(maxEvaluationValueForSequence[dominatedSequenceId]+this.epsilon, sequenceDeactivationVars[dominatedSequenceId]);
					incentiveConstraintRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[incentiveSequenceId]);
					// TODO: something needs to be flipped here. Perhaps it needs to be LB of other side
					incentiveConstraintRHS.setConstant(-maxEvaluationValueForSequence[dominatedSequenceId]);
					cplex.addGe(incentiveConstraintLHS, incentiveConstraintRHS, "PrimalIncentive("+informationSetId+";"+incentivizedAction.getName()+";"+dominatedAction.getName()+")");
					
					// add constraint requiring equality if both sequences are chosen to be incentivized, here we add one side of the two weak inequalities enforcing equality, since the other direction is also iterated over
					IloLinearNumExpr equalityRHS = cplex.linearNumExpr();
					equalityRHS.add(dominatedExpr);
					equalityRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[dominatedSequenceId]);
					equalityRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[incentiveSequenceId]);
					cplex.addGe(incentiveExpr, equalityRHS, "quality("+informationSetId+";"+incentivizedAction.getName()+";"+dominatedAction.getName()+")");
				}
			}
		}
	}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:50,代码来源:LimitedLookAheadOpponentSolver.java


示例20: addPrimalIncentiveConstraints

import ilog.concert.IloLinearNumExpr; //导入依赖的package包/类
/**
 * Outer method that loops over all informationSetIds and action pairs for the limited look-ahead player.
 * @throws IloException
 */
private void addPrimalIncentiveConstraints() throws IloException {
    for (int informationSetId = game.getSmallestInformationSetId(playerNotToSolveFor); informationSetId < (numDualInformationSets + game.getSmallestInformationSetId(playerNotToSolveFor)); informationSetId++) {
        // We need to access the set of actions available at the information set. To do this, we loop over node.actions on the (arbitrarily picked) first node in the information set.
        int idOfFirstNodeInSet = game.getInformationSet(playerNotToSolveFor, informationSetId).get(0);
        Node firstNodeInSet = game.getNodeById(idOfFirstNodeInSet);
        // Dynamic programming table for expressions representing dominated actions
        HashMap<Action, IloLinearNumExpr> dominatedActionExpressionTable = new HashMap<Action, IloLinearNumExpr>();
        for (Action incentivizedAction : firstNodeInSet.getActions()) {
            // get expr representing value of chosen action
            IloLinearNumExpr incentiveExpr = getIncentivizedActionExpression(informationSetId, incentivizedAction);

            IloLinearNumExpr incentiveConstraintLHS = cplex.linearNumExpr();
            incentiveConstraintLHS.add(incentiveExpr);

            int incentiveSequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, incentivizedAction.getName());
            // ensure that expression is only active if the sequence is chosen
            //incentiveConstraintLHS.addTerm(maxEvaluationValueForSequence[incentiveSequenceId]+this.epsilon, sequenceDeactivationVars[incentiveSequenceId]);


            for (Action dominatedAction : firstNodeInSet.getActions()) {
                if (!incentivizedAction.equals(dominatedAction)) {
                    // get expr representing value of dominated action
                    IloLinearNumExpr dominatedExpr = getDominatedActionExpression(informationSetId, dominatedAction, dominatedActionExpressionTable);
                    IloLinearNumExpr incentiveConstraintRHS = cplex.linearNumExpr();
                    incentiveConstraintRHS.add(dominatedExpr);

                    int dominatedSequenceId = getSequenceIdForPlayerNotToSolveFor(informationSetId, dominatedAction.getName());
                    // ensure that expression is only active is the sequence is deactivated
                    incentiveConstraintRHS.addTerm(maxEvaluationValueForSequence[dominatedSequenceId]+this.epsilon, sequenceDeactivationVars[dominatedSequenceId]);
                    incentiveConstraintRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[incentiveSequenceId]);
                    // TODO: something needs to be flipped here. Perhaps it needs to be LB of other side
                    incentiveConstraintRHS.setConstant(-maxEvaluationValueForSequence[dominatedSequenceId]);
                    cplex.addGe(incentiveConstraintLHS, incentiveConstraintRHS, "PrimalIncentive("+informationSetId+";"+incentivizedAction.getName()+";"+dominatedAction.getName()+")");

                    // add constraint requiring equality if both sequences are chosen to be incentivized, here we add one side of the two weak inequalities enforcing equality, since the other direction is also iterated over
                    IloLinearNumExpr equalityRHS = cplex.linearNumExpr();
                    equalityRHS.add(dominatedExpr);
                    equalityRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[dominatedSequenceId]);
                    equalityRHS.addTerm(-maxEvaluationValueForSequence[dominatedSequenceId], sequenceDeactivationVars[incentiveSequenceId]);
                    cplex.addGe(incentiveExpr, equalityRHS, "quality("+informationSetId+";"+incentivizedAction.getName()+";"+dominatedAction.getName()+")");
                }
            }
        }
    }
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:50,代码来源:LimitedLookaheadUncertaintySolver.java



注:本文中的ilog.concert.IloLinearNumExpr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BasePsiNode类代码示例发布时间:2022-05-22
下一篇:
Java QNameMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap