【发布时间】:2016-07-01 09:20:48
【问题描述】:
Optaplanner 允许影子变量有多个源(sources = {}),但只有一个 variableListsnerClass。在我的实现中,我有一个带有阴影变量的计划实体,应该能够由两个列表器更改,但这似乎不受支持,还是我错了?有没有办法让两个监听器影响一个影子变量?
我有以下计划实体:PlannerActivity、PlannerTask 和 PlannerTaskResourceAllocation。
ActivityStartIndexVariableListener 会监听 PlannerActivity startIndex(真正的 var)上的任何更改,它会在属于该活动的所有任务上移动 startindex(shadow var)和 endIndex(shadow var)。这很好用
除此之外,对 PlannerTaskResourceAllocation 资源 (geniune var) 的任何更改都会被 TaskResourceVariableListener 监听,并且当资源是产品时,还会更新该产品的 ohHandAmounts,这也可以正常工作。
我遇到的问题是我需要添加逻辑,即当在 PlannerTaskResourceAllocation 上更改资源并且该资源是设备时,我可能需要重新计算任务持续时间,因为新设备可能比原来的设备更慢或更快之前分配的。 所以我在这里需要的是 PlannerActivity 和 PlannerTask startIndex 和 endIndex 也应该能够被 TaskResourceVariableListener 更改,但它们已经被 ActivityStartIndexVariableListener,我无法为一个影子变量指定两个监听器。
public class PlannerTask extends InventoryTransactionCause {
private static final long serialVersionUID = 1L;
@Getter
@Setter
private Activity activity;
@Getter
@Setter
private Integer indexInActivity;
// shadow variable
private Integer startIndex;
@Getter
@Setter
private double startOffset;
// shadow variable
private Integer length;
// shadow variable
private Integer endIndex;
@Getter
@Setter
private double endOffset;
@Getter
@Setter
private Integer originalStartIndex;
@Getter
@Setter
private Integer originalEndIndex;
@Getter
@Setter
private String state;
// getters and setters for shadow variables
// this is one of the shadow variables that i need affected by two
// listeners, one is the ActivityStartIndexVariableListener and the
// other is TaskResourceVariableListener
@CustomShadowVariable(variableListenerClass = ActivityStartIndexVariableListener.class,
sources = { @CustomShadowVariable.Source(entityClass = PlannerActivity.class, variableName = "endIndex"),
@CustomShadowVariable.Source(entityClass = PlannerTaskResourceAllocation.class,
variableName = "resource") })
public Integer getStartIndex() {
return this.startIndex;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
@CustomShadowVariable(variableListenerClass = ActivityStartIndexVariableListener.class,
sources = { @CustomShadowVariable.Source(entityClass = PlannerActivity.class, variableName = "endIndex"),
@CustomShadowVariable.Source(entityClass = PlannerTaskResourceAllocation.class,
variableName = "resource") })
public Integer getEndIndex() {
return this.endIndex;
}
public void setEndIndex(Integer endIndex) {
this.endIndex = endIndex;
}
@CustomShadowVariable(variableListenerClass = TaskResourceVariableListener.class,
sources = { @CustomShadowVariable.Source(entityClass = PlannerTaskResourceAllocation.class,
variableName = "resource") })
public Integer getLength() {
return this.length;
}
public void setLength(Integer length) {
this.length = length;
}
}
【问题讨论】:
标签: optaplanner