具有多个源的 Optaplanner 影子变量

2024-01-17

Optaplanner 允许影子变量拥有多个源 (sources = {}),但只有一个variableListsnerClass。在我的实现中,我有一个带有影子变量的规划实体,应该能够由两个列表器更改,但这似乎不受支持,还是我错了?有没有办法让两个监听器影响一个影子变量?

我有以下计划实体:PlannerActivity、PlannerTask 和 PlannerTaskResourceAllocation。

PlannerActivity startIndex (genuine var) 上的任何更改都会由 ActivityStartIndexVariableListener 侦听,该监听器会移动属于该活动的所有任务上的 startIndex (shadow var) 和 endIndex (shadow var)。这很好用

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

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

uml 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属性:第一个影子变量有一个普通的影子变量注释,第二个影子变量指向第一个影子变量@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "firstShadow"))

例如,1 个变量侦听器更改基于 2 个真实变量的 2 个影子变量:

@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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

具有多个源的 Optaplanner 影子变量 的相关文章

随机推荐

  • Android SQLite数据库:插入速度慢

    我需要解析一个相当大的 XML 文件 大约一百千字节到几百千字节 我正在使用Xml parse String ContentHandler 我目前正在使用 152KB 文件对此进行测试 在解析过程中 我还使用类似于以下的调用将数据插入 SQ
  • Magento 自定义模块如何在 config.xml 中存储变量

    我有一个工作正常的自定义模块 但我希望能够在配置中存储变量 以便我可以在代码中使用它们 例如默认错误消息 我想我可以通过使用 Mage getStoreConfig some path here 来访问它们但我不知道如何将它们添加到模块 c
  • 将 CString 转换为字符串 (VC6)

    我想将 CString 转换为字符串 是的 我知道我在做什么 我知道如果 CString 值范围超出 ANSI 返回的字符串将不正确 但没关系 以下代码在VC2008下可以运行 std string Utils CString2String
  • 是否有可以包含资源的受支持文件类型列表?

    我正在寻找可以包含资源并可以通过以下方式加载的文件类型列表LoadLibrary http msdn microsoft com en us library windows desktop ms684175 28v vs 85 29 asp
  • python内置列表的__init__方法下面的初始化过程是什么

    我的问题是init列表类的方法调用其他方法 例如append或insert 来实现其功能 like class test list def init self values super init def append self value
  • 具有 Circe 实现的通用 json 解码器特征 [重复]

    这个问题在这里已经有答案了 我有一个用于将 json 解码器注入为项目组件依赖项的特征 trait JsonDecoder def apply T s String Option T 当我尝试用它来实现它时Circe https circe
  • 从 Xerces 获取架构数据类型

    我在 Xerces C 中使用 SAX2 并且希望在处理元素时获取 XML 架构数据 以便了解架构中定义的类型 我怎样才能做到这一点 好吧 我知道该怎么做了 关于该主题的可用文档很少 显然 我需要将 XMLReaderFactory cre
  • Rust - 调用内部值方法的枚举方法

    我有一个如下的枚举 enum Foo A X B Y C Z 其中 X Y 和 Z 是实现该方法的结构体bar 我希望能够定义一个方法bar on the Fooenum 以便调用其内部值对应的方法 现在我有这个 impl Foo pub
  • 在 extjs 中扩展电子邮件验证

    我在 ExtJs 6 0 1 250 版本中内置了以下用户注册表单 我有一个接受电子邮件字段 co com直到四个字 我需要处理最近的事情tlds并想要覆盖电子邮件验证逻辑 我尝试过validator并应用正则表达式但是regexText不
  • 更改 TableView 上 UISearchBars 的宽度

    我需要在我的 tableView 中创建两个 UISearchBar 我希望它们在桌子顶部的宽度相等 并排 我创建了两个 UISearchBar 出口 并为它们创建了属性和分配 我发现很难将它们都放置 我的意思是适合 视图中 我只看到一个搜
  • 如何跳过“按回车键启动合并解析工具”并自动打开mergetool

    Git 要求按返回按钮一一打开每个冲突文件的合并工具 gt git mergetool Normal merge conflict for local modified file remote modified file Hit retur
  • Linux下无root权限如何获取CPU序列号

    在没有root权限的Linux Ubuntu 下如何获取CPU序列号 我尝试了 cpuid 命令 它无需 root 权限即可工作 但似乎返回全零 我相信是因为需要在 BIOS 中更改某些内容 您能否建议我另一种从程序中检索 CPU 序列号的
  • 如何向 Google 表单添加登录信息以供用户填写

    我一直在网上阅读和观看许多教程 但我找不到可以最初使用单个输入文本加载某种对话框或登录页面的内容 这样我就可以使用应用程序脚本对其进行处理 onFormOpen 不会在完成表单的用户上触发 在我的 onSubmitForm 函数中 我有以下
  • 处理 Pylab 导入错误未定义符号

    我已经成功安装并从我的主目录调用 matplotlib myname sysimm51 python Python 2 7 6 default Nov 11 2013 13 13 15 GCC 4 4 7 20120313 Red Hat
  • 如何在 libcurl 中禁用 Expect 100 continue

    我正在使用 CURLOPT POST 发送 https 消息 在运行过程中 我的应用程序停留在 期望 100 继续 完成等待 100 继续 From 乔治的日志 当curl发送100 继续时 https gms tf when curl s
  • 如何在 Swift 中将字符串(数字)转换为 Int 数组

    我想知道如何在 Swift 中将 String 转换为 Int 数组 在Java中我总是这样做 String myString 123456789 int myArray new int myString lenght for int i
  • 无法在 Google Chrome 中获取 JSON 文件? [复制]

    这个问题在这里已经有答案了 可能的重复 在 Chrome 中使用本地文件的 jQuery getJSON 问题 https stackoverflow com questions 2541949 problems with jquery g
  • webgl 中的多个对象

    我正在尝试将一些对象渲染到画布上 但我在理解哪些内容不起作用时遇到了一些困难 我目前正在构建两个对象 它们代表我想要渲染的两个网格 如果我创建一个网格 代码可以正常工作 所以我认为问题在于 当我构建两个或更多网格时 数据会被搞砸 这是网格数
  • 对于 FragmentStatePagerAdapter 创建的 Fragment,Fragment getView() 始终返回 null

    我读了很多关于片段的文章 发现其他人在检索片段视图时遇到问题 因为总是返回 null 但没有答案解决我的问题 我想做的是创建一个图片库 我有一个包含图像视图的片段 为了显示片段 我使用 android support v4 view Vie
  • 具有多个源的 Optaplanner 影子变量

    Optaplanner 允许影子变量拥有多个源 sources 但只有一个variableListsnerClass 在我的实现中 我有一个带有影子变量的规划实体 应该能够由两个列表器更改 但这似乎不受支持 还是我错了 有没有办法让两个监听