Пример #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
void runConflictRefinerWithPreferences(IloCP cp, 
                                       IloConstraintArray preferredCts, 
                                       IloConstraintArray otherCts) {
  IloEnv env = cp.getEnv();
  IloConstraintArray cts(env);  
  IloNumArray prefs(env);
  IloInt i;
  for (i=0; i<otherCts.getSize(); ++i) {
    cts.add(otherCts[i]);
    prefs.add(1.0); // Normal preference
  }
  for (i=0; i<preferredCts.getSize(); ++i) {
    cts.add(preferredCts[i]);
    prefs.add(2.0); // Higher preference
  }
  if (cp.refineConflict(cts, prefs)) {
    cp.writeConflict(cp.out());
  } 
  cts.end();
  prefs.end();
}
Пример #3
0
py::list CplexTSPSolver::nextRelaxation()
{
    IloInt n   = N*N;
    py::list ret;
    IloNumArray sol(env, n);

    if(!first)
    {
        cplex.getValues(sol, x);

        IloConstraintArray constraints = subtourEliminationConstraint(env, N, sol, x, 10e-5, v);
        for(int i=0; i<constraints.getSize(); i++)
            model.add(constraints[i]);

        std::cout << constraints.getSize() << " Constraints\n";
        if(!constraints.getSize())
        {
            std::cout << "finished!\n";
            return ret; // return empty list
        }

        constraints.end();

        cplex.solve();
    }
    first = false;

    cplex.getValues(sol, x);

    //return adjacency matrix as pyList
    for(int i=0; i<n; ++i)
        ret.append(sol[i]);

    sol.end();
    return ret;
}
Пример #4
0
void runConflictRefinerPartition(IloCP cp, IloConstraintArray cts) {     
  IloEnv env = cp.getEnv();
  IloInt n = cts.getSize();
  IloNumArray prefs(env, n);   
  IloInt i;  
  for (i=0; i<n; ++i) {
    prefs[i]=1.0; // Normal preference
  }
  while (cp.refineConflict(cts, prefs)) {
    cp.writeConflict(cp.out());
    for (i=0; i<n; ++i) {
      if (cp.getConflict(cts[i])==IloCP::ConflictMember) {
        prefs[i]=-1.0; // Next run will ignore constraints of the current conflict
      }
    }
  }
  prefs.end();
}
Пример #5
0
IloModel ReadModel(IloEnv env, const char* filename,
                   IloConstraintArray& capacityCts,
                   IloConstraintArray& precedenceCts) {
  std::ifstream file(filename);
  if (!file){
    env.out() << "usage: sched_conflict <file> <failLimit>" << std::endl;
    throw FileError();
  }
  IloModel model(env);
  IloInt nbTasks, nbResources, i, j;
  file >> nbTasks;
  file >> nbResources;
  IloCumulFunctionExprArray resources(env, nbResources);
  IloIntArray capacities(env, nbResources);
  for (j=0; j<nbResources; j++) {
    IloInt c;
    file >> c;
    capacities[j] = c;
    resources[j] = IloCumulFunctionExpr(env);
  }
  IloIntervalVarArray tasks(env, nbTasks);
  char name[32];
  for (i=0; i<nbTasks; i++) {
    sprintf(name, "ACT%ld", i);
    tasks[i] = IloIntervalVar(env, name);
    ILOSETLOCATION(tasks[i]);
  }
  IloIntExprArray ends(env);
  for (i=0; i<nbTasks; i++) {
    IloIntervalVar task = tasks[i];
    IloInt d, smin, emax, nbSucc;
    file >> d >> smin >> emax;
    task.setSizeMin(d);
    task.setSizeMax(d);
    task.setStartMin(smin);
    task.setEndMax(emax);
    ends.add(IloEndOf(task));
    for (j = 0; j < nbResources; j++) {
      IloInt q;
      file >> q;
      if (q > 0) {
        resources[j] += IloPulse(task, q);
      }
    }
    file >> nbSucc;
    for (IloInt s=0; s<nbSucc; ++s) {
      IloInt succ;
      file >> succ;
      IloConstraint pct = IloEndBeforeStart(env, task, tasks[succ]);
      ILOADD(model, pct);
      precedenceCts.add(pct);
    }
  }
  for (j=0; j<nbResources; j++) {
    sprintf(name, "RES%ld", j);
    resources[j].setName(name);
    IloConstraint cct = (resources[j] <= capacities[j]);
    ILOADD(model, cct);
    capacityCts.add(cct);
  }
  model.add(IloMinimize(env, IloMax(ends)));
  return model;
}