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 46 insertions and 21 deletions:
0 comments (0 inline, 0 general)
class.schedule.php
Show inline comments
 
@@ -132,29 +132,15 @@ class Schedule
 
	    
 
				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)))
 
							{
 
								$conflict = TRUE;
 
							}
 
						}
 
		
 
				  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)
 
	  {
class.section.php
Show inline comments
 
@@ -199,6 +199,45 @@ class Section
 
  {
 
    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
0 comments (0 inline, 0 general)