当前位置: 首页>>代码示例>>Java>>正文


Java IloCplex.setParam方法代码示例

本文整理汇总了Java中ilog.cplex.IloCplex.setParam方法的典型用法代码示例。如果您正苦于以下问题:Java IloCplex.setParam方法的具体用法?Java IloCplex.setParam怎么用?Java IloCplex.setParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ilog.cplex.IloCplex的用法示例。


在下文中一共展示了IloCplex.setParam方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());
    }
}
 
开发者ID:ctlab,项目名称:sgmwcs-solver,代码行数:18,代码来源:RLTSolver.java

示例2: 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();
    }
}
 
开发者ID:coin-or,项目名称:jorlib,代码行数:26,代码来源:ExactPricingProblemSolver.java

示例3: 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();
	}
}
 
开发者ID:coin-or,项目名称:jorlib,代码行数:22,代码来源:ExactPricingProblemSolver.java

示例4: 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));
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:19,代码来源:TwoStageEdgeFailureSolver.java

示例5: CycleChainPackingCplexSolver

import ilog.cplex.IloCplex; //导入方法依赖的package包/类
protected CycleChainPackingCplexSolver(KepInstance<V, E> kepInstance,
    boolean displayOutput, Optional<Double> maxTimeSeconds,
    boolean throwExceptionNoSolution) {
  super(kepInstance, displayOutput, maxTimeSeconds);
  try {
    cplex = new IloCplex();
    this.displayOutput = displayOutput;
    if (maxTimeSeconds.isPresent()) {
      cplex.setParam(DoubleParam.TiLim, maxTimeSeconds.get().doubleValue());
    }
    if (!displayOutput) {
      cplex.setOut(null);
      cplex.setWarning(null);
    }
  } catch (IloException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:19,代码来源:CycleChainPackingCplexSolver.java

示例6: setControlParams

import ilog.cplex.IloCplex; //导入方法依赖的package包/类
public void setControlParams(IloCplex cplex, Iterable<SolveParam> params, Function<SolveParam, Object> getValue) {
    for (SolveParam solveParam : params) {
        Object value = getValue.apply(solveParam);
        if (!solveParam.isInternal()) {
            Object cplexParam = getCplexParam(solveParam);
            logger.debug("Setting " + solveParam.toString() + " to: " + value.toString());
            try {
                if (solveParam.isBoolean()) {
                    cplex.setParam((BooleanParam) cplexParam, ((Boolean) value).booleanValue());
                } else if (solveParam.isInteger()) {
                    cplex.setParam((IloCplex.IntParam) cplexParam, ((Integer) value).intValue());
                } else if (solveParam.isDouble()) {
                    cplex.setParam((DoubleParam) cplexParam, ((Double) value).doubleValue());
                } else if (solveParam.isString()) {
                    cplex.setParam((StringParam) cplexParam, (String) value);
                } else {
                    throw new MIPException("Invalid solver param time: " + value);
                }
            } catch (IloException e) {
                throw new MIPException(solveParam + ": " + value + ": " + e.toString());
            }

        } else if (solveParam == SolveParam.DISPLAY_OUTPUT && !(Boolean)getValue.apply(SolveParam.DISPLAY_OUTPUT)) {
            cplex.setOut(null);
        }
    }
}
 
开发者ID:blubin,项目名称:JOpt,代码行数:28,代码来源:CPlexMIPSolver.java

示例7: buildModel

import ilog.cplex.IloCplex; //导入方法依赖的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);
}
 
开发者ID:coin-or,项目名称:jorlib,代码行数:32,代码来源:Master.java

示例8: 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);
    }
}
 
开发者ID:blubin,项目名称:JOpt,代码行数:58,代码来源:CPlexMIPSolver.java

示例9: proposeValues

import ilog.cplex.IloCplex; //导入方法依赖的package包/类
private void proposeValues(IMIP mip, IloCplex cplex, Map<String, IloNumVar> vars, int numberOfBooleanAndIntVariables) throws IloException {
    if (!mip.getVarsWithProposedValues().isEmpty()) {
        IloNumVar varArray[];
        double valArray[];
        boolean bZeroMissingVariables = mip.getBooleanSolveParam(SolveParam.ZERO_MISSING_PROPOSED, new Boolean(false));
        Iterator iter;

        if (bZeroMissingVariables == true) {
            // In this case, prepare to zero out all missing Int/Bools
            varArray = new IloNumVar[mip.getVars().size()];
            valArray = new double[mip.getVars().size()];
            iter = mip.getVars().values().iterator();
        } else {
            // In this case, at most mip.getVarsWithProposedValues()
            // will be set.
            varArray = new IloNumVar[mip.getVarsWithProposedValues().size()];
            valArray = new double[mip.getVarsWithProposedValues().size()];
            iter = mip.getVarsWithProposedValues().iterator();
        }

        int i = 0;
        int numberOfProposedBooleanAndIntVariables = 0;
        Variable v;
        VarType type;

        for (; iter.hasNext();) {
            v = (Variable) iter.next();
            type = v.getType();
            varArray[i] = vars.get(v.getName());
            if ((!bZeroMissingVariables) || (mip.getVarsWithProposedValues().contains(v))) {
                if (type == VarType.BOOLEAN) {
                    valArray[i] = mip.getProposedBooleanValue(v) ? 1 : 0;
                    numberOfProposedBooleanAndIntVariables++;
                } else if (type == VarType.INT) {
                    valArray[i] = mip.getProposedIntValue(v);
                    numberOfProposedBooleanAndIntVariables++;
                } else if (type == VarType.DOUBLE) {
                    valArray[i] = mip.getProposedDoubleValue(v);
                }

                logger.debug("proposing value: " + v.getName() + "\t" + valArray[i]);
            } else {
                if (bZeroMissingVariables == true) {
                    valArray[i] = 0;
                    if ((type == VarType.BOOLEAN) || (type == VarType.INT)) {
                        numberOfProposedBooleanAndIntVariables++;
                    }
                }
            }
            i++;
        }

        if (numberOfProposedBooleanAndIntVariables != numberOfBooleanAndIntVariables) {
            throw new MIPException("Proposing Values: Total and Proposed Boolean and Int Variables not equal: proposition won't be feasible.\n"
                    + "numberOfBooleanAndIntVariables, numberOfProposedBooleanAndIntVariables: " + numberOfBooleanAndIntVariables + ", "
                    + numberOfProposedBooleanAndIntVariables);
            /*
             * logger.warn(
             * "Proposing Values: Total and Proposed Boolean and Int Variables not equal: proposition won't be feasible."
             * ); logger.warn(
             * "Proposing Values: numberOfBooleanAndIntVariables, numberOfProposedBooleanAndIntVariables: "
             * + numberOfBooleanAndIntVariables + ", " +
             * numberOfProposedBooleanAndIntVariables);
             */
            // See "SetVectors" at
            // http://www.eecs.harvard.edu/~jeffsh/_cplexdoc/javadocman/html/
        }

        logger.debug("Using primed start values for solving.");
        if (cplex.isMIP()) {
            cplex.addMIPStart(varArray, valArray);
        } else {
            cplex.setStart(valArray, null, varArray, null, null, null);
        }
        // AdvInd was BooleanParam.MIPStart prior to CPLEX 10.
        // 0=no MIPStart, 1=MIPStart, including partial starts.
        cplex.setParam(IloCplex.IntParam.AdvInd, 1);
    }
}
 
开发者ID:blubin,项目名称:JOpt,代码行数:80,代码来源:CPlexMIPSolver.java

示例10: initModel

import ilog.cplex.IloCplex; //导入方法依赖的package包/类
protected void initModel() throws IloException {
	
	m_model = new IloCplex();
	
	m_model.setParam( IloCplex.DoubleParam.EpRHS, PRECISION_THRESHOLD );
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:7,代码来源:CPLEXLPSolverImpl.java


注:本文中的ilog.cplex.IloCplex.setParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。