Search in sources :

Example 6 with DataProperties

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

the class StudentSwapSectioning method switchStudents.

@Override
public void switchStudents(Solution<Lecture, Placement> solution, TerminationCondition<Lecture, Placement> termination) {
    long it = 0, lastImp = 0;
    double t0 = JProf.currentTimeMillis();
    DataProperties cfg = ((TimetableModel) solution.getModel()).getProperties();
    long maxIdle = cfg.getPropertyInt("StudentSwaps.MaxIdle", 100000);
    getProgress().setStatus("Student Sectioning...");
    getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
    getProgress().setPhase("Swapping students [HC]...", 1000);
    StudentSwapGenerator g = new StudentSwapGenerator();
    while ((it - lastImp) < maxIdle && (termination == null || termination.canContinue(solution))) {
        it++;
        if ((it % 1000) == 0) {
            long prg = Math.round(1000.0 * (it - lastImp) / maxIdle);
            if (getProgress().getProgress() < prg)
                getProgress().setProgress(prg);
            if ((it % 10000) == 0)
                getProgress().info("Iter=" + (it / 1000) + "k, Idle=" + sDF2.format((it - lastImp) / 1000.0) + "k, Speed=" + sDF2.format(1000.0 * it / (JProf.currentTimeMillis() - t0)) + " it/s" + ", Value=" + sDF2.format(value(solution)) + ", Objective=" + sDF2.format(objective(solution)) + ", Group=" + sDF2.format(gp(solution)) + "%");
        }
        Neighbour<Lecture, Placement> n = g.selectNeighbour(solution);
        if (n == null)
            continue;
        double v = value(n, solution.getAssignment());
        if (v < -sEps) {
            lastImp = it;
        }
        if (v <= 0) {
            n.assign(solution.getAssignment(), it);
        }
    }
    getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
    double f = cfg.getPropertyDouble("StudentSwaps.Deluge.Factor", 0.9999999);
    double ub = cfg.getPropertyDouble("StudentSwaps.Deluge.UpperBound", 1.10);
    double lb = cfg.getPropertyDouble("StudentSwaps.Deluge.LowerBound", 0.90);
    double total = value(solution);
    double bound = ub * total;
    double best = total;
    it = 0;
    lastImp = 0;
    t0 = JProf.currentTimeMillis();
    getProgress().setPhase("Swapping students [GD]...", 1000);
    while (bound > lb * total && total > 0 && (termination == null || termination.canContinue(solution))) {
        Neighbour<Lecture, Placement> n = g.selectNeighbour(solution);
        if (n != null) {
            double value = value(n, solution.getAssignment());
            if (value < 0) {
                lastImp = it;
            }
            if (value <= 0.0 || total + value < bound) {
                n.assign(solution.getAssignment(), it);
                if (total + value < best) {
                    best = total + value;
                }
                total += value;
            }
        }
        bound *= f;
        it++;
        if ((it % 1000) == 0) {
            long prg = 1000 - Math.round(1000.0 * (bound - lb * best) / (ub * best - lb * best));
            if (getProgress().getProgress() < prg)
                getProgress().setProgress(prg);
            if ((it % 10000) == 0) {
                getProgress().info("Iter=" + (it / 1000) + "k, Idle=" + sDF2.format((it - lastImp) / 1000.0) + "k, Speed=" + sDF2.format(1000.0 * it / (JProf.currentTimeMillis() - t0)) + " it/s" + ", Value=" + sDF2.format(value(solution)) + ", Objective=" + sDF2.format(objective(solution)) + ", Group=" + sDF2.format(gp(solution)) + "%");
                getProgress().info("Bound is " + sDF2.format(bound) + ", " + "best value is " + sDF2.format(best) + " (" + sDF2.format(100.0 * bound / best) + "%), " + "current value is " + sDF2.format(total) + " (" + sDF2.format(100.0 * bound / total) + "%)");
            }
        }
    }
    getProgress().info("Student Conflicts: " + sDF2.format(objective(solution)) + " (group: " + sDF2.format(gp(solution)) + "%)");
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) DataProperties(org.cpsolver.ifs.util.DataProperties) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 7 with DataProperties

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

the class TimetableModel method main.

public static void main(String[] args) {
    try {
        // Configure logging
        ToolBox.configureLogging();
        // Load properties (take first argument as input file, containing key=value lines)
        DataProperties properties = new DataProperties();
        properties.load(new FileInputStream(args[0]));
        // Generate model
        Assignment<Activity, Location> assignment = new DefaultSingleAssignment<Activity, Location>();
        TimetableModel model = TimetableModel.generate(new DataProperties(), assignment);
        System.out.println(model.getInfo(assignment));
        // Save solution (take second argument as output file)
        model.saveAsXML(properties, true, new Solution<Activity, Location>(model, assignment), assignment, new File(args[1]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File) FileInputStream(java.io.FileInputStream) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException)

Example 8 with DataProperties

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

the class Test method test.

public 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 outDirThisTest = (outDir == null ? properties.getProperty("General.Output", ".") : outDir) + File.separator + name + File.separator + sDateFormat.format(new Date());
        properties.setProperty("General.Output", outDirThisTest.toString());
        System.out.println("Output folder: " + properties.getProperty("General.Output"));
        (new File(outDirThisTest)).mkdirs();
        ToolBox.configureLogging(outDirThisTest, null);
        FileOutputStream fos = new FileOutputStream(outDirThisTest + File.separator + "rcsp.conf");
        properties.store(fos, "Random CSP problem configuration file");
        fos.flush();
        fos.close();
        test2(properties);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) FileOutputStream(java.io.FileOutputStream) DataProperties(org.cpsolver.ifs.util.DataProperties) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date)

Example 9 with DataProperties

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

the class Test method main.

public static void main(String[] args) {
    try {
        Progress.getInstance().addProgressListener(new ProgressWriter(System.out));
        if (args.length == 0) {
            ToolBox.configureLogging();
            DataProperties config = new DataProperties(System.getProperties());
            config.setProperty("Termination.StopWhenComplete", "false");
            config.setProperty("Termination.TimeOut", "60");
            config.setProperty("General.Output", System.getProperty("user.dir"));
            test2(config);
            return;
        }
        File inputCfg = new File(args[0]);
        DataProperties properties = ToolBox.loadProperties(inputCfg);
        if (args.length == 3) {
            File xmlFile = new File(args[1]);
            String outDir = args[2] + File.separator + (sDateFormat.format(new Date()));
            properties.setProperty("General.Output", outDir.toString());
            System.out.println("Input file: " + xmlFile);
            System.out.println("Output folder: " + properties.getProperty("General.Output"));
            (new File(outDir)).mkdirs();
            ToolBox.configureLogging(outDir, null);
            test3(properties, xmlFile);
        } else if (properties.getProperty("INCLUDE_REGEXP") != null) {
            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()));
            properties.setProperty("General.Output", outDir.toString());
            System.out.println("Output folder: " + properties.getProperty("General.Output"));
            (new File(outDir)).mkdirs();
            ToolBox.configureLogging(outDir, null);
            test2(properties);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ProgressWriter(org.cpsolver.ifs.util.ProgressWriter) DataProperties(org.cpsolver.ifs.util.DataProperties) File(java.io.File) Date(java.util.Date)

Example 10 with DataProperties

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

the class Test method main.

public static void main(String[] args) throws Exception {
    ToolBox.configureLogging();
    DataProperties config = new DataProperties();
    if (System.getProperty("config") == null) {
        config.load(Test.class.getClass().getResourceAsStream("/org/cpsolver/instructor/default.properties"));
    } else {
        config.load(new FileInputStream(System.getProperty("config")));
    }
    config.putAll(System.getProperties());
    new Test(config).execute();
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) FileInputStream(java.io.FileInputStream)

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