use of org.cpsolver.studentsct.model.Student 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);
}
use of org.cpsolver.studentsct.model.Student in project cpsolver by UniTime.
the class StudentRandomRealFirstOrder method order.
/**
* Return the given set of students in a random order, however, all real
* students before last-like ({@link Student#isDummy()} is true) students.
**/
@Override
public List<Student> order(List<Student> students) {
List<Student> real = new ArrayList<Student>(students.size());
List<Student> dummy = new ArrayList<Student>(students.size());
for (Student student : students) {
if (student.isDummy())
dummy.add(student);
else
real.add(student);
}
Collections.shuffle(dummy);
Collections.shuffle(real);
dummy.addAll(real);
return dummy;
}
use of org.cpsolver.studentsct.model.Student in project cpsolver by UniTime.
the class PriorityConstructionSelection method branchAndBound.
/**
* Find best solution for the next student using {@link BranchBoundSelection}.
* @param solution current selection
* @return generated neighbour
*/
public Neighbour<Request, Enrollment> branchAndBound(Solution<Request, Enrollment> solution) {
while (iStudentsEnumeration.hasNext()) {
Student student = iStudentsEnumeration.next();
Progress.getInstance(solution.getModel()).incProgress();
/*
if (student.nrRequests() < iCycle) {
// not enough requests -> nothing to improve -> skip
continue;
}
if (student.nrAssignedRequests() + 1 < iCycle) {
// previous step cycle already did not improve the assignment -> skip
continue;
}
*/
Neighbour<Request, Enrollment> neighbour = iBranchBoundSelection.getSelection(solution.getAssignment(), student).select();
if (neighbour != null)
return neighbour;
}
return null;
}
use of org.cpsolver.studentsct.model.Student in project cpsolver by UniTime.
the class RndUnProblStudSelection method selectNeighbour.
/**
* With the given probabilty, a problematic student is randomly selected to
* be unassigned. Null is returned otherwise.
*/
@Override
public synchronized Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
if (!iProblemStudents.isEmpty() && Math.random() < iRandom) {
Student student = ToolBox.random(iProblemStudents);
iProblemStudents.remove(student);
return new UnassignStudentNeighbour(student, solution.getAssignment());
}
Progress.getInstance(solution.getModel()).incProgress();
return null;
}
use of org.cpsolver.studentsct.model.Student in project cpsolver by UniTime.
the class Test method loadCrsReqFiles.
/**
* Load course request from the given files (in the format being used by the
* old MSF system)
*
* @param model
* student sectioning model (with offerings loaded)
* @param files
* semi-colon separated list of files to be loaded
*/
public static void loadCrsReqFiles(StudentSectioningModel model, String files) {
try {
boolean lastLike = model.getProperties().getPropertyBoolean("Test.CrsReqIsLastLike", true);
boolean shuffleIds = model.getProperties().getPropertyBoolean("Test.CrsReqShuffleStudentIds", true);
boolean tryWithoutSuffix = model.getProperties().getPropertyBoolean("Test.CrsReqTryWithoutSuffix", false);
HashMap<Long, Student> students = new HashMap<Long, Student>();
long reqId = 0;
for (StringTokenizer stk = new StringTokenizer(files, ";"); stk.hasMoreTokens(); ) {
String file = stk.nextToken();
sLog.debug("Loading " + file + " ...");
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
int lineIndex = 0;
while ((line = in.readLine()) != null) {
lineIndex++;
if (line.length() <= 150)
continue;
char code = line.charAt(13);
if (code == 'H' || code == 'T')
// skip header and tail
continue;
long studentId = Long.parseLong(line.substring(14, 23));
Student student = students.get(new Long(studentId));
if (student == null) {
student = new Student(studentId);
if (lastLike)
student.setDummy(true);
students.put(new Long(studentId), student);
sLog.debug(" -- loading student " + studentId + " ...");
} else
sLog.debug(" -- updating student " + studentId + " ...");
line = line.substring(150);
while (line.length() >= 20) {
String subjectArea = line.substring(0, 4).trim();
String courseNbr = line.substring(4, 8).trim();
if (subjectArea.length() == 0 || courseNbr.length() == 0) {
line = line.substring(20);
continue;
}
/*
* // UNUSED String instrSel = line.substring(8,10);
* //ZZ - Remove previous instructor selection char
* reqPDiv = line.charAt(10); //P - Personal preference;
* C - Conflict resolution; //0 - (Zero) used by program
* only, for change requests to reschedule division //
* (used to reschedule canceled division) String reqDiv
* = line.substring(11,13); //00 - Reschedule division
* String reqSect = line.substring(13,15); //Contains
* designator for designator-required courses String
* credit = line.substring(15,19); char nameRaise =
* line.charAt(19); //N - Name raise
*/
// A - Add; D - Drop; C -
char action = line.charAt(19);
// Change
sLog.debug(" -- requesting " + subjectArea + " " + courseNbr + " (action:" + action + ") ...");
Course course = null;
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbr)) {
course = c;
break offerings;
}
}
}
if (course == null && tryWithoutSuffix && courseNbr.charAt(courseNbr.length() - 1) >= 'A' && courseNbr.charAt(courseNbr.length() - 1) <= 'Z') {
String courseNbrNoSfx = courseNbr.substring(0, courseNbr.length() - 1);
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbrNoSfx)) {
course = c;
break offerings;
}
}
}
}
if (course == null) {
if (courseNbr.charAt(courseNbr.length() - 1) >= 'A' && courseNbr.charAt(courseNbr.length() - 1) <= 'Z') {
} else {
sLog.warn(" -- course " + subjectArea + " " + courseNbr + " not found (file " + file + ", line " + lineIndex + ")");
}
} else {
CourseRequest courseRequest = null;
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest && ((CourseRequest) request).getCourses().contains(course)) {
courseRequest = (CourseRequest) request;
break;
}
}
if (action == 'A') {
if (courseRequest == null) {
List<Course> courses = new ArrayList<Course>(1);
courses.add(course);
courseRequest = new CourseRequest(reqId++, student.getRequests().size(), false, student, courses, false, null);
} else {
sLog.warn(" -- request for course " + course + " is already present");
}
} else if (action == 'D') {
if (courseRequest == null) {
sLog.warn(" -- request for course " + course + " is not present -- cannot be dropped");
} else {
student.getRequests().remove(courseRequest);
}
} else if (action == 'C') {
if (courseRequest == null) {
sLog.warn(" -- request for course " + course + " is not present -- cannot be changed");
} else {
// ?
}
} else {
sLog.warn(" -- unknown action " + action);
}
}
line = line.substring(20);
}
}
in.close();
}
HashMap<Course, List<Request>> requests = new HashMap<Course, List<Request>>();
Set<Long> studentIds = new HashSet<Long>();
for (Student student : students.values()) {
if (!student.getRequests().isEmpty())
model.addStudent(student);
if (shuffleIds) {
long newId = -1;
while (true) {
newId = 1 + (long) (999999999L * Math.random());
if (studentIds.add(new Long(newId)))
break;
}
student.setId(newId);
}
if (student.isDummy()) {
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
Course course = ((CourseRequest) request).getCourses().get(0);
List<Request> requestsThisCourse = requests.get(course);
if (requestsThisCourse == null) {
requestsThisCourse = new ArrayList<Request>();
requests.put(course, requestsThisCourse);
}
requestsThisCourse.add(request);
}
}
}
}
Collections.sort(model.getStudents(), new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
return Double.compare(o1.getId(), o2.getId());
}
});
for (Map.Entry<Course, List<Request>> entry : requests.entrySet()) {
Course course = entry.getKey();
List<Request> requestsThisCourse = entry.getValue();
double weight = getLastLikeStudentWeight(course, 0, requestsThisCourse.size());
for (Request request : requestsThisCourse) {
request.setWeight(weight);
}
}
if (model.getProperties().getProperty("Test.EtrChk") != null) {
for (StringTokenizer stk = new StringTokenizer(model.getProperties().getProperty("Test.EtrChk"), ";"); stk.hasMoreTokens(); ) {
String file = stk.nextToken();
sLog.debug("Loading " + file + " ...");
BufferedReader in = new BufferedReader(new FileReader(file));
try {
String line;
while ((line = in.readLine()) != null) {
if (line.length() < 55)
continue;
char code = line.charAt(12);
if (code == 'H' || code == 'T')
// skip header and tail
continue;
if (code == 'D' || code == 'K')
// skip delete nad cancel
continue;
long studentId = Long.parseLong(line.substring(2, 11));
Student student = students.get(new Long(studentId));
if (student == null) {
sLog.info(" -- student " + studentId + " not found");
continue;
}
sLog.info(" -- reading student " + studentId);
String area = line.substring(15, 18).trim();
if (area.length() == 0)
continue;
String clasf = line.substring(18, 20).trim();
String major = line.substring(21, 24).trim();
String minor = line.substring(24, 27).trim();
student.getAcademicAreaClasiffications().clear();
student.getMajors().clear();
student.getMinors().clear();
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(area, clasf));
if (major.length() > 0)
student.getMajors().add(new AcademicAreaCode(area, major));
if (minor.length() > 0)
student.getMinors().add(new AcademicAreaCode(area, minor));
}
} finally {
in.close();
}
}
}
int without = 0;
for (Student student : students.values()) {
if (student.getAcademicAreaClasiffications().isEmpty())
without++;
}
fixPriorities(model);
sLog.info("Students without academic area: " + without);
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
Aggregations