Page 1 of 1

Problem with complex scheduling script

Posted: Tue Dec 02, 2003 10:45 am
by Chambrln
I'm working on a script that will automatically schedule people based on the hours they are available, the maximum hours they wish to work, a rank assigned to them by a manager, and a percentage determined by a manager for how much time that employee should work in a certain location.

Currently I have 5 locations and obviously 7 days of the week. I've got pretty much everything working except for one thing that I would like to fix. I've been looking at this code for too long now and I start to see crosseye.

Anyway the problem is depending on how the employee is ranked they ocassionaly get schedule for an hour or so in one location, then immediately get scheduled for a 1/2 hour in a different location. After that 1/2 hour is up they get put back in the first location again for another 2 hours or what not.

What I need is to schedule their whole shift in one location, or at least their whole block of time since they may have more than one shift per day.

I have two arrays that I'm working with. One for the employee information and one that is created to hold the time information for each location.

In a nut shell this is the loop to generate the schedule so far

Code: Select all

<?php
for ($i=1; $i <= count($locations); $i++) {  //Loops through each location
  for ($d=0; $d <= 6; $d++) {  //Loops through the seven days of the week
    $rows = (($close - $open) * 2);  //Determines how long the location is open
    for ($r=1; $r <= $rows; $r++) {  //Loops through each 1/2 hour the location is open
      for ($m=1; $m <= $max; $m++) {  //Loops through the maximum number of employees that should be scheduled for this shift (ie. 2 cells for 2 people)
        foreach ($employee as $e) {  //Loop through each employee
          /*The code then checks to see if the first spot in the array is available and if so finds the first employee available and inserts them here.  If the first slot is filled and there is more than one employee needed on this shift we look to the second slot, etc. for an openening.

When one is found that time is removed from the employee's available times and their maximum hours available is decreased by a 1/2 hour. */
        }
      }
    }
  }
}
?>
As the loops are completed the script is also drawing the table and cells for the schedule. Maybe I should perform a final loop to go through the times and draw the table then?

Any help would be appreciated.