本文整理汇总了Java中ilog.cplex.IloCplex.addMaximize方法的典型用法代码示例。如果您正苦于以下问题:Java IloCplex.addMaximize方法的具体用法?Java IloCplex.addMaximize怎么用?Java IloCplex.addMaximize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilog.cplex.IloCplex
的用法示例。
在下文中一共展示了IloCplex.addMaximize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CplexHandler
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
/**
* Constructor
*
* @throws IloException
*/
public CplexHandler() throws IloException {
m_cplex = new IloCplex();
m_lp = m_cplex.addLPMatrix();
m_solved = false;
m_obj = m_cplex.addMaximize();
m_cplex.setOut(null);
}
示例4: build
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public SolverCPLEX build(final ExpressionsBasedModel model) {
final SolverCPLEX retVal = new SolverCPLEX(model.options);
final IloCplex delegateSolver = retVal.getDelegateSolver();
try {
final List<Variable> freeModVars = model.getFreeVariables();
final Set<IntIndex> fixedModVars = model.getFixedVariables();
final Expression modObj = model.objective().compensate(fixedModVars);
for (final Variable var : freeModVars) {
IloNumVarType type = IloNumVarType.Float;
if (var.isBinary()) {
type = IloNumVarType.Bool;
} else if (var.isInteger()) {
type = IloNumVarType.Int;
}
final IloNumVar tmpSolVar = delegateSolver.numVar(var.getAdjustedLowerLimit() / var.getAdjustmentFactor(),
var.getAdjustedUpperLimit() / var.getAdjustmentFactor(), type, var.getName());
retVal.getDelegateVariables().add(tmpSolVar);
}
for (final Expression expr : model.constraints().map(e -> e.compensate(fixedModVars)).collect(Collectors.toList())) {
final IloNumExpr solExpr = SolverCPLEX.buildExpression(model, expr, delegateSolver, retVal.getDelegateVariables());
SolverCPLEX.setBounds(solExpr, expr, delegateSolver);
}
final IloNumExpr solObj = SolverCPLEX.buildExpression(model, modObj, delegateSolver, retVal.getDelegateVariables());
if (model.isMaximisation()) {
delegateSolver.addMaximize(solObj);
} else {
delegateSolver.addMinimize(solObj);
}
} catch (final IloException exception) {
exception.printStackTrace();
}
return retVal;
}
示例5: 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());
}
}