00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "gecode/set.hh"
00042 #include "examples/support.hh"
00043
00044 namespace {
00046 typedef enum {
00047 Tom, David, Jeremy, Ron,
00048 Joe, Bill, Fred,
00049 Bob, Mario, Ed,
00050 Carol, Janet, Tracy,
00051 Marilyn, Carolyn, Cathy,
00052 Inez, Jean, Heather, Juliet
00053 } Employee;
00054 const int noOfEmployees = Juliet+1;
00055
00057 struct Flight {
00058 int staff;
00059 int stewards;
00060 int hostesses;
00061 int french;
00062 int spanish;
00063 int german;
00064 };
00065
00066 const char* employeeToName(Employee e);
00067 extern const int stewards[];
00068 extern const int noOfStewards;
00069 extern const int hostesses[];
00070 extern const int noOfHostesses;
00071 extern const int spanishSpeaking[];
00072 extern const int noOfSpanishSpeaking;
00073 extern const int frenchSpeaking[];
00074 extern const int noOfFrenchSpeaking;
00075 extern const int germanSpeaking[];
00076 extern const int noOfGermanSpeaking;
00077 extern const Flight requiredCrew[];
00078 extern const int noOfFlights;
00079 }
00080
00091 class Crew : public Example {
00092 public:
00094 SetVarArray flight;
00095
00097 Crew(const Options&) :
00098 flight(this,noOfFlights,IntSet::empty,0,noOfEmployees-1)
00099 {
00100 IntSet stewardsDS(stewards,noOfStewards);
00101 IntSet hostessesDS(hostesses,noOfHostesses);
00102 IntSet spanishDS(spanishSpeaking, noOfSpanishSpeaking);
00103 IntSet frenchDS(frenchSpeaking, noOfFrenchSpeaking);
00104 IntSet germanDS(germanSpeaking, noOfGermanSpeaking);
00105
00106 for (int i=0; i<noOfFlights; i++) {
00107 IntVarArray ia(this,5,0,noOfEmployees-1);
00108 SetVar team = flight[i];
00109
00110 int N = requiredCrew[i].staff;
00111 int NStew = requiredCrew[i].stewards;
00112 int NHost = requiredCrew[i].hostesses;
00113 int NFrench = requiredCrew[i].french;
00114 int NSpanish = requiredCrew[i].spanish;
00115 int NGerman = requiredCrew[i].german;
00116
00117 cardinality(this, team,N,N);
00118 SetVar stewardsInFS(this);
00119 SetVar hostessesInFS(this);
00120 SetVar spanishInFS(this);
00121 SetVar frenchInFS(this);
00122 SetVar germanInFS(this);
00123
00124 rel(this, team, SOT_INTER, stewardsDS, SRT_EQ, stewardsInFS);
00125 rel(this, team, SOT_INTER, hostessesDS, SRT_EQ, hostessesInFS);
00126 rel(this, team, SOT_INTER, spanishDS, SRT_EQ, spanishInFS);
00127 rel(this, team, SOT_INTER, frenchDS, SRT_EQ, frenchInFS);
00128 rel(this, team, SOT_INTER, germanDS, SRT_EQ, germanInFS);
00129
00130 cardinality(this, stewardsInFS, ia[0]);
00131 cardinality(this, hostessesInFS, ia[1]);
00132 cardinality(this, spanishInFS, ia[2]);
00133 cardinality(this, frenchInFS, ia[3]);
00134 cardinality(this, germanInFS, ia[4]);
00135
00136 rel(this, ia[0], IRT_GQ, NStew);
00137 rel(this, ia[1], IRT_GQ, NHost);
00138 rel(this, ia[2], IRT_GQ, NSpanish);
00139 rel(this, ia[3], IRT_GQ, NFrench);
00140 rel(this, ia[4], IRT_GQ, NGerman);
00141
00142 }
00143
00144 for (int i=0; i<noOfFlights-2; i++) {
00145 rel(this, flight[i], SRT_DISJ, flight[i+1]);
00146 rel(this, flight[i], SRT_DISJ, flight[i+2]);
00147 }
00148 rel(this, flight[noOfFlights-2], SRT_DISJ, flight[noOfFlights-1]);
00149
00150 branch(this, flight, SET_VAR_NONE, SET_VAL_MIN);
00151 }
00152
00154 virtual void
00155 print(std::ostream& os) {
00156 for (int i=0; i<noOfFlights; i++) {
00157 os << "\tFlight " << i+1 << ":" << std::endl;
00158 os << "\t\tCrew\tStew.\tHost.\tFrench\tSpanish\tGerman"
00159 << std::endl << "\t";
00160 os << "\t" << requiredCrew[i].staff << "\t" << requiredCrew[i].stewards
00161 << "\t" << requiredCrew[i].hostesses << "\t"
00162 << requiredCrew[i].spanish
00163 << "\t" << requiredCrew[i].french << "\t" << requiredCrew[i].german
00164 << std::endl;
00165
00166 os << "\t\tSchedule:" << std::endl << "\t\t";
00167 if (flight[i].assigned()) {
00168 for (SetVarGlbValues d(flight[i]);d();++d) {
00169 os << employeeToName(static_cast<Employee>(d.val())) << " ";
00170 }
00171 } else {
00172 os << "\tRequired: ";
00173 for (SetVarGlbValues d(flight[i]);d();++d) {
00174 os << employeeToName(static_cast<Employee>(d.val())) << " ";
00175 }
00176 os << std::endl << "\t\t\tPossible: ";
00177 for (SetVarUnknownValues d(flight[i]);d();++d) {
00178 os << employeeToName(static_cast<Employee>(d.val())) << " ";
00179 }
00180 }
00181 os << std::endl << std::endl;
00182 }
00183 }
00184
00186 Crew(bool share, Crew& s)
00187 : Example(share,s) {
00188 flight.update(this,share,s.flight);
00189 }
00191 virtual
00192 Space *copy(bool share) {
00193 return new Crew(share,*this);
00194 }
00195
00196 };
00197
00201 int
00202 main(int argc, char* argv[]) {
00203 Options o("Crew");
00204 o.iterations(100);
00205 o.parse(argc,argv);
00206 Example::run<Crew,DFS,Options>(o);
00207 return 0;
00208 }
00209
00210 namespace {
00211
00213 const char*
00214 employeeToName(Employee e) {
00215 switch(e) {
00216 case Tom : return "Tom";
00217 case David : return "David";
00218 case Jeremy: return "Jeremy";
00219 case Ron: return "Ron";
00220 case Joe: return "Joe";
00221 case Bill: return "Bill";
00222 case Fred: return "Fred";
00223 case Bob: return "Bob";
00224 case Mario: return "Mario";
00225 case Ed: return "Ed";
00226 case Carol: return "Carol";
00227 case Janet: return "Janet";
00228 case Tracy: return "Tracy";
00229 case Marilyn: return "Marilyn";
00230 case Carolyn: return "Carolyn";
00231 case Cathy: return "Cathy";
00232 case Inez: return "Inez";
00233 case Jean: return "Jean";
00234 case Heather: return "Heather";
00235 case Juliet: return "Juliet";
00236 default: GECODE_NEVER; return "";
00237 }
00238 }
00239
00240
00242 const int stewards[] =
00243 {Tom, David, Jeremy, Ron, Joe, Bill, Fred, Bob, Mario, Ed};
00245 const int noOfStewards = sizeof(stewards) / sizeof(int);
00247 const int hostesses[] =
00248 { Carol, Janet, Tracy, Marilyn, Carolyn, Cathy, Inez,
00249 Jean, Heather, Juliet };
00251 const int noOfHostesses = sizeof(hostesses) / sizeof(int);
00253 const int frenchSpeaking[] =
00254 { Bill, Inez, Jean, Juliet };
00256 const int noOfFrenchSpeaking = sizeof(frenchSpeaking) / sizeof(int);
00258 const int germanSpeaking[] =
00259 { Tom, Jeremy, Mario, Cathy, Juliet };
00261 const int noOfGermanSpeaking = sizeof(germanSpeaking) / sizeof(int);
00263 const int spanishSpeaking[] =
00264 { Joe, Bill, Fred, Mario, Marilyn, Inez, Heather };
00266 const int noOfSpanishSpeaking = sizeof(spanishSpeaking) / sizeof(int);
00267
00269 const Flight requiredCrew[] =
00270 { {4,1,1,1,1,1},
00271 {5,1,1,1,1,1},
00272 {5,1,1,1,1,1},
00273 {6,2,2,1,1,1},
00274 {7,3,3,1,1,1},
00275 {4,1,1,1,1,1},
00276 {5,1,1,1,1,1},
00277 {6,1,1,1,1,1},
00278 {6,2,2,1,1,1},
00279 {7,3,3,1,1,1} };
00280
00282 const int noOfFlights = sizeof(requiredCrew) / sizeof(Flight);
00283 }
00284
00285
00286