本文整理汇总了Java中ilog.concert.IloLinearNumExpr类的典型用法代码示例。如果您正苦于以下问题:Java IloLinearNumExpr类的具体用法?Java IloLinearNumExpr怎么用?Java IloLinearNumExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IloLinearNumExpr类属于ilog.concert包,在下文中一共展示了IloLinearNumExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
示例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);
}
示例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]);
}
}}}}
}
示例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;
}
示例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));
}
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
}}
}
示例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);
}
}}
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}
}