Exemplo n.º 1
0
    @Override
    public void unassigned(Assignment<CurVariable, CurValue> assignment, CurValue value) {
      iStudents.remove(value.getStudent());
      iSize -= value.getStudent().getWeight();
      value.getStudent().getCourses(assignment).remove(CurCourse.this);
      /*
      if (value.getStudent().getCourses().size() < ((CurModel)value.variable().getModel()).getStudentLimit().getMinLimit())
      	throw new RuntimeException("Student min limit breached for " + value.getStudent() + ".");
      	*/

    }
Exemplo n.º 2
0
 @Override
 public void assigned(Assignment<CurVariable, CurValue> assignment, CurValue value) {
   iStudents.add(value.getStudent());
   value.getStudent().getCourses(assignment).add(CurCourse.this);
   iSize += value.getStudent().getWeight();
   /*
   if (iSize > getMaxSize())
   	throw new RuntimeException("Maximal number of students in a course exceeded " + "(" + iSize + " > " + getMaxSize() + ")");
   if (value.getStudent().getCourses().size() > ((CurModel)value.variable().getModel()).getStudentLimit().getMaxLimit())
   	throw new RuntimeException("Student max limit breached for " + value.getStudent() + " (" + value.getStudent().getCourses().size() + " > " + ((CurModel)value.variable().getModel()).getStudentLimit().getMaxLimit() + ".");
   	*/
 }
Exemplo n.º 3
0
 public CurValue getValue(Assignment<CurVariable, CurValue> assignment, CurStudent student) {
   for (CurVariable var : variables()) {
     CurValue val = assignment.getValue(var);
     if (val != null && val.getStudent().equals(student)) return val;
   }
   return null;
 }
Exemplo n.º 4
0
 public void computeConflicts(
     Assignment<CurVariable, CurValue> assignment, CurValue value, Set<CurValue> conflicts) {
   if (getSize(assignment) + value.getStudent().getWeight() > getMaxSize()) {
     double excess = getSize(assignment) + value.getStudent().getWeight() - getMaxSize();
     for (CurValue conf : conflicts)
       if (conf.variable().getCourse().equals(this)) excess -= conf.getStudent().getWeight();
     /*
     if (value.variable().getAssignment() != null && !conflicts.contains(value.variable().getAssignment()))
     	excess -= value.variable().getAssignment().getStudent().getWeight();
     	*/
     while (excess > 0.0) {
       List<CurValue> adepts = new ArrayList<CurValue>();
       double best = 0;
       for (CurVariable assigned : variables()) {
         if (assigned.equals(value.variable())) continue;
         CurValue adept = assignment.getValue(assigned);
         if (adept == null) continue;
         if (conflicts.contains(adept)) continue;
         double p = adept.toDouble(assignment);
         if (adepts.isEmpty() || p < best) {
           best = p;
           adepts.clear();
           adepts.add(adept);
         } else if (p == best) {
           adepts.add(adept);
         }
       }
       if (adepts.isEmpty()) {
         conflicts.add(value);
         break;
       }
       CurValue conf = ToolBox.random(adepts);
       conflicts.add(conf);
       excess -= conf.getStudent().getWeight();
     }
   }
   if (getStudents(assignment).contains(value.getStudent()))
     for (CurVariable sc : variables()) {
       CurValue v = assignment.getValue(sc);
       if (v != null && v.getStudent().equals(value.getStudent())) {
         conflicts.add(v);
       }
     }
 }