Search in sources :

Example 11 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 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();
        test(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 12 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));
        File inputCfg = new File(args[0]);
        DataProperties properties = ToolBox.loadProperties(inputCfg);
        String outDir = properties.getProperty("General.Output", ".") + File.separator + inputCfg.getName().substring(0, inputCfg.getName().lastIndexOf('.')) + File.separator + sDateFormat.format(new Date());
        (new File(outDir)).mkdirs();
        properties.setProperty("General.Output", outDir.toString());
        ToolBox.configureLogging(outDir, null);
        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) Date(java.util.Date)

Example 13 with DataProperties

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

the class StudentRequestXml method main.

public static void main(String[] args) {
    try {
        ToolBox.configureLogging();
        StudentSectioningModel model = new StudentSectioningModel(new DataProperties());
        Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
        StudentSectioningXMLLoader xmlLoad = new StudentSectioningXMLLoader(model, assignment);
        xmlLoad.setInputFile(new File(args[0]));
        xmlLoad.load();
        Document document = exportModel(assignment, model);
        FileOutputStream fos = new FileOutputStream(new File(args[1]));
        (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document);
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) DataProperties(org.cpsolver.ifs.util.DataProperties) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 14 with DataProperties

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

the class StudentSctBBTest method getSolution.

/**
 * Compute and return the sectioning solution. It contains only the given
 * student with his/her schedule
 * @return current solution
 */
public Solution<Request, Enrollment> getSolution() {
    if (iSolution == null) {
        iSolution = new Solution<Request, Enrollment>(this, new DefaultSingleAssignment<Request, Enrollment>());
        BranchBoundSelection.Selection selection = new BranchBoundSelection(new DataProperties()).getSelection(iSolution.getAssignment(), getStudent());
        Neighbour<Request, Enrollment> neighbour = selection.select();
        if (neighbour != null)
            neighbour.assign(iSolution.getAssignment(), 0);
        iTime = selection.getTime();
        iTimeoutReached = selection.isTimeoutReached();
    }
    return iSolution;
}
Also used : BranchBoundSelection(org.cpsolver.studentsct.heuristics.selection.BranchBoundSelection) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) DataProperties(org.cpsolver.ifs.util.DataProperties) Enrollment(org.cpsolver.studentsct.model.Enrollment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment)

Example 15 with DataProperties

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

the class ChmTest method main.

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

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