Optaplanner with Hibernate - 某些 DRL 规则不起作用



我正在使用Optaplanner申请员工排班。没有坚持,一切都很好。现在,我想添加Hibernate集成。 我想从MySQL数据库中获取信息并将其用作计划输入。

在数据库中,我有位置技能表。

员工数据、时隙分配现在已在应用程序中硬编码。

我的域类,技能

import javax.persistence.*;
@Entity
@Table(name = "SKILL")
public class Skill {
private long skillId;
private String name;
public Skill(String name) {
this.name = name;
}
public Skill() {}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "SKILL_ID")
public long getSkillId() {
return this.skillId;
}
public void setSkillId(long skillId) {
this.skillId = skillId;
}
@Column(name = "SKILL_NAME", nullable = false, length=250)
public String getSkillName() {
return this.name;
}
public void setSkillName(String skillName) {
this.name = skillName;
}
@Override
public String toString() {
return name;
}
}

职位

import javax.persistence.*;
@Entity
@Table(name = "POSITION")
public class Position {
private long positionId;
private String name;
private Skill requiredSkill;
public Position(String name, Skill requiredSkill) {
this.name = name;
this.requiredSkill = requiredSkill;
}
public Position() {}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "POSITION_ID")
public long getPositionId() {
return this.positionId;
}
public void setPositionId(long positionId) {
this.positionId = positionId;
}
@Column(name="POSITION_NAME", nullable=false, length = 100)
public String getPositionName() {
return this.name;
}
public void setPositionName(String positionName) {
this.name = positionName;
}
@OneToOne(cascade = CascadeType.ALL)
public Skill getRequiredSkill() {
return this.requiredSkill;
}
public void setRequiredSkill(Skill requiredSkill) {
this.requiredSkill = requiredSkill;
}
@Override
public String toString() {
return name;
}
}

不起作用的规则:

rule "Employee works only on positions with skills he has"
when
Assignment(
employee != null,
!getEmployee().getSkillSet().contains(getPosition().getRequiredSkill()))
then
scoreHolder.addHardConstraintMatch(kcontext, -100);
end

我认为数据库还可以,因为其中的数据是以前使用此应用程序创建的。另外,我还有另一个有效的DRL规则。我没有收到任何警告/错误 - 只是在解决过程中不考虑上述规则。

在求解过程中,我得到:

08:40:11.453 [main] DEBUG org.drools.core.common.DefaultAgenda - State was INACTIVE is now FIRING_ALL_RULES
08:40:11.453 [main] DEBUG org.drools.core.common.DefaultAgenda - State was FIRING_ALL_RULES is now HALTING
08:40:11.453 [main] DEBUG org.drools.core.common.DefaultAgenda - State was HALTING is now INACTIVE
08:40:11.453 [main] DEBUG org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase -     CH step (1), time spent (134), score (-14init/-202hard/0soft), selected move count (7), picked move (domain.Assignment@4d354a3e {null -> domain.Employee@1511d157}).

另外,一开始我收到此警告:

Failed to add the foreign key constraint. Missing index for constraint 'FKqx7n7alhjrnaw173dc48i47y0' in the referenced table 'skill'

看看我们如何在optaweb-employee-rostering中添加JPA-hibernate持久性。

具体来说,对Shift类的乐观锁定提供了一个挑战,我们像这样解决了这个问题。

相关内容

最新更新