本文整理汇总了Java中ilog.cplex.IloCplex类的典型用法代码示例。如果您正苦于以下问题:Java IloCplex类的具体用法?Java IloCplex怎么用?Java IloCplex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IloCplex类属于ilog.cplex包,在下文中一共展示了IloCplex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkOutCplex
import ilog.cplex.IloCplex; //导入依赖的package包/类
public synchronized IloCplex checkOutCplex() {
while (notAvailable()) {
try {
this.wait();
} catch (InterruptedException e) {
logger.error("Interrupted while trying to get IloCPlex, resetting", e);
for (Iterator iter = inUse.iterator(); iter.hasNext();) {
IloCplex c = (IloCplex) iter.next();
try {
c.end();
} catch (RuntimeException ex) {
logger.error("Exception trying to close CPLEX", ex);
}
}
inUse.clear();
}
}
IloCplex cplex = getCplex();
inUse.add(cplex);
return cplex;
}
示例2: checkInCplex
import ilog.cplex.IloCplex; //导入依赖的package包/类
public synchronized void checkInCplex(IloCplex cplex) {
if (cplex == null) {
return;
}
try {
cplex.getParameterSet().clear();
cplex.clearCallbacks();
cplex.clearModel();
} catch (IloException e) {
logger.error("Exception clearing model: " + e.getMessage(), e);
cplex.end();
inUse.remove(cplex);
this.notify();
return;
}
inUse.remove(cplex);
available.add(cplex);
this.notify();
}
示例3: translate
import ilog.cplex.IloCplex; //导入依赖的package包/类
Optimisation.State translate(final IloCplex.Status status) {
if (status.equals(Status.Bounded)) {
return State.VALID;
} else if (status.equals(Status.Error)) {
return State.FAILED;
} else if (status.equals(Status.Feasible)) {
return State.FEASIBLE;
} else if (status.equals(Status.Infeasible)) {
return State.INFEASIBLE;
} else if (status.equals(Status.InfeasibleOrUnbounded)) {
return State.INVALID;
} else if (status.equals(Status.Optimal)) {
return State.OPTIMAL;
} else if (status.equals(Status.Unbounded)) {
return State.UNBOUNDED;
} else if (status.equals(Status.Unknown)) {
return State.UNEXPLORED;
} else {
return State.FAILED;
}
}
示例4: results
import ilog.cplex.IloCplex; //导入依赖的package包/类
@Override
public void results(LinkerResults link) throws Exception {
link.writeInt("solver-iteration", iteration);
link.writeInt("var-fixed", fixed());
link.writeInt("var-free", converted()-fixed());
link.writeInt("var-relax", relax_variables.size()-converted());
link.writeString("RFFO-Status", cpx.getStatus().toString());
if(HistoryTime>0){
link.writeArray("HistoryRFFO", "UB", listUB.toArray(new Double[listUB.size()]));
}
if(cpx.getStatus() == IloCplex.Status.Optimal || cpx.getStatus() == IloCplex.Status.Feasible){
link.writeDbl("RFFO-Obj Value", cpx.getObjValue());
link.writeDbl("RFFO-Obj Lower", cpx.getBestObjValue());
print();
}
}
示例5: tuning
import ilog.cplex.IloCplex; //导入依赖的package包/类
private void tuning(IloCplex cplex) throws IloException {
if (logLevel < 2) {
cplex.setOut(null);
cplex.setWarning(null);
}
if (isLBShared) {
cplex.use(new MIPCallback(logLevel == 0));
}
cplex.setParam(IloCplex.IntParam.Threads, threads);
cplex.setParam(IloCplex.IntParam.ParallelMode, -1);
cplex.setParam(IloCplex.IntParam.MIPOrdType, 3);
if (tl.getRemainingTime() <= 0) {
cplex.setParam(IloCplex.DoubleParam.TiLim, EPS);
} else if (tl.getRemainingTime() != Double.POSITIVE_INFINITY) {
cplex.setParam(IloCplex.DoubleParam.TiLim, tl.getRemainingTime());
}
}
示例6: solveMasterProblem
import ilog.cplex.IloCplex; //导入依赖的package包/类
/**
* Solve the master problem
* @param timeLimit Future point in time by which the solve procedure must be completed
* @return true if the master problem has been solved
* @throws TimeLimitExceededException TimeLimitExceededException
*/
@Override
protected boolean solveMasterProblem(long timeLimit) throws TimeLimitExceededException {
try {
//Set time limit
double timeRemaining=Math.max(1,(timeLimit-System.currentTimeMillis())/1000.0);
masterData.cplex.setParam(IloCplex.DoubleParam.TiLim, timeRemaining); //set time limit in seconds
//Potentially export the model
if(config.EXPORT_MODEL) masterData.cplex.exportModel(config.EXPORT_MASTER_DIR+"master_"+this.getIterationCount()+".lp");
//Solve the model
if(!masterData.cplex.solve() || masterData.cplex.getStatus()!=IloCplex.Status.Optimal){
if(masterData.cplex.getCplexStatus()==IloCplex.CplexStatus.AbortTimeLim) //Aborted due to time limit
throw new TimeLimitExceededException();
else
throw new RuntimeException("Master problem solve failed! Status: "+masterData.cplex.getStatus());
}else{
masterData.objectiveValue=masterData.cplex.getObjValue();
}
} catch (IloException e) {
e.printStackTrace();
}
return true;
}
示例7: 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();
}
}
示例8: solveMasterProblem
import ilog.cplex.IloCplex; //导入依赖的package包/类
/**
* Solve the master problem
* @param timeLimit Future point in time by which the solve procedure must be completed
* @return true if the master problem has been solved
* @throws TimeLimitExceededException TimeLimitExceededException
*/
@Override
protected boolean solveMasterProblem(long timeLimit) throws TimeLimitExceededException {
try {
//Set time limit
double timeRemaining=Math.max(1,(timeLimit-System.currentTimeMillis())/1000.0);
masterData.cplex.setParam(IloCplex.DoubleParam.TiLim, timeRemaining); //set time limit in seconds
//Potentially export the model
if(config.EXPORT_MODEL) masterData.cplex.exportModel(config.EXPORT_MASTER_DIR+"master_"+this.getIterationCount()+".lp");
//Solve the model
if(!masterData.cplex.solve() || masterData.cplex.getStatus()!=IloCplex.Status.Optimal){
if(masterData.cplex.getCplexStatus()==IloCplex.CplexStatus.AbortTimeLim) //Aborted due to time limit
throw new TimeLimitExceededException();
else
throw new RuntimeException("Master problem solve failed! Status: "+masterData.cplex.getStatus());
}else{
masterData.objectiveValue=masterData.cplex.getObjValue();
}
} catch (IloException e) {
e.printStackTrace();
}
return true;
}
示例9: solveMasterProblem
import ilog.cplex.IloCplex; //导入依赖的package包/类
/**
* Solve the cplex problem and return whether it was solved to optimality
*/
@Override
protected boolean solveMasterProblem(long timeLimit) throws TimeLimitExceededException {
try {
//Set time limit
double timeRemaining=Math.max(1,(timeLimit-System.currentTimeMillis())/1000.0);
cplex.setParam(IloCplex.DoubleParam.TiLim, timeRemaining); //set time limit in seconds
//Potentially export the model
if(config.EXPORT_MODEL) cplex.exportModel(config.EXPORT_MASTER_DIR+"master_"+this.getIterationCount()+".lp");
//Solve the model
if(!cplex.solve() || cplex.getStatus()!=IloCplex.Status.Optimal){
if(cplex.getCplexStatus()==IloCplex.CplexStatus.AbortTimeLim) //Aborted due to time limit
throw new TimeLimitExceededException();
else
throw new RuntimeException("Master problem solve failed! Status: "+ cplex.getStatus());
}else{
masterData.objectiveValue= cplex.getObjValue();
}
} catch (IloException e) {
e.printStackTrace();
}
return true;
}
示例10: 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();
}
}
示例11: setCplexParameters
import ilog.cplex.IloCplex; //导入依赖的package包/类
/**
* Sets the parameters of CPLEX such that minimal output is produced.
*/
private void setCplexParameters(double tol) {
try {
cplex.setParam(IloCplex.IntParam.RootAlg, IloCplex.Algorithm.Barrier);
cplex.setParam(IloCplex.DoubleParam.EpOpt, tol);
cplex.setParam(IloCplex.DoubleParam.BarEpComp, tol);
cplex.setParam(IloCplex.IntParam.BarCrossAlg, -1);
// cplex.setParam(IloCplex.IntParam.SimDisplay, 0);
// cplex.setParam(IloCplex.IntParam.MIPDisplay, 0);
// cplex.setParam(IloCplex.IntParam.MIPInterval, -1);
// cplex.setParam(IloCplex.IntParam.TuningDisplay, 0);
// cplex.setParam(IloCplex.IntParam.BarDisplay, 0);
// cplex.setParam(IloCplex.IntParam.SiftDisplay, 0);
// cplex.setParam(IloCplex.IntParam.ConflictDisplay, 0);
// cplex.setParam(IloCplex.IntParam.NetDisplay, 0);
cplex.setParam(IloCplex.DoubleParam.TiLim, 1e+75);
} catch (IloException e) {
e.printStackTrace();
}
}
示例12: setCplexParameters
import ilog.cplex.IloCplex; //导入依赖的package包/类
/**
* Sets the parameters of CPLEX such that minimal output is produced.
*/
private void setCplexParameters() {
try {
cplex.setParam(IloCplex.IntParam.SimDisplay, 0);
cplex.setParam(IloCplex.IntParam.MIPDisplay, 0);
cplex.setParam(IloCplex.IntParam.MIPInterval, -1);
cplex.setParam(IloCplex.IntParam.TuningDisplay, 0);
cplex.setParam(IloCplex.IntParam.BarDisplay, 0);
cplex.setParam(IloCplex.IntParam.SiftDisplay, 0);
cplex.setParam(IloCplex.IntParam.ConflictDisplay, 0);
cplex.setParam(IloCplex.IntParam.NetDisplay, 0);
cplex.setParam(IloCplex.DoubleParam.TiLim, 1e+75);
} catch (IloException e) {
e.printStackTrace();
}
}
示例13: EdgePolytope
import ilog.cplex.IloCplex; //导入依赖的package包/类
public EdgePolytope(KepInstance<V, E> kepInstance, 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.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();
if (enforceMaximumChainLength) {
MaxChainLength.constrainMaxLength(kepInstance, cplex, solverOptions,
edgeVariables, false);
}
addAuxiliaryConstraints();
}
示例14: CycleVariables
import ilog.cplex.IloCplex; //导入依赖的package包/类
public CycleVariables(DirectedSparseMultigraph<V,E> graph,
List<EdgeCycle<E>> cycles, IloCplex cplex) throws IloException{
super(new HashSet<EdgeCycle<E>>(cycles),cplex);
if(super.size() != cycles.size()){
throw new RuntimeException("cycles contained a duplicate");
}
this.graph = graph;
ImmutableListMultimap.Builder<E,EdgeCycle<E>> edgeBuilder = ImmutableListMultimap.builder();
ImmutableListMultimap.Builder<V,EdgeCycle<E>> nodeBuilder = ImmutableListMultimap.builder();
for(EdgeCycle<E> cycle: cycles){
for(E edge: cycle.getEdgesInOrder()){
edgeBuilder.put(edge, cycle);
nodeBuilder.put(graph.getSource(edge),cycle);
}
}
nodeToCycles =nodeBuilder.build();
edgeToCycles = edgeBuilder.build();
}
示例15: truncationSolver
import ilog.cplex.IloCplex; //导入依赖的package包/类
public static <V,E> TwoStageEdgeFailureSolver<V,E> truncationSolver(KepInstance<V,E> kepInstance,
List<EdgeFailureScenario<V,E>> edgeFailureScenarios, Optional<FixedThreadPool> threadPool,
boolean displayOutput, Optional<Double> maxTimeSeconds, ImmutableSet<SolverOption> solverOptions) throws IloException{
int maxCycleLengthToCreateVariables = kepInstance.getMaxCycleLength();
IloCplex cplex = new IloCplex();
if(maxTimeSeconds.isPresent()){
cplex.setParam(DoubleParam.TiLim, maxTimeSeconds.get().doubleValue());
}
if(threadPool.isPresent()){
cplex.setParam(IntParam.Threads, threadPool.get().getNumThreads());
}
List<EdgeCycle<E>> cycles = CycleGenerator.generateAllCycles(threadPool,
kepInstance.getGraph(), maxCycleLengthToCreateVariables,new ArrayList<V>(kepInstance.getPairedNodes()));
CycleChainPackingPolytope<V,E> phaseOneProblem = new CycleChainPackingPolytope<V,E>(kepInstance, cycles, cplex, threadPool,solverOptions);
return new TwoStageEdgeFailureSolver<V,E>(kepInstance,edgeFailureScenarios,cplex,
phaseOneProblem,cycles,threadPool,displayOutput,
SolverOption.phaseTwoTrunctationOptions(solverOptions));
}