Esempio n. 1
0
function run_scip($year, $season, $dept, $sname, $filename, $phantomTA, $added)
{
    /*
      error_reporting(E_ALL);
      ini_set('display_errors', TRUE);
      ini_set('display_startup_errors', TRUE);
    */
    if (!isset($db)) {
        $db = new PDO(DB_PATH, DB_LOGIN, DB_PW);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    try {
        if (!isset($phantomTA)) {
            //find minimum number of phantoms necessary.
            $phantomTA = 0;
            $phantom_units = 4;
            //find total number of section units.
            $sql2 = "select sum(c.weight * c.units)\n               FROM course c, section s\n               WHERE c.department = s.department AND c.name = s.course\n                 AND c.department = '{$dept}'\n                 AND s.quarter_season = {$season} AND s.quarter_year = {$year}\n                 AND s.status != 'deleted' AND c.status != 'deleted';";
            $result2 = $db->query($sql2)->fetch();
            $section_units = $result2[0];
            //find total number of TA units
            $sql2 = "SELECT sum(u.value)\n             FROM units u, ta t\n             WHERE u.sid = t.sid AND t.department = '{$dept}'\n               AND u.year = {$year} AND u.season = {$season};";
            $result2 = $db->query($sql2)->fetch();
            $ta_units = $result2[0];
            $p = ($section_units - $ta_units) / $phantom_units;
            if ($p > 0) {
                $phantomTA = $p;
            }
            //   return(array("error-message","You have $ta_units TA units and $section_units section units, so I think you need $phantomTA phantoms."));
            $added = 0;
        }
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    //we need to make a zpl file, then run it through SCIP, then parse that to get a csv.
    $cmd = "scip/chemfile scip/ta.csv scip/section.csv scip/pref.csv scip/input.zpl {$phantomTA} 3";
    exec($cmd, $output);
    $cmd = "scip/zimpl scip/input.zpl scip/chemobjective.zpl scip/constraints.zpl";
    exec($cmd, $output);
    $cmd = "scip/scipmip input.lp scip/scipmip.set > out.txt";
    exec($cmd, $output);
    $cmd = 'grep -F "x$" out.txt | wc -l';
    exec($cmd, $num);
    if ($num[0] == "0") {
        //infeasible. We should end if we hit the time limit, or else add more phantoms.
        $max_added = 3;
        $timeout = 0;
        $cmd = 'grep -F "time limit reached" out.txt | wc -l';
        exec($cmd, $r);
        if ($r[0] == "2") {
            $timeout = 1;
        }
        if ($added < $max_added) {
            run_scip($year, $season, $dept, $sname, $filename, $phantomTA + 1, $added + 1);
        } else {
            if ($timeout) {
                return array("error-message", "No matching available in this time limit.");
            } else {
                //give up and contact the master
                return array("error-message", "Matching is infeasible. Please contact Sam Asher at srasher@ucdavis.edu for debugging.");
            }
        }
    }
    //infeasible
    $cmd = "scip/inparser input.tbl out.txt {$filename}.csv";
    // $cmd = "scip/a.out input.tbl out.txt 2>&1";
    exec($cmd, $output);
    //  $cmd = "rm -f input.tbl input.lp Intermediate.txt test.csv";
    //  exec($cmd, $output);
}
Esempio n. 2
0
    header("Location:quarterstaff.php");
}
if (!isset($_SESSION['limit'])) {
    $_SESSION['limit'] = 5;
}
$filenamescip = 'csv/' . $_SESSION['season_name'] . '_' . $_SESSION['year'] . '_' . $_SESSION['dept'] . '_ip';
if (isset($_POST['generatescip'])) {
    $_SESSION['limit'] = $_POST['limit'];
    set_limit($_POST['limit'], 'scip/scipmip.set');
    //create csv files
    $status = scip_input($_SESSION['year'], $_SESSION['season'], $_SESSION['dept'], $_SESSION['season_name']);
    if (!isset($status)) {
        force_checks($_SESSION['dept'], $_SESSION['year'], $_SESSION['season']);
        make_constraints($_SESSION['year'], $_SESSION['season'], $_SESSION['dept']);
        //make zpl file, run through SCIP, get csv
        $status = run_scip($_SESSION['year'], $_SESSION['season'], $_SESSION['dept'], $_SESSION['season_name'], $filenamescip);
        if (!isset($status)) {
            scip_csv_append($filenamescip, $_SESSION['dept'], $_SESSION['year'], $_SESSION['season']);
            csv_xls($filenamescip);
            $_SESSION['scipfile2_exists'] = $_SESSION['season'];
        }
        //only run if no errors when running SCIP
    }
    //only run if no errors with input
}
if (isset($_GET['course'])) {
    $_SESSION['course'] = $_GET['course'];
}
if (isset($_GET['section'])) {
    $_SESSION['section'] = $_GET['section'];
}