Search in sources :

Example 1 with StudentChoiceOrder

use of org.cpsolver.studentsct.heuristics.studentord.StudentChoiceOrder in project cpsolver by UniTime.

the class Test method run.

public void run() {
    sLog.info("Input: " + ToolBox.dict2string(model().getExtendedInfo(assignment()), 2));
    List<Student> students = new ArrayList<Student>(model().getStudents());
    String sort = System.getProperty("sort", "shuffle");
    if ("shuffle".equals(sort)) {
        Collections.shuffle(students);
    } else if ("choice".equals(sort)) {
        StudentChoiceOrder ord = new StudentChoiceOrder(model().getProperties());
        ord.setReverse(false);
        Collections.sort(students, ord);
    } else if ("referse".equals(sort)) {
        StudentChoiceOrder ord = new StudentChoiceOrder(model().getProperties());
        ord.setReverse(true);
        Collections.sort(students, ord);
    }
    Iterator<Student> iterator = students.iterator();
    int nrThreads = Integer.parseInt(System.getProperty("nrConcurrent", "10"));
    List<Executor> executors = new ArrayList<Executor>();
    for (int i = 0; i < nrThreads; i++) {
        Executor executor = new Executor(iterator);
        executor.start();
        executors.add(executor);
    }
    long t0 = System.currentTimeMillis();
    while (iterator.hasNext()) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
        }
        long time = System.currentTimeMillis() - t0;
        synchronized (iModel) {
            sLog.info("Progress [" + (time / 60000) + "m]: " + ToolBox.dict2string(model().getExtendedInfo(assignment()), 2));
        }
    }
    for (Executor executor : executors) {
        try {
            executor.join();
        } catch (InterruptedException e) {
        }
    }
    sLog.info("Output: " + ToolBox.dict2string(model().getExtendedInfo(assignment()), 2));
    long time = System.currentTimeMillis() - t0;
    inc("[T] Run Time [m]", time / 60000.0);
}
Also used : ArrayList(java.util.ArrayList) StudentChoiceOrder(org.cpsolver.studentsct.heuristics.studentord.StudentChoiceOrder) Student(org.cpsolver.studentsct.model.Student)

Aggregations

ArrayList (java.util.ArrayList)1 StudentChoiceOrder (org.cpsolver.studentsct.heuristics.studentord.StudentChoiceOrder)1 Student (org.cpsolver.studentsct.model.Student)1