Changeset - 54bfd4a095e6
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 15 years ago 2010-10-18 19:38:35
ohnobinki@ohnopublishing.net
Move the conflict checking functionality into the Section class (no functional change though -- if this change causes different permutation results, I did something wrong).
2 files changed with 42 insertions and 17 deletions:
0 comments (0 inline, 0 general)
class.schedule.php
Show inline comments
 
@@ -123,43 +123,29 @@ class Schedule
 
        
 
		// Checks for conflicts in given classes, stores if none found
 
		do
 
		{
 
			$conflict = false;
 
         
 
			// Get first class to compare
 
			for ($upCounter = 0; $upCounter < $this->nclasses && !$conflict; $upCounter ++)
 
			{
 
	    
 
				for ($downCounter = $this->nclasses - 1; $downCounter > $upCounter && !$conflict; $downCounter --)
 
				{
 
					$start1 = $this->classStorage[$upCounter]->getSection($cs[$upCounter])->getStartTime();
 
					$end1 = $this->classStorage[$upCounter]->getSection($cs[$upCounter])->getEndTime();
 
					$start2 = $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getStartTime();
 
					$end2 = $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getEndTime();
 
					
 
					// If the two times overlap, then check if days overlap.
 
					if ((($start1 >= $start2) && ($start1 <= $end2)) || (($start2 >= $start1) && ($start2 <= $end1)))
 
					{
 
				
 
					for($day=0; $day<5; $day++)
 
						{
 
							if(!$conflict
 
								&& ($this->classStorage[$upCounter]->getSection($cs[$upCounter])->getDay($day)
 
								&& $this->classStorage[$downCounter]->getSection($cs[$downCounter])->getDay($day)))
 
				  if ($this->classStorage[$upCounter]->getSection($cs[$upCounter])
 
				      ->conflictsWith($this->classStorage[$downCounter]->getSection($cs[$downCounter])))
 
							{
 
								$conflict = TRUE;
 
							}
 
						}
 
		
 
				      break;
 
				}
 
			}
 
		}
 
            
 
	// Store to storage if no conflict is found.
 
	if(!$conflict)
 
	  {
 
	    for($i = 0; $i < $this->nclasses; $i++)
 
	      {
 
		$this->storage[$this->nPermutations][$i] = $cs[$i];
 
	      }
 
	    $this->nPermutations++;
class.section.php
Show inline comments
 
@@ -193,24 +193,63 @@ class Section
 
  public function getF()
 
  {
 
    return $this->bdays[4];
 
  }
 

	
 
  public function getDay($i)
 
  {
 
    return $this->bdays[$i];
 
  }
 
  
 
  /**
 
   * \brief
 
   *   Check if this section conflicts withthe given section.
 
   *
 
   * \param $that
 
   *   The other section for which I should check for conflicts.
 
   * \return
 
   *   TRUE if there is a conflict, FALSE otherwise.
 
   */
 
  public function conflictsWith(Section $that)
 
  {
 
    /*
 
     * The two sections can't conflict if the start/end times don't
 
     * overlap. Also, use >= or <= here so that one can say ``I have
 
     * gym from 10 through 11 and then latin from 11 though 12''.
 
     */	
 
    if ($this->getStartTime() >= $that->getEndTime()
 
	|| $this->getEndTime() <= $that->getStartTime())
 
      {
 
	return FALSE;
 
      }
 

	
 
    /*
 
     * Now we know that the sections overlap in start/end times. But
 
     * if they don't both meet on the same day at least once, they
 
     * don't conflict.
 
     */
 
    for ($day = 0; $day < 5; $day ++)
 
      {
 
	if ($this->getDay($day) && $that->getDay($day))
 
	  return TRUE;
 
      }
 

	
 
    /*
 
     * The sections don't both share a day of the week.
 
     */
 
    return FALSE;
 
  }
 
  
 
  /**
 
   * \brief
 
   *   Splits up a section specifier into dept, course number, and
 
   *   section.
 
   *
 
   * For example, will return array('CS', '262', 'A') for 'CS-262-A'
 
   * or 'CS262 A' or 'cs-262,a'. This function is not for dealing with
 
   * course synonyms.
 
   *
 
   * Note: Section specifiers where the section numeral/letter is
 
   * directly adjacent to the course number is not valid. Calvin
 
   * College distinguishes between normal courses and their labs by
 
   * appending an `L' to the course number. Thus, 'CS262A' is not a
 
   * valid specifier for 'CS-262-A' because there may exist another
0 comments (0 inline, 0 general)