本文整理汇总了Java中ilog.cplex.IloCplex.addLe方法的典型用法代码示例。如果您正苦于以下问题:Java IloCplex.addLe方法的具体用法?Java IloCplex.addLe怎么用?Java IloCplex.addLe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilog.cplex.IloCplex
的用法示例。
在下文中一共展示了IloCplex.addLe方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildModel
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
/**
* Build the MIP model. Essentially this model calculates maximum weight independent sets.
*/
private void buildModel(){
try {
cplex=new IloCplex();
cplex.setParam(IloCplex.IntParam.AdvInd, 0);
cplex.setParam(IloCplex.IntParam.Threads, 1);
cplex.setOut(null);
//Create the variables (a single variable per edge)
vars=cplex.boolVarArray(dataModel.getNrVertices());
//Create the objective function
obj=cplex.addMaximize();
//Create the constraints z_i+z_j <= 1 for all (i,j)\in E:
for(DefaultEdge edge : dataModel.edgeSet())
cplex.addLe(cplex.sum(vars[dataModel.getEdgeSource(edge)], vars[dataModel.getEdgeTarget(edge)]), 1);
branchingConstraints=new HashMap<>();
} catch (IloException e) {
e.printStackTrace();
}
}
示例2: buildModel
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
/**
* Build the MIP model
*/
private void buildModel(){
try {
cplex=new IloCplex();
cplex.setParam(IloCplex.IntParam.AdvInd, 0);
cplex.setParam(IloCplex.IntParam.Threads,config.MAXTHREADS);
cplex.setOut(null);
//Create the variables
vars=cplex.intVarArray(dataModel.nrFinals, 0, Integer.MAX_VALUE);
//Create the objective
obj=cplex.addMaximize(cplex.sum(vars));
//Create the constraints
cplex.addLe(cplex.scalProd(vars, dataModel.finals), dataModel.rollWidth);
} catch (IloException e) {
e.printStackTrace();
}
}
示例3: setBounds
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
static void setBounds(final IloNumExpr expression, final Expression model, final IloCplex solver) throws IloException {
if (model.isEqualityConstraint()) {
solver.addEq(model.getAdjustedLowerLimit(), expression);
} else {
if (model.isLowerConstraint()) {
solver.addLe(model.getAdjustedLowerLimit(), expression);
}
if (model.isUpperConstraint()) {
solver.addGe(model.getAdjustedUpperLimit(), expression);
}
}
}
示例4: addConstraint
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public static IloRange addConstraint(IloNumExpr expr,
RelationType relationType, double rhs, IloCplex cplex)
throws IloException {
if (relationType.equals(RelationType.eq)) {
return cplex.addEq(expr, rhs);
} else if (relationType.equals(RelationType.geq)) {
return cplex.addGe(expr, rhs);
} else if (relationType.equals(RelationType.leq)) {
return cplex.addLe(expr, rhs);
} else {
throw new RuntimeException(
"Unidentified relation type defining equation " + relationType);
}
}
示例5: CycleChainPackingPolytope
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public CycleChainPackingPolytope(KepInstance<V, E> kepInstance,
List<EdgeCycle<E>> cycles, IloCplex cplex,
Optional<FixedThreadPool> threadPool,
ImmutableSet<SolverOption> solverOptions) throws IloException {
this.kepInstance = kepInstance;
this.threadPool = threadPool;
this.cplex = cplex;
this.enforceMaximumChainLength = kepInstance.getMaxChainLength() < kepInstance
.getPairedNodes().size() + 2
&& !solverOptions.contains(SolverOption.ignoreMaxChainLength);
this.solverOptions = solverOptions;
this.cycleVariables = new CycleVariables<V, E>(kepInstance.getGraph(),
cycles, cplex);
this.flowNetwork = new IntegerFlowNetwork<V, E>(kepInstance.getGraph(),
kepInstance.getRootNodes(), kepInstance.getPairedNodes(),
kepInstance.getTerminalNodes(), cplex,
solverOptions.contains(SolverOption.expandedFormulation));
this.edgeVariables = flowNetwork.getEdgeVariables();
this.flowInterface = flowNetwork.getFlowInterface();
/*
* for(EdgeCycle<E> cycle: cycles){ for(IloRange cycleConstraint:
* this.makeConstraintForCycle(cycle)){ cplex.add(cycleConstraint); } }
*/
for (V vertex : kepInstance.getPairedNodes()) {
IloLinearIntExpr nodeUsage = cycleVariables.integerSum(cycleVariables
.getNodeToCycles().get(vertex));
flowInterface.addFlowInIntScaled(vertex, nodeUsage, 1);
cplex.addLe(nodeUsage, 1);
}
if (enforceMaximumChainLength) {
MaxChainLength.constrainMaxLength(kepInstance, cplex, solverOptions,
edgeVariables, true);
}
addAuxiliaryConstraints();
}
示例6: BoundedDegree
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public BoundedDegree(DirectedSparseMultigraph<V,E> graph,IloCplex cplex, int inDegreeMaximum, int outDegreeMaximum) throws IloException{
this.graph = graph;
this.cplex = cplex;
this.edgeVariables = new DirectedEdgeVariables<V,E>(graph,cplex);
this.inDegreeConstraints = new HashMap<V,IloRange>();
this.outDegreeConstraints = new HashMap<V,IloRange>();
for(V vertex: graph.getVertices()){
IloRange inConstraint = cplex.addLe(edgeVariables.integerSum(graph.getInEdges(vertex)), inDegreeMaximum);
inDegreeConstraints.put(vertex, inConstraint);
IloRange outConstraint = cplex.addLe(edgeVariables.integerSum(graph.getOutEdges(vertex)), outDegreeMaximum);
outDegreeConstraints.put(vertex, outConstraint);
}
}
示例7: main
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public static void main(String[] args) throws IloException {
//Define cplex reponsavel por criar variáveis e seus limites, definir restrições, parâmetros e resolver o modelo.
IloCplex cplex = new IloCplex();
//Definindo as 3 variáveis do problema no intervalo de 0 até infinito e do tipo Float
IloNumVar x[] = cplex.numVarArray(3, 0, Double.POSITIVE_INFINITY, IloNumVarType.Float);
//Mundando limite superior (ub - upper bound) da variável x1 como 5
x[0].setUB(5);
//Definindo expressão para a função objetivo
IloNumExpr objective = cplex.prod(0.5, x[0]);
objective = cplex.sum(objective, cplex.prod(4, x[1]));
objective = cplex.sum(objective, cplex.prod(7, x[2]));
//Adiciona ao cplex a expressão do objetivo como problema de maximização
cplex.addMaximize(objective);
//Definnindo a expressão para a primeira restrição do problema
IloNumExpr restriction1 = cplex.prod(7, x[0]);
restriction1 = cplex.sum(restriction1, cplex.prod(-3, x[1]));
restriction1 = cplex.sum(restriction1, cplex.prod(0.5, x[2]));
//Adiciona ao cplex a restrição como maior ou igual a 10
cplex.addGe(restriction1, 10);
//Definnindo a expressão para a segunda restrição do problema
IloNumExpr restriction2 = cplex.prod(2, x[1]);
restriction2 = cplex.sum(restriction2, cplex.prod(5, x[2]));
//Adiciona ao cplex a restrição como menor ou igual a 80
cplex.addLe(restriction2, 80);
cplex.exportModel("model.lp");
if(cplex.solve()){
System.out.println("O modelo possui solução");
System.out.println("Status: "+cplex.getStatus());
double obj = cplex.getObjValue();
System.out.println("objetivo = "+obj);
double sol[] = cplex.getValues(x);
System.out.println("x1 = "+sol[0]);
System.out.println("x2 = "+sol[1]);
System.out.println("x2 = "+sol[2]);
}else{
System.out.println("O modelo não possui solução");
System.out.println("Status: "+cplex.getStatus());
}
}