Optaplanner는 쉐도우 변수가 둘 이상의 소스 (sources = {})를 가질 수 있지만 하나의 variableListsnerClass 만 허용합니다. 내 구현에서 나는 두 listsners에 의해 변경할 수 있어야 그림자 변수와 계획 엔티티가 있지만 이것은 지원되지 않는 것 같아요 아니면 내가 잘못 됐어? 두 명의 리스너가 하나의 그림자 변수에 영향을 미치게하는 방법이 있습니까?두 개 이상의 소스가있는 Optaplanner 쉐도우 변수
다음 계획 엔티티가 있습니다. PlannerActivity, PlannerTask 및 PlannerTaskResourceAllocation.
PlannerActivity startIndex (정품 var)의 변경 사항은 해당 활동에 속한 모든 작업의 startindex (shadow var) 및 endIndex (shadow var)를 이동시키는 ActivityStartIndexVariableListener에 의해 청취됩니다. 이게 잘 작동합니다.
PlannerTaskResourceAllocation 리소스 (geniune var)의 모든 변경 사항은 TaskResourceVariableListener에 의해 수신되고 리소스가 제품 일 때 해당 제품의 ohHandAmounts도 업데이트됩니다.
내가 가진 문제는 리소스가 PlannerTaskResourceAllocation에서 리소스가 변경되고 리소스가 장비 인 경우 논리를 추가해야한다는 것입니다. 작업 기간을 새로 계산해야 할 수도 있습니다. 새 장비가 느리고 빠를 수도 있습니다. 이전에 배정되었습니다. 그래서 여기에 PlannerActivity 및 PlannerTask startIndex 및 endIndex가 TaskResourceVariableListener에 의해 변경 될 수 있어야하지만, 이미 ActivityStartIndexVariableListener에 의해 나열되어 있고 둘 중 하나의 수신기를 지정하는 방법이 없습니다. 그림자 변수.
PlannerTask :이
variableListenerRef
속성 지원
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;
}
}
이 문제는 해결되지 않습니다. 명확히하기 위해 계획 엔티티 중 하나는 다른 유형의 다른 두 개의 실제 변수로 변경할 수 있어야하는 계획 변수가 있으므로 두 개의 다른 리스너가 필요하므로 하나의 리스너를 두 개 지정할 수 있어야합니다. 그림자 변수 –
당신은 그저 복합 리스너를 만들 수 있습니까? 명확한 예제로 질문을 업데이트하십시오. 왜냐하면 제가 커버하지 않은 유스 케이스를 보지 못하기 때문입니다. –
나는 질문을 편집하고 계획 엔티티를 입력했습니다. 인터페이스가 인수로 한 유형 만 허용하는 경우 어떻게 복합 변수 수신기를 만들 수 있습니까? 어떻게 두 개의 계획 엔티티를 청취하는 리스너를 만들 수 있습니까? 귀하의 예제에서 두 정품 변수는 동일한 엔티티에 있지만 두 개의 엔티티에 있습니다. –