本文整理汇总了Java中ilog.concert.IloRange类的典型用法代码示例。如果您正苦于以下问题:Java IloRange类的具体用法?Java IloRange怎么用?Java IloRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IloRange类属于ilog.concert包,在下文中一共展示了IloRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConstraintList
import ilog.concert.IloRange; //导入依赖的package包/类
@Override
public List<ConditionalConstraint> getConstraintList() {
//There's some overhead here for avoiding duplicates
Set<ConditionalConstraint> ccSet = new HashSet<ConditionalConstraint>();
List<ConditionalConstraint> ccList = new ArrayList<ConditionalConstraint>();
for (IloRange range : getRangeList()) {
ConditionalConstraint cc = m_rangeMap.get( range );
if (cc != null) {
if (!ccSet.contains( cc )) {
ccList.add( cc );
ccSet.add( cc );
}
}
}
return ccList;
}
示例2: getConflictReactions
import ilog.concert.IloRange; //导入依赖的package包/类
/**
* returns reactions that show conflict in current lp matrix
*
* @param lp
* current calculated model
* @return list of conflict reactions
* @throws IloException
*/
protected ArrayList<String> getConflictReactions() throws IloException {
ArrayList<String> conflict = new ArrayList<String>();
IloRange[] x = m_lp.getRanges();
double[] p = new double[x.length];
for (int i = 0; i < p.length; i++) {
p[i] = 1;
}
m_cplex.refineConflict(x, p);
ConflictStatus[] cs = m_cplex.getConflict(x);
for (int i = 0; i < cs.length; i++) {
if (cs[i] == ConflictStatus.Member) {
String name = x[i].getName();
if (name.startsWith(ThermoChecker.RX_PREFIX) || name.startsWith(ThermoChecker.RX_REV_PREFIX)) {
conflict.add(name);
}
}
}
return conflict;
}
示例3: convertToIloConstraints
import ilog.concert.IloRange; //导入依赖的package包/类
private List<IloRange> convertToIloConstraints(
Iterable<Cutset<V, E>> cutsets) throws IloException {
List<IloRange> ans = Lists.newArrayList();
double best = 0;
Cutset<V, E> bestCut = null;
IloRange bestConstraint = null;
for (Cutset<V, E> cut : cutsets) {
IloRange constraint = makeCutsetConstraint(cut);
if (cut.getViolation() > best) {
bestCut = cut;
best = cut.getViolation();
bestConstraint = constraint;
}
ans.add(constraint);
}
// System.out.println(bestCut == null ? "0" : bestCut.getViolation());
// return bestCut == null ? Lists.<IloConstraint>newArrayList():
// Lists.<IloConstraint>newArrayList(bestConstraint);
return ans;
}
示例4: main
import ilog.concert.IloRange; //导入依赖的package包/类
@Override
protected void main() throws IloException {
if (!this.isAfterCutLoop()) {
return;
}
int time = numUserCutCallback++;
if (time % 500 == 0 && time != 0) {
System.err.println("completed about: " + time
+ " user cut callbacks. MIP gap: " + this.getMIPRelativeGap());
}
UserCutGenerator userCutGen = polytope.makeUserCutGenerator(this);
List<IloRange> violatedConstraints = userCutGen.quickUserCut();
if (!solverOptions.contains(SolverOption.disableFullUserCut)
&& violatedConstraints.size() == 0 && this.getNnodes64() == 0) {
violatedConstraints = userCutGen.fullUserCut();
}
for (IloRange constraint : violatedConstraints) {
this.add(constraint);
}
}
示例5: main
import ilog.concert.IloRange; //导入依赖的package包/类
@Override
protected void main() throws IloException {
int time = numLazyConstraintCallback++;
if(time %500 == 0 && time != 0){
System.err.println("completed about: " + time + " lazy cut callbacks. Integrality gap: " + this.getMIPRelativeGap());
}
List<IloRange> violatedConstraints = Lists.newArrayList();
violatedConstraints.addAll(phaseOneProblem.lazyConstraint(this));
for(CycleChainPackingPolytope<V,E> phaseTwoProbem: phaseTwoProblems){
violatedConstraints.addAll(phaseTwoProbem.lazyConstraint(this));
}
for(IloRange constraint: violatedConstraints){
this.add(constraint);
}
}
示例6: addColumn
import ilog.concert.IloRange; //导入依赖的package包/类
/**
* @param column
* @param name
* @return Index of the newly added column
* @throws CPException
*/
@Override
public int addColumn(double[] column, String name) throws CPException {
try {
IloObjective obj = m_model.getObjective();
IloColumn col = m_model.column( obj, column[0] );
int index = 1;
for (IloRange range : m_ranges) {
//Install the new column at every constraint
col = col.and( m_model.column( range, column[index++] ) );
}
addVar( m_model.numVar(col, 0.0, 1.0, name));
m_objCoeffs = ArrayUtils.add(m_objCoeffs, column[0]);//TODO This must be damn fucking slow!
return getColumnNumber() - 1 + getFirstColumnIndex();
} catch( IloException e ) {
m_logger.fatal( e );
throw new CPException(e);
}
}
示例7: addRange
import ilog.concert.IloRange; //导入依赖的package包/类
protected void addRange(IloNumVar[] vars, double[] coeffs, double lb, double ub, String name) throws IloException {
IloNumExpr expr = m_model.scalProd( coeffs, vars );
IloRange range = NumberUtils.equal( lb, ub, PRECISION_THRESHOLD )
? m_model.addEq( expr, lb, name )
: m_model.addRange( lb, expr, ub, name );
addRange( range );
}
示例8: removeRange
import ilog.concert.IloRange; //导入依赖的package包/类
protected void removeRange(int index) throws IloException {
IloRange range = m_ranges.get( index );
m_model.delete( range );
m_ranges.remove( index );
m_nameRangeMap.remove( range.getName() );
}
示例9: removeRange
import ilog.concert.IloRange; //导入依赖的package包/类
@Override
protected void removeRange(IloRange range) throws IloException {
if (range != null) {
m_rangeMap.remove( range );
super.removeRange( range );
}
}
示例10: HeuristicConcentration
import ilog.concert.IloRange; //导入依赖的package包/类
/**
* Creates a new <code>HeuristicConcentration</code>
*
* @param instance
*/
public HeuristicConcentration(IVRPInstance instance, ISolutionFactory soluitonFactory) {
mInstance = instance;
mSolutionFactory = soluitonFactory;
mCoverCtrs = new IloRange[Utilities.getMaxId(instance.getRequests()) + 1];
}
示例11: ChangeCoefficientsInSubModel
import ilog.concert.IloRange; //导入依赖的package包/类
public void ChangeCoefficientsInSubModel(double[] shadowPrices, PartialSolution partialSolutions,
double bound, double gap) throws IloException{
double[] tmp = new double[problemInstanceSingleDevice.getNumbSlots()];
Helpers.InitializeTo(tmp, 1.0 / problemInstanceSingleDevice.getNumbSlots(), 0, problemInstanceSingleDevice.getNumbSlots());
if(ReducedCost != null) patSolver.remove(ReducedCost);
ReducedCost = patSolver.addMaximize(patSolver.diff(patSolver.scalProd(x, shadowPrices), patSolver.scalProd(x, tmp)));
//setting bound on the criterion value
if(bound < 0){
patSolver.setParam(IloCplex.DoubleParam.CutLo, bound);
}
else{
patSolver.setParam(IloCplex.DoubleParam.CutLo, -Double.MAX_VALUE);
}
if(fixedAssignmentRequirements != null) patSolver.remove(fixedAssignmentRequirements);
fixedAssignmentRequirements = new IloRange [problemInstanceSingleDevice.getNumbSlots()];
//Processing partial solutions
for(int j = 0; j < problemInstanceSingleDevice.getNumbSlots(); j++){
if(partialSolutions.getPartialSolutions()[problemInstanceSingleDevice.getNumbOfDeviceInArray()][j] == 1){
fixedAssignmentRequirements[j] = patSolver.addEq(x[j], 1);
}
if(partialSolutions.getPartialSolutions()[problemInstanceSingleDevice.getNumbOfDeviceInArray()][j] == 0){
fixedAssignmentRequirements[j] = patSolver.addEq(x[j], 0);
}
}
//sub-model does not solve it to optimum, but integrality gap should be less than "gap" value
patSolver.setParam(IloCplex.DoubleParam.EpGap, gap);
}
示例12: addCut
import ilog.concert.IloRange; //导入依赖的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();
}
}
示例13: buildModel
import ilog.concert.IloRange; //导入依赖的package包/类
/**
* Build the cplex problem
*/
@Override
protected CuttingStockMasterData buildModel() {
try {
cplex =new IloCplex(); //Create cplex instance
cplex.setOut(null); //Disable cplex output
cplex.setParam(IloCplex.IntParam.Threads, config.MAXTHREADS); //Set number of threads that may be used by the cplex
//Define the objective
obj= cplex.addMinimize();
//Define constraints
satisfyDemandConstr=new IloRange[dataModel.nrFinals];
for(int i=0; i< dataModel.nrFinals; i++)
satisfyDemandConstr[i]= cplex.addRange(dataModel.demandForFinals[i], dataModel.demandForFinals[i], "satisfyDemandFinal_"+i);
//Define a container for the variables
} catch (IloException e) {
e.printStackTrace();
}
//Define a container for the variables
Map<PricingProblem,OrderedBiMap<CuttingPattern, IloNumVar>> varMap=new LinkedHashMap<>();
varMap.put(pricingProblems.get(0),new OrderedBiMap<>());
//Return a new data object which will hold data from the Master Problem. Since we are not working with inequalities in this example,
//we can simply return the default.
return new CuttingStockMasterData(varMap);
}
示例14: getDominatedActionExpression
import ilog.concert.IloRange; //导入依赖的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;
}
}
示例15: getDominatedActionExpression
import ilog.concert.IloRange; //导入依赖的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;
}
}