Search in sources :

Example 1 with DataProperties

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

the class GetInfo method getInfoOfASolution.

public static HashMap<String, String> getInfoOfASolution(File file) {
    try {
        DataProperties properties = new DataProperties();
        properties.setProperty("General.Input", file.getPath());
        TimetableXMLLoader loader = new TimetableXMLLoader(new TimetableModel(properties), new DefaultSingleAssignment<Lecture, Placement>());
        loader.load();
        File newOutputFile = new File(file.getParentFile(), "new-output.csv");
        Test.saveOutputCSV(new Solution<Lecture, Placement>(loader.getModel(), loader.getAssignment()), newOutputFile);
        Progress.removeInstance(loader.getModel());
        System.out.println("  Reading " + newOutputFile + " ...");
        HashMap<String, String> info = getInfo(newOutputFile);
        File outputFile = new File(file.getParentFile(), "output.csv");
        if (outputFile.exists()) {
            System.out.println("  Reading " + outputFile + " ...");
            HashMap<String, String> info2 = getInfo(outputFile);
            if (info2.containsKey("000.002 Time [sec]"))
                info.put("000.002 Time [sec]", info2.get("000.002 Time [sec]"));
        }
        return info;
    } catch (Exception e) {
        System.err.println("Error reading info, message: " + e.getMessage());
        e.printStackTrace();
        return null;
    }
}
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) File(java.io.File) CSVFile(org.cpsolver.ifs.util.CSVFile)

Example 2 with DataProperties

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

the class GroupConstraint method setModel.

@Override
public void setModel(Model<Lecture, Placement> model) {
    super.setModel(model);
    if (model != null) {
        DataProperties config = ((TimetableModel) model).getProperties();
        iDayOfWeekOffset = config.getPropertyInt("DatePattern.DayOfWeekOffset", 0);
        iPrecedenceConsiderDatePatterns = config.getPropertyBoolean("Precedence.ConsiderDatePatterns", true);
        iForwardCheckMaxDepth = config.getPropertyInt("ForwardCheck.MaxDepth", iForwardCheckMaxDepth);
        iForwardCheckMaxDomainSize = config.getPropertyInt("ForwardCheck.MaxDomainSize", iForwardCheckMaxDomainSize);
        iMaxNHoursADayConsiderDatePatterns = config.getPropertyBoolean("MaxNHoursADay.ConsiderDatePatterns", iMaxNHoursADayConsiderDatePatterns);
        iNrWorkDays = (config.getPropertyInt("General.LastWorkDay", 4) - config.getPropertyInt("General.FirstWorkDay", 0) + 1);
        if (iNrWorkDays <= 0)
            iNrWorkDays += 7;
        if (iNrWorkDays > 7)
            iNrWorkDays -= 7;
        iFirstWorkDay = config.getPropertyInt("General.FirstWorkDay", 0);
    }
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 3 with DataProperties

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

the class JenrlConstraint method setModel.

@Override
public void setModel(Model<Lecture, Placement> model) {
    super.setModel(model);
    if (model != null && model instanceof TimetableModel) {
        DataProperties config = ((TimetableModel) model).getProperties();
        iJenrlMaxConflicts = config.getPropertyDouble("General.JenrlMaxConflicts", 1.0);
        iJenrlMaxConflictsWeaken = config.getPropertyDouble("General.JenrlMaxConflictsWeaken", 0.001);
    }
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 4 with DataProperties

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

the class RoomConstraint method setModel.

@Override
public void setModel(Model<Lecture, Placement> model) {
    super.setModel(model);
    if (model != null) {
        DataProperties config = ((TimetableModel) model).getProperties();
        iDayOfWeekOffset = config.getPropertyInt("DatePattern.DayOfWeekOffset", 0);
    }
}
Also used : DataProperties(org.cpsolver.ifs.util.DataProperties) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 5 with DataProperties

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

the class Test method main.

/**
 * Main program
 *
 * @param args
 *            problem property file, input file (optional, may be set by
 *            General.Input property), output file (optional, may be set by
 *            General.OutputFile property)
 */
public static void main(String[] args) {
    try {
        DataProperties cfg = new DataProperties();
        cfg.setProperty("Termination.StopWhenComplete", "false");
        cfg.setProperty("Termination.TimeOut", "1800");
        cfg.setProperty("General.SaveBestUnassigned", "-1");
        cfg.setProperty("Neighbour.Class", "org.cpsolver.exam.heuristics.ExamNeighbourSelection");
        if (args.length >= 1) {
            cfg.load(new FileInputStream(args[0]));
            cfg.setProperty("General.Config", new File(args[0]).getName());
        }
        cfg.putAll(System.getProperties());
        File inputFile = new File("c:\\test\\exam\\exam1070.xml");
        if (args.length >= 2) {
            inputFile = new File(args[1]);
        }
        ToolBox.setSeed(cfg.getPropertyLong("General.Seed", Math.round(Long.MAX_VALUE * Math.random())));
        cfg.setProperty("General.Input", inputFile.toString());
        String outName = inputFile.getName();
        if (outName.indexOf('.') >= 0)
            outName = outName.substring(0, outName.lastIndexOf('.')) + "s.xml";
        File outFile = new File(inputFile.getParentFile(), outName);
        if (args.length >= 3) {
            outFile = new File(args[2]);
            if (outFile.exists() && outFile.isDirectory())
                outFile = new File(outFile, outName);
            if (!outFile.exists() && !outFile.getName().endsWith(".xml"))
                outFile = new File(outFile, outName);
        }
        if (outFile.getParentFile() != null)
            outFile.getParentFile().mkdirs();
        cfg.setProperty("General.OutputFile", outFile.toString());
        cfg.setProperty("General.Output", outFile.getParent());
        String logName = outFile.getName();
        if (logName.indexOf('.') >= 0)
            logName = logName.substring(0, logName.lastIndexOf('.')) + ".log";
        ToolBox.setupLogging(new File(outFile.getParent(), logName), "true".equals(System.getProperty("debug", "false")));
        ExamModel model = new ExamModel(cfg);
        Document document = (new SAXReader()).read(new File(cfg.getProperty("General.Input")));
        int nrSolvers = cfg.getPropertyInt("Parallel.NrSolvers", 1);
        Assignment<Exam, ExamPlacement> assignment = (nrSolvers <= 1 ? new DefaultSingleAssignment<Exam, ExamPlacement>() : new DefaultParallelAssignment<Exam, ExamPlacement>());
        model.load(document, assignment);
        Solver<Exam, ExamPlacement> solver = (nrSolvers == 1 ? new Solver<Exam, ExamPlacement>(cfg) : new ParallelSolver<Exam, ExamPlacement>(cfg));
        solver.setInitalSolution(new Solution<Exam, ExamPlacement>(model, assignment));
        solver.currentSolution().addSolutionListener(new SolutionListener<Exam, ExamPlacement>() {

            @Override
            public void solutionUpdated(Solution<Exam, ExamPlacement> solution) {
            }

            @Override
            public void getInfo(Solution<Exam, ExamPlacement> solution, Map<String, String> info) {
            }

            @Override
            public void getInfo(Solution<Exam, ExamPlacement> solution, Map<String, String> info, Collection<Exam> variables) {
            }

            @Override
            public void bestCleared(Solution<Exam, ExamPlacement> solution) {
            }

            @Override
            public void bestSaved(Solution<Exam, ExamPlacement> solution) {
                ExamModel m = (ExamModel) solution.getModel();
                Assignment<Exam, ExamPlacement> a = solution.getAssignment();
                if (sLog.isInfoEnabled()) {
                    sLog.info("**BEST[" + solution.getIteration() + "]** " + (m.variables().size() > a.nrAssignedVariables() ? "V:" + a.nrAssignedVariables() + "/" + m.variables().size() + " - " : "") + "T:" + new DecimalFormat("0.00").format(m.getTotalValue(a)) + " " + m.toString(a) + (solution.getFailedIterations() > 0 ? ", F:" + sDoubleFormat.format(100.0 * solution.getFailedIterations() / solution.getIteration()) + "%" : ""));
                }
            }

            @Override
            public void bestRestored(Solution<Exam, ExamPlacement> solution) {
            }
        });
        Runtime.getRuntime().addShutdownHook(new ShutdownHook(solver));
        solver.start();
        try {
            solver.getSolverThread().join();
        } catch (InterruptedException e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Solver(org.cpsolver.ifs.solver.Solver) ParallelSolver(org.cpsolver.ifs.solver.ParallelSolver) DefaultParallelAssignment(org.cpsolver.ifs.assignment.DefaultParallelAssignment) ExamModel(org.cpsolver.exam.model.ExamModel) SAXReader(org.dom4j.io.SAXReader) DecimalFormat(java.text.DecimalFormat) DataProperties(org.cpsolver.ifs.util.DataProperties) Document(org.dom4j.Document) DefaultParallelAssignment(org.cpsolver.ifs.assignment.DefaultParallelAssignment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Assignment(org.cpsolver.ifs.assignment.Assignment) ExamStudentConflictsPerExam(org.cpsolver.exam.reports.ExamStudentConflictsPerExam) Exam(org.cpsolver.exam.model.Exam) ParallelSolver(org.cpsolver.ifs.solver.ParallelSolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File)

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