具有多个来源的Optaplanner阴影变量 [英] Optaplanner shadow variable with more than one source

查看:290
本文介绍了具有多个来源的Optaplanner阴影变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Optaplanner允许阴影变量具有多个源(sources = {}),但只有一个variableListsnerClass.在我的实现中,我有一个带有阴影变量的计划实体,该影子实体应该可以由两个列表员进行更改,但这似乎不被支持,或者我错了吗?有没有办法让两个侦听器影响一个阴影变量?

Optaplanner allows for a shadow variable to have more than one source (sources = {}) but only one variableListsnerClass. In my implementation i have a planning entity with shadow variables that should be able to change by two listsners, but this is not supported it seems or am i wrong? is there a way to have two listeners affect one shadow variable?

我有以下计划实体:PlannerActivity,PlannerTask和PlannerTaskResourceAllocation.

I have the following planning entities: PlannerActivity, PlannerTask and PlannerTaskResourceAllocation.

ActivityStartIndexVariableListener侦听PlannerActivity startIndex(真正的var)上的任何更改,它会在属于该活动的所有任务上移动startindex(阴影var)和endIndex(阴影var).这很好

Any change on a PlannerActivity startIndex (genuine var) is listened to by the ActivityStartIndexVariableListener which moves the startindex (shadow var) and endIndex (shadow var) on all tasks belonging to that activity. this works fine

除此之外,TaskResourceVariableListener会侦听PlannerTaskResourceAllocation资源(geniune var)上的任何更改,并且当该资源是产品时,还更新该产品的ohHandAmounts,这也可以很好地工作.

In addition to that, any change on a PlannerTaskResourceAllocation resource (geniune var), is listened to by TaskResourceVariableListener, and when the resource is a product, also updates the ohHandAmounts for that product, this also works fine.

我的问题是我需要添加逻辑,当在PlannerTaskResourceAllocation上更改资源并且该资源是设​​备时,我可能需要重新计算任务持续时间,因为新设备的速度可能比以前慢或快之前分配的. 所以我在这里需要的是PlannerActivity和PlannerTask的startIndex和endIndex应该也可以由TaskResourceVariableListener进行更改,但是它们已经被列出了. ActivityStartIndexVariableListener,我无法为一个阴影变量指定两个侦听器.

The problem i have is that i need to add logic that when a resource is changed on a PlannerTaskResourceAllocation and that resource is an equipment, i need to possibly recalculate the task duration is the new equipment might be slower or faster than what was assigned before. so what i need here is that the PlannerActivity and PlannerTask startIndex and endIndex should be able to be changed by the TaskResourceVariableListener as well, but they are already listed to by the ActivityStartIndexVariableListener, and there's no way for me to specify two listeners for one shadow variable.

PlannerTask:

PlannerTask:

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;
}
}

推荐答案

variableListenerRef属性支持此功能:第一个阴影变量具有普通的阴影变量批注,第二个阴影变量使用<指向第一个阴影变量c1>

This is supported with the variableListenerRef attribute: the first shadow variable has a normal shadow variable annotation and the second shadow variable points to the first shadow variable with @CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "firstShadow"))

例如,一个变量侦听器会更改基于2个真实变量的2个阴影变量:

For example, 1 variable listener that changes 2 shadow variables that is based on 2 genuine variables:

@PlanningVariable(valueRangeProviderRefs = "valueRange")
public TestdataValue getPrimaryValue() {
    return primaryValue;
}

public void setPrimaryValue(TestdataValue primaryValue) {
    this.primaryValue = primaryValue;
}

@PlanningVariable(valueRangeProviderRefs = "valueRange")
public TestdataValue getSecondaryValue() {
    return secondaryValue;
}

public void setSecondaryValue(TestdataValue secondaryValue) {
    this.secondaryValue = secondaryValue;
}

@CustomShadowVariable(variableListenerClass = ComposedValuesUpdatingVariableListener.class,
        sources = {@CustomShadowVariable.Source(variableName = "primaryValue"),
                @CustomShadowVariable.Source(variableName = "secondaryValue")})
public String getComposedCode() {
    return composedCode;
}

public void setComposedCode(String composedCode) {
    this.composedCode = composedCode;
}

@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "composedCode"))
public String getReverseComposedCode() {
    return reverseComposedCode;
}

public void setReverseComposedCode(String reverseComposedCode) {
    this.reverseComposedCode = reverseComposedCode;
}

这篇关于具有多个来源的Optaplanner阴影变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆