Beispiel #1
0
  /// Actual model
  TSP(const SizeOptions& opt)
    : p(ps[opt.size()]),
      succ(*this, p.size(), 0, p.size()-1),
      total(*this, 0, p.max()) {
    int n = p.size();

    // Cost matrix
    IntArgs c(n*n, p.d());

    for (int i=n; i--; )
      for (int j=n; j--; )
        if (p.d(i,j) == 0)
          rel(*this, succ[i], IRT_NQ, j);

    // Cost of each edge
    IntVarArgs costs(*this, n, Int::Limits::min, Int::Limits::max);

    // Enforce that the succesors yield a tour with appropriate costs
    circuit(*this, c, succ, costs, total, opt.icl());

    // Just assume that the circle starts forwards
    {
      IntVar p0(*this, 0, n-1);
      element(*this, succ, p0, 0);
      rel(*this, p0, IRT_LE, succ[0]);
    }

    // First enumerate cost values, prefer those that maximize cost reduction
    branch(*this, costs, INT_VAR_REGRET_MAX_MAX(), INT_VAL_SPLIT_MIN());

    // Then fix the remaining successors
    branch(*this, succ,  INT_VAR_MIN_MIN(), INT_VAL_MIN());
  }
Beispiel #2
0
int chooseVar6(const Problem<type,type2>& P,type epsilon){
  type2 max=std::numeric_limits<type2>::min();
  int j=-1;
  int i=0;
  while (i<P.nbTask){
    if (P.A[i].Fi(P.bmax(i))*(P.d(i)-P.r(i))-P.W(i)>=max && P.smax(i) - P.r(i)>epsilon) {
      j=i;
      max=P.A[i].Fi(P.bmax(i))*(P.d(i)-P.r(i))-P.W(i);
    }
    if (P.A[i].Fi(P.bmax(i))*(P.d(i)-P.r(i))-P.W(i)>max && P.d(i)-P.emin(i)>epsilon){ 
      j=i+P.nbTask;
      max=P.A[i].Fi(P.bmax(i))*(P.d(i)-P.r(i))-P.W(i);
    }
    ++i;
  }
  return j;
}
Beispiel #3
0
int chooseVar3(const Problem<type,type2>& P,type epsilon){
  type min=std::numeric_limits<type>::max();
  int j=-1;
  int i=0;
  while (i<P.nbTask){
    if (P.smax(i) - P.r(i)<=min && P.smax(i) - P.r(i)>epsilon)	{
      j=i;
      min=P.smax(i) - P.r(i);
    }
    if (P.d(i) - P.emin(i) < min && P.d(i) - P.emin(i)>epsilon){ 
      j=i+P.nbTask;
      min=P.d(i) - P.emin(i);
    }
    ++i;
  }
  return j;
}
Beispiel #4
0
int chooseVar1(const Problem<type,type2>& P, type epsilon){
  int i=0;
  while (i<P.nbTask){
    if (P.smax(i) - P.r(i) > epsilon) return i;
    if (P.d(i) - P.emin(i) > epsilon) return i+P.nbTask;
    ++i;
  }
  return -1;
}
Beispiel #5
0
int createVars(const Problem<double>& P, IloEnv& env, IloNumVarMatrix& x, IloNumVarMatrix& y, IloNumVarMatrix& b, IloNumVarMatrix& w){
  try{
    int i;
    const int nbTask=P.nbTask;
    const int E= 2*nbTask;
    
    for (i=0;i<nbTask;i++){
      x[i]=IloNumVarArray(env, E, 0, 1, ILOINT);
      y[i]=IloNumVarArray(env, E, 0, 1, ILOINT);
      b[i]=IloNumVarArray(env, E-1, 0, ((P.d(i)-P.r(i))*P.bmax(i)), ILOFLOAT);
      w[i]=IloNumVarArray(env, E-1, 0, (P.d(i)-P.r(i))*P.A[i].Fi(P.bmax(i)), ILOFLOAT);
  }  
  return 0;
}
catch (IloException &e){
  std::cout << "iloexception in create vars" <<e <<std::endl;
  e.end();
  return  1;
 }
}
Beispiel #6
0
int chooseVar2(const Problem<type,type2>& P,type epsilon){
  const uint n = P.nbTask;
  int real_size = 0;
  uint i;
  int s, j = -1;
  for (i = 0 ; i < n ; ++i) {
    if (P.smax(i) - P.r(i) > epsilon) ++real_size;
    if (P.d(i) - P.emin(i) > epsilon) ++real_size;
  }
  if (!real_size) return -1;
  if (real_size == 1) s = 1;
  else s = rand() % real_size;
  for (i = 0 ; i < n && j < 0 ; ++i) {
    if (P.smax(i) - P.r(i) > epsilon) --s;
    if (!s) j = i;
    else {
      if (P.d(i) - P.emin(i)> epsilon) --s;
      if (!s) j = i +n;
    }
  }
  return j;
}
Beispiel #7
0
int createConstraintTimeW(const Problem<double>& P, IloModel& model,
			  IloNumVarArray& t, IloNumVarMatrix& x,  IloNumVarMatrix& y, const std::vector<double>& M_te){
  const int E=2*P.nbTask;  
  for (int i=0;i<P.nbTask;i++) {
    for (int e=0;e<E;++e){
      model.add(x[i][e]*P.r(i) <= t[e]);
      model.add(t[e] <= x[i][e]*P.smax(i) + 
		(1-x[i][e])*M_te[e]);
      model.add(P.d(i)*y[i][e] + (1-y[i][e])*M_te[e]>= t[e]);
      model.add(t[e] >= y[i][e]*P.emin(i));
    }
  }
  return 0;
}
Beispiel #8
0
void createBranch(Problem<type,type2>& P,int x,std::stack<Problem<type,type2>>& explore, double param){
  Problem<type,type2> Q(P);
  if (x < P.nbTask){
    P.A[x].smax-=(P.smax(x)-P.r(x))*(1.0-param);
    explore.push(P);
    Q.A[x].ri+=(Q.smax(x)-Q.r(x))*param;
    Q.A[x].updateEMin();
    explore.push(Q);
  }
  else  { 
    P.A[x-P.nbTask].emin+=(P.d(x-P.nbTask)-P.emin(x-P.nbTask))*(1.0-param);
    explore.push(P);
    Q.A[x-Q.nbTask].di-=(Q.d(x-Q.nbTask)-Q.emin(x-Q.nbTask))*param;
    Q.A[x-Q.nbTask].updateSMax();
    explore.push(Q);
  }
}
Beispiel #9
0
int createConstraintNonConsump(const Problem<double>& P, IloModel& model, IloEnv& env,
			       IloNumVarMatrix& x, IloNumVarMatrix& y , IloNumVarMatrix& b, int bigM){
  for (int i=0;i<P.nbTask;i++){
    for (int e=0;e<2*P.nbTask-1;e++){	
      IloExpr expr(env);
      for (int f=0;f<=e;f++){
	expr+= x[i][f];
	expr-= y[i][f];
      }
      if (!bigM)
	expr*=P.bmax(i)*(P.d(i)-P.r(i));
      else 
	expr*=M;
      model.add(expr >=b[i][e]);
      expr.end();
    }
  }
  return 0;
}
Beispiel #10
0
int createConstraintBmin(const Problem<double>&P, IloModel& model, IloEnv& env, IloNumVarArray& t, IloNumVarMatrix& x, IloNumVarMatrix& y,IloNumVarMatrix& b, const int& bigM){
  for (int i=0;i<P.nbTask;i++){
    for (int e=0;e<2*P.nbTask-1;e++){
      IloExpr expr(env);
    for (int f=0;f<=e;f++){
      expr-= x[i][f];
      expr+= y[i][f];
    }
    expr+=1;
    if (bigM)
      expr*=-M;
    else 
      expr*= - P.bmin(i)*(P.d(i)-P.r(i));
    expr+=(t[e+1]-t[e])*P.A[i].bmin;
    model.add(expr <= b[i][e]);
    expr.end();
    }
  }
  
  return 0;
}