Search in sources :

Example 21 with DataProperties

use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.

the class Test method main.

/**
 * Main
 * @param args program arguments
 */
public static void main(String[] args) {
    try {
        DataProperties cfg = new DataProperties();
        cfg.setProperty("Termination.Class", "org.cpsolver.ifs.termination.GeneralTerminationCondition");
        cfg.setProperty("Termination.StopWhenComplete", "true");
        cfg.setProperty("Termination.TimeOut", "600");
        cfg.setProperty("Comparator.Class", "org.cpsolver.ifs.solution.GeneralSolutionComparator");
        // org.cpsolver.ifs.heuristics.GeneralValueSelection
        cfg.setProperty("Value.Class", "org.cpsolver.studentsct.heuristics.EnrollmentSelection");
        cfg.setProperty("Value.WeightConflicts", "1.0");
        cfg.setProperty("Value.WeightNrAssignments", "0.0");
        cfg.setProperty("Variable.Class", "org.cpsolver.ifs.heuristics.GeneralVariableSelection");
        cfg.setProperty("Neighbour.Class", "org.cpsolver.studentsct.heuristics.StudentSctNeighbourSelection");
        cfg.setProperty("General.SaveBestUnassigned", "0");
        cfg.setProperty("Extensions.Classes", "org.cpsolver.ifs.extension.ConflictStatistics;org.cpsolver.studentsct.extension.DistanceConflict" + ";org.cpsolver.studentsct.extension.TimeOverlapsCounter");
        cfg.setProperty("Data.Initiative", "puWestLafayetteTrdtn");
        cfg.setProperty("Data.Term", "Fal");
        cfg.setProperty("Data.Year", "2007");
        cfg.setProperty("General.Input", "pu-sectll-fal07-s.xml");
        if (args.length >= 1) {
            cfg.load(new FileInputStream(args[0]));
        }
        cfg.putAll(System.getProperties());
        if (args.length >= 2) {
            cfg.setProperty("General.Input", args[1]);
        }
        File outDir = null;
        if (args.length >= 3) {
            outDir = new File(args[2], sDateFormat.format(new Date()));
        } else if (cfg.getProperty("General.Output") != null) {
            outDir = new File(cfg.getProperty("General.Output", "."), sDateFormat.format(new Date()));
        } else {
            outDir = new File(System.getProperty("user.home", ".") + File.separator + "Sectioning-Test" + File.separator + (sDateFormat.format(new Date())));
        }
        outDir.mkdirs();
        ToolBox.setupLogging(new File(outDir, "debug.log"), "true".equals(System.getProperty("debug", "false")));
        cfg.setProperty("General.Output", outDir.getAbsolutePath());
        if (args.length >= 4 && "online".equals(args[3])) {
            onlineSectioning(cfg);
        } else if (args.length >= 4 && "simple".equals(args[3])) {
            cfg.setProperty("Sectioning.UseOnlinePenalties", "false");
            onlineSectioning(cfg);
        } else {
            batchSectioning(cfg);
        }
    } catch (Exception e) {
        sLog.error(e.getMessage(), e);
        e.printStackTrace();
    }
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) IOException(java.io.IOException)

Example 22 with DataProperties

use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.

the class Solution2Expectations method main.

public static void main(String[] args) {
    try {
        ToolBox.configureLogging();
        DataProperties config = new DataProperties();
        String command = args[0];
        if ("real2exp".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.load();
            sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            for (Student s : model.getStudents()) s.setDummy(true);
            model.computeOnlineSectioningInfos(assignment);
            for (Student s : model.getStudents()) s.setDummy(false);
            for (Request request : model.variables()) assignment.unassign(0, request);
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[2]));
            sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else if ("ll2exp".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.load();
            sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            model.computeOnlineSectioningInfos(assignment);
            for (Request request : model.variables()) assignment.unassign(0, request);
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[2]));
            sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else if ("students".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.setLoadStudents(false);
            loader.load();
            sLog.info("Loaded [1]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            StudentSectioningXMLLoader loder2 = new StudentSectioningXMLLoader(model, assignment);
            loder2.setInputFile(new File(args[2]));
            loder2.setLoadOfferings(false);
            loder2.setLoadStudents(true);
            loder2.load();
            sLog.info("Loaded [2]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[3]));
            sLog.info("Saved [3]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else {
            sLog.error("Unknown command: " + command);
        }
    } catch (Exception e) {
        sLog.error(e.getMessage(), e);
    }
}
Also used : Solver(org.cpsolver.ifs.solver.Solver) DataProperties(org.cpsolver.ifs.util.DataProperties) Request(org.cpsolver.studentsct.model.Request) Student(org.cpsolver.studentsct.model.Student) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Assignment(org.cpsolver.ifs.assignment.Assignment) Enrollment(org.cpsolver.studentsct.model.Enrollment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File) Solution(org.cpsolver.ifs.solution.Solution)

Example 23 with DataProperties

use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.

the class MathTest method main.

public static void main(String[] args) throws Exception {
    DataProperties config = new DataProperties();
    config.load(MathTest.class.getClass().getResourceAsStream("/org/cpsolver/instructor/test/math.properties"));
    config.putAll(System.getProperties());
    ToolBox.configureLogging();
    new MathTest(config).execute();
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties)

Example 24 with DataProperties

use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.

the class Test method test.

private static void test(File inputCfg, String name, String include, String regexp, String outDir) throws Exception {
    if (regexp != null) {
        String incFile;
        if (regexp.indexOf(';') > 0) {
            incFile = regexp.substring(0, regexp.indexOf(';'));
            regexp = regexp.substring(regexp.indexOf(';') + 1);
        } else {
            incFile = regexp;
            regexp = null;
        }
        if (incFile.startsWith("[") && incFile.endsWith("]")) {
            test(inputCfg, name, include, regexp, outDir);
            incFile = incFile.substring(1, incFile.length() - 1);
        }
        if (incFile.indexOf('{') >= 0 && incFile.indexOf('}') >= 0) {
            String prefix = incFile.substring(0, incFile.indexOf('{'));
            StringTokenizer middle = new StringTokenizer(incFile.substring(incFile.indexOf('{') + 1, incFile.indexOf('}')), "|");
            String sufix = incFile.substring(incFile.indexOf('}') + 1);
            while (middle.hasMoreTokens()) {
                String m = middle.nextToken();
                test(inputCfg, (name == null ? "" : name + "_") + m, (include == null ? "" : include + ";") + prefix + m + sufix, regexp, outDir);
            }
        } else {
            test(inputCfg, name, (include == null ? "" : include + ";") + incFile, regexp, outDir);
        }
    } else {
        DataProperties properties = ToolBox.loadProperties(inputCfg);
        StringTokenizer inc = new StringTokenizer(include, ";");
        while (inc.hasMoreTokens()) {
            String aFile = inc.nextToken();
            System.out.println("  Loading included file '" + aFile + "' ... ");
            FileInputStream is = null;
            if ((new File(aFile)).exists())
                is = new FileInputStream(aFile);
            if ((new File(inputCfg.getParent() + File.separator + aFile)).exists())
                is = new FileInputStream(inputCfg.getParent() + File.separator + aFile);
            if (is == null)
                System.err.println("Unable to find include file '" + aFile + "'.");
            properties.load(is);
            is.close();
        }
        String outDirTisTest = (outDir == null ? properties.getProperty("General.Output", ".") : outDir) + File.separator + name + File.separator + sDateFormat.format(new Date());
        properties.setProperty("General.Output", outDirTisTest.toString());
        System.out.println("Output folder: " + properties.getProperty("General.Output"));
        (new File(outDirTisTest)).mkdirs();
        ToolBox.configureLogging(outDirTisTest, null);
        FileOutputStream fos = new FileOutputStream(outDirTisTest + File.separator + "rcsp.conf");
        properties.store(fos, "Random CSP problem configuration file");
        fos.flush();
        fos.close();
        boolean mpp = properties.getPropertyBoolean("General.MPP", true);
        if (mpp)
            testMPP(properties);
        else
            test(properties);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) FileOutputStream(java.io.FileOutputStream) DataProperties(org.cpsolver.ifs.util.DataProperties) File(java.io.File) PrologFile(org.cpsolver.ifs.util.PrologFile) FileInputStream(java.io.FileInputStream) Date(java.util.Date)

Example 25 with DataProperties

use of org.cpsolver.ifs.util.DataProperties in project cpsolver by UniTime.

the class Test method main.

/**
 * RPP test.
 *
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {
    try {
        Progress.getInstance().addProgressListener(new ProgressWriter(System.out));
        File inputCfg = new File(args[0]);
        DataProperties properties = ToolBox.loadProperties(inputCfg);
        if (properties.getProperty("INCLUDE_REGEXP") != null) {
            if (args.length > 1)
                properties.setProperty("General.Output", args[1]);
            test(inputCfg, null, null, properties.getProperty("INCLUDE_REGEXP"), (args.length > 1 ? args[1] : null));
        } else {
            String outDir = properties.getProperty("General.Output", ".") + File.separator + inputCfg.getName().substring(0, inputCfg.getName().lastIndexOf('.')) + File.separator + sDateFormat.format(new Date());
            if (args.length > 1)
                outDir = args[1] + File.separator + (sDateFormat.format(new Date()));
            (new File(outDir)).mkdirs();
            properties.setProperty("General.Output", outDir.toString());
            System.out.println("Output folder: " + properties.getProperty("General.Output"));
            ToolBox.configureLogging(outDir, null);
            boolean mpp = properties.getPropertyBoolean("General.MPP", false);
            if (mpp)
                testMPP(properties);
            else
                test(properties);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ProgressWriter(org.cpsolver.ifs.util.ProgressWriter) DataProperties(org.cpsolver.ifs.util.DataProperties) File(java.io.File) PrologFile(org.cpsolver.ifs.util.PrologFile) Date(java.util.Date)

Aggregations

DataProperties (org.cpsolver.ifs.util.DataProperties)29 File (java.io.File)16 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)10 Enrollment (org.cpsolver.studentsct.model.Enrollment)9 Request (org.cpsolver.studentsct.model.Request)9 Date (java.util.Date)8 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)8 FileInputStream (java.io.FileInputStream)7 Placement (org.cpsolver.coursett.model.Placement)6 TimetableModel (org.cpsolver.coursett.model.TimetableModel)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Course (org.cpsolver.studentsct.model.Course)5 FileOutputStream (java.io.FileOutputStream)4 DecimalFormat (java.text.DecimalFormat)4 ProgressWriter (org.cpsolver.ifs.util.ProgressWriter)4 Section (org.cpsolver.studentsct.model.Section)4 Student (org.cpsolver.studentsct.model.Student)4 BitSet (java.util.BitSet)3 StringTokenizer (java.util.StringTokenizer)3