hey guys,
hope everyone is well. so im working on a problem which models placing med students at hospitals in a 30 day plus epsilon period. the code is commented pretty well, so i think u can get the idea of what im aiming for. students are name sequentially by their id from S01, S02,...S30; on with the code
$this->currStudent = $student = reset($allStudents); //get the first student
$e = 0; //epsilon
//Each day
for($day = 1; $day <= 30 + $e; $day++){
$this->logger->addEvent("start of day, ".$day);
$hospital = $this->getHospital(reset($student->hospPrefs));
$this->logger->addEvent("day ".$day." got hospital ".$hospital->id.". is student ".$student->id." most pref hosp");
while($student->currHosp == NULL){// while we have unplaced student S:
if($hospital->numDoctors() < 6){//max 6 docs at a hospital
$this->doPlacement($student, $hospital);//place student at hospital
$this->logger->addEvent("day ".$day." placed student ".$student->id." in hospital ".$hospital->id." < 6 docs");
}else{
$leastPrefStudent = $this->getStudent($hospital->leastPrefDoc());//get the least prefered student at the hosp
$this->logger->addEvent("day ".$day." got least prefered student ".$leastPrefStudent->id);
//if hosp would be mor sat with new student than least pref. then dump the least pref, add the more prefered
if($hospital->satWithDoctor($student->id) > $hospital->satWithDoctor($leastPrefStudent->id)){
//dump the student and increase epsilon
$this->doDump($leastPrefStudent, $hospital);
$this->logger->addEvent("day ".$day." dumped student ".$leastPrefStudent->id." from hospital "
.$hospital->id);
$e++; //increase episolon by one day, because we had to dump student
$this->logger->addEvent("epsilon increased to ".$e);
//Place S in the slot formerly occupied at H by S'
$this->doPlacement($student, $hospital);
$this->logger->addEvent("day ".$day." placed student ".$student->id." in hospital ".$hospital->id);
}else{
//least prefered student stays at thier currrent hospital
$this->logger->addEvent("day ".$day." least prefered student ".$leastPrefStudent->id." stayed at hospital "
.$hospital->id);
//get the next prefered hospital
$hospital = $this->getHospital(next($student->hospPrefs));
}
}
}//end while
$this->doEndOfDay();
//$this->logger->addEvent("end of day, ".$day);
/**print("<pre>");
print_r($this->currStudent);
print("</pre>");**/
$this->currStudent = $student = next($this->students);//get the next student
}//end for
this works well through about half of the students, then i get some results. it is easier explained by the log i created:
7 => start of day, 1
8 => day 1 got hospital H1. is student S01 most pref hosp
9 => day 1 placed student S01 in hospital H1 < 6 docs
10 => start of day, 2
11 => day 2 got hospital H5. is student S02 most pref hosp
12 => day 2 placed student S02 in hospital H5 < 6 docs
13 => start of day, 3
14 => day 3 got hospital H5. is student S03 most pref hosp
15 => day 3 placed student S03 in hospital H5 < 6 docs
16 => start of day, 4
17 => day 4 got hospital H3. is student S04 most pref hosp
18 => day 4 placed student S04 in hospital H3 < 6 docs
19 => start of day, 5
20 => day 5 got hospital H1. is student S05 most pref hosp
21 => day 5 placed student S05 in hospital H1 < 6 docs
22 => start of day, 6
23 => day 6 got hospital H3. is student S06 most pref hosp
24 => day 6 placed student S06 in hospital H3 < 6 docs
25 => start of day, 7
26 => day 7 got hospital H2. is student S07 most pref hosp
27 => day 7 placed student S07 in hospital H2 < 6 docs
28 => start of day, 8
29 => day 8 got hospital H1. is student S08 most pref hosp
30 => day 8 placed student S08 in hospital H1 < 6 docs
31 => start of day, 9
32 => day 9 got hospital H1. is student S09 most pref hosp
33 => day 9 placed student S09 in hospital H1 < 6 docs
34 => start of day, 10
35 => day 10 got hospital H5. is student S10 most pref hosp
36 => day 10 placed student S10 in hospital H5 < 6 docs
37 => start of day, 11
38 => day 11 got hospital H1. is student S11 most pref hosp
39 => day 11 placed student S11 in hospital H1 < 6 docs
40 => start of day, 12
41 => day 12 got hospital H3. is student S12 most pref hosp
42 => day 12 placed student S12 in hospital H3 < 6 docs
43 => start of day, 13
44 => day 13 got hospital H2. is student S13 most pref hosp
45 => day 13 placed student S13 in hospital H2 < 6 docs
46 => start of day, 14
47 => day 14 got hospital H2. is student S14 most pref hosp
48 => day 14 placed student S14 in hospital H2 < 6 docs
49 => start of day, 15
50 => day 15 got hospital H4. is student S15 most pref hosp
51 => day 15 placed student S15 in hospital H4 < 6 docs
52 => start of day, 16
53 => day 16 got hospital H1. is student S16 most pref hosp
54 => day 16 placed student S16 in hospital H1 < 6 docs
55 => start of day, 17
56 => day 17 got hospital H1. is student S17 most pref hosp
57 => day 17 got least prefered student S16
58 => day 17 least prefered student S16 stayed at hospital H1
59 => day 17 placed student S17 in hospital H4 < 6 docs
60 => start of day, 18
61 => day 18 got hospital H1. is student S18 most pref hosp
62 => day 18 got least prefered student S16
63 => day 18 least prefered student S16 stayed at hospital H1
64 => day 18 placed student S18 in hospital H2 < 6 docs
65 => start of day, 19
66 => day 19 got hospital H1. is student S18 most pref hosp
67 => start of day, 20
68 => day 20 got hospital H1. is student S19 most pref hosp
69 => day 20 got least prefered student S16
70 => day 20 least prefered student S16 stayed at hospital H1
71 => day 20 placed student S19 in hospital H3 < 6 docs
72 => start of day, 21
73 => day 21 got hospital H1. is student S18 most pref hosp
74 => start of day, 22
75 => day 22 got hospital H1. is student S19 most pref hosp
76 => start of day, 23
77 => day 23 got hospital H3. is student S20 most pref hosp
78 => day 23 placed student S20 in hospital H3 < 6 docs
79 => start of day, 24
80 => day 24 got hospital H1. is student S21 most pref hosp
81 => day 24 got least prefered student S16
82 => day 24 least prefered student S16 stayed at hospital H1
83 => day 24 placed student S21 in hospital H6 < 6 docs
84 => start of day, 25
85 => day 25 got hospital H1. is student S18 most pref hosp
86 => start of day, 26
87 => day 26 got hospital H1. is student S19 most pref hosp
88 => start of day, 27
89 => day 27 got hospital H3. is student S20 most pref hosp
90 => start of day, 28
91 => day 28 got hospital H1. is student S21 most pref hosp
92 => start of day, 29
93 => day 29 got hospital H3. is student S22 most pref hosp
94 => day 29 placed student S22 in hospital H3 < 6 docs
95 => start of day, 30
96 => day 30 got hospital H1. is student S23 most pref hosp
97 => day 30 got least prefered student S16
98 => day 30 least prefered student S16 stayed at hospital H1
99 => day 30 placed student S23 in hospital H4 < 6 docs
it seems the array pointer some how gets set to S18, but i see no reason or mechanism for i to do so. since this student, or subsequent students have already been placed, this wastes a day, and because epsilon is not increased, we don't extend the period for the loop by a day. any idea why this is doing this? ive been tearing my hair out for a week with this, and have tried looking for similar problems through google and here, but to no avail! i also attached a zip of the whole data model (5 files - student, hospital, placer, logger, definitions; just run placer.php) if your interested. i thank you in advance for your help!
ps - sorry for the length of this post, but the code and log takes up a lot of room .