当前位置: 首页>>代码示例>>Java>>正文


Java IloLinearNumExpr.setConstant方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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.setConstant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。