コード例 #1
0
ファイル: utilities.php プロジェクト: Rosengren/CourseBuilder
function flatArray($array)
{
    $result = [];
    if (is_array($array)) {
        foreach ($array as $element) {
            $result = array_merge($result, flatArray($element));
        }
    } else {
        array_push($result, $array);
    }
    return $result;
}
コード例 #2
0
 /**
  * [recursiveGetTimeTables description]
  * @param  [type] $combination Courses combination to pick
  * @param  [type] &$result     result
  * @param  [type] $path        path to store solution path
  * @param  [type] $x           start point in array
  * @param  [type] $y           start point in sub-array
  * @return [type]              [description]
  */
 private function recursiveGetTimeTables(&$result, $combination, $path, $x, $y)
 {
     if (isset($combination[$x]) and isset($combination[$x][$y])) {
         if (!hasTimeConflictArrayToClass($this->getArrayByPath($path, $combination), $combination[$x][$y])) {
             $path[] = [$x, $y];
             if ($x == sizeof($combination) - 1) {
                 // Found one solution
                 $this->numOfSulotion--;
                 $oneSolution = flatArray($this->getArrayByPath($path, $combination));
                 $resultInArray = [];
                 foreach ($oneSolution as $class) {
                     $resultInArray[] = $class->toArray();
                 }
                 $result[] = $resultInArray;
                 if ($this->numOfSulotion != 0) {
                     // next solution
                     array_pop($path);
                     $this->recursiveGetTimeTables($result, $combination, $path, $x, $y + 1);
                 }
             } else {
                 // Keep working
                 $this->recursiveGetTimeTables($result, $combination, $path, $x + 1, 0);
             }
             return;
         }
         $this->recursiveGetTimeTables($result, $combination, $path, $x, $y + 1);
     } else {
         if ($x == 0 and $y > sizeof($combination[$x]) - 1) {
             // Seach End
             return;
         }
         if ($y > sizeof($combination[$x]) - 1) {
             // back Search
             $postion = array_pop($path);
             $this->recursiveGetTimeTables($result, $combination, $path, $postion[0], $postion[1] + 1);
         }
     }
 }
コード例 #3
0
ファイル: database.php プロジェクト: Rosengren/CourseBuilder
 function getCourseArray($courseCompleted, $prerequisiteTree, $program)
 {
     $yearStanding = $this->getYearStanding($courseCompleted, $program);
     // function checkRequirement($requirement, $completedCourses)
     $openingClasses = $this->getOpeningClasses();
     $requiredCourses = flatArray($prerequisiteTree);
     // get courses that uncompleted in prerequisite Tree
     $unCompletedCourse = array_diff($requiredCourses, $courseCompleted);
     // get course that unCompletedCourses open in current term
     // check if this course open or not
     $unCompletedOpeningCourses = array_diff($unCompletedCourse, array_diff($unCompletedCourse, $openingClasses));
     $unCompletedOpeningCourses = $this->filterCourseListByPrerequisite($courseCompleted, $yearStanding, $unCompletedOpeningCourses);
     $classInfo = $this->getCourseInfoByCourseArray($unCompletedOpeningCourses);
     $courseArray = createCourseArray($unCompletedOpeningCourses, $classInfo);
     return $courseArray;
 }