本文整理汇总了Java中ilog.cplex.IloCplex.exportModel方法的典型用法代码示例。如果您正苦于以下问题:Java IloCplex.exportModel方法的具体用法?Java IloCplex.exportModel怎么用?Java IloCplex.exportModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilog.cplex.IloCplex
的用法示例。
在下文中一共展示了IloCplex.exportModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportToDisk
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public void exportToDisk(IMIP mip, Path path) {
try {
IloCplex cplex = CPLEXInstanceManager.INSTANCE.checkOutCplex();
setControlParams(cplex, mip.getSpecifiedSolveParams(),mip::getSolveParam);
Map<String, IloNumVar> vars = setupVariables(mip, cplex);
setupConstraints(mip, cplex, vars);
setUpObjective(mip, cplex, vars);
cplex.exportModel(path.toString());
} catch (Exception ex) {
logger.error("Failed to write cplex model to disk", ex);
}
}
示例2: solve
import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public IMIPResult solve(IMIP mip) throws MIPException {
IloCplex cplex = CPLEXInstanceManager.INSTANCE.checkOutCplex();
try {
// This blocks until one can be obtained:
while (cplex.getObjective() != null) {
CPLEXInstanceManager.INSTANCE.checkInCplex(cplex);
logger.warn("Model not cleared");
cplex = CPLEXInstanceManager.INSTANCE.checkOutCplex();
}
logger.debug("About to set parameters... ");
setControlParams(cplex, mip.getSpecifiedSolveParams(), mip::getSolveParam);
// Log only on info logging level
if (!mip.getBooleanSolveParam(SolveParam.DISPLAY_OUTPUT, false) && !logger.isDebugEnabled()) {
cplex.setParam((IntParam) getCplexParam(SolveParam.MIP_DISPLAY), 0);
}
// cplex.setParam(IloCplex.DoubleParam.EpInt,
// 1.0/(MIP.MAX_VALUE*1.0-1));
// cplex.setParam(IloCplex.DoubleParam.EpRHS,
// 1.0/(MIP.MAX_VALUE*1.0-1));
long convertStartTime = System.currentTimeMillis();
logger.debug("Starting to convert mip to Cplex object.");
Map<String, IloNumVar> vars = setupVariables(mip, cplex);
Map<Constraint, IloRange> constraintsToIloConstraints = setupConstraints(mip, cplex, vars);
setUpObjective(mip, cplex, vars);
logger.debug("Converting mip done. Took: " + (System.currentTimeMillis() - convertStartTime) + " ms");
// write model to file for debugging:
// ///////////////////////////////////
String fileName = mip.getStringSolveParam(SolveParam.PROBLEM_FILE, new String("mipInstance"));
if (!fileName.equals("")) {
cplex.exportModel(/* "" + */fileName + ".lp");// + ".txt");
}
return solveMip(mip, cplex, vars, constraintsToIloConstraints);
} catch (IloException e) {
if (mip.getBooleanSolveParam(SolveParam.DISPLAY_OUTPUT, true)) {
e.printStackTrace();
}
throw new MIPException("Cplex Exception: " + e.toString());
} catch (RuntimeException ex) {
if (mip.getBooleanSolveParam(SolveParam.DISPLAY_OUTPUT, true)) {
ex.printStackTrace();
}
throw ex;
} finally {
CPLEXInstanceManager.INSTANCE.checkInCplex(cplex);
}
}
示例3: 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());
}
}