Generated on Wed Nov 1 15:04:27 2006 for Gecode by doxygen 1.4.5

crew.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-08-04 16:06:52 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00012  *     $Revision: 3517 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 
00025 #include "gecode/set.hh"
00026 #include "examples/support.hh"
00027 
00028 typedef enum {
00029   Tom, David, Jeremy, Ron,
00030   Joe, Bill, Fred,
00031   Bob, Mario, Ed,
00032   Carol, Janet, Tracy,
00033   Marilyn, Carolyn, Cathy,
00034   Inez, Jean, Heather, Juliet
00035 } Employees;
00036 
00037 const Employees employees[] =
00038   { Tom, David, Jeremy, Ron,
00039     Joe, Bill, Fred,
00040     Bob, Mario, Ed,
00041     Carol, Janet, Tracy,
00042     Marilyn, Carolyn, Cathy,
00043     Inez, Jean, Heather, Juliet };
00044 const int lastEmployee = Juliet;
00045 
00046 const char*
00047 employeeToName(Employees e) {
00048   switch(e) {
00049   case Tom : return "Tom";
00050   case David : return "David";
00051   case Jeremy: return "Jeremy";
00052   case Ron: return "Ron";
00053   case Joe: return "Joe";
00054   case Bill: return "Bill";
00055   case Fred: return "Fred";
00056   case Bob: return "Bob";
00057   case Mario: return "Mario";
00058   case Ed: return "Ed";
00059   case Carol: return "Carol";
00060   case Janet: return "Janet";
00061   case Tracy: return "Tracy";
00062   case Marilyn: return "Marilyn";
00063   case Carolyn: return "Carolyn";
00064   case Cathy: return "Cathy";
00065   case Inez: return "Inez";
00066   case Jean: return "Jean";
00067   case Heather: return "Heather";
00068   case Juliet: return "Juliet";
00069   }
00070   return "None";
00071 }
00072 
00073 // these have to be sorted!
00074 const Employees stewards[] =
00075   {Tom, David, Jeremy, Ron, Joe, Bill, Fred, Bob, Mario, Ed};
00076 const int noOfStewards = 10;
00077 const Employees hostesses[] =
00078   { Carol, Janet, Tracy, Marilyn, Carolyn, Cathy, Inez,
00079     Jean, Heather, Juliet };
00080 const int noOfHostesses = 10;
00081 const Employees frenchSpeaking[] =
00082   { Bill, Inez, Jean, Juliet };
00083 const int noOfFrenchSpeaking = 4;
00084 const Employees germanSpeaking[] =
00085   { Tom, Jeremy, Mario, Cathy, Juliet };
00086 const int noOfGermanSpeaking = 5;
00087 const Employees spanishSpeaking[] =
00088   { Joe, Bill, Fred, Mario, Marilyn, Inez, Heather };
00089 const int noOfSpanishSpeaking = 7;
00090 
00091 const int flights[][7] =
00092   { {1,4,1,1,1,1,1},
00093     {2,5,1,1,1,1,1},
00094     {3,5,1,1,1,1,1},
00095     {4,6,2,2,1,1,1},
00096     {5,7,3,3,1,1,1},
00097     {6,4,1,1,1,1,1},
00098     {7,5,1,1,1,1,1},
00099     {8,6,1,1,1,1,1},
00100     {9,6,2,2,1,1,1},
00101     {10,7,3,3,1,1,1} };
00102 
00103 const int len = 10;
00104 
00105 
00116 class Crew : public Example {
00117 public:
00118   SetVarArray root;
00119 
00120   Crew(const Options& o) :
00121     root(this,len,IntSet::empty,0,lastEmployee)
00122   {
00123     IntSet stewardsDS((int*)stewards,noOfStewards);
00124     IntSet hostessesDS((int*)hostesses,noOfHostesses);
00125     IntSet spanishDS((int*)spanishSpeaking, noOfSpanishSpeaking);
00126     IntSet frenchDS((int*)frenchSpeaking, noOfFrenchSpeaking);
00127     IntSet germanDS((int*)germanSpeaking, noOfGermanSpeaking);
00128 
00129     for (int i=0; i<len; i++) {
00130       IntVarArray ia(this,5,0,lastEmployee);
00131       SetVar team = root[i];
00132       const int* flight = flights[i];
00133 
00134       const int N        = flight[1];
00135       const int NStew    = flight[2];
00136       const int NHost    = flight[3];
00137       const int NFrench  = flight[4];
00138       const int NSpanish = flight[5];
00139       const int NGerman  = flight[6];
00140 
00141       cardinality(this, team,N,N);
00142       SetVar stewardsInFS(this);
00143       SetVar hostessesInFS(this);
00144       SetVar spanishInFS(this);
00145       SetVar frenchInFS(this);
00146       SetVar germanInFS(this);
00147 
00148       rel(this, team, SOT_INTER, stewardsDS, SRT_EQ, stewardsInFS);
00149       rel(this, team, SOT_INTER, hostessesDS, SRT_EQ, hostessesInFS);
00150       rel(this, team, SOT_INTER, spanishDS, SRT_EQ, spanishInFS);
00151       rel(this, team, SOT_INTER, frenchDS, SRT_EQ, frenchInFS);
00152       rel(this, team, SOT_INTER, germanDS, SRT_EQ, germanInFS);
00153 
00154       cardinality(this, stewardsInFS, ia[0]);
00155       cardinality(this, hostessesInFS, ia[1]);
00156       cardinality(this, spanishInFS, ia[2]);
00157       cardinality(this, frenchInFS, ia[3]);
00158       cardinality(this, germanInFS, ia[4]);
00159 
00160       rel(this, ia[0], IRT_GQ, NStew);
00161       rel(this, ia[1], IRT_GQ, NHost);
00162       rel(this, ia[2], IRT_GQ, NSpanish);
00163       rel(this, ia[3], IRT_GQ, NFrench);
00164       rel(this, ia[4], IRT_GQ, NGerman);
00165 
00166     }
00167 
00168     for (int i=0; i<len-2; i++) {
00169       rel(this, root[i], SRT_DISJ, root[i+1]);
00170       rel(this, root[i], SRT_DISJ, root[i+2]);
00171     }
00172     rel(this, root[len-2], SRT_DISJ, root[len-1]);
00173 
00174     branch(this, root, SETBVAR_NONE, SETBVAL_MIN);
00175   }
00176 
00177   Crew(bool share, Crew& s)
00178     : Example(share,s) {
00179     root.update(this,share,s.root);
00180   }
00181 
00182   virtual
00183   Space *copy(bool share) {
00184     return new Crew(share,*this);
00185   }
00186 
00187   virtual void
00188   print(void) {
00189     for (int i=0; i<len; i++) {
00190       SetVarGlbValues d(root[i]);
00191 
00192       std::cout << "\tFlight " << i+1 << ":" << std::endl;
00193       std::cout << "\t\tCrew\tStew.\tHost.\tFrench\tSpanish\tGerman"
00194                 << std::endl << "\t";
00195       for (int j=1; j<7; j++)
00196         std::cout << "\t" << flights[i][j];
00197       std::cout << std::endl;
00198 
00199       std::cout << "\t\tSchedule:" << std::endl << "\t\t";
00200       for (;d();++d) {
00201         std::cout << employeeToName((Employees)d.val()) << " ";
00202       }
00203       std::cout << std::endl << std::endl;
00204     }
00205 
00206   }
00207 };
00208 
00209 int
00210 main(int argc, char** argv) {
00211   Options o("Crew");
00212   o.iterations = 100;
00213   o.parse(argc,argv);
00214   Example::run<Crew,DFS>(o);
00215   return 0;
00216 }
00217 
00218 
00219 // STATISTICS: example-any
00220