Exemple #1
0
 /// Post constraint on \a x
 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
   SetVarArgs xs(x.size()-2);
   for (int i=x.size()-2; i--;)
     xs[i]=x[i];
   Gecode::element(home, SOT_INTER, xs, x[x.size()-2], x[x.size()-1], 
     ds_12);
 }
Exemple #2
0
  /// Actual model
  Golf(const GolfOptions& opt) : g(opt.g()), s(opt.s()), w(opt.w()),
    groups(*this,g*w,IntSet::empty,0,g*s-1,s,s) {
    Matrix<SetVarArray> schedule(groups,g,w);

    // Groups in one week must be disjoint
    SetVar allPlayers(*this, 0,g*s-1, 0,g*s-1);
    for (int i=0; i<w; i++)
      rel(*this, setdunion(schedule.row(i)) == allPlayers);

    // No two golfers play in the same group more than once
    for (int i=0; i<groups.size()-1; i++)
      for (int j=i+1; j<groups.size(); j++)
        rel(*this, cardinality(groups[i] & groups[j]) <= 1);

    if (opt.model() == MODEL_SYMMETRY) {

      /*
       * Redundant constraints and static symmetry breaking from
       * "Solving Kirkman's Schoolgirl Problem in a Few Seconds"
       * Nicolas Barnier, Pascal Brisset, Constraints, 10, 7-21, 2005
       *
       */

      // Redundant constraint:
      // in each week, one player plays in only one group
      for (int j=0; j<w; j++) {
         for (int p=0; p < g*s; p++) {
           BoolVarArgs b(g);
           for (int i=0; i<g; i++)
             b[i] = expr(*this, (singleton(p) <= schedule(i,j)));
           linear(*this, b, IRT_EQ, 1);
         }
       }

      // Symmetry breaking: order groups
      for (int j=0; j<w; j++) {
        IntVarArgs m(g);
        for (int i=0; i<g; i++)
          m[i] = expr(*this, min(schedule(i,j)));
        rel(*this, m, IRT_LE);
      }

      // Symmetry breaking: order weeks
      // minElem(group(w,0)\{0}) < minElem(group(w+1,0)\{0})
      {
        IntVarArgs m(w);
        for (int i=0; i<w; i++)
          m[i] = expr(*this, min(schedule(0,i)-IntSet(0,0)));
        rel(*this, m, IRT_LE);
      }

      // Symmetry breaking: value symmetry of player numbers
      precede(*this, groups, IntArgs::create(groups.size(),0));
    }

    branch(*this, groups, SET_VAR_MIN_MIN, SET_VAL_MIN_INC);
  }
Exemple #3
0
  /// Actual model
  Hamming(const HammingOptions& opt) :
    x(*this,opt.size(),IntSet::empty,1,opt.bits()) {
    SetVarArgs cx(x.size());
    for (int i=x.size(); i--;)
      cx[i] = expr(*this, -x[i]);

    for (int i=0; i<x.size(); i++)
      for (int j=i+1; j<x.size(); j++)
        rel(*this,
            cardinality(x[j] & cx[i]) +
            cardinality(x[i] & cx[j]) >= opt.distance());

    branch(*this, x, SET_VAR_NONE, SET_VAL_MIN_INC);
  }
Exemple #4
0
	/// Print solution
	virtual void
	print(std::ostream& os) const {
		for (int i=0; i<xs.size(); i++) {
			os << "\t[" << i << "] = " << xs[i] << std::endl;
		}
		print_to_string();
	}
Exemple #5
0
	virtual void
	print_to_string() const {	
		std::ostringstream outputstring;
		outputstring << "(" ;
		
		for (int i=0; i<xs.size(); i++) {
			outputstring << "(" ;
			for (int j=0;j<=xs[i].glbMax();j++)
				if (xs[i].contains(j))
					outputstring << j << " " ;
		    outputstring << ")" ;
		}
		outputstring << ")" ;
		
		std::cout << "OUTPUT" << outputstring.str();

		
		strcpy(result,outputstring.str().c_str());		
		
	}
Exemple #6
0
 /// Constructor for copying \a s
 Golf(bool share, Golf& s) : Script(share,s), g(s.g), s(s.s), w(s.w) {
   groups.update(*this, share, s.groups);
 }
Exemple #7
0
 /// Constructor for cloning \a s
 Crew(bool share, Crew& s)
   : Script(share,s) {
   flight.update(*this,share,s.flight);
 }
 /// Post constraint on \a x
 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
   SetVarArgs xs(x.size()-1);
   for (int i=x.size()-1; i--;)
     xs[i]=x[i];
   Gecode::sequence(home, xs, x[x.size()-1]);
 }
Exemple #9
0
	/// Constructor for copying \a s
	Profils(Profils& s) : Script(s) {
		xs.update(*this, s.xs);
	}
Exemple #10
0
	//int bpfs[1][12];
	/// Actual model
	Profils(const ProfilsOptions& opt) :
	  	Script(opt),
    xs(*this,opt.size(),IntSet::empty,1,opt.nn()) {
# if 0 // was the hamming constrain
		SetVarArray cxs(*this,xs.size());
		for (int i=0; i<xs.size(); i++)
			rel(*this, xs[i], SRT_CMPL, cxs[i]);
		
		for (int i=0; i<xs.size(); i++) {
			SetVar y = xs[i];
			SetVar cy = cxs[i];
			for (int j=i+1; j<xs.size(); j++) {
				SetVar x = xs[j];
				SetVar cx = cxs[j];
				
				SetVar xIntCy(*this);
				SetVar yIntCx(*this);
				
				rel(*this, x, SOT_INTER, cy, SRT_EQ, xIntCy);
				rel(*this, y, SOT_INTER, cx, SRT_EQ, yIntCx);
				IntVar xIntCyCard(*this,0,x.cardMax());
				IntVar yIntCxCard(*this,0,y.cardMax());
				cardinality(*this, xIntCy, xIntCyCard);
				cardinality(*this, yIntCx, yIntCxCard);
				post(*this, xIntCyCard+yIntCxCard >= opt.distance());
			}
		}
#endif
		
		
		for (int i=0; i<(xs.size() - 1); i++)
		{
			IntVar min0(*this,0,120);
			IntVar min1(*this,0,120);
			IntVar max0(*this,0,120);
			IntVar max1(*this,0,120);
			
			
			min(*this,xs[i],min0);
			min(*this,xs[i+1],min1);
			if (opt.profils[0][i] == 1) 
				rel(*this, min1,IRT_GR, min0);
			else
				rel(*this, min1,IRT_LE, min0);
			
			max(*this,xs[i],max0);
			max(*this,xs[i+1],max1);
			if (opt.profils[1][i] == 1) 
				rel(*this, max1,IRT_GR, max0);
			else
				rel(*this, max1,IRT_LE, max0);
			
		}
	
		//contrainte de cardinalité
		IntVar card(*this,opt.densMin,opt.densMax);
		for (int i=0; i<(xs.size()); i++)
			cardinality(*this, xs[i], card);

		
		branch(*this, xs, SET_VAR_NONE(), SET_VAL_MIN_INC());
	}
 /// Constructor for copying \a s
 Steiner(bool share, Steiner& s) : Script(share,s), n(s.n), noOfTriples(s.noOfTriples) {
   triples.update(*this, share, s.triples);
 }
Exemple #12
0
 /// Constructor for copying \a s
 Hamming(bool share, Hamming& s) : Script(share,s) {
   x.update(*this, share, s.x);
 }
Exemple #13
0
 /// Print solution
 virtual void
 print(std::ostream& os) const {
   for (int i=0; i<x.size(); i++) {
     os << "\t[" << i << "] = " << x[i] << std::endl;
   }
 }
Exemple #14
0
 /// Post constraint on \a x
 virtual void post(Space& home, SetVarArray& x, IntVarArray& y) {
   SetVarArgs xs(x.size()-1);
   for (int i=x.size()-1; i--;)
     xs[i]=x[i];
   Gecode::element(home, xs, y[0], x[x.size()-1]);
 }