function updateAutoloadCache()
{
    $pDIR = realpath(dirname(__FILE__) . '/..') . '/';
    $folders = '{lib,modules,autoload,admin_plugins,plugins,ui}/';
    $paths = implode(PATH_SEPARATOR, array_unique(findDirectoriesWithFiles($pDIR . $folders, '*.php')));
    file_put_contents(CACHE_DIR . 'path.cache', $paths);
    addPath($paths);
}
function algorithmLoop3($startPaths, $endPaths, $completedPaths)
{
    $debug = true;
    outputDebug("algorithmLoop3()", $debug);
    // this variable is an array, but at the same time, it's only for paths of the same time.
    /*
        This loop will continue to run until we have exhausted all possibilities.
        For each start path that exists, compare the lines with those of the end paths.
    */
    while (count($startPaths) > 0) {
        ksort($startPaths);
        ksort($endPaths);
        //$keys = array_keys($startPaths);
        //$startArray = array_shift($startPaths);
        outputDebug("startPaths count = " . count($startPaths), $debug);
        $newEndPaths = array();
        $newStartPaths = array();
        $buildOnce = true;
        foreach ($startPaths as $startKey => $startArray) {
            outputDebug("startKey = " . $startKey, $debug);
            outputDebug("startArray count = " . count($startArray), $debug);
            /*
                $startArray denotes a list of paths that share the same area, where area
                is denoted by the last station in the path and the destination.
            */
            foreach ($startArray as $startPath) {
                outputDebug("##foreach startArray", $debug);
                $startAdded = false;
                $limit = 0;
                if (count($completedPath) > 0) {
                    $limit = $completedPaths[0]->duration;
                }
                if ($limit > 0 && $startPath->duration > $limit) {
                    outputDebug("ignoring startPath because it is too long.", $debug);
                    continue;
                }
                // check to see if this path is complete. If so, we don't need to do anything.
                if ($end instanceof Station2) {
                    if ($debug) {
                        echo "looking for: ";
                        $end->printInfo();
                        echo "currently @: ";
                        $startPath->getCurrentStation()->printInfo();
                    }
                    if ($startPath->getCurrentStation() == $end) {
                        outputDebug("path is complete.", $debug);
                        $completedPaths = addPath($completedPaths, $startPath);
                        $startAdded = true;
                        continue;
                    }
                }
                $endACount = 0;
                foreach ($endPaths as $endKey => $endArray) {
                    $endcount = 0;
                    if ($debug) {
                        echo "endKey = " . $endKey . "<br/>\n";
                        echo "endPaths count = " . count($endPaths) . "<br/>\n";
                        echo "endArray count = " . count($endArray) . "<br/>\n";
                    }
                    foreach ($endArray as $endPath) {
                        //outputDebug($endcount++ . " of " . $endACount, $debug);
                        outputDebug("startpath = " . $startPath->toString(), $debug);
                        outputDebug("endpath = " . $endPath->toString(), $debug);
                        $box = new Box($startPath->getCurrentStation()->point, $endPath->getCurrentStation()->point);
                        if ($startPath->stationBox == null) {
                            if ($box->getArea() > 0) {
                                $startPath->stationBox = $box;
                            }
                        } else {
                            if ($box->getArea() < $startPath->stationBox->getArea()) {
                                outputDebug("replacing box with new box.", $debug);
                                $startPath->stationBox = $box;
                            }
                        }
                        if (count($completedPaths) > 0) {
                            $limit = $completedPaths[0]->duration;
                            if ($startPath->stationBox != null) {
                                $cArea = $completedPaths[0]->getBox()->getArea();
                                $sArea = $startPath->stationBox->getArea();
                                if ($cArea < $sArea) {
                                    outputDebug($cArea . " < " . $sArea . ". Skipping path check.", $debug);
                                    continue;
                                }
                            }
                        }
                        if ($limit > 0 && $endPath->duration > $limit) {
                            outputDebug("ignoring endPath because it is too long.", $debug);
                            continue;
                        }
                        // check to see if both paths have the same current station
                        if ($startPath->getCurrentStation() == $endPath->getCurrentStation()) {
                            outputDebug("startPath and endPath match", $debug);
                            // we have a completed path.
                            $path = mergePaths($startPath, $endPath);
                            $completedPaths = addPath($completedPaths, $path);
                            $limit = $completedPaths[0]->duration;
                            $startAdded = true;
                        }
                        // see if the paths have an overlapping line
                        $line = compareLines($startPath, $endPath);
                        if ($line != null) {
                            outputDebug("found line match of " . $line->name, $debug);
                            // we have an overlapping line
                            if (count($completedPaths) > 0) {
                                $limit = $completedPaths[0]->duration;
                            }
                            $path = completePath($startPath, $endPath, $line, $limit);
                            if ($path != null) {
                                $completedPaths = addPath($completedPaths, $path);
                                $limit = $completedPaths[0]->duration;
                                $startAdded = true;
                            }
                        } else {
                            outputDebug("No line match found between startPath and endPath.", $debug);
                        }
                        /*
                            Even if a path is completed, it isn't guaranteed to be the faster than any new ones.
                            But how do we save cycles from doing repeat information?
                        */
                        /*
                            We need to extend each path that we look at and store it for the next loop.
                        */
                        if ($buildOnce) {
                            $newEndPaths = extendPath($endPath, $newEndPaths, $limit);
                        }
                    }
                    // foreach ($endArray)
                    $endACount++;
                }
                // foreach ($endPaths)
                if ($buildOnce) {
                    // we only want to build the new paths once, so set it to false after the first loop through
                    // all the paths.
                    $buildOnce = false;
                }
                if (!$startAdded) {
                    $newStartPaths = extendPath($startPath, $newStartPaths, $limit);
                }
            }
            // foreach ($startArray)
        }
        // foreach ($startPaths)
        // next loop, we want to overwrite with the new possibilities.
        /*outputDebug("newStartPaths count = " . count($newStartPaths), $debug);
          outputDebug("startPaths count = " . count($startPaths), $debug);*/
        $startPaths = $newStartPaths;
        outputDebug("startPaths count = " . count($startPaths), $debug);
        /*outputDebug("newEndPaths count = " . count($newEndPaths), $debug);
          outputDebug("endPaths count = " . count($endPaths), $debug);*/
        $endPaths = $newEndPaths;
        outputDebug("endPaths count = " . count($endPaths), $debug);
    }
    // while
    if ($debug) {
        echo "completedPath count = " . count($completedPaths) . "<br/>\n";
        foreach ($completedPaths as $cpath) {
            if ($cpath instanceof Path) {
                echo $cpath->toString() . "<br/>\n";
            }
        }
        echo "<br/>\n";
    }
    return $completedPaths;
}
Beispiel #3
0
            }
            $opts["outDir"] = $v;
        } else {
            die("*** unknonw option `{$opt}`.\n");
        }
        continue;
    }
    $opts["srcDir"] = $opt;
}
if (is_null($opts["srcDir"])) {
    die("*** require param srcDir.");
}
if (!is_dir($opts["srcDir"])) {
    die("*** not a folder: `{$opts["srcDir"]}`\n");
}
addPath();
// load config
$cfg = $opts["srcDir"] . "/" . CFG_FILE;
if (is_file($cfg)) {
    echo "=== load config `{$cfg}`\n";
    require $cfg;
}
$COPY_EXCLUDE[] = CFG_FILE;
//}}}
@mkdir($opts["outDir"], 0777, true);
$outDir = realpath($opts["outDir"]);
$verFile = "{$outDir}/revision.txt";
$oldVer = null;
if (file_exists($verFile)) {
    $oldVer = @file($verFile, FILE_IGNORE_NEW_LINES)[0];
}