本文整理汇总了Java中org.cpsolver.ifs.assignment.Assignment类的典型用法代码示例。如果您正苦于以下问题:Java Assignment类的具体用法?Java Assignment怎么用?Java Assignment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Assignment类属于org.cpsolver.ifs.assignment包,在下文中一共展示了Assignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: XStudent
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public XStudent(org.cpsolver.studentsct.model.Student student, Assignment<Request, Enrollment> assignment) {
super(student);
iStatus = student.getStatus();
iEmailTimeStamp = (student.getEmailTimeStamp() == null ? null : new Date(student.getEmailTimeStamp()));
for (AreaClassificationMajor acm: student.getAreaClassificationMajors()) {
iMajors.add(new XAreaClassificationMajor(acm.getArea(), acm.getClassification(), acm.getMajor()));
}
for (int i = 0; i < Math.min(student.getAcademicAreaClasiffications().size(), student.getMajors().size()); i++) {
iMajors.add(new XAreaClassificationMajor(student.getMajors().get(i).getArea(), student.getAcademicAreaClasiffications().get(i).getCode(), student.getMajors().get(i).getCode()));
}
for (AcademicAreaCode aac: student.getMinors()) {
if ("A".equals(aac.getArea()))
iAccomodations.add(aac.getCode());
else
iGroups.add(aac.getCode());
}
for (Request request: student.getRequests()) {
if (request instanceof FreeTimeRequest) {
iRequests.add(new XFreeTimeRequest((FreeTimeRequest)request));
} else if (request instanceof CourseRequest) {
iRequests.add(new XCourseRequest((CourseRequest)request, assignment == null ? null : assignment.getValue(request)));
}
}
}
示例2: getSection
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
protected Section getSection(TeachingClassRequest req) {
Class_ clazz = req.getTeachingClass();
CourseOffering course = clazz.getSchedulingSubpart().getControllingCourseOffering();
String room = null;
TimeLocation time = null;
org.unitime.timetable.model.Assignment assignment = clazz.getCommittedAssignment();
if (assignment != null) {
time = assignment.getTimeLocation();
for (Location location: assignment.getRooms()) {
if (room == null) room = location.getLabel();
else room += ", " + location.getLabel();
}
}
return new Section(clazz.getUniqueId(), getClassExternalId(course, clazz),
clazz.getSchedulingSubpart().getItypeDesc().trim(), clazz.getClassLabel(course),
time, room, req.isCanOverlap(), req.isCommon());
}
示例3: penalty
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public double penalty(Assignment<CurVariable, CurValue> assignment, CurStudent student) {
return penalty(assignment, student, null);
/*
if (student == null) return 0.0;
double penalty = 0;
for (CurCourse course: iModel.getCourses()) {
if (course.getCourseId().equals(getCourseId())) continue;
double target = getTargetShare(course.getCourseId());
double share = share(course);
boolean contains = course.getStudents().contains(student);
double size = course.getSize();
if (!getStudents().contains(student)) {
size += student.getWeight();
if (contains) share += student.getWeight();
}
if ((share < target && !contains) || (share > target && contains))
penalty += ((double)Math.abs(share - target)) / (contains ? share : size - share);
}
return penalty;
*/
}
示例4: computeConflicts
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
@Override
public void computeConflicts(Assignment<CurVariable, CurValue> assignment, CurValue value, Set<CurValue> conflicts) {
Set<CurCourse> courses = value.getStudent().getCourses(assignment);
int nrCourses = courses.size();
if (!courses.contains(value.variable().getCourse())) nrCourses++;
for (CurValue conflict: conflicts) {
if (conflict.getStudent().equals(value.getStudent()) && courses.contains(conflict.variable().getCourse()))
nrCourses--;
}
if (nrCourses > iMaxLimit) {
List<CurValue> adepts = new ArrayList<CurValue>();
for (CurCourse course: courses) {
if (course.equals(value.variable().getCourse())) continue;
CurValue adept = course.getValue(assignment, value.getStudent());
if (conflicts.contains(adept)) continue;
adepts.add(adept);
}
conflicts.add(ToolBox.random(adepts));
nrCourses --;
}
}
示例5: selectNeighbour
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
@Override
public Neighbour<CurVariable, CurValue> selectNeighbour(Solution<CurVariable, CurValue> solution) {
CurModel model = (CurModel)solution.getModel();
Assignment<CurVariable, CurValue> assignment = solution.getAssignment();
int ix = ToolBox.random(model.variables().size());
for (int i = 0; i < model.variables().size(); i++) {
CurVariable course = model.variables().get((ix + i) % model.variables().size());
CurValue current = assignment.getValue(course);
if (!course.getCourse().isComplete(assignment) && current != null) continue;
int jx = ToolBox.random(course.values(solution.getAssignment()).size());
if (current != null && current.getStudent().getCourses(assignment).size() <= model.getStudentLimit().getMinLimit()) continue;
for (int j = 0; j < course.values(solution.getAssignment()).size(); j++) {
CurValue student = course.values(solution.getAssignment()).get((j + jx) % course.values(solution.getAssignment()).size());
if (course.getCourse().getStudents(assignment).contains(student.getStudent())) continue;
if (student.getStudent().getCourses(assignment).size() >= model.getStudentLimit().getMaxLimit()) continue;
if (course.getCourse().getSize(assignment) + student.getStudent().getWeight() - (current == null ? 0.0 : current.getStudent().getWeight())
> course.getCourse().getMaxSize()) continue;
if (current != null && course.getCourse().getSize(assignment) + student.getStudent().getWeight() - current.getStudent().getWeight()
< course.getCourse().getMaxSize() - model.getMinStudentWidth()) continue;
return new CurSimpleAssignment(student);
}
}
return null;
}
示例6: naive
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public void naive(DataProperties cfg, Assignment<CurVariable, CurValue> assignment) {
int maxIdle = cfg.getPropertyInt("Curriculum.Naive.MaxIdle", 1000);
sLog.debug(" -- running naive");
int idle = 0, it = 0;
double best = getTotalValue(assignment);
CurStudentSwap sw = new CurStudentSwap(cfg);
Solution<CurVariable, CurValue> solution = new Solution<CurVariable, CurValue>(this, assignment);
while (!getSwapCourses().isEmpty() && idle < maxIdle && canContinue()) {
Neighbour<CurVariable, CurValue> n = sw.selectNeighbour(solution);
if (n == null) break;
double value = n.value(assignment);
if (value < -0.00001) {
idle = 0;
n.assign(assignment, it);
} else if (value <= 0.0) {
n.assign(assignment, it);
}
if (getTotalValue(assignment) < best) {
best = getTotalValue(assignment);
sLog.debug(" -- best value: " + toString(assignment));
}
it++; idle++;
}
sLog.debug(" -- final value: " + toString(assignment));
}
示例7: DeptBalancingGroup
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public DeptBalancingGroup(Solver solver, DepartmentSpreadConstraint deptSpread) {
Assignment<Lecture, Placement> assignment = solver.currentSolution().getAssignment();
iDeptId = deptSpread.getDepartmentId();
iDeptName = deptSpread.getName();
iLimit = new int[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
iUsage = new int[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
iCourses = new HashSet[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
Hashtable detailCache = new Hashtable();
SpreadConstraint.SpreadConstraintContext context = deptSpread.getContext(assignment);
for (int i=0;i<iLastDaySlot - iFirstDaySlot + 1;i++) {
for (int j=0;j<iLastWorkDay - iFirstWorkDay + 1;j++) {
iLimit[i][j]=context.getMaxCourses(i + iFirstDaySlot, j + iFirstWorkDay);
iUsage[i][j]=context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay).size();
iCourses[i][j]=new HashSet(context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay).size());
for (Placement placement: context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay)) {
Lecture lecture = (Lecture)placement.variable();
ClassAssignmentDetails ca = (ClassAssignmentDetails)detailCache.get(lecture.getClassId());
if (ca==null) {
ca = new ClassAssignmentDetails(solver, lecture, false);
detailCache.put(lecture.getClassId(),ca);
}
iCourses[i][j].add(ca);
}
}
}
}
示例8: SameSubpartBalancingGroup
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public SameSubpartBalancingGroup(Solver solver, SpreadConstraint spread) {
Assignment<Lecture, Placement> assignment = solver.currentSolution().getAssignment();
SpreadConstraint.SpreadConstraintContext context = spread.getContext(assignment);
iName = spread.getName();
iLimit = new int[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
iUsage = new int[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
iCourses = new HashSet[iLastDaySlot - iFirstDaySlot + 1][iLastWorkDay - iFirstWorkDay + 1];
Hashtable detailCache = new Hashtable();
for (int i=0;i<iLastDaySlot - iFirstDaySlot + 1;i++) {
for (int j=0;j<iLastWorkDay - iFirstWorkDay + 1;j++) {
iLimit[i][j]=context.getMaxCourses(i + iFirstDaySlot, j + iFirstWorkDay);
iUsage[i][j]=context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay).size();
iCourses[i][j]=new HashSet(context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay).size());
for (Placement placement: context.getCourses(i + iFirstDaySlot, j + iFirstWorkDay)) {
Lecture lecture = (Lecture)placement.variable();
ClassAssignmentDetails ca = (ClassAssignmentDetails)detailCache.get(lecture.getClassId());
if (ca==null) {
ca = new ClassAssignmentDetails(solver, lecture, false);
detailCache.put(lecture.getClassId(),ca);
}
iCourses[i][j].add(ca);
}
}
}
}
示例9: createModel
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public static TimetableGridModel createModel(TimetableSolver solver, DepartmentSpreadConstraint department, TimetableGridContext context) {
TimetableGridModel model = new TimetableGridModel(ResourceType.DEPARTMENT.ordinal(), department.getDepartmentId());
model.setName(department.getName());
model.setSize(department.variables().size());
model.setFirstDay(context.getFirstDay());
model.setFirstSessionDay(context.getFirstSessionDay());
model.setFirstDate(context.getFirstDate());
Assignment<Lecture, Placement> assignment = solver.currentSolution().getAssignment();
List<Placement> placements = new ArrayList<Placement>();
for (Lecture lecture: department.variables()) {
Placement placement = assignment.getValue(lecture);
if (placement != null)
placements.add(placement);
}
createCells(model, solver, placements, context, false);
return model;
}
示例10: ExamContext
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ExamContext(ExamModel model, Assignment<Exam, ExamPlacement> assignment) {
iStudentTable = new Map[model.getNrPeriods()];
for (int i = 0; i < iStudentTable.length; i++)
iStudentTable[i] = new HashMap<ExamStudent, Set<Exam>>();
iStudentDayTable = new Map[model.getNrDays()];
for (int i = 0; i < iStudentDayTable.length; i++)
iStudentDayTable[i] = new HashMap<ExamStudent, Set<Exam>>();
iInstructorTable = new Map[model.getNrPeriods()];
for (int i = 0; i < iInstructorTable.length; i++)
iInstructorTable[i] = new HashMap<ExamInstructor, Set<Exam>>();
iInstructorDayTable = new Map[model.getNrDays()];
for (int i = 0; i < iInstructorDayTable.length; i++)
iInstructorDayTable[i] = new HashMap<ExamInstructor, Set<Exam>>();
for (Exam exam: model.variables()) {
ExamPlacement placement = assignment.getValue(exam);
if (placement != null)
assigned(assignment, placement);
}
}
示例11: toString
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
/**
* String representation -- returns a list of values of objective criteria
* @param assignment current assignment
* @return comma separated string of {@link TimetablingCriterion#toString(Assignment)}
*/
public String toString(Assignment<V, T> assignment) {
List<Criterion<V, T>> criteria = new ArrayList<Criterion<V,T>>(getCriteria());
Collections.sort(criteria, new Comparator<Criterion<V, T>>() {
@Override
public int compare(Criterion<V, T> c1, Criterion<V, T> c2) {
int cmp = -Double.compare(c1.getWeight(), c2.getWeight());
if (cmp != 0) return cmp;
return c1.getName().compareTo(c2.getName());
}
});
String ret = "";
for (Criterion<V, T> criterion: criteria) {
String val = criterion.toString(assignment);
if (val != null && !val.isEmpty())
ret += ", " + val;
}
return (nrUnassignedVariables(assignment) == 0 ? "" : "V:" + nrAssignedVariables(assignment) + "/" + variables().size() + ", ") + "T:" + sDoubleFormat.format(getTotalValue(assignment)) + ret;
}
示例12: findRooms
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
public Set<ExamRoomPlacement> findRooms(Assignment<Exam, ExamPlacement> assignment, Exam exam, ExamPeriodPlacement period) {
Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
if (rooms != null) return rooms;
rooms = new HashSet<ExamRoomPlacement>();
int size = 0;
while (size < exam.getSize()) {
ExamRoomPlacement bestRoom = null; int bestSize = 0;
for (ExamRoomPlacement r: exam.getRoomPlacements()) {
if (!r.isAvailable(period.getPeriod())) continue;
if (rooms.contains(r)) continue;
if (!r.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty()) continue;
int s = r.getSize(exam.hasAltSeating());
if (bestRoom == null || s > bestSize) {
bestRoom = r;
bestSize = s;
}
}
if (bestRoom == null) return rooms;
rooms.add(bestRoom); size += bestSize;
}
return rooms;
}
示例13: getPenaltyIfUnassigned
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
private int getPenaltyIfUnassigned(Assignment<Lecture, Placement> assignment, Placement placement, int[][] nrCourses) {
SpreadConstraintContext context = getContext(assignment);
int firstSlot = placement.getTimeLocation().getStartSlot();
if (firstSlot > iLastDaySlot)
return 0;
int endSlot = firstSlot + placement.getTimeLocation().getNrSlotsPerMeeting() - 1;
if (endSlot < iFirstDaySlot)
return 0;
int penalty = 0;
for (int i = Math.max(firstSlot, iFirstDaySlot); i <= Math.min(endSlot, iLastDaySlot); i++) {
for (int j = iFirstWorkDay; j <= iLastWorkDay; j++) {
int dayCode = Constants.DAY_CODES[j % 7];
if ((dayCode & placement.getTimeLocation().getDayCode()) != 0 && nrCourses[i - iFirstDaySlot][j - iFirstWorkDay] > context.getMaxCourses(i, j))
penalty++;
}
}
return penalty;
}
示例14: restoreBest
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
@Override
public void restoreBest(Assignment<Request, Enrollment> assignment) {
restoreBest(assignment, new Comparator<Request>() {
@Override
public int compare(Request r1, Request r2) {
Enrollment e1 = r1.getBestAssignment();
Enrollment e2 = r2.getBestAssignment();
// Reservations first
if (e1.getReservation() != null && e2.getReservation() == null) return -1;
if (e1.getReservation() == null && e2.getReservation() != null) return 1;
// Then assignment iteration (i.e., order in which assignments were made)
if (r1.getBestAssignmentIteration() != r2.getBestAssignmentIteration())
return (r1.getBestAssignmentIteration() < r2.getBestAssignmentIteration() ? -1 : 1);
// Then student and priority
return r1.compareTo(r2);
}
});
}
示例15: accept
import org.cpsolver.ifs.assignment.Assignment; //导入依赖的package包/类
/**
* True if the given neighboir is to be be accepted
*
* @param solution
* current solution
* @param neighbour
* proposed move
* @return true if generated random number is below
* {@link ExamSimulatedAnnealing.Context#prob(double)}
*/
protected boolean accept(Solution<Exam, ExamPlacement> solution, Neighbour<Exam, ExamPlacement> neighbour) {
if (neighbour instanceof LazyNeighbour) {
((LazyNeighbour<Exam, ExamPlacement>)neighbour).setAcceptanceCriterion(this);
return true;
}
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
double value = (iRelativeAcceptance ? neighbour.value(assignment) : solution.getModel().getTotalValue(assignment) + neighbour.value(assignment) - solution.getBestValue());
Context context = getContext(solution.getAssignment());
double prob = context.prob(value);
if (prob >= 1.0 || ToolBox.random() < prob) {
context.accepted(neighbour.value(assignment));
return true;
}
return false;
}