Package ilog.concert

Examples of ilog.concert.IloLinearNumExpr


          expr = master.sum(expr, master.prod(coefficients[i], rhs.get(c)));
        }
        // generate a feasibility cut
        IloRange r = master.le(master.sum(temp, expr), 0);
        //test the cut against the current solution
        IloLinearNumExpr rexpr = (IloLinearNumExpr) r.getExpr();
        IloLinearNumExprIterator it = rexpr.linearIterator();
        double lhs = 0;
        double rhs = r.getUB();
        while (it.hasNext()) {
          IloNumVar v = it.nextNumVar();
          lhs += it.getValue()*msol.get(v);
        }
        // if a violation occurs, add a feasibility cut
        if (lhs > rhs + FUZZ) {
          System.out.println("!!! Adding user feasibility cut: " + r);
          add(r);         
        }
      } else if (status == IloCplex.Status.Optimal) {
        if (zMaster < sub.getObjValue() - FUZZ) {
          // the master problem surrogate variable underestimates the actual
          // flow cost -- add an optimality cut
          double[] lambda = sub.getDuals(cDemand);
          double[] mu = sub.getDuals(cSupply);
          // compute the scalar product of the RHS of the demand constraints
          // with the duals for those constraints
          for (int j = 0; j < nCustomers; j++) {
            expr = master.sum(expr, master.prod(lambda[j], rhs.get(cDemand[j])));
          }
          // repeat for the supply constraints
          for (int i = 0; i < nWarehouses; i++) {
            expr = master.sum(expr, master.prod(mu[i], rhs.get(cSupply[i])));
          }
          // generate an optimality cut
          IloRange r = (IloRange) master.le(master.diff(expr, flowCost), 0);
          //test the cut against the current solution
          IloLinearNumExpr rexpr = (IloLinearNumExpr) r.getExpr();
          IloLinearNumExprIterator it = rexpr.linearIterator();
          double lhs = 0;
          double rhs = r.getUB();
          while (it.hasNext()) {
            IloNumVar v = it.nextNumVar();
            lhs += it.getValue()*msol.get(v);
 
View Full Code Here


  public SingleModel(int nW, int nC, double[] capacity, double[] demand,
                     double[] fixed, double[][] flow) throws IloException {
    cplex = new IloCplex();
    use = new IloNumVar[nW];
    ship = new IloNumVar[nW][nC];
    IloLinearNumExpr expr = cplex.linearNumExpr();
    // declare the variables and simultaneously assemble the objective function
    for (int i = 0; i < nW; i++) {
      use[i] = cplex.boolVar("Use" + i);
      expr.addTerm(fixed[i], use[i]);
      for (int j = 0; j < nC; j++) {
        ship[i][j] = cplex.numVar(0.0, Math.min(capacity[i], demand[j]),
                                  "Ship_" + i + "_" + j);
        expr.addTerm(flow[i][j], ship[i][j]);
      }
    }
    cplex.addMinimize(expr, "TotalCost")// minimize total cost
    // add demand constraints
    for (int j = 0; j < nC; j++) {
      expr.clear();
      for (int i = 0; i < nW; i++) {
        expr.addTerm(1.0, ship[i][j]);
      }
      cplex.addGe(expr, demand[j], "Demand_" + j);
    }
    // add supply constraints
    for (int i = 0; i < nW; i++) {
View Full Code Here

                       "TotalCost");
    // attach a Benders callback to the master
    master.use(new BendersCallback());
    // set up the subproblem
    ship = new IloNumVar[nW][nC];
    IloLinearNumExpr expr = sub.linearNumExpr();
    for (int i = 0; i < nW; i++) {
      for (int j = 0; j < nC; j++) {
        ship[i][j] = sub.numVar(0.0, Double.MAX_VALUE, "Flow_" + i + "_" + j);
        expr.addTerm(unitCost[i][j], ship[i][j]);
      }
    }
    sub.addMinimize(expr, "FlowCost")// minimize total flow cost
    // constrain demand to be satisfied -- record the constraints for use later
    cDemand = new IloRange[nC];
    for (int j = 0; j < nC; j++) {
      expr.clear();
      for (int i = 0; i < nW; i++) {
        expr.addTerm(1.0, ship[i][j]);
      }
      cDemand[j] = sub.addGe(expr, demand[j], "Demand_" + j);
      rhs.put(cDemand[j], master.linearNumExpr(demand[j]));
    }
    // add supply limits (initially all zero, which makes the subproblem
View Full Code Here

TOP

Related Classes of ilog.concert.IloLinearNumExpr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.