本文整理汇总了Java中ilog.concert.IloException类的典型用法代码示例。如果您正苦于以下问题:Java IloException类的具体用法?Java IloException怎么用?Java IloException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IloException类属于ilog.concert包,在下文中一共展示了IloException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkInCplex
import ilog.concert.IloException; //导入依赖的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();
}
示例2: addObjective
import ilog.concert.IloException; //导入依赖的package包/类
private void addObjective() throws IloException {
// one binary variable per concept
if (DEBUG) {
String[] names = new String[this.concepts.size()];
for (int i = 0; i < names.length; i++)
names[i] = "c" + i;
this.conceptVars = this.problem.boolVarArray(this.concepts.size(), names);
} else {
this.conceptVars = this.problem.boolVarArray(this.concepts.size());
}
// sum of weights of selected concepts
IloLinearNumExpr obj = this.problem.linearNumExpr();
for (int i = 0; i < this.conceptVars.length; i++)
obj.addTerm(this.conceptVars[i], this.concepts.get(i).weight);
this.problem.addMaximize(obj);
}
示例3: addVariable
import ilog.concert.IloException; //导入依赖的package包/类
@Override
public void addVariable(String varName, double objWeight, double lowerBound, double upperBound, boolean override, boolean isZVar) throws ILPException
{
try {
IloNumVarType type = null;
if(upperBound > 1) {
type = IloNumVarType.Int;
} else {
type = IloNumVarType.Bool;
}
IloNumVar var = cplex.numVar(lowerBound, upperBound, type, varName);
if(override || !variables.containsKey(varName)) {
variables.put(varName, var);
cplex.add(var);
objective.put(varName, objWeight);
}
} catch(IloException e) {
throw new ILPException(e.getMessage());
}
}
示例4: addConstraint
import ilog.concert.IloException; //导入依赖的package包/类
@Override
public void addConstraint(ArrayList<ILPVariable> lhs, ILPOperator operator, double rhs) throws ILPException
{
try {
IloLinearNumExpr constraint = cplex.linearNumExpr();
for(ILPVariable var : lhs) {
if(!variables.containsKey(var.getName())) {
this.addVariable(var.getName(), 0d, 0d, 1d, false, var.isZVar());
}
constraint.addTerm(var.getValue(), variables.get(var.getName()));
}
switch(operator) {
case LEQ:
cplex.addLe(constraint, rhs);
break;
case GEQ:
cplex.addGe(constraint, rhs);
break;
default:
break;
}
} catch(IloException e) {
throw new ILPException(e.getMessage());
}
}
示例5: dfs
import ilog.concert.IloException; //导入依赖的package包/类
private void dfs(Node root, Set<Node> component, boolean fake, Blocks bs, Separator separator) throws IloException {
separator.addComponent(graph.subgraph(component), root);
if (!fake) {
for (Node node : component) {
cplex.addLe(cplex.diff(y.get(node), y.get(root)), 0);
}
}
for (Edge e : graph.edgesOf(root)) {
if (!component.contains(graph.getOppositeVertex(root, e))) {
continue;
}
cplex.addEq(getX(e, root), 0);
}
for (Node cp : bs.cutpointsOf(component)) {
if (root != cp) {
for (Set<Node> comp : bs.incidentBlocks(cp)) {
if (comp != component) {
dfs(cp, comp, false, bs, separator);
}
}
}
}
}
示例6: initVariables
import ilog.concert.IloException; //导入依赖的package包/类
private void initVariables() throws IloException {
y = new LinkedHashMap<>();
w = new LinkedHashMap<>();
d = new LinkedHashMap<>();
x = new LinkedHashMap<>();
x0 = new LinkedHashMap<>();
for (Node node : graph.vertexSet()) {
String nodeName = Integer.toString(node.getNum() + 1);
d.put(node, cplex.numVar(0, Double.MAX_VALUE, "d" + nodeName));
y.put(node, cplex.boolVar("y" + nodeName));
x0.put(node, cplex.boolVar("x_0_" + (node.getNum() + 1)));
}
for (Edge edge : graph.edgeSet()) {
Node from = graph.getEdgeSource(edge);
Node to = graph.getEdgeTarget(edge);
String edgeName = (from.getNum() + 1) + "_" + (to.getNum() + 1);
w.put(edge, cplex.boolVar("w_" + edgeName));
IloNumVar in = cplex.boolVar("x_" + edgeName + "_in");
IloNumVar out = cplex.boolVar("x_" + edgeName + "_out");
x.put(edge, new Pair<>(in, out));
}
}
示例7: tuning
import ilog.concert.IloException; //导入依赖的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());
}
}
示例8: breakRootSymmetry
import ilog.concert.IloException; //导入依赖的package包/类
private void breakRootSymmetry() throws IloException {
int n = graph.vertexSet().size();
PriorityQueue<Node> nodes = new PriorityQueue<>();
nodes.addAll(graph.vertexSet());
int k = n;
IloNumExpr[] terms = new IloNumExpr[n];
IloNumExpr[] rs = new IloNumExpr[n];
while (!nodes.isEmpty()) {
Node node = nodes.poll();
terms[k - 1] = cplex.prod(k, x0.get(node));
rs[k - 1] = cplex.prod(k, y.get(node));
k--;
}
IloNumVar sum = cplex.numVar(0, n, "prSum");
cplex.addEq(sum, cplex.sum(terms));
for (int i = 0; i < n; i++) {
cplex.addGe(sum, rs[i]);
}
}
示例9: sumConstraints
import ilog.concert.IloException; //导入依赖的package包/类
private void sumConstraints() throws IloException {
// (31)
cplex.addLe(cplex.sum(graph.vertexSet().stream().map(x -> x0.get(x)).toArray(IloNumVar[]::new)), 1);
if (root != null) {
cplex.addEq(x0.get(root), 1);
}
// (32)
for (Node node : graph.vertexSet()) {
Set<Edge> edges = graph.edgesOf(node);
IloNumVar xSum[] = new IloNumVar[edges.size() + 1];
int i = 0;
for (Edge edge : edges) {
xSum[i++] = getX(edge, node);
}
xSum[xSum.length - 1] = x0.get(node);
cplex.addEq(cplex.sum(xSum), y.get(node));
}
}
示例10: initWeights
import ilog.concert.IloException; //导入依赖的package包/类
private void initWeights() throws IloException {
if (!inited) {
init();
}
double[] values = getValues(vars);
for (CutGenerator generator : generatorList) {
Set<Edge> visited = new HashSet<>();
for (Edge edge : generator.getEdges()) {
if (visited.contains(edge)) {
continue;
}
double weight = 0;
for (Edge e : graph.getAllEdges(graph.getEdgeSource(edge), graph.getEdgeTarget(edge))) {
weight += values[indices.get(e)];
visited.add(e);
}
generator.setCapacity(edge, weight + ADDITION_CAPACITY);
}
for (Node node : generator.getNodes()) {
generator.setVertexCapacity(node, values[indices.get(node)] - EPS);
}
}
}
示例11: dispose
import ilog.concert.IloException; //导入依赖的package包/类
/**
*
*/
@Override
public void dispose() {
try {
if( m_model != null ) {
removeAllRanges();
removeAllVars();
m_model.clearModel();
}
} catch( IloException e ) {
m_logger.fatal( e );
throw new RuntimeException(e);
}
}
示例12: removeColumn
import ilog.concert.IloException; //导入依赖的package包/类
/**
* @param index
* @throws CPException
*/
@Override
public void removeColumn(int index) throws CPException {
IloNumVar var = getVar( index );
try {
m_model.delete( var );
removeVar( index );
ArrayUtils.remove( m_objCoeffs, index );
} catch( IloException e ) {
m_logger.fatal( e );
throw new CPException( e );
}
}
示例13: removeColumns
import ilog.concert.IloException; //导入依赖的package包/类
public void removeColumns(String namePrefix) {
try {
for (Iterator<IloNumVar> varIter = m_vars.iterator(); varIter.hasNext();) {
IloNumVar var = varIter.next();
String name = var.getName();
if (name != null && name.startsWith( namePrefix )) {
m_model.delete( var );
m_nameVarMap.remove( var.getName() );
varIter.remove();
}
}
} catch( IloException e ) {
m_logger.fatal( e );
throw new RuntimeException( e );
}
}
示例14: addColumn
import ilog.concert.IloException; //导入依赖的package包/类
/**
* Function which adds a new column to the cplex problem
*/
@Override
public void addColumn(CuttingPattern column) {
try {
//Register column with objective
IloColumn iloColumn= cplex.column(obj,1);
//Register column with demand constraint
for(int i=0; i< dataModel.nrFinals; i++)
iloColumn=iloColumn.and(cplex.column(satisfyDemandConstr[i], column.yieldVector[i]));
//Create the variable and store it
IloNumVar var= cplex.numVar(iloColumn, 0, Double.MAX_VALUE, "z_"+","+masterData.getNrColumns());
cplex.add(var);
masterData.addColumn(column, var);
} catch (IloException e) {
e.printStackTrace();
}
}
示例15: defineMode
import ilog.concert.IloException; //导入依赖的package包/类
/**
* creates constraints for linear problem
*
* @param mode
* BitSet, active reaction = 0
* @param booleanSize
* number of converted reactions
*/
protected void defineMode(final BitSet mode, int booleanSize) {
BitSet t_mode = (BitSet) mode.clone();
t_mode.flip(0, booleanSize);
try {
m_solver.removeRows(m_drgConstrStartIndex);
int i = -1;
while ((i = t_mode.nextSetBit(i + 1)) > -1) {
if (m_predefinedReactions.containsKey(i)) {
PredefinedReaction pr = m_predefinedReactions.get(i);
ArrayList<LpReaction> rx = pr.getReactions();
ArrayList<Integer> dir = pr.getDirections();
for (int j = 0; j < rx.size(); j++) {
m_solver.addReaction(rx.get(j), dir.get(j));
}
}
}
} catch (IloException e) {
System.out.println(e);
}
}