コード例 #1
0
void runConflictRefinerAllConflicts(IloCP cp, IloConstraintArray cts) {     
  IloEnv env = cp.getEnv();
  IloInt n = cts.getSize();
  IloNumArray prefs(env, n);   
  IloInt i;  
  IloIntArray2 forbiddenCts(env);
  // Initial iteration: no forbidden constraints
  forbiddenCts.add(IloIntArray(env));
  while (0<forbiddenCts.getSize()) {
    IloIntArray forbidden = forbiddenCts[0];
    forbiddenCts.remove(0);
    for (i=0; i<n; ++i) {
      prefs[i]=1.0; // Initialize to normal preference
    }
    for (i=0; i<forbidden.getSize(); ++i) {
      prefs[forbidden[i]]=-1.0; // Remove constraint
    }
    if (cp.refineConflict(cts, prefs)) {
      cp.writeConflict(cp.out());
      // Next iterations
      for (i=0; i<n; ++i) {
        if (cp.getConflict(cts[i])==IloCP::ConflictMember) {
            IloIntArray newforbidden(env, 1, i);
            newforbidden.add(forbidden);           
            forbiddenCts.add(newforbidden);
        }
      }
    }
    forbidden.end();
  }
}
コード例 #2
0
ファイル: ilosocpex1.cpp プロジェクト: renvieir/ioc
// This function creates the following model:
//   Minimize
//    obj: x1 + x2 + x3 + x4 + x5 + x6
//   Subject To
//    c1: x1 + x2      + x5      = 8
//    c2:           x3 + x5 + x6 = 10
//    q1: [ -x1^2 + x2^2 + x3^2 ] <= 0
//    q2: [ -x4^2 + x5^2 ] <= 0
//   Bounds
//    x2 Free
//    x3 Free
//    x5 Free
//   End
// which is a second order cone program in standard form.
// The function returns objective, variables and constraints in the
// values obj, vars and rngs.
// The function also sets up cone so that for a column j we have
// cone[j] >= 0               Column j is in a cone constraint and is the
//                            cone's head variable.
// cone[j] == NOT_CONE_HEAD   Column j is in a cone constraint but is
//                            not the cone's head variable..
// cone[j] == NOT_IN_CONE     Column j is not contained in any cone constraint.
static void
createmodel (IloModel& model, IloObjective &obj, IloNumVarArray &vars,
             IloRangeArray &rngs, IloIntArray& cone)
{
   // The indices we assign as user objects to the modeling objects.
   // We define them as static data so that we don't have to worry about
   // dynamic memory allocation/leakage.
   static int indices[] = { 0, 1, 2, 3, 4, 5, 6 };

   IloEnv env = model.getEnv();

   // Create variables.
   IloNumVar x1(env,            0, IloInfinity, "x1");
   IloNumVar x2(env, -IloInfinity, IloInfinity, "x2");
   IloNumVar x3(env, -IloInfinity, IloInfinity, "x3");
   IloNumVar x4(env,            0, IloInfinity, "x4");
   IloNumVar x5(env, -IloInfinity, IloInfinity, "x5");
   IloNumVar x6(env,            0, IloInfinity, "x6");

   // Create objective function and immediately store it in return value.
   obj = IloMinimize(env, x1 + x2 + x3 + x4 + x5 + x6);

   // Create constraints.
   IloRange c1(env, 8,  x1 + x2      + x5,       8, "c1");
   IloRange c2(env, 10,           x3 + x5 + x6, 10, "c2");
   IloRange q1(env, -IloInfinity, -x1*x1 + x2*x2 + x3*x3, 0, "q1");
   cone.add(2);             // x1, cone head of constraint at index 2
   cone.add(NOT_CONE_HEAD); // x2
   cone.add(NOT_CONE_HEAD); // x3
   IloRange q2(env, -IloInfinity, -x4*x4 + x5*x5, 0, "q2");
   cone.add(3);             // x4, cone head of constraint at index 3
   cone.add(NOT_CONE_HEAD); // x5

   cone.add(NOT_IN_CONE);   // x6

   // Setup model.
   model.add(obj);
   model.add(obj);
   model.add(c1);
   model.add(c2);
   model.add(q1);
   model.add(q2);

   // Setup return values.
   vars.add(x1);
   vars.add(x2);
   vars.add(x3);
   vars.add(x4);
   vars.add(x5);
   vars.add(x6);

   rngs.add(c1);
   rngs.add(c2);
   rngs.add(q1);
   rngs.add(q2);

   // We set the user object for each modeling object to its index in the
   // respective array. This makes the code in checkkkt a little simpler.
   for (IloInt i = 0; i < vars.getSize(); ++i)
      vars[i].setObject(&indices[i]);
   for (IloInt i = 0; i < rngs.getSize(); ++i)
      rngs[i].setObject(&indices[i]);
}
コード例 #3
0
void MakeHouse(IloModel model,
               IloNumExpr cost,
               IloIntervalVarArray allTasks,
               IloIntervalVarArray joeTasks,
               IloIntervalVarArray jimTasks,
               IloIntArray joeLocations,
               IloIntArray jimLocations,
               IloInt loc,
               IloInt rd,
               IloInt dd,
               IloNum weight) {
    IloEnv env = model.getEnv();

    /* CREATE THE INTERVALS VARIABLES. */
    char name[128];

    IloIntervalVarArray tasks(env, NbTasks);
    for (IloInt i=0; i<NbTasks; ++i) {
        sprintf(name, "H%ld-%s", loc, TaskNames[i]);
        tasks[i] = IloIntervalVar(env, TaskDurations[i], name);
        allTasks.add(tasks[i]);
    }

    /* SPAN CONSTRAINT. */
    sprintf(name, "H%ld", loc);
    IloIntervalVar house(env, name);
    model.add(IloSpan(env, house, tasks));

    /* ADDING PRECEDENCE CONSTRAINTS. */
    house.setStartMin(rd);
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[carpentry]));
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[plumbing]));
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[ceiling]));
    model.add(IloEndBeforeStart(env, tasks[carpentry], tasks[roofing]));
    model.add(IloEndBeforeStart(env, tasks[ceiling],   tasks[painting]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[windows]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[facade]));
    model.add(IloEndBeforeStart(env, tasks[plumbing],  tasks[facade]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[garden]));
    model.add(IloEndBeforeStart(env, tasks[plumbing],  tasks[garden]));
    model.add(IloEndBeforeStart(env, tasks[windows],   tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[facade],    tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[garden],    tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[painting],  tasks[moving]));

    /* ALLOCATING TASKS TO WORKERS. */
    joeTasks.add(tasks[masonry]);
    joeLocations.add(loc);
    joeTasks.add(tasks[carpentry]);
    joeLocations.add(loc);
    jimTasks.add(tasks[plumbing]);
    jimLocations.add(loc);
    jimTasks.add(tasks[ceiling]);
    jimLocations.add(loc);
    joeTasks.add(tasks[roofing]);
    joeLocations.add(loc);
    jimTasks.add(tasks[painting]);
    jimLocations.add(loc);
    jimTasks.add(tasks[windows]);
    jimLocations.add(loc);
    joeTasks.add(tasks[facade]);
    joeLocations.add(loc);
    joeTasks.add(tasks[garden]);
    joeLocations.add(loc);
    jimTasks.add(tasks[moving]);
    jimLocations.add(loc);

    /* DEFINING MINIMIZATION OBJECTIVE. */
    cost += TardinessCost(house, dd, weight);
    cost += IloLengthOf(house);
}