use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class StudentMoreThan1ADayConflicts method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
int ret = 0;
ExamModel m = (ExamModel) getModel();
Set<Integer> days = new HashSet<Integer>();
for (ExamPeriod p : m.getPeriods()) {
if (days.add(p.getDay())) {
Map<ExamStudent, Set<Exam>> students = ((ExamModel) getModel()).getStudentsOfDay(assignment, p);
for (Set<Exam> exams : students.values()) {
int nrExams = exams.size();
if (nrExams > 1)
ret += nrExams - 1;
}
}
}
return ret;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamHillClimbing method selectNeighbour.
/**
* Select one of the given neighbourhoods randomly, select neighbour, return
* it if its value is below or equal to zero (continue with the next
* selection otherwise). Return null when the given number of idle
* iterations is reached.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
Context context = getContext(solution.getAssignment());
context.activateIfNeeded();
while (true) {
if (context.incIter(solution))
break;
NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
if (n != null) {
if (n instanceof LazyNeighbour) {
((LazyNeighbour<Exam, ExamPlacement>) n).setAcceptanceCriterion(this);
return n;
} else if (n.value(solution.getAssignment()) <= 0.0)
return n;
}
}
context.reset();
return null;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamUnassignedVariableSelection method selectVariable.
/**
* Variable selection
*/
@Override
public Exam selectVariable(Solution<Exam, ExamPlacement> solution) {
ExamModel model = (ExamModel) solution.getModel();
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
if (model.variables().size() == assignment.nrAssignedVariables())
return null;
if (iRandomSelection) {
int idx = ToolBox.random(model.variables().size() - assignment.nrAssignedVariables());
for (Exam v : model.variables()) {
if (assignment.getValue(v) != null)
continue;
if (idx == 0)
return v;
idx--;
}
}
Exam variable = null;
for (Exam v : model.variables()) {
if (assignment.getValue(v) != null)
continue;
if (variable == null || v.compareTo(variable) < 0)
variable = v;
}
return variable;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class MistaTables method main.
public static void main(String[] args) {
try {
ToolBox.configureLogging();
DataProperties config = new DataProperties();
Table[] tables = new Table[] { new Problems(), new Rooms() };
for (int i = 0; i < args.length; i++) {
File file = new File(args[i]);
sLog.info("Loading " + file);
ExamModel model = new ExamModel(config);
Assignment<Exam, ExamPlacement> assignment = new DefaultSingleAssignment<Exam, ExamPlacement>();
model.load(new SAXReader().read(file), assignment);
String name = file.getName();
if (name.contains("."))
name = name.substring(0, name.indexOf('.'));
for (Table table : tables) table.add(name, model);
Progress.removeInstance(model);
}
sLog.info("Saving tables...");
File output = new File("tables");
output.mkdir();
for (Table table : tables) table.save(output);
sLog.info("All done.");
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class DistributionPenalty method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
int penalty = 0;
Set<ExamDistributionConstraint> added = new HashSet<ExamDistributionConstraint>();
for (Exam exam : variables) {
for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
if (added.add(dc)) {
if (dc.isHard() || (iSoftDistributions != null && iSoftDistributions == dc.getWeight()))
continue;
if (!dc.isSatisfied(assignment))
penalty += dc.getWeight();
}
}
}
return penalty;
}
Aggregations