问题描述
我开始使用Optaplanner并想使用Maven/Spring Boot扩展其时间表问题的示例-现在,我希望有多个学生组应该参加特定课程-我的计划中保存了这些变量为List<StudentGroupFact> studentGroupFacts
(见下文)。
我正在将讲座分配给插槽和房间,插槽基本上是一天/小时的唯一组合。 (请参阅下面的我的计划实体LecturePlanning
)
现在,我将在ConstraintProvider中制定以下约束:
private Constraint studentGroupConflict(ConstraintFactory constraintFactory) {
return constraintFactory.from(LecturePlanning.class)
.join(LecturePlanning.class,Joiners.equal(LecturePlanning::getLectureSlot),Joiners.equal(LecturePlanning::getAssignedStudentGroups),Joiners.greaterThan(LecturePlanning::getLectureID))
.penalize("Student Group Conflict",HardSoftscore.ONE_HARD);
}
应该比较我的LecturePlanning
对象(基本上是讲课),以便对是否分配了某个演讲会导致StudentGroup
列表中的AssignedStudentGroups
进行惩罚)需要同时访问两个课程。
如果AssignedStudentGroups
列表中有交集,但它们不相等,这当然会失败-遗憾的是,我没有找到解决此问题的方法,而且我还没有看到类似教程-有人可以帮我这个忙吗?
计划实体:
@PlanningEntity
public class LecturePlanning {
private int lectureID;
private String lectureName;
private int requiredRoomType;
private int numberOfRoomsParallel;
private boolean onlyTutors;
private List<LecturerFact> lecturerFacts;
private List<StudentGroupFact> assignedStudentGroups;
@PlanningVariable(valueRangeProviderRefs = "lectureSlotRange")
private LectureSlotFact lectureSlot;
@PlanningVariable(valueRangeProviderRefs = "roomrange")
private RoomFact room;
//..
}
The Constraint Provider class (currently full impl. - includes the snippet at the beginning of this post):
public class ScheduleConstraintProvider implements ConstraintProvider {
@Override
public Constraint[] defineConstraints(ConstraintFactory constraintFactory) {
return new Constraint[] {
roomConflict(constraintFactory),teacherConflict(constraintFactory),studentGroupConflict(constraintFactory)
};
}
private Constraint roomConflict(ConstraintFactory constraintFactory) {
return constraintFactory.from(LecturePlanning.class)
.join(LecturePlanning.class,Joiners.equal(LecturePlanning::getRoom),Joiners.greaterThan(LecturePlanning::getLectureID))
.penalize("Room Conflict",HardSoftscore.ONE_HARD);
}
private Constraint teacherConflict(ConstraintFactory constraintFactory) {
return constraintFactory.from(LecturePlanning.class)
.join(LecturePlanning.class,Joiners.equal(LecturePlanning::getLecturerFacts),Joiners.greaterThan(LecturePlanning::getLectureID))
.penalize("Lecturer Conflict",HardSoftscore.ONE_HARD);
}
private Constraint studentGroupConflict(ConstraintFactory constraintFactory) {
return constraintFactory.from(LecturePlanning.class)
.join(LecturePlanning.class,Joiners.greaterThan(LecturePlanning::getLectureID))
.penalize("Student Group Conflict",HardSoftscore.ONE_HARD);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)