如何解决如何在计划变量的列表属性中将相交定义为Optaplanner约束?
我开始使用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 举报,一经查实,本站将立刻删除。