本文整理汇总了Java中ilog.concert.IloNumExpr类的典型用法代码示例。如果您正苦于以下问题:Java IloNumExpr类的具体用法?Java IloNumExpr怎么用?Java IloNumExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IloNumExpr类属于ilog.concert包,在下文中一共展示了IloNumExpr类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: breakRootSymmetry
import ilog.concert.IloNumExpr; //导入依赖的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]);
}
}
开发者ID:ctlab,项目名称:sgmwcs-solver,代码行数:20,代码来源:RLTSolver.java
示例2: setBounds
import ilog.concert.IloNumExpr; //导入依赖的package包/类
static void setBounds(final IloNumExpr expression, final Expression model, final IloCplex solver) throws IloException {
if (model.isEqualityConstraint()) {
solver.addEq(model.getAdjustedLowerLimit(), expression);
} else {
if (model.isLowerConstraint()) {
solver.addLe(model.getAdjustedLowerLimit(), expression);
}
if (model.isUpperConstraint()) {
solver.addGe(model.getAdjustedUpperLimit(), expression);
}
}
}
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:14,代码来源:SolverCPLEX.java
示例3: addRange
import ilog.concert.IloNumExpr; //导入依赖的package包/类
protected void addRange(IloNumVar[] vars, double[] coeffs, double lb, double ub, String name) throws IloException {
IloNumExpr expr = m_model.scalProd( coeffs, vars );
IloRange range = NumberUtils.equal( lb, ub, PRECISION_THRESHOLD )
? m_model.addEq( expr, lb, name )
: m_model.addRange( lb, expr, ub, name );
addRange( range );
}
开发者ID:klinovp,项目名称:pronto,代码行数:10,代码来源:CPLEXLPSolverImpl.java
示例4: addObjective
import ilog.concert.IloNumExpr; //导入依赖的package包/类
/**
* add objective to the lp problem
*
* @param obj
* objective variable
* @param maximize
* true if maximize
* @throws IloException
*/
protected void addObjective(IloNumExpr obj, boolean maximize) throws IloException {
m_cplex.remove(m_obj);
if (maximize) {
m_obj = m_cplex.addMaximize(obj);
} else {
m_obj = m_cplex.addMinimize(obj);
}
m_solved = false;
}
开发者ID:mpgerstl,项目名称:tEFMA,代码行数:19,代码来源:CplexHandler.java
示例5: addConstraint
import ilog.concert.IloNumExpr; //导入依赖的package包/类
public static IloRange addConstraint(IloNumExpr expr,
RelationType relationType, double rhs, IloCplex cplex)
throws IloException {
if (relationType.equals(RelationType.eq)) {
return cplex.addEq(expr, rhs);
} else if (relationType.equals(RelationType.geq)) {
return cplex.addGe(expr, rhs);
} else if (relationType.equals(RelationType.leq)) {
return cplex.addLe(expr, rhs);
} else {
throw new RuntimeException(
"Unidentified relation type defining equation " + relationType);
}
}
开发者ID:rma350,项目名称:kidneyExchange,代码行数:15,代码来源:CplexUtil.java
示例6: getTotalProduction
import ilog.concert.IloNumExpr; //导入依赖的package包/类
@Override
public double getTotalProduction(int t) {
try {
IloNumExpr expr = this.totalProductionMap.get(t);
return this.model.getCplex().getValue(expr);
} catch (IloException e) {
e.printStackTrace();
}
return 0;
}
开发者ID:Alexander-Schiendorfer,项目名称:SynthesisAbstractionICAART,代码行数:11,代码来源:CPLEXSolverFacade.java
示例7: build
import ilog.concert.IloNumExpr; //导入依赖的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;
}
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:48,代码来源:SolverCPLEX.java
示例8: main
import ilog.concert.IloNumExpr; //导入依赖的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());
}
}
开发者ID:marcio-da-silva-arantes,项目名称:ProOF,代码行数:50,代码来源:TesteCplex.java
示例9: model
import ilog.concert.IloNumExpr; //导入依赖的package包/类
public void model(boolean relaxed) throws Exception {
if(relaxed){
Xij = cpx.numVarArray(inst.N, inst.N, 0.0, 1.0, "Xij"); //binary relaxed
}else{
Xij = cpx.boolVarArray(inst.N, inst.N, "Xij");
}
Ui = cpx.numVarArray(inst.N-1, 0, inst.N*2, "Ui");
IloNumExpr sum = null;
for(int i=0; i<inst.N; i++){
for(int j=0; j<inst.N; j++){
sum = cpx.SumProd(sum, inst.Cij[i][j], Xij[i][j]);
}
}
cpx.addMinimize(sum);
for(int j=0; j<inst.N; j++){
sum = null;
for(int i=0; i<inst.N; i++){
sum = cpx.SumProd(sum, 1, Xij[i][j]);
}
cpx.addEq(sum, 1, "Col["+(j+1)+"]");
}
for(int i=0; i<inst.N; i++){
sum = null;
for(int j=0; j<inst.N; j++){
sum = cpx.SumProd(sum, 1, Xij[i][j]);
}
cpx.addEq(sum, 1, "Row["+(i+1)+"]");
}
for(int i=0; i<inst.N-1; i++){
for(int j=0; j<inst.N-1; j++){
if(i!=j){
IloNumExpr aux[] = new IloNumExpr[3];
aux[0] = cpx.prod(+1, Ui[i]);
aux[1] = cpx.prod(-1, Ui[j]);
aux[2] = cpx.prod(inst.N, Xij[i][j]);
cpx.addLe(cpx.sum(aux), inst.N-1);
}
}
}
for(int i=0; i<inst.N; i++){
Xij[i][i].setLB(0);
Xij[i][i].setUB(0);
}
}
开发者ID:marcio-da-silva-arantes,项目名称:ProOF,代码行数:47,代码来源:TSPmodel.java
示例10: setObjective
import ilog.concert.IloNumExpr; //导入依赖的package包/类
private void setObjective(double[] coeffs, boolean max) throws IloException{
if (coeffs.length == getColumnNumber()) {
IloNumExpr objExpr = m_model.scalProd( coeffs, getVarArray() );
if (coeffs != m_objCoeffs) m_objCoeffs = ArrayUtils.clone( coeffs );
if (max) {
m_model.addMaximize( objExpr );
} else m_model.addMinimize( objExpr );
} else {
throw new IllegalArgumentException("Wrong number of objective coefficients");
}
}
开发者ID:klinovp,项目名称:pronto,代码行数:20,代码来源:CPLEXLPSolverImpl.java
示例11: buildExpression
import ilog.concert.IloNumExpr; //导入依赖的package包/类
static IloNumExpr buildExpression(final ExpressionsBasedModel model, final Expression expression, final IloCplex solver, final List<IloNumVar> variables)
throws IloException {
if (expression.isFunctionCompound()) {
final IloLQNumExpr tmpIloLQNumExpr = solver.lqNumExpr();
SolverCPLEX.addQuadratic(expression, tmpIloLQNumExpr, model, variables);
SolverCPLEX.addLinear(expression, tmpIloLQNumExpr, model, variables);
return tmpIloLQNumExpr;
} else if (expression.isFunctionQuadratic()) {
final IloQuadNumExpr tmpIloQuadNumExpr = solver.quadNumExpr();
SolverCPLEX.addQuadratic(expression, tmpIloQuadNumExpr, model, variables);
return tmpIloQuadNumExpr;
} else if (expression.isFunctionLinear()) {
final IloLinearNumExpr tmpIloLinearNumExpr = solver.linearNumExpr();
SolverCPLEX.addLinear(expression, tmpIloLinearNumExpr, model, variables);
return tmpIloLinearNumExpr;
}
return null;
}
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:32,代码来源:SolverCPLEX.java
注:本文中的ilog.concert.IloNumExpr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论