Red Hat Process Automation Manager 入门


Red Hat Process Automation Manager 7.12

摘要

本文档论述了如何在 Red Hat Process Automation Manager 中使用决策服务、流程服务和规划解决方案。

前言

作为业务决策和流程的开发人员,您可以使用红帽流程自动化管理器来利用各种可用资产开发决策服务和流程服务。您还可以使用红帽构建的 OptaPlanner 来查找根据一组有限资源和特定限制规划问题的最佳解决方案。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。详情请查看 CTO Chris Wright 信息

作为业务规则开发人员,您可以在红帽流程自动化管理器或 VS Code 中的红帽流程自动化管理器 DMN 模型程序中使用 Business Central 来设计各种决策服务。Red Hat Process Automation Manager 为示例项目提供在 Business Central 中直接获得商业资产的示例,作为参考。本文档论述了如何基于 Business Central 中包含的 Traffic_Violation 示例项目创建和测试流量违反项目示例。此示例项目使用 Decision Model 和 Notation (DMN)模型在流量违反决策服务中定义驱动程序损失和暂停规则。您可以按照本文档中的步骤创建项目及其包含的资产,或者打开并查看现有的 Traffic_Violation 示例项目。

有关 Red Hat Process Automation Manager 中的 DMN 组件和实施的更多信息,请参阅使用 DMN 模型设计决策服务

先决条件

Business Central 包含示例项目,您可以使用这些资产作为您在您自己的红帽流程自动化管理器项目中创建的规则、流程或其他资产的引用。每个示例项目都通过不同的设计来演示红帽流程自动化、决策管理或业务优化资产和逻辑。

注意

红帽不支持 Red Hat Process Automation Manager 发行版中包含的示例代码。

Business Central 中提供了以下示例项目:

  • course_Scheduling :(业务优化)课程安排和课程决策流程.为房间分配讲座,并根据课程冲突和课堂房间容量等因素确定学员的课程。
  • Dinner_Party :(业务优化)使用指导决策表优化客户机。根据客户机的作业类型、策略以及已知关系分配客户机席位。
  • Employee_Rostering: (业务优化)使用决策和解决者资产来增强优化。为员工提供基于技能的转变。
  • Evaluation_Process: (处理自动化)使用业务流程资产的评估流程。根据性能评估员工。
  • IT_Orders :(处理自动化和案例管理)使用业务流程和案例排序。根据需求和批准放置 IT 硬件订单。
  • 抵制 处理:(规则决策管理)使用基于规则的决策资产的批准流程。根据适用范围数据和资格确定出不满意。
  • Mortgage_Process: (处理自动化)使用业务流程和决策资产进行循环审批流程。根据适用范围数据和资格确定出不满意。
  • OptaCloud :(业务优化)使用决策和解决资产进行资源分配优化。为具有有限资源的计算机分配进程。
  • 流量_Violation :(通过 DMN 决策管理)使用决策模型和符号(DMN)模型进行流量违反决策服务。根据流量违反情况决定驱动损失和挂起。

您可以使用 Business Central 中的示例项目来探索业务资产,作为您在您自己的红帽流程自动化管理器项目中创建的规则或其他资产的参考。

先决条件

流程

  1. 在 Business Central 中,前往 MenuDesignProjects。如果存在现有项目,您可以点击 MySpace 默认空间,然后从 Add Project 下拉菜单中选择 Try Samples 来访问示例。如果没有现有项目,请单击 Try samples
  2. 查看每个示例项目的描述,以确定您要探索的项目。每个示例项目都通过不同的设计来演示红帽流程自动化、决策管理或业务优化资产和逻辑。
  3. 选择一个或多个示例项目,然后点 Ok 将项目添加到您的空间。
  4. 在空格的 Projects 页面中,选择一个示例项目来查看该项目的资产。
  5. 选择每个资产来探索项目如何实现指定目标或工作流。一些示例项目包含多个资产页面。点击右上角的左或向右箭头查看完整的资产列表。

    图 1.1. 资产页面选择

  6. 在项目 资产 页面的右上角,单击 Build 以构建示例项目或 Deploy 以构建项目,然后将其部署到 KIE Server。

    注意

    您还可以选择 Build & Install 选项来构建项目,并将 KJAR 文件发布到配置的 Maven 存储库,而无需部署到 KIE 服务器。在开发环境中,您可以点击 Deploy 将构建的 KJAR 文件部署到 KIE 服务器,而无需停止任何正在运行的实例(如果适用),或者点击 Redeploy 部署构建的 KJAR 文件并替换所有实例。下次部署或重新部署构建的 KJAR 时,以前的部署单元(KIE 容器)会在同一目标 KIE 服务器中自动更新。在生产环境中,Redeploy 选项被禁用,您可以点 Deploy only 将构建的 KJAR 文件部署到 KIE 服务器上的新部署单元(KIE 容器)。

    要配置 KIE 服务器环境模式,请将 org.kie.server.mode 系统属性设置为 org.kie.server.mode=developmentorg.kie.server.mode=production。要在 Business Central 中配置对应项目的部署行为,请转至 Project SettingsGeneral SettingsVersion,切换 Development Mode 选项,然后点 Save。默认情况下,KIE 服务器和 Business Central 中的所有新项目都处于开发模式中。您不能部署打开 Development 模式 的项目,或使用手动将 SNAPSHOT 版本后缀添加到生产模式的 KIE 服务器中。

    要查看项目部署详情,请单击屏幕顶部的部署横幅中的 View deployment details,或者在 Deploy 下拉菜单中。这个选项将您定向到 MenuDeployExecution Servers 页面。

Red Hat Process Automation Manager 提供以下扩展或应用程序,您可以使用它们设计业务流程模型和符号(BPMN)流程模型和决策模型和使用图形模型(DMN)决策模型。

  • Business Central :使您能够在相关的嵌入式设计人员中查看和设计 BPMN 模型、DMN 模型和测试场景文件。

    要使用 Business Central,您可以设置一个包含 Business Central 的开发环境,以设计业务规则和流程,以及一个 KIE 服务器来执行并测试所创建的业务规则和流程。

  • Red Hat Process Automation Manager VS Code 扩展 :允许您在 Visual Studio Code (VS Code)中查看和设计简单模型、DMN 模型和测试场景文件。VS Code 扩展需要 VS Code 1.46.0 或更高版本。

    要安装 Red Hat Process Automation Manager VS Code 扩展,请在 VS Code 中选择 Extensions 菜单选项,搜索并安装 Red Hat Business Automation Bundle 扩展。

  • 独立 BPMN 和 DMN 编辑器 :使您能够查看并设计嵌入在 web 应用程序中的 BPMN 和 DMN 模型。要下载所需的文件,您可以使用 NPM registry 中的 NPM 工件,或直接从 https://<YOUR_PAGE>/dmn/index.js(为 DMN独立编辑器库)或从 https://<YOUR_PAGE>/bpmn/index.js(为 BPMN 独立编辑器库)下载 JavaScript。

Red Hat Process Automation Manager 提供了一个 Red Hat Business Automation Bundle VS Code 扩展,它可让您在 VS Code 中设计决策模型和符号(DMN)决策模型、业务流程模型和符号(BPMN) 2.0 业务流程,并在 VS Code 中直接测试场景。VS Code 是开发新业务应用程序的首选集成开发环境(IDE)。Red Hat Process Automation Manager 还会根据需要为 DMNBPMN Editor VS Code 扩展提供单独的 DMN 编辑器和简单编辑器 VS Code 扩展。

重要

VS Code 中的编辑器部分与 Business Central 中的编辑器兼容,而 VS Code 不支持几个 Business Central 功能。

先决条件

  • 已安装 VS Code 的最新稳定版本。

流程

  1. 在 VS Code IDE 中,选择 Extensions 菜单选项,再搜索 Red Hat Business Automation Bundle for DMN、Janllanand 和 test scenario 文件支持。

    对于 DMN 或 BPMN 文件支持,您还可以搜索单独的 DMN Editor 或soa Editor 扩展。

  2. Red Hat Business Automation Bundle 扩展出现在 VS Code 中时,选择它并单击 Install
  3. 为获得最佳 VS Code 编辑器行为,请在扩展安装完成后,重新加载或关闭并重新启动 VS Code 的实例。

安装 VS Code 扩展捆绑包后,在 VS Code 中打开或创建的任何 .dmn.bpmn.bpmn2 文件将自动显示为图形模型。此外,您打开或创建的任何 .scesim 文件都自动显示为测试您的业务决策功能的表格测试方案模型。

如果 DMN、GINX 或测试方案模型器只打开 DMN、Payango 或测试场景文件的 XML 源,并显示错误消息,请查看报告的错误和型号文件,以确保正确定义了所有元素。

注意

对于新的 DMN 或 HPP 模型,您还可以在 Web 浏览器中输入 dmn.newbpmn.new,以在在线模型程序中设计您的 DMN 或 FDO 模型。完成模型创建后,您可以点击在线模型页面中的 Download,将 DMN 或 mail 文件导入到 VS Code 中的 Red Hat Process Automation Manager 项目中。

Red Hat Process Automation Manager 提供独立编辑器,可在自包含的库中分发,为每个编辑器提供一体化 JavaScript 文件。JavaScript 文件使用全面的 API 来设置和控制编辑器。

您可以使用以下方法安装独立编辑器:

  • 手动下载每个 JavaScript 文件
  • 使用 NPM 软件包

流程

  1. 使用以下方法之一安装独立编辑器:

    手动下载每个 JavaScript 文件 :对于此方法,请按照以下步骤操作:

    1. 下载 JavaScript 文件。
    2. 将下载的 Javascript 文件添加到您托管的应用程序中。
    3. 将以下 &lt ;script& gt; 标签添加到 HTML 页面中:

      DMN 编辑器的 HTML 页面的脚本标签

      <script src="https://<YOUR_PAGE>/dmn/index.js"></script>
      Copy to Clipboard Toggle word wrap

      FDO 编辑器的 HTML 页面的脚本标签

      <script src="https://<YOUR_PAGE>/bpmn/index.js"></script>
      Copy to Clipboard Toggle word wrap

    使用 NPM 软件包 :对于此方法,请按照以下步骤操作:

    1. 将 NPM 软件包添加到您的 package.json 文件中:

      添加 NPM 软件包

      npm install @kogito-tooling/kie-editors-standalone
      Copy to Clipboard Toggle word wrap

    2. 将每个编辑器库导入到您的 TypeScript 文件中:

      导入每个编辑器

      import * as DmnEditor from "@kogito-tooling/kie-editors-standalone/dist/dmn"
      import * as BpmnEditor from "@kogito-tooling/kie-editors-standalone/dist/bpmn"
      Copy to Clipboard Toggle word wrap

  2. 安装独立编辑器后,使用提供的编辑器 API 打开所需的编辑器,如下例所示以打开 DMN 编辑器。每个编辑器的 API 相同。

    打开 DMN 独立编辑器

    const editor = DmnEditor.open({
      container: document.getElementById("dmn-editor-container"),
      initialContent: Promise.resolve(""),
      readOnly: false,
      origin: "",
      resources: new Map([
        [
          "MyIncludedModel.dmn",
          {
            contentType: "text",
            content: Promise.resolve("")
          }
        ]
      ])
    });
    Copy to Clipboard Toggle word wrap

    在编辑器 API 中使用以下参数:

    Expand
    表 2.1. 参数示例
    参数描述

    container

    附加编辑器的 HTML 元素。

    initialContent

    对 DMN 模型内容的承诺.这个参数可以为空,如下例所示:

    • Promise.resolve("")
    • Promise.resolve("<DIAGRAM_CONTENT_DIRECTLY_HERE>")
    • fetch("MyDmnModel.dmn").then(content ⇒ content.text())

    ReadOnly (可选)

    允许您允许编辑器中的更改。设置为 false (默认)以允许在编辑器中为只读模式进行内容编辑和 true

    origin (可选)

    存储库的来源。默认值为 window.location.origin

    资源 (可选)

    编辑器的资源映射。例如,此参数用于为 DMN 编辑器提供包括的模型,或为 FDO 编辑器的工作项目定义。映射中的每个条目都包含一个资源名称,以及一个由 content-type (textbinary) 和 content (与 initialContent 参数类似) 组成的对象。

    返回的对象包含操作编辑器所需的方法。

    Expand
    表 2.2. 返回的对象方法
    方法描述

    getContent(): Promise<string>

    返回包含编辑器内容的承诺。

    setContent(path: string, content: string): void

    设置编辑器的内容。

    getPreview(): Promise<string>

    返回包含当前图表 SVG 字符串的承诺。

    subscribeToContentChanges(callback: (isDirty: boolean) ⇒ void): (isDirty: boolean) ⇒ void

    将回调设置为在编辑器中的内容更改时,并返回相同的回调以用于取消订阅。

    unsubscribeToContentChanges(callback: (isDirty: boolean) ⇒ void): void

    在编辑器中的内容更改时取消订阅传递的回调。

    markAsSaved(): void

    重置编辑器状态,指示编辑器中的内容已保存。另外,它还激活与内容更改相关的订阅回调。

    undo(): void

    撤销编辑器中的最后更改。另外,它还激活与内容更改相关的订阅回调。

    redo(): void

    在编辑器中执行最近一次撤消的更改。另外,它还激活与内容更改相关的订阅回调。

    close(): void

    关闭编辑器。

    getElementPosition (selector: string): Promise<Rect>

    提供了在可组合或视频组件内存在元素时扩展标准查询选择器的替代选择。selector 参数必须遵循 < PROVIDER>:::<SELECT& gt; 格式,如 Canvas:::MySquarevideo:::PresenterHand。此方法返回一个代表元素位置的 Rect

    envelopeApi: MessageBusClientApi<KogitoEditorEnvelopeApi>

    这是高级编辑器 API。有关高级编辑器 API 的更多信息,请参阅 MessageBusClientApiKogitoEditorEnvelopeApi

您可以使用 Maven archetypes 使用 Red Hat Process Automation Manager VS Code 扩展而不是 Business Central 在 VS Code 中开发 DMN 和 ClusterClaim 模型。然后,您可以根据需要将您的架构类型与您的红帽流程自动化管理器决策和流程服务集成。这种开发 DMN 和 BPMN 模型的方法有助于使用红帽流程自动化管理器 VS Code 扩展构建新的业务应用程序。

流程

  1. 在命令终端中,导航到要存储新 Red Hat Process Automation Manager 项目的本地文件夹。
  2. 输入以下命令使用 Maven archtype 在定义的文件夹中生成项目:

    使用 Maven archetype 生成项目

    mvn archetype:generate \
        -DarchetypeGroupId=org.kie \
        -DarchetypeArtifactId=kie-kjar-archetype \
        -DarchetypeVersion=7.59.0.Final-redhat-00006
    Copy to Clipboard Toggle word wrap

    此命令生成具有所需依赖项的 Maven 项目,并生成所需的目录和文件来构建您的业务应用程序。在开发项目时,您可以使用 Git 版本控制系统(推荐)。

    如果要在同一目录中生成多个项目,请在上一个命令中添加 -DgroupId=<groupid> -DartifactId=<artifactId> 来指定生成的业务应用程序的 artifactIdgroupId

  3. 在 VS Code IDE 中,单击 File,选择 Open Folder,再导航到使用上一命令生成的文件夹。
  4. 在创建第一个资产前,为您的业务应用程序设置软件包,例如 org.kie. businessapp,并在以下路径中创建对应的目录:

    • PROJECT_HOME/src/main/java
    • PROJECT_HOME/src/main/resources
    • PROJECT_HOME/src/test/resources

    例如,您可以为 org.kie. businessapp 软件包创建 PROJECT_HOME/src/main/java/org/kie/ businessapp

  5. 使用 VS Code 为业务应用程序创建资产。您可以使用以下方法创建 Red Hat Process Automation Manager VS Code 扩展支持的资产:

    • 要创建业务流程,请在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个 .bpmn.bpmn2 的新文件,如 Process.bpmn
    • 要创建 DMN 模型,在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个包含 .dmn 的新文件,如 AgeDecision.dmn
    • 要创建测试场景模拟模型,请在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个包含 .scesim 的新文件,如 TestAgeScenario.scesim
  6. 在 Maven archetype 中创建资产后,在命令行中导航到项目的根目录(包含 pom.xml)并运行以下命令来构建项目的知识 JAR (KJAR):

    mvn clean install
    Copy to Clipboard Toggle word wrap

    如果构建失败,请解决命令行错误消息中描述的任何问题,然后再次尝试验证项目,直到构建成功为止。但是,如果构建成功,您可以在 PROJECT_HOME/target 目录中找到业务应用程序的工件。

    注意

    在开发过程中,使用 mvn clean install 命令通常会在每次主要更改后验证项目。

您可以使用 REST API 将业务应用程序生成的知识 JAR (KJAR)部署到运行的 KIE 服务器上。有关使用 REST API 的更多信息,请参阅使用 KIE API 与红帽流程自动化管理器交互

在本例中,创建一个名为 traffic-violation 的新项目。项目是数据对象、DMN 资产和测试场景等资产的容器。您要创建的示例项目与 Business Central 中的现有 Traffic_Violation 示例项目类似。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects

    Red Hat Process Automation Manager 提供一个名为 MySpace 的默认空间,如下图所示。您可以使用默认空间来创建和测试示例项目。

    图 4.1. 默认空间

  2. 单击 Add Project
  3. Name 字段中输入 traffic-violation
  4. 点击 Add

    图 4.2. 添加项目窗口

    项目的 Assets 视图将打开。

第 5 章 决策模型和符号(DMN)

决策模型和符号(DMN)是由 Object Management Group (OMG)建立的一种标准,用于描述和建模操作决策。DMN 定义了一个 XML 模式,使 DMN 模型能够在 DMN 兼容平台和跨组织之间共享,以便业务分析员和业务规则开发人员能够就设计和实施 DMN 决策服务进行协作。DMN 标准与 相似,可用于设计和建模业务流程模型和符号(BPMN)标准。

有关 DMN 的后台和应用的更多信息,请参阅 OMG Decision Model 和 Notation 规格

5.1. 创建流量违反 DMN 决策要求图(DRD)

决策要求图(DRD)是 DMN 模型的可视化表示。在 Business Central 中使用 DMN 设计器设计流量违反项目的 DRD,并定义 DRD 组件的决策逻辑。

图 5.1. 用于流量冲突的 DRD 示例

先决条件

  • 您已在 Business Central 中创建了流量违反情况项目。

流程

  1. traffic-violation 项目的主页上,单击 Add Asset
  2. Add Asset 页面上,单击 DMNCreate new DMN 窗口将打开。

    1. Create new DMN 窗口中,在 DMN name 字段中输入 流量冲突
    2. Package 列表,选择 com.myspace.traffic_violation
    3. 确定。DMN 设计程序中的 DMN 资产被打开。
  3. 在 DMN Designer canvas 中,将两个 DMN 输入数据输入 节点拖到 canvas 中。

    图 5.2. DMN 输入数据节点

  4. 在右上角点击 diagram properties 图标。
  5. 双击输入节点,再将一个重命名为 Driver,另一个重命名为 Violation
  6. DMN Decision 决定节点拖到 canvas 中。
  7. 双击决策节点,并将它重命名为 Fine
  8. 单击 Violation 输入节点,选择 Create DMN Information Requirement 图标,然后单击 Fine 决定节点来链接两个节点。

    图 5.3. 创建 DMN 信息要求图标

  9. DMN Decision 决定节点拖到 canvas 中。
  10. 双击决策节点,将它重命名为 Should the driver are suspended?
  11. 单击 Driver 输入节点,选择 Create DMN Information Requirement 图标,然后单击 Should the driver be suspended? decision node 以链接两个节点。
  12. Fine decision node,选择 Create DMN Information Requirement 图标,然后选择 Should the driver be suspended? decision node。
  13. 点击 Save

    注意

    定期保存 DRD 时,DMN 设计程序执行 DMN 模型的静态验证,并可能会在完全定义模型前生成错误消息。完成完全定义 DMN 模型后,如果保留任何错误,请相应地排除指定的问题。

5.2. 创建流量违反 DMN 自定义数据类型

DMN 数据类型决定了您在 DMN 框中的表达式中的表、列或字段中使用的数据结构,用于定义决策逻辑。您可以使用默认的 DMN 数据类型(如字符串、数字或布尔值)或者创建自定义数据类型来指定您要为框表达式值实施的其他字段和限制。在 Business Central 中使用 DMN 设计程序 的数据类型 选项卡,为流量违反项目定义自定义数据类型。

图 5.4. 自定义数据类型标签页

下表列出了 tDrivertViolationtFine 为此项目创建的自定义数据类型。

Expand
表 5.1. tDriver 自定义数据类型
名称类型

tDriver

结构

名称

字符串

年龄

number

状态

字符串

城市

字符串

number

Expand
表 5.2. tViolation 自定义数据类型
名称类型

tViolation

结构

代码

字符串

Date

date

类型

字符串

速度限制

number

实际需求

number

Expand
表 5.3. tFine 自定义数据类型
名称类型

tFine

结构

amount

number

number

先决条件

  • 您在 Business Central 中创建了流量违反了 DMN 决策要求图(DRD)。

流程

  1. 要创建 tDriver 自定义数据类型,请单击 Data Types 选项卡上的 Add a custom Data Type,在 Name 字段中输入 tDriver,然后从 Type 列表中选择 Structure
  2. 单击新数据类型右侧的复选标记,以保存您的更改。

    图 5.5. tDriver 自定义数据类型

  3. 为每个新嵌套数据类型点 tDriver 旁边的加号,将以下嵌套数据类型添加到 tDriver 结构化数据类型。点每个新数据类型右侧的检查标记保存您的更改。

    • Name (字符串)
    • 年龄 (数字)
    • State (字符串)
    • 城市 (字符串)
    • (数字)
  4. 要创建 tViolation 自定义数据类型,请单击 New Data Type,在 Name 字段中输入 tViolation,然后从 Type 列表中选择 Structure
  5. 单击新数据类型右侧的复选标记,以保存您的更改。

    图 5.6. tViolation 自定义数据类型

  6. 为每个新嵌套数据类型点 tViolation 旁边的加号,将以下嵌套数据类型添加到 tViolation 结构化数据类型。点每个新数据类型右侧的检查标记保存您的更改。

    • code (字符串)
    • 日期 (date)
    • 类型 (字符串)
    • 速度限制 (数字)
    • 实际需求 (数字)
  7. 要在 Type nested data type 中添加以下限制,点编辑图标,点 Add Constraints,然后从 Select constraint type 下拉菜单中选择 Enumeration

    • 速度
    • parking
    • 驱动影响
  8. 单击 OK,然后单击 Type 数据类型右侧的复选标记以保存您的更改。
  9. 要创建 tFine 自定义数据类型,请单击 New Data Type,在 Name 字段中输入 tFine,从 Type 列表中选择 Structure,然后单击 Save

    图 5.7. tFine 自定义数据类型

  10. 为每个新嵌套数据类型点 tFine 旁边的加号,将以下嵌套数据类型添加到 tFine 结构化数据类型。点每个新数据类型右侧的检查标记保存您的更改。

    • 数字 (数字)
    • (数字)
  11. 点击 Save

创建 DMN 自定义数据类型后,将它们分配到流量违反 DRD 中的适当的 DMN 输入 数据和 DMN Decision 节点。

先决条件

  • 您已在 Business Central 中创建了流量违反了 DMN 自定义数据类型。

流程

  1. 点 DMN Designer 上的 Model 选项卡,然后点击 DMN 设计器右上角的 Properties diagram properties 图标公开 DRD 属性。
  2. 在 DRD 中,选择 Driver 输入数据节点并在 Properties 面板中,从 Data type 下拉菜单中选择 tDriver
  3. 选择 Violation 输入数据节点,然后从 Data type 下拉菜单中选择 tViolation
  4. 选择 Fine 决定节点,然后从 Data type 下拉菜单中选择 tFine
  5. 选择 Should the driver are suspended? decision node 并设置以下属性:

    • 数据类型字符串
    • 问题 :由于指向其驱动程序许可证,是否应该暂停驱动程序?
    • 允许答案是,否
  6. 点击 Save

您已将自定义数据类型分配给 DRD 的输入和输出节点。

5.4. 定义流量违反 DMN 决策逻辑

要计算细节并决定是否要暂停驱动程序,您可以使用 DMN 决策表和上下文框定义流量违反 DMN 决策逻辑。

图 5.8. 微调表达式

图 5.9. 是否应该暂停驱动程序的表达式

先决条件

  • 您已将 DMN 自定义数据类型分配给 Business Central 中流量违反 DRD 中的相应决定和输入节点。

流程

  1. 要计算好的效果,在 DMN Designer canvas 中,选择 Fine 决定节点,然后单击 Edit 图标以打开 DMN 框的表达式设计程序。

    图 5.10. 决定节点编辑图标

  2. Select expressionDecision Table

    图 5.11. 选择 Decisiong Table 逻辑类型

  3. 对于 Violation.DateVaolation.CodeViolation.Speed Limit 列,右键单击每个字段的 Delete
  4. 单击 Violation.Actual Speed 列标题,然后在 Expression 字段中输入表达式 Violation.Actual Speed - Violation.Speed Limit "。
  5. 在路由表的第一行中输入以下值:

    • violation.Type:"speed"
    • violation.Actual Speed - Violation.Speed Limit:[10..30)
    • 数量:500
    • :3

      右键点击第一行并选择 下面的 Insert 来添加另一个行。

  6. 在路由表的第二行中输入以下值:

    • violation.Type:"speed"
    • violation.Actual Speed - Violation.Speed Limit : &gt;= 30
    • 数量:1000
    • :7

      右键单击第二行,再选择 下面的 Insert 来添加另一个行。

  7. 在路由表的第三个行中输入以下值:

    • violation.Type:"parking"
    • violation.Actual Speed - Violation.Speed Limit:-
    • 数量 :100
    • :1

      右键单击第三行,再选择 下面的 Insert 来添加另一个行。

  8. 在路由表的第四行中输入以下值:

    • violation.Type:"driving under the influence"
    • violation.Actual Speed - Violation.Speed Limit:-
    • 数量:1000
    • :5
  9. 点击 Save
  10. 要定义驱动程序挂起规则,请返回到 DMN 设计器 canvas,选择 Should the driver is suspended? decision node,然后单击 Edit 图标以打开 DMN 框的表达式设计程序。
  11. Select expressionContext
  12. ContextEntry-1,输入 Total Points 作为 Name,然后从 Data Type 下拉菜单中选择 数字
  13. 单击 Total Points 旁边的单元格,从上下文菜单中选择 Literal 表达式,并输入 Driver.Points + Fine.Points 作为表达式。
  14. Driver.Points + Fine.Points 下的单元格中,从上下文菜单中选择 Literal Expression,然后输入 Total Points >= 20,然后"否 "。
  15. 点击 Save

    您已定义如何计算调优和上下文,以决定何时暂停驱动程序。您可以导航到 traffic-violation 项目页面,再单击 Build 以构建示例项目,并解决 Alerts 面板中记录的任何错误。

第 6 章 测试场景

在 Red Hat Process Automation Manager 中测试场景可让您验证业务规则和业务规则数据的功能(用于基于规则的测试场景)或 DMN 模型(用于基于 DMN 的测试场景),然后再在生产环境中进行部署。通过测试场景,您可以使用项目中的数据根据一个或多个定义的业务规则设置给定条件和预期结果。运行场景时,比较预期的结果和规则实例的实际结果。如果预期的结果与实际结果匹配,则测试成功。如果预期的结果与实际结果不匹配,则测试会失败。

Red Hat Process Automation Manager 包括新的 测试场景 设计人员和之前的 测试场景(Legacy)设计程序。默认设计程序是新的测试场景设计器,它支持测试规则和 DMN 模型,并通过测试场景提供增强的整体用户体验。如果需要,您可以继续使用传统的测试场景设计器,该设计仅支持基于规则的测试场景。

重要

旧的测试场景设计程序已从 Red Hat Process Automation Manager 版本 7.3.0 中弃用。它将在以后的 Red Hat Process Automation Manager 发行版本中删除。改为使用新的测试场景设计器。

您可以使用多种方法运行定义的测试场景,例如,您可以在项目级别或特定测试场景资产内运行可用的测试场景。测试场景是独立的,不会影响或修改其他测试场景。您可以在 Business Central 的项目开发过程中随时运行测试场景。您不必编译或部署决策服务来运行测试场景。

您可以将数据对象从不同的软件包导入到与测试场景相同的项目软件包。默认情况下,同一软件包中的资产会导入。创建必要的数据对象和测试场景后,您可以使用测试场景设计器的 Data Objects 选项卡来验证所有必需的数据对象是否都已列出或导入其他现有 的数据对象

重要

在测试场景文档中,所有测试 场景 和测试 场景设计器 都适用于新版本,除非明确声明为旧版本。

6.1. 使用测试场景测试流量违反情况

在 Business Central 中使用测试场景设计器测试 DMN 决策要求图(DRD),并为流量违反项目定义决策逻辑。

图 6.1. 流量违反示例测试场景

先决条件

  • 您已在 Business Central 中成功构建了流量违反项目。

流程

  1. traffic-violation 项目的主页屏幕上,单击 Add Asset 以打开 Add Asset 屏幕。
  2. 单击 Test scenarios 以打开 Create new Test scenarios 对话框。

    1. Test Scenario 字段中输入 Violation Scenarios
    2. Package 列表,选择 com.myspace.traffic_violation
    3. 选择 DMN 作为 Source 类型
    4. Choose a DMN asset 列表中,选择 DMN 资产的路径。
    5. OkTest Scenarios designer 中打开 Violation Scenarios 测试。
  3. Driver 列子标题下,右键单击 StateCityAgeName 值 cells,然后从上下文菜单选项中选择 Delete 列 来删除它们。
  4. Violation 列子标题下,右键单击 Date and Code 值 cells,然后选择 Delete 列 来删除它们。
  5. 在测试场景的第一行中输入以下信息:

    • 场景描述Above speed limit: 10km/h 和 30 km/h
    • (在 Given 列标题下): 10
    • 类型:"speed"
    • 速度限制 :100
    • 实际需求120
    • :3
    • 数量:500
    • 是否应该暂停驱动程序?" 否"

      右键点击第一行并选择 下面的 Insert 行 来添加另一个行。

  6. 在测试场景的第二行中输入以下信息:

    • 场景描述:Above speed limit: more than 30 km/h
    • (在 Given 列标题下): 10
    • 类型:"speed"
    • 速度限制 :100
    • 实际分片:150
    • :7
    • 数量:1000
    • 是否应该暂停驱动程序?" 否"

      右键单击第二行,再选择 下面的 Insert 行 来添加另一个行。

  7. 在测试场景的第三个行中输入以下信息:

    • Scenario description: Parking violation
    • (在 Given 列标题下): 10
    • 键入:"parking"
    • 速度限制 :留空
    • 实际分片 :留空
    • :1
    • 数量 :100
    • 是否应该暂停驱动程序?" 否"

      右键单击第三行,再选择 下面的 Insert 行 来添加另一个行。

  8. 在测试场景的第四行中输入以下信息:

    • 场景描述DUI 违反
    • (在 Given 列标题下): 10
    • 键入"在影响下划分"
    • 速度限制 :留空
    • 实际分片 :留空
    • :5
    • 数量:1000
    • 是否应该暂停驱动程序?" 否"

      右键单击第四行,再选择 下面的 Insert 行 来添加另一个行。

  9. 在测试场景的第五个行中输入以下信息:

    • 场景描述驱动程序暂停
    • (在 Given 列标题下) :15
    • 类型:"speed"
    • 速度限制 :100
    • 实际需求140
    • :7
    • 数量:1000
    • Should the driver be suspended?: "Yes"
  10. 点击 Save
  11. Play 图标 dmn play icon 检查测试场景通过或失败。

    图 6.2. 测试流量违反示例的场景执行结果

    如果失败,请更正错误并再次运行测试场景。

第 7 章 DMN 模型执行

您可以使用 Business Central 在 Red Hat Process Automation Manager 项目中创建或导入 DMN 文件,也可以将 DMN 文件打包为项目知识 JAR (KJAR)文件的一部分,而无需 Business Central。在 Red Hat Process Automation Manager 项目中实现 DMN 文件后,您可以通过部署 KIE Server REST API 的 KIE 服务器执行 DMN 决策服务来执行 DMN 决策服务。

有关使用项目打包和部署方法包括外部 DMN 资产的信息,请参阅 打包和部署红帽流程自动化管理器项目

7.1. 使用 KIE Server REST API 执行 DMN 服务

直接与 KIE 服务器的 REST 端点交互,提供调用代码和决策逻辑定义之间的最大分离。调用代码完全没有直接依赖项,您可以在完全不同的开发平台(如 Node.js.NET )中实施。本节中的示例演示了 Nix 风格的 curl 命令,但提供相关信息以适应任何 REST 客户端。

当您使用 KIE Server 的 REST 端点时,最佳实践是定义域对象 POJO Java 类,使用标准 KIE Server marshalling 注解进行注解。例如,以下代码使用域对象 Person 类,该类被正确注解:

POJO Java 类示例

@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
public class Person implements java.io.Serializable {

    static final long serialVersionUID = 1L;

    private java.lang.String id;
    private java.lang.String name;
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(org.kie.internal.jaxb.LocalDateXmlAdapter.class)
    private java.time.LocalDate dojoining;

    public Person() {
    }

    public java.lang.String getId() {
        return this.id;
    }

    public void setId(java.lang.String id) {
        this.id = id;
    }

    public java.lang.String getName() {
        return this.name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    public java.time.LocalDate getDojoining() {
        return this.dojoining;
    }

    public void setDojoining(java.time.LocalDate dojoining) {
        this.dojoining = dojoining;
    }

    public Person(java.lang.String id, java.lang.String name,
            java.time.LocalDate dojoining) {
        this.id = id;
        this.name = name;
        this.dojoining = dojoining;
    }

}
Copy to Clipboard Toggle word wrap

有关 KIE 服务器 REST API 的更多信息,请参阅使用 KIE API 与 Red Hat Process Automation Manager 进行交互

先决条件

  • KIE 服务器已安装并配置,包括具有 kie-server 角色的用户的已知用户名和凭证。有关安装选项,请参阅 规划 Red Hat Process Automation Manager 安装
  • 您已将 DMN 项目构建为 KJAR 工件并将其部署到 KIE Server:

    mvn clean install
    Copy to Clipboard Toggle word wrap

    如需有关项目打包和部署以及可执行模型的更多信息,请参阅 打包和部署 Red Hat Process Automation Manager 项目

  • 您有包含 DMN 模型的 KIE 容器的 ID。如果存在多个模型,还必须知道相关模型的 model 命名空间和模型名称。

流程

  1. 确定用于访问 KIE Server REST API 端点的基本 URL。这要求了解以下值(使用默认的本地部署值作为示例):

    • 主机(本地主机)
    • 端口(8080)
    • 根上下文(kie-server)
    • 基础 REST 路径(services/rest/)

    流量违反项目的本地部署中的基本 URL 示例:

    http://localhost:8080/kie-server/services/rest/server/containers/traffic-violation_1.0.0-SNAPSHOT

  2. 确定用户身份验证要求。

    当用户直接在 KIE 服务器配置中定义时,会使用 HTTP 基本身份验证,并需要用户名和密码。成功请求要求用户具有 kie-server 角色。

    以下示例演示了如何在 curl 请求中添加凭证:

    curl -u username:password <request>
    Copy to Clipboard Toggle word wrap

    如果使用 Red Hat Single Sign-On 配置 KIE 服务器,请求必须包含 bearer 令牌:

    curl -H "Authorization: bearer $TOKEN" <request>
    Copy to Clipboard Toggle word wrap
  3. 指定请求和响应的格式。REST API 端点可用于 JSON 和 XML 格式,并使用请求标头设置:

    JSON

    curl -H "accept: application/json" -H "content-type: application/json"
    Copy to Clipboard Toggle word wrap

    XML

    curl -H "accept: application/xml" -H "content-type: application/xml"
    Copy to Clipboard Toggle word wrap

  4. 可选:查询容器以获取已部署决策模型的列表:

    [GET] server/containers/{containerId}/dmn

    curl 请求示例:

    curl -u wbadmin:wbadmin -H "accept: application/xml" -X GET "http://localhost:8080/kie-server/services/rest/server/containers/traffic-violation_1.0.0-SNAPSHOT/dmn"
    Copy to Clipboard Toggle word wrap

    XML 输出示例:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <response type="SUCCESS" msg="Ok models successfully retrieved from container 'traffic-violation_1.0.0-SNAPSHOT'">
        <dmn-model-info-list>
            <model>
                <model-namespace>https://github.com/kiegroup/drools/kie-dmn/_60b01f4d-e407-43f7-848e-258723b5fac8</model-namespace>
                <model-name>Traffic Violation</model-name>
                <model-id>_2CD7D1AA-BD84-4B43-AD21-B0342ADE655A</model-id>
                <decisions>
                    <dmn-decision-info>
                        <decision-id>_23428EE8-DC8B-4067-8E67-9D7C53EC975F</decision-id>
                        <decision-name>Fine</decision-name>
                    </dmn-decision-info>
                    <dmn-decision-info>
                        <decision-id>_B5EEE2B1-915C-44DC-BE43-C244DC066FD8</decision-id>
                        <decision-name>Should the driver be suspended?</decision-name>
                    </dmn-decision-info>
                </decisions>
                <inputs>
                    <dmn-inputdata-info>
                        <inputdata-id>_CEB959CD-3638-4A87-93BA-03CD0FB63AE3</inputdata-id>
                        <inputdata-name>Violation</inputdata-name>
                        <inputdata-typeref>
                            <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                            <local-part>tViolation</local-part>
                            <prefix></prefix>
                        </inputdata-typeref>
                    </dmn-inputdata-info>
                    <dmn-inputdata-info>
                        <inputdata-id>_B0E810E6-7596-430A-B5CF-67CE16863B6C</inputdata-id>
                        <inputdata-name>Driver</inputdata-name>
                        <inputdata-typeref>
                            <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                            <local-part>tDriver</local-part>
                            <prefix></prefix>
                        </inputdata-typeref>
                    </dmn-inputdata-info>
                </inputs>
                <itemdefinitions>
                    <dmn-itemdefinition-info>
                        <itemdefinition-id>_9C758F4A-7D72-4D0F-B63F-2F5B8405980E</itemdefinition-id>
                        <itemdefinition-name>tViolation</itemdefinition-name>
                        <itemdefinition-itemcomponent>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_0B6FF1E2-ACE9-4FB3-876B-5BB30B88009B</itemdefinition-id>
                                <itemdefinition-name>Code</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60b01f4d-e407-43f7-848e-258723b5fac8</namespace-uri>
                                    <local-part>string</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_27A5DA18-3CA7-4C06-81B7-CF7F2F050E29</itemdefinition-id>
                                <itemdefinition-name>date</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>date</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_8961969A-8A80-4F12-B568-346920C0F038</itemdefinition-id>
                                <itemdefinition-name>type</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>string</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_7450F12A-3E95-4D5E-8DCE-2CB1FAC2BDD4</itemdefinition-id>
                                <itemdefinition-name>speed limit</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60b01f4d-e407-43f7-848e-258723b5fac8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_0A9A6F26-6C14-414D-A9BF-765E5850429A</itemdefinition-id>
                                <itemdefinition-name>Actual Speed</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                        </itemdefinition-itemcomponent>
                        <itemdefinition-iscollection>false</itemdefinition-iscollection>
                    </dmn-itemdefinition-info>
                    <dmn-itemdefinition-info>
                        <itemdefinition-id>_13C7EFD8-B85C-43BF-94D3-14FABE39A4A0</itemdefinition-id>
                        <itemdefinition-name>tDriver</itemdefinition-name>
                        <itemdefinition-itemcomponent>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_EC11744C-4160-4549-9610-2C757F40DFE8</itemdefinition-id>
                                <itemdefinition-name>Name</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>string</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_E95BE3DB-4A51-4658-A166-02493EAAC9D2</itemdefinition-id>
                                <itemdefinition-name>Age</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_7B3023E2-BC44-4BF3-BF7E-773C240FB9AD</itemdefinition-id>
                                <itemdefinition-name>State</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>string</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_3D4B49DD-700C-4925-99A7-3B2B873F7800</itemdefinition-id>
                                <itemdefinition-name>city</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>string</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_B37C49E8-B0D9-4B20-9DC6-D655BB1CA7B1</itemdefinition-id>
                                <itemdefinition-name>Points</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                        </itemdefinition-itemcomponent>
                        <itemdefinition-iscollection>false</itemdefinition-iscollection>
                    </dmn-itemdefinition-info>
                    <dmn-itemdefinition-info>
                        <itemdefinition-id>_A4077C7E-B57A-4DEE-9C65-7769636316F3</itemdefinition-id>
                        <itemdefinition-name>tFine</itemdefinition-name>
                        <itemdefinition-itemcomponent>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_79B152A8-DE83-4001-B88B-52DFF0D73B2D</itemdefinition-id>
                                <itemdefinition-name>Amount</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                            <dmn-itemdefinition-info>
                                <itemdefinition-id>_D7CB5F9C-9D55-48C2-83EE-D47045EC90D0</itemdefinition-id>
                                <itemdefinition-name>Points</itemdefinition-name>
                                <itemdefinition-typeref>
                                    <namespace-uri>https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8</namespace-uri>
                                    <local-part>number</local-part>
                                    <prefix></prefix>
                                </itemdefinition-typeref>
                                <itemdefinition-itemcomponent/>
                                <itemdefinition-iscollection>false</itemdefinition-iscollection>
                            </dmn-itemdefinition-info>
                        </itemdefinition-itemcomponent>
                        <itemdefinition-iscollection>false</itemdefinition-iscollection>
                    </dmn-itemdefinition-info>
                </itemdefinitions>
                <decisionservices/>
            </model>
        </dmn-model-info-list>
    </response>
    Copy to Clipboard Toggle word wrap

    JSON 输出示例:

    {
      "type" : "SUCCESS",
      "msg" : "OK models successfully retrieved from container 'Traffic-Violation_1.0.0-SNAPSHOT'",
      "result" : {
        "dmn-model-info-list" : {
          "models" : [ {
            "model-namespace" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
            "model-name" : "Traffic Violation",
            "model-id" : "_2CD7D1AA-BD84-4B43-AD21-B0342ADE655A",
            "decisions" : [ {
              "decision-id" : "_23428EE8-DC8B-4067-8E67-9D7C53EC975F",
              "decision-name" : "Fine"
            }, {
              "decision-id" : "_B5EEE2B1-915C-44DC-BE43-C244DC066FD8",
              "decision-name" : "Should the driver be suspended?"
            } ],
            "inputs" : [ {
              "inputdata-id" : "_CEB959CD-3638-4A87-93BA-03CD0FB63AE3",
              "inputdata-name" : "Violation",
              "inputdata-typeRef" : {
                "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                "local-part" : "tViolation",
                "prefix" : ""
              }
            }, {
              "inputdata-id" : "_B0E810E6-7596-430A-B5CF-67CE16863B6C",
              "inputdata-name" : "Driver",
              "inputdata-typeRef" : {
                "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                "local-part" : "tDriver",
                "prefix" : ""
              }
            } ],
            "itemDefinitions" : [ {
              "itemdefinition-id" : "_13C7EFD8-B85C-43BF-94D3-14FABE39A4A0",
              "itemdefinition-name" : "tDriver",
              "itemdefinition-typeRef" : null,
              "itemdefinition-itemComponent" : [ {
                "itemdefinition-id" : "_EC11744C-4160-4549-9610-2C757F40DFE8",
                "itemdefinition-name" : "Name",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "string",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_E95BE3DB-4A51-4658-A166-02493EAAC9D2",
                "itemdefinition-name" : "Age",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_7B3023E2-BC44-4BF3-BF7E-773C240FB9AD",
                "itemdefinition-name" : "State",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "string",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_3D4B49DD-700C-4925-99A7-3B2B873F7800",
                "itemdefinition-name" : "City",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "string",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_B37C49E8-B0D9-4B20-9DC6-D655BB1CA7B1",
                "itemdefinition-name" : "Points",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              } ],
              "itemdefinition-isCollection" : false
            }, {
              "itemdefinition-id" : "_A4077C7E-B57A-4DEE-9C65-7769636316F3",
              "itemdefinition-name" : "tFine",
              "itemdefinition-typeRef" : null,
              "itemdefinition-itemComponent" : [ {
                "itemdefinition-id" : "_79B152A8-DE83-4001-B88B-52DFF0D73B2D",
                "itemdefinition-name" : "Amount",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_D7CB5F9C-9D55-48C2-83EE-D47045EC90D0",
                "itemdefinition-name" : "Points",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              } ],
              "itemdefinition-isCollection" : false
            }, {
              "itemdefinition-id" : "_9C758F4A-7D72-4D0F-B63F-2F5B8405980E",
              "itemdefinition-name" : "tViolation",
              "itemdefinition-typeRef" : null,
              "itemdefinition-itemComponent" : [ {
                "itemdefinition-id" : "_0B6FF1E2-ACE9-4FB3-876B-5BB30B88009B",
                "itemdefinition-name" : "Code",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "string",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_27A5DA18-3CA7-4C06-81B7-CF7F2F050E29",
                "itemdefinition-name" : "Date",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "date",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_8961969A-8A80-4F12-B568-346920C0F038",
                "itemdefinition-name" : "Type",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "string",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_7450F12A-3E95-4D5E-8DCE-2CB1FAC2BDD4",
                "itemdefinition-name" : "Speed Limit",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              }, {
                "itemdefinition-id" : "_0A9A6F26-6C14-414D-A9BF-765E5850429A",
                "itemdefinition-name" : "Actual Speed",
                "itemdefinition-typeRef" : {
                  "namespace-uri" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
                  "local-part" : "number",
                  "prefix" : ""
                },
                "itemdefinition-itemComponent" : [ ],
                "itemdefinition-isCollection" : false
              } ],
              "itemdefinition-isCollection" : false
            } ],
            "decisionServices" : [ ]
          } ]
        }
      }
    }
    Copy to Clipboard Toggle word wrap
  5. 执行模型:

    [POST] server/containers/{containerId}/dmn

    注意

    属性 model-namespace 会自动生成,每个用户都有所不同。确保所用的 model-namespacemodel-name 属性与部署的模型匹配。

    curl 请求示例:

    curl -u wbadmin:wbadmin -H "accept: application/json" -H "content-type: application/json" -X POST "http://localhost:8080/kie-server/services/rest/server/containers/traffic-violation_1.0.0-SNAPSHOT/dmn" -d "{ \"model-namespace\" : \"https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8\", \"model-name\" : \"Traffic Violation\", \"dmn-context\" : {\"Driver\" : {\"Points\" : 15}, \"Violation\" : {\"Type\" : \"speed\", \"Actual Speed\" : 135, \"Speed Limit\" : 100}}}"
    Copy to Clipboard Toggle word wrap

    JSON 请求示例:

    {
      "model-namespace" : "https://github.com/kiegroup/drools/kie-dmn/_60B01F4D-E407-43F7-848E-258723B5FAC8",
      "model-name" : "Traffic Violation",
      "dmn-context" :
      {
        "Driver" :
        {
      	   "Points" : 15
        },
      	"Violation" :
        {
      		"Type" : "speed",
      		"Actual Speed" : 135,
      		"Speed Limit" : 100
      	}
      }
    }
    Copy to Clipboard Toggle word wrap

    XML 请求示例(JAXB 格式):

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <dmn-evaluation-context>
        <dmn-context xsi:type="jaxbListWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <type>MAP</type>
            <element xsi:type="jaxbStringObjectPair" key="Violation">
                <value xsi:type="jaxbListWrapper">
                    <type>MAP</type>
                    <element xsi:type="jaxbStringObjectPair" key="Type">
                        <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">speed</value>
                    </element>
                    <element xsi:type="jaxbStringObjectPair" key="Speed Limit">
                        <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">100</value>
                    </element>
                    <element xsi:type="jaxbStringObjectPair" key="Actual Speed">
                        <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">135</value>
                    </element>
                </value>
            </element>
            <element xsi:type="jaxbStringObjectPair" key="Driver">
                <value xsi:type="jaxbListWrapper">
                    <type>MAP</type>
                    <element xsi:type="jaxbStringObjectPair" key="Points">
                        <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">15</value>
                    </element>
                </value>
            </element>
        </dmn-context>
    </dmn-evaluation-context>
    Copy to Clipboard Toggle word wrap
    注意

    无论请求格式是什么,请求都需要以下元素:

    • 模型命名空间
    • 型号名称
    • 包含输入值的上下文对象

    JSON 响应示例:

    {
      "type": "SUCCESS",
      "msg": "OK from container 'Traffic-Violation_1.0.0-SNAPSHOT'",
      "result": {
          "dmn-evaluation-result": {
              "messages": [],
              "model-namespace": "https://github.com/kiegroup/drools/kie-dmn/_7D8116DE-ADF5-4560-A116-FE1A2EAFFF48",
              "model-name": "Traffic Violation",
              "decision-name": [],
              "dmn-context": {
                  "Violation": {
                    "Type": "speed",
                    "Speed Limit": 100,
                    "Actual Speed": 135
                  },
                  "Should Driver be Suspended?": "Yes",
                    "Driver": {
                      "Points": 15
                    },
                    "Fine": {
                      "Points": 7,
                      "Amount": 1000
                    }
                },
          "decision-results": {
              "_E1AF5AC2-E259-455C-96E4-596E30D3BC86": {
                  "messages": [],
                  "decision-id": "_E1AF5AC2-E259-455C-96E4-596E30D3BC86",
                  "decision-name": "Should the Driver be Suspended?",
                  "result": "Yes",
                  "status": "SUCCEEDED"
                },
              "_D7F02CE0-AF50-4505-AB80-C7D6DE257920": {
                  "messages": [],
                  "decision-id": "_D7F02CE0-AF50-4505-AB80-C7D6DE257920",
                  "decision-name": "Fine",
                  "result": {
                    "Points": 7,
                    "Amount": 1000
                  },
              "status": "SUCCEEDED"
            }
          }
        }
      }
    }
    Copy to Clipboard Toggle word wrap

    XML (JAXB 格式)响应示例:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <response type="SUCCESS" msg="OK from container 'Traffic_1.0.0-SNAPSHOT'">
        <dmn-evaluation-result>
            <model-namespace>https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF</model-namespace>
            <model-name>Traffic Violation</model-name>
            <dmn-context xsi:type="jaxbListWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <type>MAP</type>
                <element xsi:type="jaxbStringObjectPair" key="Violation">
                    <value xsi:type="jaxbListWrapper">
                        <type>MAP</type>
                        <element xsi:type="jaxbStringObjectPair" key="Type">
                            <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">speed</value>
                        </element>
                        <element xsi:type="jaxbStringObjectPair" key="Speed Limit">
                            <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">100</value>
                        </element>
                        <element xsi:type="jaxbStringObjectPair" key="Actual Speed">
                            <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">135</value>
                        </element>
                    </value>
                </element>
                <element xsi:type="jaxbStringObjectPair" key="Driver">
                    <value xsi:type="jaxbListWrapper">
                        <type>MAP</type>
                        <element xsi:type="jaxbStringObjectPair" key="Points">
                            <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">15</value>
                        </element>
                    </value>
                </element>
                <element xsi:type="jaxbStringObjectPair" key="Fine">
                    <value xsi:type="jaxbListWrapper">
                        <type>MAP</type>
                        <element xsi:type="jaxbStringObjectPair" key="Points">
                            <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">7</value>
                        </element>
                        <element xsi:type="jaxbStringObjectPair" key="Amount">
                            <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">1000</value>
                        </element>
                    </value>
                </element>
                <element xsi:type="jaxbStringObjectPair" key="Should the driver be suspended?">
                    <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">Yes</value>
                </element>
            </dmn-context>
            <messages/>
            <decisionResults>
                <entry>
                    <key>_4055D956-1C47-479C-B3F4-BAEB61F1C929</key>
                    <value>
                        <decision-id>_4055D956-1C47-479C-B3F4-BAEB61F1C929</decision-id>
                        <decision-name>Fine</decision-name>
                        <result xsi:type="jaxbListWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                            <type>MAP</type>
                            <element xsi:type="jaxbStringObjectPair" key="Points">
                                <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">7</value>
                            </element>
                            <element xsi:type="jaxbStringObjectPair" key="Amount">
                                <value xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema">1000</value>
                            </element>
                        </result>
                        <messages/>
                        <status>SUCCEEDED</status>
                    </value>
                </entry>
                <entry>
                    <key>_8A408366-D8E9-4626-ABF3-5F69AA01F880</key>
                    <value>
                        <decision-id>_8A408366-D8E9-4626-ABF3-5F69AA01F880</decision-id>
                        <decision-name>Should the driver be suspended?</decision-name>
                        <result xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Yes</result>
                        <messages/>
                        <status>SUCCEEDED</status>
                    </value>
                </entry>
            </decisionResults>
        </dmn-evaluation-result>
    </response>
    Copy to Clipboard Toggle word wrap

第 8 章 其他资源

作为业务规则和流程开发人员,您可以在红帽流程自动化管理器中使用 Business Central,或在 VS Code 中使用红帽流程自动化管理器和红帽流程自动化管理器进行设计,以设计业务流程来满足特定的业务需求。Red Hat Process Automation Manager 在 Business Central 中提供示例项目,其中包含业务资产以参考目的。本文档论述了如何创建新的抵制流程项目、数据对象和业务流程,以熟悉 Business Central 和流程设计人员。

然后,您将参考 Business Central 中包含的 Mortgage_Process 示例项目,以查看示例项目的业务规则、决策表和表单。您将构建和部署 Mortgage_Process 示例项目,并执行项目的定义功能。

先决条件

第 9 章 概述

Business Central 使您能够自动化您的业务流程。业务流程是一个图,用于描述执行一系列步骤的顺序,它由预定义的节点和连接组成。每个节点都代表进程中的一个步骤,而连接指定了如何从一个节点过渡到另一个节点。

例如,银行提供住房地产业服务。使用 Business Central,银行的危险部门为抵御贷款公司创建完整的业务流程。

当客户想要使用 credit 购买一个新属性时,会执行以下步骤:

  1. 客户联系了银行的代理,帮助其为抵御贷款。
  2. 代理收集有关属性和客户的信息,如客户的工资、社交安全号码、属性销售价格以及请求的 loan 数量。
  3. 然后代理代表客户提交请求。

每当客户提交请求时,都会创建一个新进程实例。这样可确保评估每个请求的质量的一致性,提供每个请求状态的完整可见性,并使流程高效。

Business Central 包含示例项目,您可以使用这些资产作为您在您自己的红帽流程自动化管理器项目中创建的规则、流程或其他资产的引用。每个示例项目都通过不同的设计来演示红帽流程自动化、决策管理或业务优化资产和逻辑。

注意

红帽不支持 Red Hat Process Automation Manager 发行版中包含的示例代码。

Business Central 中提供了以下示例项目:

  • course_Scheduling :(业务优化)课程安排和课程决策流程.为房间分配讲座,并根据课程冲突和课堂房间容量等因素确定学员的课程。
  • Dinner_Party :(业务优化)使用指导决策表优化客户机。根据客户机的作业类型、策略以及已知关系分配客户机席位。
  • Employee_Rostering: (业务优化)使用决策和解决者资产来增强优化。为员工提供基于技能的转变。
  • Evaluation_Process: (处理自动化)使用业务流程资产的评估流程。根据性能评估员工。
  • IT_Orders :(处理自动化和案例管理)使用业务流程和案例排序。根据需求和批准放置 IT 硬件订单。
  • 抵制 处理:(规则决策管理)使用基于规则的决策资产的批准流程。根据适用范围数据和资格确定出不满意。
  • Mortgage_Process: (处理自动化)使用业务流程和决策资产进行循环审批流程。根据适用范围数据和资格确定出不满意。
  • OptaCloud :(业务优化)使用决策和解决资产进行资源分配优化。为具有有限资源的计算机分配进程。
  • 流量_Violation :(通过 DMN 决策管理)使用决策模型和符号(DMN)模型进行流量违反决策服务。根据流量违反情况决定驱动损失和挂起。

您可以使用 Business Central 中的示例项目来探索业务资产,作为您在您自己的红帽流程自动化管理器项目中创建的规则或其他资产的参考。

先决条件

流程

  1. 在 Business Central 中,前往 MenuDesignProjects。如果存在现有项目,您可以点击 MySpace 默认空间,然后从 Add Project 下拉菜单中选择 Try Samples 来访问示例。如果没有现有项目,请单击 Try samples
  2. 查看每个示例项目的描述,以确定您要探索的项目。每个示例项目都通过不同的设计来演示红帽流程自动化、决策管理或业务优化资产和逻辑。
  3. 选择一个或多个示例项目,然后点 Ok 将项目添加到您的空间。
  4. 在空格的 Projects 页面中,选择一个示例项目来查看该项目的资产。
  5. 选择每个资产来探索项目如何实现指定目标或工作流。一些示例项目包含多个资产页面。点击右上角的左或向右箭头查看完整的资产列表。

    图 10.1. 资产页面选择

  6. 在项目 资产 页面的右上角,单击 Build 以构建示例项目或 Deploy 以构建项目,然后将其部署到 KIE Server。

    注意

    您还可以选择 Build & Install 选项来构建项目,并将 KJAR 文件发布到配置的 Maven 存储库,而无需部署到 KIE 服务器。在开发环境中,您可以点击 Deploy 将构建的 KJAR 文件部署到 KIE 服务器,而无需停止任何正在运行的实例(如果适用),或者点击 Redeploy 部署构建的 KJAR 文件并替换所有实例。下次部署或重新部署构建的 KJAR 时,以前的部署单元(KIE 容器)会在同一目标 KIE 服务器中自动更新。在生产环境中,Redeploy 选项被禁用,您可以点 Deploy only 将构建的 KJAR 文件部署到 KIE 服务器上的新部署单元(KIE 容器)。

    要配置 KIE 服务器环境模式,请将 org.kie.server.mode 系统属性设置为 org.kie.server.mode=developmentorg.kie.server.mode=production。要在 Business Central 中配置对应项目的部署行为,请转至 Project SettingsGeneral SettingsVersion,切换 Development Mode 选项,然后点 Save。默认情况下,KIE 服务器和 Business Central 中的所有新项目都处于开发模式中。您不能部署打开 Development 模式 的项目,或使用手动将 SNAPSHOT 版本后缀添加到生产模式的 KIE 服务器中。

    要查看项目部署详情,请单击屏幕顶部的部署横幅中的 View deployment details,或者在 Deploy 下拉菜单中。这个选项将您定向到 MenuDeployExecution Servers 页面。

Red Hat Process Automation Manager 提供以下扩展或应用程序,您可以使用它们设计业务流程模型和符号(BPMN)流程模型和决策模型和使用图形模型(DMN)决策模型。

  • Business Central :使您能够在相关的嵌入式设计人员中查看和设计 BPMN 模型、DMN 模型和测试场景文件。

    要使用 Business Central,您可以设置一个包含 Business Central 的开发环境,以设计业务规则和流程,以及一个 KIE 服务器来执行并测试所创建的业务规则和流程。

  • Red Hat Process Automation Manager VS Code 扩展 :允许您在 Visual Studio Code (VS Code)中查看和设计简单模型、DMN 模型和测试场景文件。VS Code 扩展需要 VS Code 1.46.0 或更高版本。

    要安装 Red Hat Process Automation Manager VS Code 扩展,请在 VS Code 中选择 Extensions 菜单选项,搜索并安装 Red Hat Business Automation Bundle 扩展。

  • 独立 BPMN 和 DMN 编辑器 :使您能够查看并设计嵌入在 web 应用程序中的 BPMN 和 DMN 模型。要下载所需的文件,您可以使用 NPM registry 中的 NPM 工件,或直接从 https://<YOUR_PAGE>/dmn/index.js(为 DMN独立编辑器库)或从 https://<YOUR_PAGE>/bpmn/index.js(为 BPMN 独立编辑器库)下载 JavaScript。

Red Hat Process Automation Manager 提供了一个 Red Hat Business Automation Bundle VS Code 扩展,它可让您在 VS Code 中设计决策模型和符号(DMN)决策模型、业务流程模型和符号(BPMN) 2.0 业务流程,并在 VS Code 中直接测试场景。VS Code 是开发新业务应用程序的首选集成开发环境(IDE)。Red Hat Process Automation Manager 还会根据需要为 DMNBPMN Editor VS Code 扩展提供单独的 DMN 编辑器和简单编辑器 VS Code 扩展。

重要

VS Code 中的编辑器部分与 Business Central 中的编辑器兼容,而 VS Code 不支持几个 Business Central 功能。

先决条件

  • 已安装 VS Code 的最新稳定版本。

流程

  1. 在 VS Code IDE 中,选择 Extensions 菜单选项,再搜索 Red Hat Business Automation Bundle for DMN、Janllanand 和 test scenario 文件支持。

    对于 DMN 或 BPMN 文件支持,您还可以搜索单独的 DMN Editor 或soa Editor 扩展。

  2. Red Hat Business Automation Bundle 扩展出现在 VS Code 中时,选择它并单击 Install
  3. 为获得最佳 VS Code 编辑器行为,请在扩展安装完成后,重新加载或关闭并重新启动 VS Code 的实例。

安装 VS Code 扩展捆绑包后,在 VS Code 中打开或创建的任何 .dmn.bpmn.bpmn2 文件将自动显示为图形模型。此外,您打开或创建的任何 .scesim 文件都自动显示为测试您的业务决策功能的表格测试方案模型。

如果 DMN、GINX 或测试方案模型器只打开 DMN、Payango 或测试场景文件的 XML 源,并显示错误消息,请查看报告的错误和型号文件,以确保正确定义了所有元素。

注意

对于新的 DMN 或 HPP 模型,您还可以在 Web 浏览器中输入 dmn.newbpmn.new,以在在线模型程序中设计您的 DMN 或 FDO 模型。完成模型创建后,您可以点击在线模型页面中的 Download,将 DMN 或 mail 文件导入到 VS Code 中的 Red Hat Process Automation Manager 项目中。

Red Hat Process Automation Manager 提供独立编辑器,可在自包含的库中分发,为每个编辑器提供一体化 JavaScript 文件。JavaScript 文件使用全面的 API 来设置和控制编辑器。

您可以使用以下方法安装独立编辑器:

  • 手动下载每个 JavaScript 文件
  • 使用 NPM 软件包

流程

  1. 使用以下方法之一安装独立编辑器:

    手动下载每个 JavaScript 文件 :对于此方法,请按照以下步骤操作:

    1. 下载 JavaScript 文件。
    2. 将下载的 Javascript 文件添加到您托管的应用程序中。
    3. 将以下 &lt ;script& gt; 标签添加到 HTML 页面中:

      DMN 编辑器的 HTML 页面的脚本标签

      <script src="https://<YOUR_PAGE>/dmn/index.js"></script>
      Copy to Clipboard Toggle word wrap

      FDO 编辑器的 HTML 页面的脚本标签

      <script src="https://<YOUR_PAGE>/bpmn/index.js"></script>
      Copy to Clipboard Toggle word wrap

    使用 NPM 软件包 :对于此方法,请按照以下步骤操作:

    1. 将 NPM 软件包添加到您的 package.json 文件中:

      添加 NPM 软件包

      npm install @kogito-tooling/kie-editors-standalone
      Copy to Clipboard Toggle word wrap

    2. 将每个编辑器库导入到您的 TypeScript 文件中:

      导入每个编辑器

      import * as DmnEditor from "@kogito-tooling/kie-editors-standalone/dist/dmn"
      import * as BpmnEditor from "@kogito-tooling/kie-editors-standalone/dist/bpmn"
      Copy to Clipboard Toggle word wrap

  2. 安装独立编辑器后,使用提供的编辑器 API 打开所需的编辑器,如下例所示以打开 DMN 编辑器。每个编辑器的 API 相同。

    打开 DMN 独立编辑器

    const editor = DmnEditor.open({
      container: document.getElementById("dmn-editor-container"),
      initialContent: Promise.resolve(""),
      readOnly: false,
      origin: "",
      resources: new Map([
        [
          "MyIncludedModel.dmn",
          {
            contentType: "text",
            content: Promise.resolve("")
          }
        ]
      ])
    });
    Copy to Clipboard Toggle word wrap

    在编辑器 API 中使用以下参数:

    Expand
    表 11.1. 参数示例
    参数描述

    container

    附加编辑器的 HTML 元素。

    initialContent

    对 DMN 模型内容的承诺.这个参数可以为空,如下例所示:

    • Promise.resolve("")
    • Promise.resolve("<DIAGRAM_CONTENT_DIRECTLY_HERE>")
    • fetch("MyDmnModel.dmn").then(content ⇒ content.text())

    ReadOnly (可选)

    允许您允许编辑器中的更改。设置为 false (默认)以允许在编辑器中为只读模式进行内容编辑和 true

    origin (可选)

    存储库的来源。默认值为 window.location.origin

    资源 (可选)

    编辑器的资源映射。例如,此参数用于为 DMN 编辑器提供包括的模型,或为 FDO 编辑器的工作项目定义。映射中的每个条目都包含一个资源名称,以及一个由 content-type (textbinary) 和 content (与 initialContent 参数类似) 组成的对象。

    返回的对象包含操作编辑器所需的方法。

    Expand
    表 11.2. 返回的对象方法
    方法描述

    getContent(): Promise<string>

    返回包含编辑器内容的承诺。

    setContent(path: string, content: string): void

    设置编辑器的内容。

    getPreview(): Promise<string>

    返回包含当前图表 SVG 字符串的承诺。

    subscribeToContentChanges(callback: (isDirty: boolean) ⇒ void): (isDirty: boolean) ⇒ void

    将回调设置为在编辑器中的内容更改时,并返回相同的回调以用于取消订阅。

    unsubscribeToContentChanges(callback: (isDirty: boolean) ⇒ void): void

    在编辑器中的内容更改时取消订阅传递的回调。

    markAsSaved(): void

    重置编辑器状态,指示编辑器中的内容已保存。另外,它还激活与内容更改相关的订阅回调。

    undo(): void

    撤销编辑器中的最后更改。另外,它还激活与内容更改相关的订阅回调。

    redo(): void

    在编辑器中执行最近一次撤消的更改。另外,它还激活与内容更改相关的订阅回调。

    close(): void

    关闭编辑器。

    getElementPosition (selector: string): Promise<Rect>

    提供了在可组合或视频组件内存在元素时扩展标准查询选择器的替代选择。selector 参数必须遵循 < PROVIDER>:::<SELECT& gt; 格式,如 Canvas:::MySquarevideo:::PresenterHand。此方法返回一个代表元素位置的 Rect

    envelopeApi: MessageBusClientApi<KogitoEditorEnvelopeApi>

    这是高级编辑器 API。有关高级编辑器 API 的更多信息,请参阅 MessageBusClientApiKogitoEditorEnvelopeApi

您可以使用 Maven archetypes 使用 Red Hat Process Automation Manager VS Code 扩展而不是 Business Central 在 VS Code 中开发 DMN 和 ClusterClaim 模型。然后,您可以根据需要将您的架构类型与您的红帽流程自动化管理器决策和流程服务集成。这种开发 DMN 和 BPMN 模型的方法有助于使用红帽流程自动化管理器 VS Code 扩展构建新的业务应用程序。

流程

  1. 在命令终端中,导航到要存储新 Red Hat Process Automation Manager 项目的本地文件夹。
  2. 输入以下命令使用 Maven archtype 在定义的文件夹中生成项目:

    使用 Maven archetype 生成项目

    mvn archetype:generate \
        -DarchetypeGroupId=org.kie \
        -DarchetypeArtifactId=kie-kjar-archetype \
        -DarchetypeVersion=7.59.0.Final-redhat-00006
    Copy to Clipboard Toggle word wrap

    此命令生成具有所需依赖项的 Maven 项目,并生成所需的目录和文件来构建您的业务应用程序。在开发项目时,您可以使用 Git 版本控制系统(推荐)。

    如果要在同一目录中生成多个项目,请在上一个命令中添加 -DgroupId=<groupid> -DartifactId=<artifactId> 来指定生成的业务应用程序的 artifactIdgroupId

  3. 在 VS Code IDE 中,单击 File,选择 Open Folder,再导航到使用上一命令生成的文件夹。
  4. 在创建第一个资产前,为您的业务应用程序设置软件包,例如 org.kie. businessapp,并在以下路径中创建对应的目录:

    • PROJECT_HOME/src/main/java
    • PROJECT_HOME/src/main/resources
    • PROJECT_HOME/src/test/resources

    例如,您可以为 org.kie. businessapp 软件包创建 PROJECT_HOME/src/main/java/org/kie/ businessapp

  5. 使用 VS Code 为业务应用程序创建资产。您可以使用以下方法创建 Red Hat Process Automation Manager VS Code 扩展支持的资产:

    • 要创建业务流程,请在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个 .bpmn.bpmn2 的新文件,如 Process.bpmn
    • 要创建 DMN 模型,在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个包含 .dmn 的新文件,如 AgeDecision.dmn
    • 要创建测试场景模拟模型,请在 PROJECT_HOME/src/main/java/org/kie/ businessapp 目录中创建一个包含 .scesim 的新文件,如 TestAgeScenario.scesim
  6. 在 Maven archetype 中创建资产后,在命令行中导航到项目的根目录(包含 pom.xml)并运行以下命令来构建项目的知识 JAR (KJAR):

    mvn clean install
    Copy to Clipboard Toggle word wrap

    如果构建失败,请解决命令行错误消息中描述的任何问题,然后再次尝试验证项目,直到构建成功为止。但是,如果构建成功,您可以在 PROJECT_HOME/target 目录中找到业务应用程序的工件。

    注意

    在开发过程中,使用 mvn clean install 命令通常会在每次主要更改后验证项目。

您可以使用 REST API 将业务应用程序生成的知识 JAR (KJAR)部署到运行的 KIE 服务器上。有关使用 REST API 的更多信息,请参阅使用 KIE API 与红帽流程自动化管理器交互

第 13 章 创建用户

您可以根据需要创建任意数量的 Business Central 用户。用户特权和设置由分配给用户和组的角色控制。在本例中,您必须创建两个新用户:K ty 将充当银行的 loan 经理和批准人,Bill 将被作为 loan 的代理。有关创建用户的更多信息,请参阅 Installing and configuring Red Hat Process Automation Manager on Red Hat JBoss EAP 7.4 中的创建用户一章。

在 Business Central 中,您可以使用组和角色来控制一组用户的权限。您可以根据需要创建任意数量的组和角色,但组必须至少有一个用户。

  • 在本例中,工作任务的用户或用户必须分配给以下一个或多个组和角色:

    • approver 组:对于 Qualify 任务
    • broker 组: 对于 更正 数据 并增加关闭 任务
    • Manager 角色: 对于 最终批准 任务

流程

  1. 点击右上角的齿轮图标 gear icon 并点 Users
  2. new user ,输入 Katy,点 Next,然后点 Create
  3. Yes 设定密码,在两个字段中输入 Katy,然后点 Change
  4. 输入 Bill,点 Next,然后点 Create
  5. 单击 Yes 以设置密码,在这两个字段中输入 Bill,然后点 Change
  6. Groups 选项卡并点击 new group ,输入 approver,然后点 Next
  7. 从用户列表中选择 Katy,然后点 Add selected users
  8. 输入 broker,然后点 Next
  9. 从用户列表中选择 Bill,然后点 Add selected users
  10. Users 选项卡,选择 Katy,然后点 EditRolesAdd roles
  11. 选择 manager,点 Add to selected roles,然后点 Save
  12. Groups 标签页,点 EditGroupsAdd to groups
  13. 选择 approverkie-server,然后点 Add to selected groups
  14. 点击 Save
  15. Users 选项卡,从用户列表中选择 Bill,然后点 EditRolesAdd roles
  16. 选择 用户,然后单击 Add to selected roles
  17. Groups 选项卡,点 new group ,选择 kie-server,然后点 Add to selected groups
  18. 点击 Save

第 14 章 创建 mortgage-process 项目

项目是数据对象、业务流程、指导规则、决策表和表单等资产的容器。您要创建的项目与 Business Central 中的现有 Mortgage_Process 示例项目类似。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects

    Red Hat Process Automation Manager 提供一个名为 MySpace 的默认空间,如下图所示。您可以使用默认空间来创建和测试示例项目。

    图 14.1. 默认空间

  2. 单击 Add Project
  3. Name 字段中输入 mortgage-process
  4. 点击 Configure Advanced Options 并使用以下值修改 GAV 字段:

    • 组 IDcom.myspace
    • 工件 ID:mortgage-process
    • Version:1.0.0
  5. 点击 Add

项目的 Assets 视图将打开。

第 15 章 创建 mortgage-process 数据对象

数据对象是您创建的规则资产的构建块。数据对象是作为项目指定软件包中的 Java 类实施的自定义数据类型。这些自定义数据类型决定了您的资产和您的决定服务所基于的数据。

mortgage 进程项目使用以下数据对象:

  • Applicant
  • 属性
  • ValidationErrorDO
  • Application(应用程序)

15.1. 创建 Applicant 数据对象

创建 Applicant 数据对象,其中包含有关适用者的信息。这是本教程中适用于 loan 所必需的基本信息。

流程

  1. 在 Business Central 中,单击 MySpace 默认空间。
  2. MenuDesignProjects 并点击 mortgage-process
  3. 单击 Add Asset,再选择 Data Object
  4. Create new Data Object 窗口的 Data Object 字段中输入 Applicant
  5. Package 下拉菜单中选择 com.myspace.mortgage_app然后单击确定
  6. 'Applicant'- general properties 部分的 Label 字段中输入 Applicant
  7. +add 字段 并输入以下 Applicant data object 值。在每个添加后点 Create and continue。对于最后的添加,请单击 Create

    图 15.1. 应用的数据对象字段值

  8. 点击 Save

15.2. 创建属性数据对象

创建 Property data 对象,其中包含有关属性详细信息的信息,如属性年龄和价格。

流程

  1. 在 Business Central 中,单击 MySpace 默认空间。
  2. MenuDesignProjects 并点击 mortgage-process
  3. 单击 Add Asset,再选择 Data Object
  4. Create new Data Object 窗口的 Data Object 字段输入 Property
  5. Package 下拉菜单中选择 com.myspace.mortgage_app然后单击确定
  6. 'Property'- general properties 部分的 Label 字段中输入 Property
  7. 单击 +add 字段,并输入以下 属性 数据对象值。在每个添加后点 Create and continue。对于最后的添加,请单击 Create

    图 15.2. 属性数据对象字段值

  8. 点击 Save

15.3. 创建 ValidationErrorDO 数据对象

创建 ValidationErrorDO data 对象,它指定应用错误的原因。

流程

  1. 在 Business Central 中,单击 MySpace 默认空间。
  2. MenuDesignProjects 并点击 mortgage-process
  3. 单击 Add Asset,再选择 Data Object
  4. Create new Data Object 窗口的 Data Object 字段中输入 ValidationErrorDO
  5. Package 下拉菜单中选择 com.myspace.mortgage_app然后单击确定
  6. 'ValidationErrorDO'- general properties 部分的 Label 字段中输入 ValidationErrorDO
  7. 单击 +add 字段,然后输入以下 ValidationErrorDO data 对象值。在每个添加后点 Create and continue。对于最后的添加,请单击 Create

    图 15.3. ValidationErrorDO data 对象字段值

  8. 点击 Save

15.4. 创建应用程序数据对象

创建应用 数据对象,其中包含有关 mortgage 详细信息的信息,如下支付和抵制数。

流程

  1. 在 Business Central 中,单击 MySpace 默认空间。
  2. MenuDesignProjects 并点击 mortgage-process
  3. 单击 Add Asset,再选择 Data Object
  4. Create new Data Object 窗口的 Data Object 字段中输入 Application
  5. Package 下拉菜单中选择 com.myspace.mortgage_app然后单击确定
  6. 'Application'- general properties 部分的 Label 字段中输入 Application
  7. +add 字段 并输入以下 Application data 对象值。在每个添加后点 Create and continue。对于最后的添加,请单击 Create

    图 15.4. 应用程序数据对象字段值

  8. 点击 Save

第 16 章 Business Central 中的业务流程

迁移过程是一个图表,用于描述必须使用流图执行一系列步骤的顺序。业务流程由一组节点组成,它们通过连接相互连接。每个节点代表整个过程中的一个步骤,连接指定了如何从一个节点过渡到另一个节点。

Mortgage_Process 示例包含以下预定义的 MortgageApprovalProcess 业务流程。

sampleBP

16.1. 创建业务流程

以下流程指导您创建组成 MortgageApprovalProcess 业务流程的任务、连接和网关。抵制验证业务流程决定是否包含所有需要的数据。如果满足指定的数据要求,应用程序将继续计算业务流程。

流程

  1. 在 Business Central 中,进入 MenuDesignProjectsMortgage-Process
  2. Add AssetBusiness Process
  3. 输入以下值:

    • 业务流程MortgageApprovalProcess
    • 软件包 :选择 com.myspace.mortgage_app

      Package 指定创建资产的现有项目内的位置。在本例中,它在 com/myspace/mortgage_app 中创建。

  4. 确定。示意图编辑器将打开。
  5. 在右上角点击 Properties diagram properties 图标。
  6. 向下滚动并展开 Process Data,然后点击 Process Variables 部分中的 btn plus
  7. 输入以下值:

    • 名称application
    • 数据类型Application [com.myspace.mortgage_app]

16.1.1. 创建传出连接和专用网关

本节介绍如何创建传出连接、专用网关和业务规则任务。使用专用网关根据可用数据做出决策并响应事件。

Red Hat Process Automation Manager 包含预定义的节点类型选择,以简化迁移过程创建。预定义的节点面板位于图编辑器的左侧。

node panel

流程

  1. 将启动事件节点拖到 canvas 中。
  2. 创建从启动事件到专用网关的传出连接:

    1. 在 canvas 上,点启动事件节点并点 Create Parallel 图标。

    2. 将鼠标悬停在并行的 config icon 图标上,然后点击 Convert into Exclusive 图标。

  3. 创建从专用网关到业务规则任务传出的连接:

    1. 在 canvas 上,点 exclusive 网关并点 Create Task 图标。
    2. 将鼠标悬停在任务的 config icon 图标上,然后点击 Convert into Business Rule 图标。

  4. 配置商业规则任务:

    1. 点 业务规则 任务。
    2. 如果没有打开 Properties 面板,点右上角的 Properties diagram properties 图标。
    3. Properties 面板中,在 Name 字段中输入 Validation
    4. 展开 Implementation/Execution,从 Rule Flow Group 菜单中选择 New,并输入 验证
    5. On Exit Action 字段中,输入以下 Java 表达式:

      System.out.println(application.getProperty());
      Copy to Clipboard Toggle word wrap
    6. 展开 数据分配,然后点击分配 btn assign 旁边的
    7. Validation Data I/O 窗口中,点 Add 并创建以下分配:

      • 数据输入和分配

        • Name: application
        • 数据类型:Application [com.myspace.mortgage_app]
        • Source: application
      • 数据块和分配

        • Name: application
        • 数据类型:Application [com.myspace.mortgage_app]
        • target: application

          图 16.1. 验证数据 I/O 分配

  5. Validation Data I/O 窗口中,单击 OK
  6. 在 canvas 上方,单击 Save 以确认更改。

16.1.2. 定义验证数据

本节演示了如何定义验证数据,以确定应用程序数据是否正确、包含错误或缺少信息。

流程

  1. 创建从 Validation 任务到专用网关的传出连接:

    1. 单击 Validation 任务,再单击 Create Parallel 图标。
    2. 将鼠标悬停在并行的 config icon 图标上,然后点击 Convert into Exclusive 图标。

  2. 创建从专用网关到新业务规则任务的传出连接:

    1. 点 exclusive gateway 并点 Create Task 图标。
    2. 按照下图所示,拖动专用网关下的新任务。
    3. 将鼠标悬停在任务的 config icon 图标上,然后点击 Convert into Business Rule 图标。

    4. 如果没有打开 Properties 面板,点右上角的 Properties diagram properties 图标。
    5. Properties 面板中,在 Name 字段中输入 Retract Validation
    6. 展开 Implementation/Execution,从 Rule Flow Group 菜单中选择 New,并 输入错误
  3. 配置专用网关和业务规则任务之间的连接:

    1. 点连接。

    2. 如果没有打开 Properties 面板,点右上角的 Properties diagram properties 图标。
    3. Properties 面板中,在 Name 字段中输入 Invalid
    4. 展开 Implementation/Execution,然后在 Condition Expression 部分中选择 Expression
    5. 从列表中,选择 drools,然后在 Condition Expression 字段中输入 ValidationErrorDO ()

  4. 创建从 Retract Validation 任务到新用户任务的传出连接:

    1. 单击 Retract Validation 任务,再单击 Create Task 图标。
    2. 按照如下所示,拖动 Validation 任务下的新任务。
    3. 将鼠标悬停在任务的 config icon 图标上,然后点击 Convert into User 图标。

    4. 单击新用户任务并在 Properties 面板中,在 Name 字段中输入 Correct Data
    5. 展开 Implementation/Execution,并在 Task Name 字段中输入 CorrectData
    6. Groups 菜单中选择 New,输入 代理
    7. Assignments 旁边的 btn assign
    8. Correct Data Data I/O 窗口中,点 Add 并创建以下分配:

      • Name: application
      • 数据类型:Application [com.myspace.mortgage_app]
      • Source: application

        • 数据块和分配
      • Name: application
      • 数据类型:Application [com.myspace.mortgage_app]
      • target: application

        图 16.2. 正确的数据 I/O 分配

    9. 在 Correct Data I/O 窗口中,单击 OK
    10. 在 canvas 上方单击 Save
  5. 单击 Correct Data user 任务,然后单击 Create sequence Flow 图标,并将它拖到第一个专用网关。您的工作流应类似以下示例:

16.1.3. 计算抵制处理

抵制计算业务流程决定了应用程序的增长限制。

流程

  1. 返回到第二家网关,并创建与新业务规则任务传出的连接。
  2. 单击创建的连接,然后在 Properties 面板中,在 Name 字段中输入 Valid

    1. 展开 Implementation/Execution,然后在 Condition Expression 部分中选择 Expression
    2. 从列表中,选择 drools,然后在 Condition Expression 字段中输入 not ValidationErrorDO ()
  3. 单击新的业务规则任务并在 Properties 面板中,在 Name 字段中输入 Mortgage Calculation

    1. 展开 Implementation/Execution,从 Rule Flow Group 菜单中选择 New,输入 mortgagecalculation
  4. 展开 数据分配,然后点击分配 btn assign 旁边的
  5. Mortgage Calculation Data I/O 窗口中,单击 Add 以创建以下分配,然后单击 Save

    图 16.3. 抵制数据 I/O 分配

  6. Mortgage Calculation Data I/O 窗口中,单击 OK
  7. 点 canvas 上的空空间,向下滚动、展开 Process Data,然后点击 Process Variables 旁边的 btn plus 。输入以下值:

    • 名称:inlimit
    • 数据类型布尔值
  8. 创建从 Mortgage Calculation 任务到新用户任务的传出连接。
  9. 点 user 任务, Name 字段中输入 Qualify。
  10. 展开 Implementation/Execution并在 Task Name 字段中输入 Qualify。
  11. Groups 菜单中选择 New,并输入 approver
  12. Assignments 旁边的 btn assign 。在 Qualify Data I/O 窗口中,点击 Add 来创建以下分配:

    图 16.4. 符合数据 I/O 分配功能

  13. Qualify Data I/O 窗口中,单击 OK
  14. 在 canvas 上方,单击 Save 以确认更改。
  15. 单击 Qualify 用户任务,单击 Create parallel 菜单图标,并将其转换为专用网关。
  16. Qualify 用户任务下拖动新的独家网关。
  17. 从专用网关创建传出连接,并将它连接到新用户任务。
  18. Properties 面板的 Name 字段中,单击连接并输入 In Limit
  19. 展开 Implementation/Execution,然后在 Condition Expression 部分中选择 Condition
  20. Process Variable 下拉菜单中选择 inlimit,然后从 Condition 下拉菜单中选择 Is true

  21. 点 user 任务,在 Name 字段中输入 Final Approval
  22. 展开 Implementation/Execution,并在 Task Name 字段中输入 FinalApproval
  23. Groups 菜单中选择 New,并输入 manager
  24. Assignments 旁边的 btn assign 。在 Final Approval Data I/O 窗口中,点 Add 创建以下分配:

    图 16.5. 最终批准数据 I/O 分配

  25. Final Approval Data I/O 窗口中点 OK
  26. 在 canvas 上方,单击 Save 以确认更改。

16.1.4. 增加下支付

增加 Down Payment 业务流程检查,通过增加付款来查看适用适用象限是否达到了严重影响。最终的结果是最终的 loan 批准,或根据适用方无法增加付款而拒绝。

流程

  1. Final Approval user 任务,然后从 user 任务快速菜单中选择 Create End
  2. 将最终事件移到 Final Approval user 任务下。

  3. 返回到与 最终批准 用户任务连接的专用网关。创建第二个传出连接,并将它连接到新用户任务。

  4. Properties 面板的 Name 字段中,单击连接并输入 Not in Limit
  5. 展开 Implementation/Execution,然后在 Condition Expression 部分中选择 Condition
  6. Process Variable 下拉菜单中选择 inlimit,然后从 Condition 下拉菜单中选择 Is false
  7. 点 canvas 上的空空间,向下滚动、展开 Process Data,然后点击 Process Variables 旁边的 btn plus 。输入以下值:

  8. 单击新用户任务,然后在 Properties 面板中,在 Name 字段中输入 increasing Down Payment
  9. 展开 Implementation/Execution,并在 Task Name 字段中输入 increasing DownPayment
  10. Groups 菜单中选择 New,输入 代理
  11. Assignments 旁边的 btn assign 。在 increasing Down Payment Data I/O 窗口中,点 Add 创建以下分配:

    图 16.6. 增加停机数据 I/O 分配

  12. 在 increasing Down Payment Data I/O 窗口中,单击 OK
  13. 在 canvas 上方,单击 Save 以确认更改。
  14. 单击 increasing Down Payment user 任务,单击 Create parallel 菜单图标,并将其转换为专用网关。
  15. 在 increasing Down Payment user 任务下拖动新的独家网关。
  16. 创建从专用网关到结束事件的传出连接。
  17. Properties 面板的 Name 字段中,单击连接并输入 Down 付款
  18. 展开 Implementation/Execution,并在 Condition Expression 部分中选择 Expresssion
  19. 输入 返回 !incdownpayment; 然后从下拉菜单中选择 java
  20. 从专用网关创建传出连接,并将它连接到第一个专用网关。
  21. Properties 面板的 Name 字段中,单击连接并输入 Down 付款
  22. 展开 Implementation/Execution,并在 Condition Expression 部分中选择 Expresssion
  23. 输入 返回 incdownpayment; 然后从下拉菜单中选择 java
  24. 在 canvas 上方,单击 Save 以确认更改并保存整个业务流程。

图 16.7. 业务流程的最终版本

第 17 章 指导规则

指导规则是在 Business Central 中的基于 UI 的引导规则设计程序中创建的业务规则,引导您通过规则创建流程。指导规则设计程序根据所定义的规则的数据对象提供可接受的输入字段和选项。您定义的指导规则被编译到 Drools 规则语言(DRL)规则中,与所有其他规则资产一样。

与指导规则相关的所有数据对象都必须与指导规则位于同一个项目中。默认情况下,同一软件包中的资产会导入。创建必要的数据对象和指导规则后,您可以使用指导规则设计器的 Data Objects 选项卡来验证所有所需的数据对象是否都已列出或导入其他现有 的数据对象

17.1. 查看 Mortgage_Process 业务规则

本章的目标是向您介绍 Mortgage_Process 项目的预定义业务规则。在本教程中,您不会创建和定义业务规则。相反,请查看 Mortgage_Process 示例项目预先配置的 WHENTHEN 规则。有关创建指导业务规则的详情,请参考使用指导规则设计决策服务

17.1.1. 查看 Validate Down Payment 指导规则

查看 WHENTHEN 规则,以便了解条件如何设置并在运行进程时如何使用。

流程

  1. MenuDesignProjects,然后点 Mortgage_Process
  2. 在资产列表中,点击右箭头查看资产列表的第二个页面,然后点击 Validate Down Payment 指导规则。
  3. 查看 Validate Down Payment 指导规则的 WHEN 和 RED N 条件和值。

17.1.2. 查看 RetractValidationErr guided 规则

查看 WHENTHEN 规则,以便了解条件如何设置并在运行进程时如何使用。

流程

  1. MenuDesignProjects,然后点 Mortgage_Process
  2. 在资产列表中,点击向右箭头查看资产列表的第二个页面,然后点击 RetractValidationErr guided 规则。
  3. 查看 RetractValidationErr ationErr guided 规则的 WHENpro N 条件和值。

第 18 章 指导决策表

指导决策表是一种带向导的替代方法,用于以表格形式定义业务规则。通过指导决策表,您由 Business Central 中的基于 UI 的向导引导,它可帮助您根据项目中的指定数据对象定义规则属性、元数据、条件和操作。创建引导决策表后,您定义的规则将编译到 Drools 规则语言(DRL)规则中,与所有其他规则资产一样。

与引导决策表相关的所有数据对象都必须与引导决策表位于同一个项目软件包中。默认情况下,同一软件包中的资产会导入。创建必要的数据对象和指导决策表后,您可以使用指导决策表设计器的 Data Objects 选项卡来验证所有所需的数据对象是否都已列出或导入其他现有 的数据对象

18.1. 查看 mortgage 决策表

本章的目标是向您介绍 MortgageDecisionTable 决策表。在本教程中,您不会创建和设置路由表条件。相反,请查看 Mortgage_Process sample 项目的 Mortgage DecisionTable Guided Decision Tables asset 中的值和状况。有关创建决策表的详情,请参考使用指导决策表设计决策服务

先决条件

流程

  1. 在 Business Central 中,进入 MenuDesignProjectsMortgage_Process
  2. 向下滚动并单击 MortgageDecisionTable Guided Decision Tables asset。

    loans guided dt

第 19 章 在 Business Central 中形成形式

表单是页面的布局定义,定义为 HTML,在进程和任务实例化过程中显示为用户的对话框窗口。任务表单从用户获取进程和任务实例执行的数据,而进程表单则从进程变量获取输入和输出。

然后,输入将使用数据输入分配来映射到任务,您可以在任务内部使用。任务完成后,数据映射为数据输出分配,以向父进程实例提供数据。

19.1. 查看 Mortgage_Process 表单

本章的目标是向您介绍 Mortgage_Process 示例项目的预定义形式,用于为抵御应用程序业务流程收集用户数据。在本教程中,您不会创建和修改 Mortgage_Process 表单。相反,请查看预定义的示例表单。有关创建表单的详情,请参考使用 BPMN 模型设计业务流程

流程

  1. 在 Business Central 中,进入 MenuDesignProjectsMortgage_Process
  2. 在资产列表中,点击右箭头查看资产列表的第二个页面,然后选择 Applicant 表单。

    图 19.1. Applicant 示例表单

  3. MenuDesignProjectsMortgage_Process
  4. 从资产列表中,选择 Property 表单。Property 表单在以下屏幕截图中显示:

    图 19.2. 属性示例表单

  5. MenuDesignProjectsMortgage_Process
  6. 从资产列表中,选择 Application 表单。Application 表单在以下屏幕截图中显示:

    图 19.3. 应用程序示例表单

  7. 单击右上角的 X 图标以关闭编辑器。

本章介绍了如何在红帽流程自动化管理器中构建和部署 Mortgage_Process 应用程序的新实例。

先决条件

  • KIE 服务器已部署并连接到 Business Central。

流程

  1. 在 Business Central 中,进入 MenuDesignProjectsMortgage_Process
  2. 单击 Deploy

    • 如果项目名称中不包含 KIE 容器(部署单元),则会自动创建具有默认值的容器。
    • 如果已经部署了项目的旧版本,请转至项目设置并更改项目版本。完成后,保存更改并点 Deploy。这会部署同一项目的新版本,并有最新的更改,以及旧版本。

      注意

      您还可以选择 Build & Install 选项来构建项目,并将 KJAR 文件发布到配置的 Maven 存储库,而无需部署到 KIE 服务器。在开发环境中,您可以点击 Deploy 将构建的 KJAR 文件部署到 KIE 服务器,而无需停止任何正在运行的实例(如果适用),或者点击 Redeploy 部署构建的 KJAR 文件并替换所有实例。下次部署或重新部署构建的 KJAR 时,以前的部署单元(KIE 容器)会在同一目标 KIE 服务器中自动更新。在生产环境中,Redeploy 选项被禁用,您可以点 Deploy only 将构建的 KJAR 文件部署到 KIE 服务器上的新部署单元(KIE 容器)。

      要配置 KIE 服务器环境模式,请将 org.kie.server.mode 系统属性设置为 org.kie.server.mode=developmentorg.kie.server.mode=production。要在 Business Central 中为对应项目配置部署行为,请转至 Project SettingsGeneral SettingsVersion 并切换 Development Mode 选项。默认情况下,KIE 服务器和 Business Central 中的所有新项目都处于开发模式中。您不能部署打开 Development 模式 的项目,或使用手动将 SNAPSHOT 版本后缀添加到生产模式的 KIE 服务器中。

  3. 要查看项目部署详情,请单击屏幕顶部的部署横幅中的 View deployment details,或者在 Deploy 下拉菜单中。这个选项将您定向到 MenuDeployExecution Servers 页面。

现在您已经部署了项目,您可以执行项目的定义功能。在本教程中,您可以将数据输入到作为 mortgage 代理的 mortgage 应用程序表单中。MortgageApprovalProcess 业务流程运行并决定是否根据您之前定义的决策规则提供了可接受的付款。业务流程结束规则测试或申请者增加付款的请求。如果应用程序通过业务规则测试,银行的批准者将审查该应用程序并批准或拒绝该遗漏。

先决条件

  • KIE 服务器已部署并连接到 Business Central。
  • Mortgage_Process 应用程序已被部署。
  • 处理任务的用户是以下组和角色的成员:

    • approver 组:对于 Qualify 任务
    • broker 组: 对于 更正 数据 并增加关闭 任务
    • Manager 角色: 对于 最终批准 任务

流程

  1. Bill (代理)登录到 Red Hat Process Automation Manager,然后点击 MenuManageProcess Definitions
  2. Actions 列中的三个垂直点,然后选择 Start 来打开 Application 表单,并在表单字段中输入以下值:

    • 下拉支付30000
    • 抵制的 年份:10
    • 名称Ivo
    • Annual Income: 60000
    • SSN:123456789
    • 属性的年龄8
    • 属性地址 :Brno
    • locale:Rural
    • 属性价格50000
  3. Submit 以开始新进程实例。启动进程实例后,Instance Details 视图将打开。
  4. 单击 Diagram 选项卡,以查看进程图中的进程流。进程的状态在移动每个任务时突出显示。

  5. 从 Business Central 注销,然后以 Katy 重新登录。
  6. MenuTrackTask Inbox。这将使您进入 Qualify 表单
  7. 单击 Actions 列中的三个垂直点,再选择 并单击 Claim。Qualify 任务 Status 现在 被保留
  8. Qualify 任务行打开并查看任务信息。在表单的底部点 Claim 然后点 Start

    现在,应用程序表单处于活跃状态用于批准或拒绝。

  9. 要批准应用程序,请选择 mortgage 应用程序是否限制?,然后点 Complete
  10. Task Inbox 中,点 Final Approval 行中的任意位置打开 Final Approval 任务。
  11. Final Approval 行中,点 Actions 列中的三个垂直点,然后点击 Claim
  12. 点击 Final Approval 行中的任意位置,以打开 Final Approval 任务。单击表单底部的 Start
  13. 请注意,选择了 Inlimit 复选框来反映应用程序已准备好进行最终批准。单击 Complete
注意

SaveRelease 按钮仅用于暂停批准过程,并在等待字段值时保存实例,或者释放其他用户的任务。

下面的章节演示了不同的银行员工(如系统管理员或知识工作者)如何使用部分监控功能来跟踪抵御审批流程的实例。

先决条件

  • KIE 服务器已部署并连接到 Business Central。

流程

  1. 登录到 Red Hat Process Automation Manager,再点击 MenuManageProcess Instances
  2. Manage Process Instances 窗口中,您可以设置过滤器,如 StateErrorsId 等等。
  3. State 过滤器中选择 Completed 来查看所有已完成的 MortgageApprovalProcess 实例。
  4. 点完成的进程实例。
  5. 单击以下每个选项卡,以感觉哪些类型的信息可用于监控特定进程实例:

    • 实例详情
    • 进程变量
    • 文档
    • 日志
    • 图表
  6. MenuTrackProcess Reports。此视图包含各种图表,可显示基于 Type, Start Date, Running Time 等生成的高级别的任务报告。

22.1. 使用默认或高级过滤器过滤进程实例

Business Central 现在为您提供默认和高级过滤器,可帮助您过滤和搜索运行中的进程实例。您还可以使用 Advanced Filters 选项创建自定义过滤器。

22.1.1. 使用默认过滤器过滤进程实例

根据 StateErrorsFilter ByNameStart DateLast update 等属性过滤进程实例。

流程

  1. 在 Business Central 中,前往 MenuManageProcess Instances
  2. Manage Process Instances 页面上,单击页面左侧的过滤器图标以展开 Filters 窗格。

    此窗格列出了可用于过滤进程实例的以下进程属性:

    • State :根据状态(ActiveAbortedCompletedPendingSuspended)过滤进程实例。
    • 错误 :根据错误过滤进程实例。
    • Filter By: Filter process instances based Id,Initiator,Correlation Key, 或 Description 属性。

      1. 选择 required 属性。
      2. 在下面的文本字段中输入搜索查询。
      3. 应用
    • 名称 :按定义名称过滤进程实例。
    • 定义 Id :按进程定义 ID 过滤进程实例。
    • Deployment Id :按进程部署 ID 过滤进程实例。
    • 父进程实例 Id :按父进程实例 ID 过滤进程实例。
    • SLA 合规性 :按 SLA 合规性状态过滤进程实例.
    • 起始日期 :按创建日期过滤进程实例。
    • 最后更新 : 按上次修改的日期过滤进程实例。

22.1.2. 使用高级过滤器过滤进程实例

使用 Advanced Filters 选项创建自定义进程实例过滤器。新创建的自定义过滤器添加到 Saved Filters 窗格中,可通过单击 Manage Process Instances 页面左侧的 star 图标来访问。

流程

  1. 在 Business Central 中,前往 MenuManageProcess Instances
  2. Manage Process Instances 页面上,单击页面左侧的 Advanced Filters 图标。
  3. Advanced Filters 窗格中,输入过滤器的名称和描述,然后单击 Add New
  4. Select column 下拉列表中选择一个属性,如 processName。下拉列表的内容更改为 processName != value1
  5. 再次单击下拉菜单并选择所需的逻辑查询。对于 processName 属性,选择 等于
  6. 将文本字段的值更改为您要过滤的进程的名称。

    注意

    名称必须与项目的业务流程中定义的值匹配。

  7. Save,并根据过滤器定义过滤进程。
  8. 单击星形图标,以打开 Saved Filters 窗格。

    Saved Filters 窗格中,您可以查看所有保存的高级过滤器。

第 23 章 其他资源

作为业务规则和流程开发人员,您可以在 Business Central 中使用案例管理资产来创建不可预测的和临时案例流程。问题单工作者或流程管理员还可以使用 Business Central 进行案例管理和执行。Red Hat Process Automation Manager 为示例项目提供 Business Central 中的示例业务资产作为参考。本文档论述了如何基于 Business Central 中包含的 IT_Orders 示例项目创建并测试示例 IT 订购项目。

先决条件

第 24 章 检查 IT_Orders 示例项目

在创建自己的案例管理项目之前,请先查阅 Business Central 中的现有 IT_Orders 示例管理项目。此示例项目包含预定义的问题单管理资产,作为您自己案例项目的参考。

重要

业务流程应用程序示例仅包含技术预览。红帽产品服务等级协议(SLA)不支持技术预览功能,且可能并不完善,且不建议在生产环境中使用。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

流程

  1. 在 Business Central 中,前往 MenuDesignProjects。如果存在现有项目,您可以点击 MySpace 默认空间,然后从 Add Project 下拉菜单中选择 Try Samples 来访问示例。如果没有现有项目,请单击 Try samples
  2. 选择 IT_Orders 并单击确定

项目的 Assets 视图将打开。选择每个示例资产来探索项目如何实现指定目标或工作流。

查看 订单硬件 业务流程,以帮助您了解业务流程流。

第 25 章 创建新的 IT_Orders case 项目

在 Business Central 中创建一个新的 IT_Orders 项目,以了解所有必要的资产及其在项目中的使用情况。

流程

  1. 登录 Business Central 并前往 MenuDesignProjects

    Business Central 提供一个名为 MySpace 的默认空间,如下图所示。您可以使用默认空间来创建和测试示例项目。

    图 25.1. 默认空格

  2. 点击 Add Project 旁边的箭头并选择 Case 项目

    图 25.2. 问题单项目

  3. Add Project 窗口中,在 Name 字段中输入 IT_Orders_New,再输入 项目描述

    图 25.3. 添加项目窗口

  4. 点击 Add

    项目的 Assets 视图将打开。

第 26 章 数据对象

数据对象是您创建的规则资产的构建块。数据对象是项目指定软件包中作为 Java 对象实施的自定义数据类型。例如,您可以创建一个带有数据字段 Name, Address, 和 DateOfBirthPerson 对象,以指定 loan 应用程序规则的个人详情。这些自定义数据类型决定了您的资产和您的决定服务所基于的数据。

26.1. 创建 ITOrderService 数据对象

ITOrderService 数据对象指定用于定义 IT Orders 变量的数据类型。

先决条件

  • IT_Orders_New 项目已创建并在 Business Central 中打开。

流程

  1. IT_Orders_New 项目中,单击 Add Asset,然后单击 Data Object
  2. 在 Create new Data Object 向导中输入以下值:

    • 数据对象: ITOrderService
    • package: com.myspace.it_orders_new
  3. 确定
  4. 点击 Package 下拉菜单旁的 plus sign 为数据对象创建新软件包。
  5. 输入 org.jbpm.demo.it_orders.services 并点 Add
  6. 单击 Save,然后单击 Yes, Move 以确认您的更改。

26.2. 创建问卷调查数据对象

Survey data 对象包含数据字段,如 deliveredOnTimemissingEquipment。在设计您的情况时,您将使用数据和值。

先决条件

  • IT_Orders_New 项目已创建并在 Business Central 中打开。

流程

  1. Add AssetData Object
  2. Create new Data Object 向导中输入以下值:

    • 数据对象问卷调查
    • 软件包com.myspace.it_orders_new
  3. 确定
  4. 添加 Survey 数据对象约束。

    1. 添加字段
    2. 输入以下值,然后点 Create and Continue

      • id:comment
      • 标签 :留空
      • 类型字符串
    3. Create 并继续,然后输入以下值:

      • ID:deliveredOnTime
      • 标签 :留空
      • 键入:布尔值
    4. New Field 窗口中,输入以下值:

      • id:missingEquipment
      • 标签 :留空
      • 类型字符串
    5. Create 并继续,输入以下值:

      • ID满足
      • 键入:布尔值
    6. Create
  5. 在调查窗口中,单击 Save 以确认更改。

    图 26.1. 问卷调查数据对象详情

第 27 章 设计问题单定义

您在 Business Central 中使用流程设计程序设计案例。案例设计是案例管理的基础,为每个情况设置具体目标和任务。可以通过添加动态任务或进程在运行时动态修改案例流。在此过程中,您将创建相同的问题单定义以熟悉案例定义设计过程。

Business Central 中的 IT_Orders 示例项目包括以下 订单硬件 业务流程定义:

图 27.1. 订购硬件商业流程定义

先决条件

流程

  1. IT_Orders_New 项目中,点 Add Asset
  2. Add Asset 窗口中点击 Case Definition
  3. Create new Case 定义 窗口中,在 case 定义框中输入 orderhardware。这通常是管理案例或项目的主题。

    • Package 菜单中选择 com.myspace.it_orders_new,以指定在其中创建问题单文件的位置。
  4. 确定。进程设计器将打开。
  5. 为案例中使用的子进程、子问题单和业务规则访问案例文件变量的值。

    1. 在右上角点击 Properties diagram properties 图标。
    2. 向下滚动并展开 Case Management,点 Case File Variables 部分中的 btn plus ,并输入以下内容:

      图 27.2. 顺序硬件问题单文件变量

    注意

    以下问题单文件变量是自定义数据类型:

    • hwSpec :org.jbpm.document.Document (这个值中的类型)
    • 调查 :调查 [com.myspace.it_orders_new](选择这个值)
  6. 点击 Save
  7. 定义案例中涉及的角色。

    1. 在右上角点击 Properties diagram properties 图标。
    2. 向下滚动并展开 Case Management,点 Case Roles 部分中的 btn plus ,并输入以下内容:

      图 27.3. 顺序硬件案例角色

      • 所有者 :正在发出硬件订单请求的员工。角色卡设置为 1,这意味着只能为这个角色分配一个个人或组。
      • 管理器 :员工的经理;批准或拒绝请求的硬件的人员。角色卡设置为 1,这意味着只能为这个角色分配一个个人或组。
      • 供应商 :系统中 IT 硬件的可用供应商。角色卡设置为 2,这意味着可以为这个角色分配多个供应商。
  8. 点击 Save

27.1. 创建 Place Order 子进程

Place order 子进程是一个可重复使用的进程,在课程执行时,如 第 27 章 设计问题单定义 所述。它是由供应商执行的单独业务流程。

先决条件

流程

  1. 在 Business Central 中,进入 MenuDesignProjectsIT_Orders_New
  2. IT_Orders_new 页中,点 Add Asset
  3. Add Asset 窗口中,单击 Business Process
  4. Create new Business Process 窗口中输入以下值:

    • 业务流程位置顺序
    • 软件包 :选择 com.myspace.it_orders_new
  5. 确定。示意图编辑器将打开。
  6. 单击 canvas 中的空空格。
  7. 如果没有打开 Properties 面板,点右上角的 Properties diagram properties 图标。
  8. 向下滚动并展开 Process Data,点 Process Variables 部分中的 btn plus ,并输入以下内容:

  9. 点击 Save
  10. 将启动事件拖到 canvas 中,并创建从启动事件到任务传出的连接,并将新任务转换为用户任务。

  11. 单击用户任务并在 Properties 面板中,在 Name 字段中输入 Place order
  12. 展开 Implementation/Execution,点 Groups 菜单下的 Add,点 SelectNew,并输入 供应商
  13. Assignments 字段中点 diagram properties 并添加以下内容:

    对于第一个输入分配,为 Data Type 并选择 Custom,输入 org.jbpm.document.Document

  14. 点击 OK
  15. Properties 面板中,选择 Skippable 复选框,并在 Description 字段中输入以下文本:

    要放置的批准顺序 #{CaseId}

  16. Place order user 任务。
  17. 单击 Create End 图标,以从 Place order 用户任务创建传出连接,并将它连接到结束事件。

  18. 点击 Save

您可以在 Business Central 中的新编辑器中打开子进程,方法是单击主流程中的 Place order 任务,然后单击 Open Sub-process 任务图标。

27.2. 创建 Manager 批准过程

管理器批准过程决定是否放置或拒绝订购。

流程

  1. IT_Orders_New 项目中,单击 订单硬件业务流程
  2. 创建并配置 Prepare hardware spec user 任务:

    1. Object Library 中展开 Tasks,并将用户任务拖到画板中,并将新任务转换为用户任务。
    2. 点新用户任务并点击右上角的 Properties diagram properties 图标。
    3. Name 字段中输入 Prepare hardware spec
    4. 展开 Implementation/Execution,点 Groups 菜单下的 Add,点 SelectNew,并输入 供应商
    5. Task Name 字段中输入 PrepareHardwareSpec
    6. 选择 Skippable 复选框,并在 Description 字段中输入以下文本:

      为 #{initiator}(排序号 #{CaseId})准备硬件规格

    7. Assignments 字段中点 diagram properties 并添加以下内容:

    8. 点击 OK
  3. 创建并配置 manager approval user 任务:

    1. 单击 Prepare hardware spec user 任务,再创建新用户任务。
    2. 点新用户任务并点击右上角的 Properties diagram properties 图标。
    3. 单击用户任务,并在 Name 字段中的 Properties 面板输入 管理器批准 中。
    4. 展开 Implementation/Execution,点 Actors 菜单下面的 Add,点 SelectNew,并输入 管理器
    5. Task Name 字段中输入 ManagerApproval
    6. Assignments 字段中点 diagram properties 并添加以下内容:

    7. 点击 OK
    8. 选择 Skippable 复选框,并在 Description 字段中输入以下文本:

      #{initiator}(排序号 #{CaseId})的批准请求

    9. On Exit Action 字段中输入以下 Java 表达式:

      kcontext.setVariable("caseFile_managerDecision", approved);

    10. 点击 Save
  4. Manager approval user 任务,并创建一个基于 Data 的 Exclusive (XOR)网关。

  5. 创建并配置 Place 顺序 可重复利用的子进程:

    1. Object Library 中,展开 子进程,单击 Reusable,并将新元素拖到基于 Data-based Exclusive (XOR)网关右侧的 canvas 中。

    2. 将基于 Data 的 Exclusive (XOR)网关连接到子进程。

    3. 点新的子任务,然后点击右上角的 Properties diagram properties 图标。
    4. Name 字段中输入 Place order
    5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties 并添加以下内容:

    6. 点击 OK
    7. 点基于 Data-based Exclusive (XOR)网关到子进程的连接,然后点击 Properties diagram properties 图标。
    8. 展开 Implementation/Execution,选择 Condition,并设置以下条件表达式。

    9. 单击 Place order 用户任务并创建最终事件。
  6. 创建并配置拒绝用户任务的顺序:

    1. 单击基于 Data-based Exclusive (XOR)网关并创建新用户任务。
    2. 拖动新任务,使其与 Place order 任务下保持一致。

    3. 点新用户任务并点击右上角的 Properties diagram properties 图标。
    4. Name 字段中 拒绝的输入顺序
    5. Task Name 字段中,展开 Implementation/Execution 和 input OrderRejected
    6. Actors 菜单下的 Add,点 SelectNew,并输入 所有者
    7. Assignments 字段中点 diagram properties 并添加以下内容:

    8. 点击 OK
    9. 选择 Skippable 复选框,并在 Description 字段中输入以下文本:

      管理器拒绝了订购 #{CaseId}

    10. 单击 Order rejected user 任务,再创建一个最终事件。
    11. 点击 Save
  7. 点基于 Data 的 Exclusive (XOR)网关的连接到 Order rejected user 任务,然后点 Properties diagram properties 图标。
  8. 展开 Implementation/Execution,选择 Condition,并设置以下条件表达式。

  9. 点击 Save

    图 27.4. Manager 批准批准过程

第 28 章 milestones

milestones 是一个特殊的服务任务,可以通过将 milestone 节点添加到进程设计面板,在案例定义设计器中配置。在创建新问题单定义时,默认情况下,设计 palette 中包含了配置为 AdHoc Autostart 的 milestone。新创建的 milestones 默认没有设置为 AdHoc Autostart

案例管理层通常在阶段结束时发生,但它们也可能是实现其他里程碑的结果。milestone 始终需要定义一个条件才能跟踪进度。当数据添加到问题单时,Milestones 会响应案例的文件数据。milestone 代表 case 实例中的单点实现。它可用于标记某些事件,这对于密钥性能指示器(KPI)跟踪或识别仍在完成的任务非常有用。

在执行 case 时,Milestones 可以处于以下状态:

  • Active :该条件已在里程上定义,但尚未满足。
  • completed :Milestone 条件已得到满足,Milestone 已实现,这种情况可以继续进行下一任务。
  • 已终止 :Milestone 不再是问题单进程的一部分,不再需要。

虽然 milestone 可用或已完成,但可以在一个问题单实例启动时配置 AdHoc Autostart,则可以通过信号手动触发。可以根据需要多次触发 milestones,但在满足条件时直接实现。

28.1. 创建硬件 spec ready milestone

创建一个在完成所需硬件规格文档时达到的 HardwareSpecReady milestone。

流程

  1. 在进程设计器中,展开 Milestone in the Object Library 中,再拖动一个新的里程碑,并将它放到 Place order event 右侧。
  2. 点新的 milestone,然后点击右上角的 Properties diagram properties 图标。
  3. Name 字段中输入 Hardware spec ready
  4. 展开 Implementation/Execution,再选择 AdHoc Autostart
  5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties ,并添加以下内容:

    Source 列下拉菜单,选择 Constant,并输入 org.kie.api.runtime.process.CaseData (data.get ("hwSpec")!= null)

  6. 点击 OK

28.2. 创建 Manager 决策里程碑

managerDecision 变量被授予响应时,会达到此 milestone。

流程

  1. 在进程设计器中,展开 Milestone in the Object Library 中,并将新的里程一拖到 hardware SpecReady milestone 下的 canvas 中。
  2. 点新的 milestone,然后点击右上角的 Properties diagram properties 图标。
  3. Name 字段中的输入 管理器决定
  4. 展开 Implementation/Execution,再选择 AdHoc Autostart
  5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties 并添加以下内容:

    Source 列下拉菜单,选择 Constant,并输入 org.kie.api.runtime.process.CaseData (data.get ("managerDecision")!= null)

  6. 点击 OK

28.3. 创建排序放置 milestone

排序 的变量(属于 Place order 子进程的一部分)时,会达到此 milestone。

流程

  1. 在进程设计器中,展开 Milestone in the Object Library 中,并在 Prepare hardware spec user 任务下拖到 canvas 下的新里程碑。
  2. 点新的 milestone,然后点击右上角的 Properties diagram properties 图标。
  3. Input Milestone 1:排序放置在 Name 字段中。
  4. 展开 Implementation/Execution,再选择 AdHoc Autostart
  5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties ,并添加以下内容:

    Source 列下拉菜单,选择 Constant,并输入 org.kie.api.runtime.process.CaseData (data.get ("ordered")== true)。这意味着,存在名为 ordered 的 case 变量,其值为 true

  6. 点击 OK
  7. 单击 Milestone 1: Order put 并创建新脚本任务。
  8. 点新脚本任务,然后点击右上角的 Properties diagram properties 图标。
  9. Name 字段中输入 Notify requestor
  10. 展开 Implementation/Execution 和 input System.out.println ("Notification::Order placed");.
  11. 单击 Notify requestor 脚本任务,再创建一个信号结束事件。
  12. 单击右上角的信号事件,再单击 属性diagram properties 图标。
  13. 展开 Implementation/Execution,单击 Signal 字段中的下箭头,然后选择 New
  14. Input Milestone 2:排序提供的顺序.
  15. 单击 Signal Scope 字段中的下箭头,选择 Process Instance
  16. 点击 Save

    图 28.1. 订购放置 milestone

28.4. 创建 Order shipped milestone

此 milestone 的条件是,名为 shipped 的案例文件变量为 true。此里程碑未启用 临时自动启动。相反,它将由订购准备好发送时由信号事件触发。

流程

  1. 在进程设计器中,展开 Milestone in the Object Library 中,并在 Notify requestor 脚本任务下拖到 canvas 下的新里程碑。
  2. 点新的 milestone,然后点击右上角的 Properties diagram properties 图标。
  3. Name 字段中输入 Milestone 2: Order shipped
  4. 展开 Implementation/Execution,并确保未选择 AdHoc Autostart
  5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties ,并添加以下内容:

    Source 列下拉菜单,选择 Constant,并输入 org.kie.api.runtime.process.CaseData (data.get ("shipped")== true)。这意味着,名为 shipped 的值为 true 的 case 变量存在。

  6. 点击 OK
  7. 单击 Milestone 2: Order shipped,再创建一个新的脚本任务。
  8. 点新脚本任务,然后点击右上角的 Properties diagram properties 图标。
  9. Name 字段中输入 Send 以跟踪系统
  10. 展开 Implementation/Execution 和 input System.out.println ("Order added to tracking system");.
  11. 单击 Send 以跟踪系统 脚本任务,再创建一个信号结束事件。
  12. 单击右上角的信号事件,再单击 属性diagram properties 图标。
  13. 展开 Implementation/Execution,单击 Signal 字段中的下箭头,然后选择 New
  14. 输入 Milestone 3:为客户提供.
  15. 单击 Signal Scope 字段中的下箭头,选择 Process Instance
  16. 点击 Save

    图 28.2. 顺序提供 milestone

28.5. 创建交付给客户里程碑

此 milestone 的条件是名为 delivered 的 case file 变量为 true。此里程碑未启用 临时自动启动。相反,它会在订购成功提供给客户后由信号事件触发。

流程

  1. 在进程设计器中,展开 Milestone in the Object Library 中,并在 Send to tracking system script 任务下拖动新的里程碑。
  2. 点新的 milestone,然后点击右上角的 Properties diagram properties 图标。
  3. 输入 Milestone 3:在 Name 字段中向客户交付。
  4. 展开 Implementation/Execution,并确保未选择 AdHoc Autostart
  5. 展开 Data Assignments,点 Assignments 字段中的 diagram properties ,并添加以下内容:

    Source 列下拉菜单,选择 Constant,并输入 org.kie.api.runtime.process.CaseData (data.get ("delivered")== true)。这意味着,存在名为 delivered 的 case 变量,其值为 true

  6. 点击 OK
  7. 单击 Milestone 3:向客户交付 并创建新用户任务。

    1. 点新用户任务并点击右上角的 Properties diagram properties 图标。
    2. Name 字段中输入 客户满意度调查
    3. 展开 Implementation/Execution,点 Actors 菜单下面的 Add,点 SelectNew,并输入 所有者
    4. Task Name 字段中输入 CustomerSurvey
    5. 选择 Skippable 复选框,并在 Description 字段中输入以下文本:

      订购的满意度调查 #{CaseId}

    6. Assignments 字段中点 diagram properties 并添加以下内容:

    7. 点击 OK
  8. 点击 客户满意度调查用户任务 并创建最终活动。
  9. 单击 Save 以确认更改。

    图 28.3. 交付给客户里程碑

在所有里程碑完成后,可以关闭 IT 订单。但是,由于特别情况的原因,如果客户不会收到该顺序,或者项目有故障,可能会重新打开案例。可以根据需要重新触发任务或添加到案例定义中,即使在运行时也是如此。

第 29 章 部署和测试 IT 订单案例项目

创建并定义新 IT_Orders_New case 项目的所有组件后,部署并测试新项目。

先决条件

流程

  1. 在 Business Central 中,进入 MenuDesignProjects,然后点 IT_Orders_New
  2. 单击 Deploy
  3. 进入 MenuManageProcess DefinitionsManage Process InstancesNew Process Instance
  4. 进入 MenuDeploy 并点击 Execution Servers,再验证是否部署了新容器。

  5. 使用 Case Management Showcase 应用程序启动一个新的问题单实例。有关使用 Showcase 应用程序的说明,请参阅使用 Showcase 应用程序进行问题单管理

第 30 章 其他资源

部分 IV. 红帽构建的 OptaPlanner 入门

作为业务规则开发人员,您可以使用红帽构建的 OptaPlanner 来查找根据一组有限资源和特定限制规划问题的最佳解决方案。

使用本文档通过 OptaPlanner 开始开发解决者。

第 31 章 红帽构建的 OptaPlanner 简介

OptaPlanner 是一个轻量级、可嵌入的规划引擎,可优化计划问题。它有助于一般的 Java 编程人员有效地解决规划问题,并将优化风格和元化与高效率的分数计算相结合。

例如,OptaPlanner 帮助解决各种用例:

  • 员工/基本文章 :它有助于为国业创建时间,并跟踪病人护理管理。
  • 教育 时间表:它有助于安排课程、课程、考试和会议演示。
  • Shop Schedules :跟踪回车装配行、机器队列规划和工作任务规划。
  • Cutting Stock :通过减少纸张和钢材等消耗来最小化浪费。

每个机构都面临规划问题;也就是说,它们为产品和服务提供有限的受限资源(员工、资产、时间和金钱)。

OptaPlanner 是 Apache 软件许可证 2.0 下的开源软件。这是 100% 的纯 Java,在大多数 Java 虚拟机(JVM)上运行。

31.1. 规划问题

规划问题 具有最佳目标,基于有限的资源和特定限制。最佳目标可以是任意数量的内容,例如:

  • 最大化利润 - 最佳目标使利润达到最高可能。
  • 最小化的经济占用空间 - 最佳目标对环境的影响最少。
  • 最大化员工或客户满意度 - 最佳目标优先选择员工或客户的需求。

实现这些目标的能力取决于可用资源的数量。例如,可能会限制以下资源:

  • 人员数量
  • 时间量
  • 预算
  • 物理资产,如 machinery、vehicles、计算机、构建

您还必须考虑与这些资源相关的特定限制,如个人工作的小时数、他们使用某些机器或设备组件之间的兼容性的能力。

红帽构建的 OptaPlanner 帮助 Java 编程人员有效地解决约束问题。它结合了优化 heuristics 和 metaheuristics 与有效的分数计算。

31.2. 计划问题中的 NP-completeness

提供的用例 可能是 NP-complete 或 NP-hard,这意味着适用以下语句:

  • 可轻松验证特定解决方案以便获得合理的时间。
  • 合理的时间无法找到问题的最佳解决方案。

这意味着,解决您的问题可能比您期望的更难,因为两种常见的技术不可靠:

  • 括号强制算法(甚至更高级变体)用时过长。
  • 例如,一个快速算法(例如,在组合问题 中)放在最大的项目中,首先返回一个远于 最佳的解决方案。

通过使用高级优化算法,OptaPlanner 在这类规划问题合理时间内找到了很好的解决方案。

31.3. 规划问题的解决方案

计划问题有很多解决方案。

几种解决方案类别有:

可能的解决方案
可能的解决方案是任何解决方案,无论它是否破坏了任意数量的限制。规划问题通常具有大量可能的解决方案。其中许多解决方案都不可用。
可行的解决方案
可行的解决方案是不会破坏任何(负)硬约束的解决方案。可行的解决方案数量与可能的解决方案数量相对。有时没有可行的解决方案。每种可行的解决方案都是可能的解决方案。
最佳解决方案
最佳解决方案是具有最高分数的解决方案。规划问题通常具有几个最佳解决方案。它们始终至少有一个最佳解决方案,即使是没有可行的解决方案,且最佳解决方案不可行。
最佳解决方案发现
最佳解决方案是实施在指定时间内获得的最高分数的解决方案。找到的最佳解决方案可能可行,考虑到足够的时间,这是最佳解决方案。

Counterintuitive,可能的解决方案数量是很大(如果正确计算),即使数据集小也是如此。

planner-engine 分发文件夹中提供的示例中,大多数实例都有大量可能的解决方案。由于无法保证找到最佳解决方案,任何实施都强制评估所有可能解决方案的子集。

OptaPlanner 支持多种优化算法,通过非常广泛的可能的解决方案来高效地偏离。

根据用例,一些优化算法的性能优于其他算法,但无法提前了解。使用 OptaPlanner,您可以通过更改 XML 或代码的几行中的 solver 配置来切换优化算法。

31.4. 对规划问题的约束

通常,计划问题至少有两个级别的限制:

  • (负)硬约束 不能中断。

    例如,一个教员无法同时教授两个不同的课程。

  • 如果可以避免,不应破坏 (负)软约束

    例如,Teacher A 不喜欢在周五之后教授。

有些问题也具有正限制:

  • 应尽可能 实现正软约束(或 获得者)。

    例如,Teacher B 喜欢在周早上教授。

某些基本问题只有硬限制。有些问题有三个或更多个约束,如 hard、medium 和 soft 约束。

这些限制定义了规划问题 的分数计算 (也称为适合 函数)。规划问题的每个解决方案均以分数的形式进行评分。使用 OptaPlanner 时,分数限制使用面向对象的语言(如 Java)或 Drools 规则编写。

这种代码非常灵活且可扩展的。

31.5. 红帽构建的 OptaPlanner 提供的示例

Red Hat Process Automation Manager 提供了几个红帽构建的 OptaPlanner 示例。您可以查看示例的代码,并根据需要进行修改,以满足您的需要。

注意

红帽不提供对 Red Hat Process Automation Manager 发行版中包含的示例代码的支持。

某些 OptaPlanner 示例解决了在紧张中呈现的问题。以下表中的 Contest 列列出了 contests。它也识别一个示例为 realisticunrealistic 用于 contest 的目的。真实的 contest 是符合以下标准的官方独立调查:

  • 明确定义的实际用例
  • 实时限制
  • 多个现实数据集
  • 在特定硬件上的特定时间限制中可重复生成结果
  • 积极参与来自院校和/或企业运营研究社区的严格参与。

real real contests 提供 OptaPlanner 与竞争软件和学术研究的目标比较。

Expand
表 31.1. 示例概述
示例Domain大小候选人目录名称

N queens

1 个实体类

(1 变量)

实体 rhacm 256

值 mvapich 256

搜索空间 rhacm 10^616

无点(可热点)

nqueens

负载均衡

1 个实体类

(1 变量)

实体 hawkular 2400

值 mvapich 800

搜索空间 rhacm 10^6967

否(由我们定义)

Cloudbalancing

traveling salesman

1 个实体类

(1 个串联变量)

实体 rhacm 980

值 mvapich 980

搜索空间 rhacm 10^2504

unrealistic TSP web

tsp

Tennis club 调度

1 个实体类

(1 变量)

实体 hawkular 72

值 mvapich 7

搜索空间 rhacm 10^60

否(由我们定义)

tennis

满足调度

1 个实体类

(2 变量)

实体 hawkular 10

值 mvapich 320 和 mvapich 5

搜索空间 rhacm 10^320

否(由我们定义)

会议调度

课程时间组

1 个实体类

(2 变量)

实体 rhacm 434

值 mvapich 25 和 mvapich 20

搜索空间 rhacm 10^1171

真实的 ITC 2007 跟踪 3

curriculumCourse

机器重新分配

1 个实体类

(1 变量)

实体 hawkular 50000

值 mvapich 5000

搜索空间 rhacm 10^184948

2012 年现实 ROADEF

machineReassignment

vehicle 路由

1 个实体类

(1 个串联变量)

1 个影子实体类

(1 个自动影子变量)

实体 rhacm 2740

值 mvapich 2795

搜索空间 rhacm 10^8380

不切实际的 VRP 网络

vehiclerouting

带有时间窗的载体 路由

所有 Vehicle 路由

(1 shadow 变量)

实体 rhacm 2740

值 mvapich 2795

搜索空间 rhacm 10^8380

不切实际的 VRP 网络

vehiclerouting

项目作业调度

1 个实体类

(2 变量)

(1 shadow 变量)

实体 rhacm 640

Value ? 和 hawkular ?

搜索空格 DAEMON ?

2013 年几乎真实的 MISTA

projectjobscheduling

任务分配

1 个实体类

(1 个串联变量)

(1 shadow 变量)

1 个影子实体类

(1 个自动影子变量)

实体 mvapich 500

值 mvapich 520

搜索空间 rhacm 10^1168

没有由我们定义

任务分配

考试时间组

2 个实体类(相同层次结构)

(2 变量)

实体 hawkular 1096

值 mvapich 80 和 mvapich 49

搜索空间 rhacm 10^3374

2007 年真实的 ITC 研究 1

检查

Nurse rostering

1 个实体类

(1 变量)

实体 rhacm 752

值 mvapich 50

搜索空间 rhacm 10^1277

2010 年现实的 INRC

nurserostering

traveling tournament

1 个实体类

(1 变量)

实体 hawkular 1560

值 mvapich 78

搜索空间 rhacm 10^2301

不切实际的 TTP

travelingtournament

更便宜的时间调度

1 个实体类

(2 变量)

实体 mvapich 500

值 mvapich 100 和 rhacm 288

搜索空间 rhacm 10^20078

几乎真实的 ICON Energy

cheaptimescheduling

投资

1 个实体类

(1 变量)

实体 rhacm 11

Value = 1000

搜索空间 rhacm 10^4

没有由我们定义

投资

会议调度

1 个实体类

(2 变量)

实体 rhacm 216

值 mvapich 18 和 mvapich 20

搜索空间 rhacm 10^552

没有由我们定义

conferencescheduling

rock Tur

1 个实体类

(1 个串联变量)

(4 个影子变量)

1 个影子实体类

(1 个自动影子变量)

实体 hawkular 47

值 mvapich 48

搜索空间 rhacm 10^59

没有由我们定义

rocktour

飞行人员的调度

1 个实体类

(1 变量)

1 个影子实体类

(1 个自动影子变量)

实体 DAEMON 4375

值 mvapich 750

搜索空间 rhacm 10^12578

没有由我们定义

flightcrewscheduling

31.6. N queens

在一个 n 大小的象棋盘中放置 n 个皇后,没有两个皇后可以相互攻击。最常见的 n queens puzzle 是八个 queens puzzle,n = 8

约束:

  • 使用 n 列和 n 行。
  • n queens 放置到 chessboard 上。
  • 没有两个 queens 相互攻击。queen 可以在同一个横向、垂直或诊断行中互相攻击。

本文档主要使用 4 queens puzzle 作为主要示例。

建议的解决方案可以是:

图 31.1. 错误解决方案,用于 4 queens puzzle

以上解决方案错误,因为 queens A1B0 可以相互攻击(从而可以相互攻击 B0D0)。删除 queen B0 会遵守"无两个 queens 可相互攻击"约束,但可能会破坏"place n queens"约束。

以下是正确的解决方案:

图 31.2. 用于 Four queens puzzle 的正确解决方案

满足了所有限制,因此解决方案正确。

请注意,最多 n queens puzzles 具有多个正确的解决方案。我们将专注于为特定 n 查找单个正确的解决方案,而不是查找特定 n 可能的正确解决方案。

问题大小

4queens   has   4 queens with a search space of    256.
8queens   has   8 queens with a search space of   10^7.
16queens  has  16 queens with a search space of  10^19.
32queens  has  32 queens with a search space of  10^48.
64queens  has  64 queens with a search space of 10^115.
256queens has 256 queens with a search space of 10^616.
Copy to Clipboard Toggle word wrap

n queens 示例中的实现没有被优化,因为它作为初学者示例运行。然而,它可以轻松处理 64 个问题。随着一些更改,它已被显示,可以轻松地处理 5000 频率等。

31.6.1. N queens 的域模型

这个示例使用域模型解决四个问题。

  • 创建域模型

    良好的域模型将使您更轻松地理解和解决您的规划问题。

    这是 n queens 示例的域模型:

    public class Column {
    
        private int index;
    
        // ... getters and setters
    }
    Copy to Clipboard Toggle word wrap
    public class Row {
    
        private int index;
    
        // ... getters and setters
    }
    Copy to Clipboard Toggle word wrap
    public class Queen {
    
        private Column column;
        private Row row;
    
        public int getAscendingDiagonalIndex() {...}
        public int getDescendingDiagonalIndex() {...}
    
        // ... getters and setters
    }
    Copy to Clipboard Toggle word wrap
  • 计算搜索空间.

    Queen 实例有一个 Column (例如: 0 是列 A, 1 is column B, …​) 和一个 Row (例如,0 为行 0,1 为行 1, …​)。

    可以按列和行计算升序诊断行和降序诊断行。

    列和行索引从 chessboard 的左上角启动。

    public class NQueens {
    
        private int n;
        private List<Column> columnList;
        private List<Row> rowList;
    
        private List<Queen> queenList;
    
        private SimpleScore score;
    
        // ... getters and setters
    }
    Copy to Clipboard Toggle word wrap
  • 查找解决方案

    单个 NQueens 实例包含所有 Queen 实例的列表。它是 Solution 实现,提供给、解决并从 Solver 检索的解决方案实施。

请注意,在四个 queens 示例中,NQueens getN () 方法始终返回四个。

图 31.3. Four Queens 的解决方案

Expand
表 31.2. 域模型中的解决方案详情
 columnIndexrowIndexatingDiagonalIndex (columnIndex + rowIndex)descendingDiagonalIndex (columnIndex - rowIndex)

A1

0

1

1 (**)

-1

B0

1

0 (*)

1 (**)

1

C2

2

2

4

0

D0

3

0 (*)

3

3

当两个 queens 共享同一列时,行或诊断行,如 principal 和(**),他们可以相互攻击。

31.7. 负载均衡

有关此示例的详情,请参考 红帽构建的 OptaPlanner 快速启动指南

31.8. 旅行销售员(TSP - traveling Salesman 问题)

考虑到城市列表,请找到获得每个城市完全访问的销售人员的最短产品。

这个问题由 Wikipedia 定义。它是计算数学 中最广泛的问题之一。然而,在现实世界中,它通常只是规划问题的一部分,以及其他限制,如员工的转变限制。

问题大小

dj38     has  38 cities with a search space of   10^43.
europe40 has  40 cities with a search space of   10^46.
st70     has  70 cities with a search space of   10^98.
pcb442   has 442 cities with a search space of  10^976.
lu980    has 980 cities with a search space of 10^2504.
Copy to Clipboard Toggle word wrap

问题困难

尽管 TSP 的简单定义,但问题很难解决。因为它是一个 NP-hard 问题(如大多数规划问题),所以当问题数据集略有变化时,特定问题数据集的最佳解决方案可能会有较大变化:

31.9. Tennis club 调度

每周,10nis club 均有四个团队互相扮演循环。为团队随机分配这四个点。

硬限制:

  • 冲突:团队每天只能执行一次。
  • 不可用:有些团队在某些日期不可用。

中型限制:

  • 公平分配:所有团队都应对(几乎)等于次数。

软限制:

  • evenly confrontation:每个团队应针对其他团队执行相同次数的团队。

问题大小

munich-7teams has 7 teams, 18 days, 12 unavailabilityPenalties and 72 teamAssignments with a search space of 10^60.
Copy to Clipboard Toggle word wrap

图 31.4. 域模型

31.10. 满足调度

为开始时间和房间分配每个会议。会议有不同的持续时间。

硬限制:

  • 房间冲突:两个会议不能同时使用同一个房间。
  • 需要的参与者:同时,一个人员不能同时拥有两个所需的会议。
  • 所需房间容量:会议不得位于无法满足所有会议的参与者的房间。
  • 在同一天开始和结束:不计划超过多天的会议。

中型限制:

  • 首选参与者:个人不能同时拥有两个首选的会议,也不能同时拥有首选的会议。

软限制:

  • 早于早于:尽快计划所有会议。
  • 会议间断:两个会议之间应至少一张时间休息。
  • 重叠会议:为了尽可能减少并行会议的数量,因此人们不必选择彼此的会议。
  • 首先分配更大的房间:如果有大房可用,则应该为这个空间分配任何会议,以便尽可能多地容纳尽可能多的人,即使他们未签约该会议。
  • 房间稳定性:如果个人连续两个会议,它们之间有两个或更少的时间中断,则它们之间可以更好地位于相同的房间。

问题大小

50meetings-160timegrains-5rooms  has  50 meetings, 160 timeGrains and 5 rooms with a search space of 10^145.
100meetings-320timegrains-5rooms has 100 meetings, 320 timeGrains and 5 rooms with a search space of 10^320.
200meetings-640timegrains-5rooms has 200 meetings, 640 timeGrains and 5 rooms with a search space of 10^701.
400meetings-1280timegrains-5rooms has 400 meetings, 1280 timeGrains and 5 rooms with a search space of 10^1522.
800meetings-2560timegrains-5rooms has 800 meetings, 2560 timeGrains and 5 rooms with a search space of 10^3285.
Copy to Clipboard Toggle word wrap

将每个讲座安排成分机和房间。

硬限制:

  • 教师冲突:老师不得在同一期间有两门讲座。
  • 课程冲突:在同一期间,课程不能有两门课程。
  • 房间两个讲座:两个讲座不能在同一期间处于同一个房间。
  • 不可用期限(每个数据集指定):不能将特定的讲座分配给特定期间。

软限制:

  • 房间容量:房间容量不应小于其讲座中的学员数量。
  • 最小工作日:同一课程的指南应分布到最少的天数。
  • 课程紧凑性:属于相同课程的内容应相互相邻(连续的期间)。
  • 房间稳定性:同一课程的概念应当分配到同一个房间。

此问题由 2007 年国际时间稳定竞争 3 定义

问题大小

comp01 has 24 teachers,  14 curricula,  30 courses, 160 lectures, 30 periods,  6 rooms and   53 unavailable period constraints with a search space of  10^360.
comp02 has 71 teachers,  70 curricula,  82 courses, 283 lectures, 25 periods, 16 rooms and  513 unavailable period constraints with a search space of  10^736.
comp03 has 61 teachers,  68 curricula,  72 courses, 251 lectures, 25 periods, 16 rooms and  382 unavailable period constraints with a search space of  10^653.
comp04 has 70 teachers,  57 curricula,  79 courses, 286 lectures, 25 periods, 18 rooms and  396 unavailable period constraints with a search space of  10^758.
comp05 has 47 teachers, 139 curricula,  54 courses, 152 lectures, 36 periods,  9 rooms and  771 unavailable period constraints with a search space of  10^381.
comp06 has 87 teachers,  70 curricula, 108 courses, 361 lectures, 25 periods, 18 rooms and  632 unavailable period constraints with a search space of  10^957.
comp07 has 99 teachers,  77 curricula, 131 courses, 434 lectures, 25 periods, 20 rooms and  667 unavailable period constraints with a search space of 10^1171.
comp08 has 76 teachers,  61 curricula,  86 courses, 324 lectures, 25 periods, 18 rooms and  478 unavailable period constraints with a search space of  10^859.
comp09 has 68 teachers,  75 curricula,  76 courses, 279 lectures, 25 periods, 18 rooms and  405 unavailable period constraints with a search space of  10^740.
comp10 has 88 teachers,  67 curricula, 115 courses, 370 lectures, 25 periods, 18 rooms and  694 unavailable period constraints with a search space of  10^981.
comp11 has 24 teachers,  13 curricula,  30 courses, 162 lectures, 45 periods,  5 rooms and   94 unavailable period constraints with a search space of  10^381.
comp12 has 74 teachers, 150 curricula,  88 courses, 218 lectures, 36 periods, 11 rooms and 1368 unavailable period constraints with a search space of  10^566.
comp13 has 77 teachers,  66 curricula,  82 courses, 308 lectures, 25 periods, 19 rooms and  468 unavailable period constraints with a search space of  10^824.
comp14 has 68 teachers,  60 curricula,  85 courses, 275 lectures, 25 periods, 17 rooms and  486 unavailable period constraints with a search space of  10^722.
Copy to Clipboard Toggle word wrap

图 31.5. 域模型

31.12. Machine reassignment (Google ROADEF 2012)

为机器分配每个进程。所有进程已经有原始(未优化)分配。每个进程需要每个资源(如 CPU 或 RAM)的数量。这是 Cloud Balancing 示例的一个更加复杂的版本。

硬限制:

  • 最大容量:不得超过每台机器的最大资源容量。
  • 冲突:同一服务的进程必须在不同的机器上运行。
  • 分散 :同一服务的进程必须在不同的位置分散。
  • 依赖项:服务的进程取决于另一个服务的进程,必须在其他服务的进程的邻居中运行。
  • 临时使用:有些资源是临时的,计算原始机器作为新分配的机器的最大容量。

软限制:

  • load :不应超过每台机器的每个资源的安全容量。
  • Balance:通过平衡每台计算机上的可用资源,为未来分配留出空间。
  • 进程移动成本:流程具有移动成本。
  • 服务移动成本:服务具有移动成本。
  • 机器移动成本:将流程从机器 A 移到机器 B 具有另一个 A-B 特定移动成本。

这个问题由 Google ROADEF/EURO Challenge 2012 定义。

图 31.6. 价值定位

问题大小

model_a1_1 has  2 resources,  1 neighborhoods,   4 locations,    4 machines,    79 services,   100 processes and 1 balancePenalties with a search space of     10^60.
model_a1_2 has  4 resources,  2 neighborhoods,   4 locations,  100 machines,   980 services,  1000 processes and 0 balancePenalties with a search space of   10^2000.
model_a1_3 has  3 resources,  5 neighborhoods,  25 locations,  100 machines,   216 services,  1000 processes and 0 balancePenalties with a search space of   10^2000.
model_a1_4 has  3 resources, 50 neighborhoods,  50 locations,   50 machines,   142 services,  1000 processes and 1 balancePenalties with a search space of   10^1698.
model_a1_5 has  4 resources,  2 neighborhoods,   4 locations,   12 machines,   981 services,  1000 processes and 1 balancePenalties with a search space of   10^1079.
model_a2_1 has  3 resources,  1 neighborhoods,   1 locations,  100 machines,  1000 services,  1000 processes and 0 balancePenalties with a search space of   10^2000.
model_a2_2 has 12 resources,  5 neighborhoods,  25 locations,  100 machines,   170 services,  1000 processes and 0 balancePenalties with a search space of   10^2000.
model_a2_3 has 12 resources,  5 neighborhoods,  25 locations,  100 machines,   129 services,  1000 processes and 0 balancePenalties with a search space of   10^2000.
model_a2_4 has 12 resources,  5 neighborhoods,  25 locations,   50 machines,   180 services,  1000 processes and 1 balancePenalties with a search space of   10^1698.
model_a2_5 has 12 resources,  5 neighborhoods,  25 locations,   50 machines,   153 services,  1000 processes and 0 balancePenalties with a search space of   10^1698.
model_b_1  has 12 resources,  5 neighborhoods,  10 locations,  100 machines,  2512 services,  5000 processes and 0 balancePenalties with a search space of  10^10000.
model_b_2  has 12 resources,  5 neighborhoods,  10 locations,  100 machines,  2462 services,  5000 processes and 1 balancePenalties with a search space of  10^10000.
model_b_3  has  6 resources,  5 neighborhoods,  10 locations,  100 machines, 15025 services, 20000 processes and 0 balancePenalties with a search space of  10^40000.
model_b_4  has  6 resources,  5 neighborhoods,  50 locations,  500 machines,  1732 services, 20000 processes and 1 balancePenalties with a search space of  10^53979.
model_b_5  has  6 resources,  5 neighborhoods,  10 locations,  100 machines, 35082 services, 40000 processes and 0 balancePenalties with a search space of  10^80000.
model_b_6  has  6 resources,  5 neighborhoods,  50 locations,  200 machines, 14680 services, 40000 processes and 1 balancePenalties with a search space of  10^92041.
model_b_7  has  6 resources,  5 neighborhoods,  50 locations, 4000 machines, 15050 services, 40000 processes and 1 balancePenalties with a search space of 10^144082.
model_b_8  has  3 resources,  5 neighborhoods,  10 locations,  100 machines, 45030 services, 50000 processes and 0 balancePenalties with a search space of 10^100000.
model_b_9  has  3 resources,  5 neighborhoods, 100 locations, 1000 machines,  4609 services, 50000 processes and 1 balancePenalties with a search space of 10^150000.
model_b_10 has  3 resources,  5 neighborhoods, 100 locations, 5000 machines,  4896 services, 50000 processes and 1 balancePenalties with a search space of 10^184948.
Copy to Clipboard Toggle word wrap

图 31.7. 域模型

31.13. vehicle 路由

使用一组车辆,获取每个客户的对象并将其引入独立。每个 vehicle 都可以服务于多个客户,但其容量有限。

除了基本大小写(CVRP)外,还有一个包含时间窗(CVRPTW)的变体。

硬限制:

  • 载体容量:其容量之后无法处理更多项目。
  • 时间窗口(仅在 CVRPTW 中):

    • 差旅时间:从一个地点到另一地点时间。
    • 客户服务持续时间:在服务持续时间内必须保持客户保持在客户时限。
    • 客户准备时间:客户准备时间之前可能到达,但必须在服务前等待就绪时间。
    • 客户到期时间:由于时间,在客户到期之前,Pevehicle 必须到达时间。

软限制:

  • 总计 distance :减少所有 vehicles 的总距离驱动(fuel 消耗)。

capacitated vehicle 路由问题(CVRP)及其定时序变体(CVRPTW)由 VRP Web 定义。

图 31.8. 价值定位

问题大小

CVRP 实例(无时间窗口):

belgium-n50-k10             has  1 depots, 10 vehicles and   49 customers with a search space of   10^74.
belgium-n100-k10            has  1 depots, 10 vehicles and   99 customers with a search space of  10^170.
belgium-n500-k20            has  1 depots, 20 vehicles and  499 customers with a search space of 10^1168.
belgium-n1000-k20           has  1 depots, 20 vehicles and  999 customers with a search space of 10^2607.
belgium-n2750-k55           has  1 depots, 55 vehicles and 2749 customers with a search space of 10^8380.
belgium-road-km-n50-k10     has  1 depots, 10 vehicles and   49 customers with a search space of   10^74.
belgium-road-km-n100-k10    has  1 depots, 10 vehicles and   99 customers with a search space of  10^170.
belgium-road-km-n500-k20    has  1 depots, 20 vehicles and  499 customers with a search space of 10^1168.
belgium-road-km-n1000-k20   has  1 depots, 20 vehicles and  999 customers with a search space of 10^2607.
belgium-road-km-n2750-k55   has  1 depots, 55 vehicles and 2749 customers with a search space of 10^8380.
belgium-road-time-n50-k10   has  1 depots, 10 vehicles and   49 customers with a search space of   10^74.
belgium-road-time-n100-k10  has  1 depots, 10 vehicles and   99 customers with a search space of  10^170.
belgium-road-time-n500-k20  has  1 depots, 20 vehicles and  499 customers with a search space of 10^1168.
belgium-road-time-n1000-k20 has  1 depots, 20 vehicles and  999 customers with a search space of 10^2607.
belgium-road-time-n2750-k55 has  1 depots, 55 vehicles and 2749 customers with a search space of 10^8380.
belgium-d2-n50-k10          has  2 depots, 10 vehicles and   48 customers with a search space of   10^74.
belgium-d3-n100-k10         has  3 depots, 10 vehicles and   97 customers with a search space of  10^170.
belgium-d5-n500-k20         has  5 depots, 20 vehicles and  495 customers with a search space of 10^1168.
belgium-d8-n1000-k20        has  8 depots, 20 vehicles and  992 customers with a search space of 10^2607.
belgium-d10-n2750-k55       has 10 depots, 55 vehicles and 2740 customers with a search space of 10^8380.

A-n32-k5  has 1 depots,  5 vehicles and  31 customers with a search space of  10^40.
A-n33-k5  has 1 depots,  5 vehicles and  32 customers with a search space of  10^41.
A-n33-k6  has 1 depots,  6 vehicles and  32 customers with a search space of  10^42.
A-n34-k5  has 1 depots,  5 vehicles and  33 customers with a search space of  10^43.
A-n36-k5  has 1 depots,  5 vehicles and  35 customers with a search space of  10^46.
A-n37-k5  has 1 depots,  5 vehicles and  36 customers with a search space of  10^48.
A-n37-k6  has 1 depots,  6 vehicles and  36 customers with a search space of  10^49.
A-n38-k5  has 1 depots,  5 vehicles and  37 customers with a search space of  10^49.
A-n39-k5  has 1 depots,  5 vehicles and  38 customers with a search space of  10^51.
A-n39-k6  has 1 depots,  6 vehicles and  38 customers with a search space of  10^52.
A-n44-k7  has 1 depots,  7 vehicles and  43 customers with a search space of  10^61.
A-n45-k6  has 1 depots,  6 vehicles and  44 customers with a search space of  10^62.
A-n45-k7  has 1 depots,  7 vehicles and  44 customers with a search space of  10^63.
A-n46-k7  has 1 depots,  7 vehicles and  45 customers with a search space of  10^65.
A-n48-k7  has 1 depots,  7 vehicles and  47 customers with a search space of  10^68.
A-n53-k7  has 1 depots,  7 vehicles and  52 customers with a search space of  10^77.
A-n54-k7  has 1 depots,  7 vehicles and  53 customers with a search space of  10^79.
A-n55-k9  has 1 depots,  9 vehicles and  54 customers with a search space of  10^82.
A-n60-k9  has 1 depots,  9 vehicles and  59 customers with a search space of  10^91.
A-n61-k9  has 1 depots,  9 vehicles and  60 customers with a search space of  10^93.
A-n62-k8  has 1 depots,  8 vehicles and  61 customers with a search space of  10^94.
A-n63-k9  has 1 depots,  9 vehicles and  62 customers with a search space of  10^97.
A-n63-k10 has 1 depots, 10 vehicles and  62 customers with a search space of  10^98.
A-n64-k9  has 1 depots,  9 vehicles and  63 customers with a search space of  10^99.
A-n65-k9  has 1 depots,  9 vehicles and  64 customers with a search space of 10^101.
A-n69-k9  has 1 depots,  9 vehicles and  68 customers with a search space of 10^108.
A-n80-k10 has 1 depots, 10 vehicles and  79 customers with a search space of 10^130.
F-n45-k4  has 1 depots,  4 vehicles and  44 customers with a search space of  10^60.
F-n72-k4  has 1 depots,  4 vehicles and  71 customers with a search space of 10^108.
F-n135-k7 has 1 depots,  7 vehicles and 134 customers with a search space of 10^240.
Copy to Clipboard Toggle word wrap

CVRPTW 实例(有时间窗):

belgium-tw-d2-n50-k10    has  2 depots, 10 vehicles and   48 customers with a search space of   10^74.
belgium-tw-d3-n100-k10   has  3 depots, 10 vehicles and   97 customers with a search space of  10^170.
belgium-tw-d5-n500-k20   has  5 depots, 20 vehicles and  495 customers with a search space of 10^1168.
belgium-tw-d8-n1000-k20  has  8 depots, 20 vehicles and  992 customers with a search space of 10^2607.
belgium-tw-d10-n2750-k55 has 10 depots, 55 vehicles and 2740 customers with a search space of 10^8380.
belgium-tw-n50-k10       has  1 depots, 10 vehicles and   49 customers with a search space of   10^74.
belgium-tw-n100-k10      has  1 depots, 10 vehicles and   99 customers with a search space of  10^170.
belgium-tw-n500-k20      has  1 depots, 20 vehicles and  499 customers with a search space of 10^1168.
belgium-tw-n1000-k20     has  1 depots, 20 vehicles and  999 customers with a search space of 10^2607.
belgium-tw-n2750-k55     has  1 depots, 55 vehicles and 2749 customers with a search space of 10^8380.

Solomon_025_C101       has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_025_C201       has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_025_R101       has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_025_R201       has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_025_RC101      has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_025_RC201      has 1 depots,  25 vehicles and   25 customers with a search space of   10^40.
Solomon_100_C101       has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Solomon_100_C201       has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Solomon_100_R101       has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Solomon_100_R201       has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Solomon_100_RC101      has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Solomon_100_RC201      has 1 depots,  25 vehicles and  100 customers with a search space of  10^185.
Homberger_0200_C1_2_1  has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0200_C2_2_1  has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0200_R1_2_1  has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0200_R2_2_1  has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0200_RC1_2_1 has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0200_RC2_2_1 has 1 depots,  50 vehicles and  200 customers with a search space of  10^429.
Homberger_0400_C1_4_1  has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0400_C2_4_1  has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0400_R1_4_1  has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0400_R2_4_1  has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0400_RC1_4_1 has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0400_RC2_4_1 has 1 depots, 100 vehicles and  400 customers with a search space of  10^978.
Homberger_0600_C1_6_1  has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0600_C2_6_1  has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0600_R1_6_1  has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0600_R2_6_1  has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0600_RC1_6_1 has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0600_RC2_6_1 has 1 depots, 150 vehicles and  600 customers with a search space of 10^1571.
Homberger_0800_C1_8_1  has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_0800_C2_8_1  has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_0800_R1_8_1  has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_0800_R2_8_1  has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_0800_RC1_8_1 has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_0800_RC2_8_1 has 1 depots, 200 vehicles and  800 customers with a search space of 10^2195.
Homberger_1000_C110_1  has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Homberger_1000_C210_1  has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Homberger_1000_R110_1  has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Homberger_1000_R210_1  has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Homberger_1000_RC110_1 has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Homberger_1000_RC210_1 has 1 depots, 250 vehicles and 1000 customers with a search space of 10^2840.
Copy to Clipboard Toggle word wrap

31.13.1. Vehicle 路由的域模型

带有时间窗域模型的载体路由大量使用影子变量功能。这样,它可以更加自然地表达其约束,因为 arrivalTimedepartureTime 等属性在域模型上直接可用。

road Distances Instead of Air Distances

在现实世界中,vehicles 无法直接跟随位置到位置:他们必须使用路线和高路。从业务角度来看,这很重要:

对于优化算法,这无关紧要,只要可以查找两个点之间的距离(最好是预先计算的)。路线成本甚至不需要距离。它还可以是出差时间、控制成本或其加权的功能。有多种技术可用于预先计算路线成本,如 GraphHopper (可能,离线 Java 引擎)、Open MapQuest (web service)和 Google Maps Client API (web 服务)。

另外,还有多种技术可供开发人员呈现,如 LeafletGoogle Maps

甚至可以使用 GraphHopper 或 Google Map Directions 呈现实际的路线图路由,但由于路由在高方面重叠,因此查看独立顺序可能会变得困难:

请特别注意两点之间的路线成本使用与 OptaPlanner 中使用的优化标准相同的优化标准。例如,G GraphHopper 默认返回最快的路由,而不是最短的路由。不要使用最快的 GPS 路由的 km (或 miles)来优化 OptaPlanner 中的最短往返:这会带来子优化的解决方案,如下所示:

最受欢迎的是,大多数用户都不希望最短的路由:他们希望获得最快的路由。他们更喜欢比普通路线的高路。他们更喜欢使用 dirt 路线的正常路。在现实世界中,最快速和最短的路由很少相同。

31.14. 项目作业调度

以时间和执行模式调度所有作业,以最小化项目延迟。每个作业都是一个项目的一部分。某个作业可以以不同的方式执行:每个执行模式都是一个执行模式,这意味着不同的持续时间,但也有不同的资源使用量。这是灵活的 作业跃点调度的一种形式

硬限制:

  • 作业优先级 :作业只能在所有 preesor 作业完成后启动。
  • 资源容量:不使用比可用的资源多。

    • 资源是本地(同一项目中作业之间共享)或全局资源(在所有作业间共享)
    • 资源是可续订的(每天可用的容量)或不可续订(所有天都提供容量)

中型限制:

  • 项目总延迟:最小化每个项目的持续时间(makespan)。

软限制:

  • 总计 makespan:最小化整个多项目调度的持续时间。

这个问题由 MISTA 2013 挑战 定义。

问题大小

Schedule A-1  has  2 projects,  24 jobs,   64 execution modes,  7 resources and  150 resource requirements.
Schedule A-2  has  2 projects,  44 jobs,  124 execution modes,  7 resources and  420 resource requirements.
Schedule A-3  has  2 projects,  64 jobs,  184 execution modes,  7 resources and  630 resource requirements.
Schedule A-4  has  5 projects,  60 jobs,  160 execution modes, 16 resources and  390 resource requirements.
Schedule A-5  has  5 projects, 110 jobs,  310 execution modes, 16 resources and  900 resource requirements.
Schedule A-6  has  5 projects, 160 jobs,  460 execution modes, 16 resources and 1440 resource requirements.
Schedule A-7  has 10 projects, 120 jobs,  320 execution modes, 22 resources and  900 resource requirements.
Schedule A-8  has 10 projects, 220 jobs,  620 execution modes, 22 resources and 1860 resource requirements.
Schedule A-9  has 10 projects, 320 jobs,  920 execution modes, 31 resources and 2880 resource requirements.
Schedule A-10 has 10 projects, 320 jobs,  920 execution modes, 31 resources and 2970 resource requirements.
Schedule B-1  has 10 projects, 120 jobs,  320 execution modes, 31 resources and  900 resource requirements.
Schedule B-2  has 10 projects, 220 jobs,  620 execution modes, 22 resources and 1740 resource requirements.
Schedule B-3  has 10 projects, 320 jobs,  920 execution modes, 31 resources and 3060 resource requirements.
Schedule B-4  has 15 projects, 180 jobs,  480 execution modes, 46 resources and 1530 resource requirements.
Schedule B-5  has 15 projects, 330 jobs,  930 execution modes, 46 resources and 2760 resource requirements.
Schedule B-6  has 15 projects, 480 jobs, 1380 execution modes, 46 resources and 4500 resource requirements.
Schedule B-7  has 20 projects, 240 jobs,  640 execution modes, 61 resources and 1710 resource requirements.
Schedule B-8  has 20 projects, 440 jobs, 1240 execution modes, 42 resources and 3180 resource requirements.
Schedule B-9  has 20 projects, 640 jobs, 1840 execution modes, 61 resources and 5940 resource requirements.
Schedule B-10 has 20 projects, 460 jobs, 1300 execution modes, 42 resources and 4260 resource requirements.
Copy to Clipboard Toggle word wrap

31.15. 任务分配

将每个任务分配到员工队列中的位置。每个任务都有一个持续时间,受员工的关联级别与任务的客户影响。

硬限制:

  • 技能:每个任务都需要一个或多个技能。员工必须具有所有这些技能。

软级别 0 约束:

  • 关键任务:首先完成关键任务,比主要和次要任务快。

软级别 1 约束:

  • 最小化 makespan:减少完成所有任务的时间。

    • 首先,首先从工作员工的最长时间开始,然后是员工的最长最长时间,以便创建公平和负载平衡。

软级别 2 约束:

  • 主要任务:尽快完成主要任务,比次要任务快。

软级别 3 约束:

  • 小任务:尽快完成次要任务。

图 31.9. 价值定位

问题大小

24tasks-8employees   has  24 tasks, 6 skills,  8 employees,   4 task types and  4 customers with a search space of   10^30.
50tasks-5employees   has  50 tasks, 5 skills,  5 employees,  10 task types and 10 customers with a search space of   10^69.
100tasks-5employees  has 100 tasks, 5 skills,  5 employees,  20 task types and 15 customers with a search space of  10^164.
500tasks-20employees has 500 tasks, 6 skills, 20 employees, 100 task types and 60 customers with a search space of 10^1168.
Copy to Clipboard Toggle word wrap

图 31.10. 域模型

31.16. 考试时间稳定(ITC 2007 跟踪 1 - 检查)

将每个考试计划在一个时段和房间。多个考试在同一期间内共享相同的房间。

硬限制:

  • 冲突:两个共享学员的考试不能在同一期间内发生。
  • 房间容量:房间容量必须随时可用。
  • 周期持续时间:其所有考试的期限必须有效。
  • 相关硬约束(每个数据集指定):

    • coincidence:两个指定的考试必须使用相同的期间(但可能还有其他房间)。
    • 排除:两个指定的考试不能使用相同的期间。
    • 之后:在另一指定考试期后,必须进行指定的考试。
  • 与房间相关的硬约束(每个数据集指定):

    • 排他:指定一个指定考试不必与任何其他考试共享其房间。

软限制(每个限制具有重要影响):

  • 同一学员不应连续两个考试。
  • 同一名学员不应在同一天拥有两个考试。
  • 布置:两门共享学员的考试是以下几个时期。
  • 混合持续时间:共享房间的两个考试不应具有不同的持续时间。
  • 前端负载:在计划前应提前安排大的考试。
  • 周期损失(每个数据集指定):一些句点在使用时会有损失。
  • 房间罚款(每个数据集指定):一些空间在使用时会有损失。

它使用大型测试数据集。

问题由 2007 年国际时间稳定注释 1 进行定义。Geoffrey De Smet 通过 OptaPlanner 的早期版本完成 4 个竞争。自那时起,我们做出了很多改进。

问题大小

exam_comp_set1 has  7883 students,  607 exams, 54 periods,  7 rooms,  12 period constraints and  0 room constraints with a search space of 10^1564.
exam_comp_set2 has 12484 students,  870 exams, 40 periods, 49 rooms,  12 period constraints and  2 room constraints with a search space of 10^2864.
exam_comp_set3 has 16365 students,  934 exams, 36 periods, 48 rooms, 168 period constraints and 15 room constraints with a search space of 10^3023.
exam_comp_set4 has  4421 students,  273 exams, 21 periods,  1 rooms,  40 period constraints and  0 room constraints with a search space of  10^360.
exam_comp_set5 has  8719 students, 1018 exams, 42 periods,  3 rooms,  27 period constraints and  0 room constraints with a search space of 10^2138.
exam_comp_set6 has  7909 students,  242 exams, 16 periods,  8 rooms,  22 period constraints and  0 room constraints with a search space of  10^509.
exam_comp_set7 has 13795 students, 1096 exams, 80 periods, 15 rooms,  28 period constraints and  0 room constraints with a search space of 10^3374.
exam_comp_set8 has  7718 students,  598 exams, 80 periods,  8 rooms,  20 period constraints and  1 room constraints with a search space of 10^1678.
Copy to Clipboard Toggle word wrap

31.16.1. 考试时间组的域模型

下图显示了主要的考试域类:

图 31.11. 检查域类图

请注意,我们已将考试概念分成 考试 课程和主题课程。在解决时(这是计划实体类)的考试实例在它们的期间或房间属性发生变化时发生了变化。主题 PeriodRoom 实例在解决过程中不会改变(就像其它类一样是问题事实。)

31.17. Nurse rostering (2010 年)

对于每个变动,为进行这种转变分配一元化。

硬限制:

  • 没有未分配的 转换(内置):需要将每个变换分配到员工。
  • 改变冲突 :员工每天只能有一个变化。

软限制:

  • 合同义务。企业经常违反这些,因此他们决定将这些定义为软限制,而不是硬限制。

    • 最小和最大分配量 :每个员工都需要与 x 相比变化的工作多,且少于 y 个变化(取决于其合同)。
    • 最小和最大连续工作日 :每个员工都需要在 x 和 y 天之间工作(取决于其合同)。
    • 最少和连续的免费天数 :每个员工都需要在 x 到 y 天之间自由使用(取决于其合同)。
    • 最小和最大连续工作周末 :每个员工都需要在 x 到 y weekends 之间在一行(取决于其合同)之间工作。
    • 完整周末 :每个员工都需要每天每天工作,或者根本不需要工作。
    • 每周端的相同转变类型 :同一名员工的相同周末转换都必须是相同的转换类型。
    • 不需要 的模式 :一行中不需要的切换的组合,例如转换后再进行早期转换,然后转换。
  • 员工希望:

    • 申请 日期:员工希望在一个特定日期工作。
    • 每天到期请求 :员工不希望在某个特定日期工作。
    • 行动请求 :员工希望分配给一个特定变化。
    • 转放请求 :员工不希望被分配给特定变化。
  • 备选技能 :分配给技能的员工应精通该变化所需的各种技能。

问题由 2010 年国际子公司定义

图 31.12. 价值定位

问题大小

有三个数据集类型:

  • print: 必须以秒为单位解决。
  • Medium:必须在数分钟内解决。
  • 长:必须在几小时内解决。
toy1          has 1 skills, 3 shiftTypes, 2 patterns, 1 contracts,  6 employees,  7 shiftDates,  35 shiftAssignments and   0 requests with a search space of   10^27.
toy2          has 1 skills, 3 shiftTypes, 3 patterns, 2 contracts, 20 employees, 28 shiftDates, 180 shiftAssignments and 140 requests with a search space of  10^234.

sprint01      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint02      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint03      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint04      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint05      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint06      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint07      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint08      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint09      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint10      has 1 skills, 4 shiftTypes, 3 patterns, 4 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_hint01 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_hint02 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_hint03 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_late01 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_late02 has 1 skills, 3 shiftTypes, 4 patterns, 3 contracts, 10 employees, 28 shiftDates, 144 shiftAssignments and 139 requests with a search space of  10^144.
sprint_late03 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 160 shiftAssignments and 150 requests with a search space of  10^160.
sprint_late04 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 160 shiftAssignments and 150 requests with a search space of  10^160.
sprint_late05 has 1 skills, 4 shiftTypes, 8 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_late06 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_late07 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.
sprint_late08 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and   0 requests with a search space of  10^152.
sprint_late09 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and   0 requests with a search space of  10^152.
sprint_late10 has 1 skills, 4 shiftTypes, 0 patterns, 3 contracts, 10 employees, 28 shiftDates, 152 shiftAssignments and 150 requests with a search space of  10^152.

medium01      has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 31 employees, 28 shiftDates, 608 shiftAssignments and 403 requests with a search space of  10^906.
medium02      has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 31 employees, 28 shiftDates, 608 shiftAssignments and 403 requests with a search space of  10^906.
medium03      has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 31 employees, 28 shiftDates, 608 shiftAssignments and 403 requests with a search space of  10^906.
medium04      has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 31 employees, 28 shiftDates, 608 shiftAssignments and 403 requests with a search space of  10^906.
medium05      has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 31 employees, 28 shiftDates, 608 shiftAssignments and 403 requests with a search space of  10^906.
medium_hint01 has 1 skills, 4 shiftTypes, 7 patterns, 4 contracts, 30 employees, 28 shiftDates, 428 shiftAssignments and 390 requests with a search space of  10^632.
medium_hint02 has 1 skills, 4 shiftTypes, 7 patterns, 3 contracts, 30 employees, 28 shiftDates, 428 shiftAssignments and 390 requests with a search space of  10^632.
medium_hint03 has 1 skills, 4 shiftTypes, 7 patterns, 4 contracts, 30 employees, 28 shiftDates, 428 shiftAssignments and 390 requests with a search space of  10^632.
medium_late01 has 1 skills, 4 shiftTypes, 7 patterns, 4 contracts, 30 employees, 28 shiftDates, 424 shiftAssignments and 390 requests with a search space of  10^626.
medium_late02 has 1 skills, 4 shiftTypes, 7 patterns, 3 contracts, 30 employees, 28 shiftDates, 428 shiftAssignments and 390 requests with a search space of  10^632.
medium_late03 has 1 skills, 4 shiftTypes, 0 patterns, 4 contracts, 30 employees, 28 shiftDates, 428 shiftAssignments and 390 requests with a search space of  10^632.
medium_late04 has 1 skills, 4 shiftTypes, 7 patterns, 3 contracts, 30 employees, 28 shiftDates, 416 shiftAssignments and 390 requests with a search space of  10^614.
medium_late05 has 2 skills, 5 shiftTypes, 7 patterns, 4 contracts, 30 employees, 28 shiftDates, 452 shiftAssignments and 390 requests with a search space of  10^667.

long01        has 2 skills, 5 shiftTypes, 3 patterns, 3 contracts, 49 employees, 28 shiftDates, 740 shiftAssignments and 735 requests with a search space of 10^1250.
long02        has 2 skills, 5 shiftTypes, 3 patterns, 3 contracts, 49 employees, 28 shiftDates, 740 shiftAssignments and 735 requests with a search space of 10^1250.
long03        has 2 skills, 5 shiftTypes, 3 patterns, 3 contracts, 49 employees, 28 shiftDates, 740 shiftAssignments and 735 requests with a search space of 10^1250.
long04        has 2 skills, 5 shiftTypes, 3 patterns, 3 contracts, 49 employees, 28 shiftDates, 740 shiftAssignments and 735 requests with a search space of 10^1250.
long05        has 2 skills, 5 shiftTypes, 3 patterns, 3 contracts, 49 employees, 28 shiftDates, 740 shiftAssignments and 735 requests with a search space of 10^1250.
long_hint01   has 2 skills, 5 shiftTypes, 9 patterns, 3 contracts, 50 employees, 28 shiftDates, 740 shiftAssignments and   0 requests with a search space of 10^1257.
long_hint02   has 2 skills, 5 shiftTypes, 7 patterns, 3 contracts, 50 employees, 28 shiftDates, 740 shiftAssignments and   0 requests with a search space of 10^1257.
long_hint03   has 2 skills, 5 shiftTypes, 7 patterns, 3 contracts, 50 employees, 28 shiftDates, 740 shiftAssignments and   0 requests with a search space of 10^1257.
long_late01   has 2 skills, 5 shiftTypes, 9 patterns, 3 contracts, 50 employees, 28 shiftDates, 752 shiftAssignments and   0 requests with a search space of 10^1277.
long_late02   has 2 skills, 5 shiftTypes, 9 patterns, 4 contracts, 50 employees, 28 shiftDates, 752 shiftAssignments and   0 requests with a search space of 10^1277.
long_late03   has 2 skills, 5 shiftTypes, 9 patterns, 3 contracts, 50 employees, 28 shiftDates, 752 shiftAssignments and   0 requests with a search space of 10^1277.
long_late04   has 2 skills, 5 shiftTypes, 9 patterns, 4 contracts, 50 employees, 28 shiftDates, 752 shiftAssignments and   0 requests with a search space of 10^1277.
long_late05   has 2 skills, 5 shiftTypes, 9 patterns, 3 contracts, 50 employees, 28 shiftDates, 740 shiftAssignments and   0 requests with a search space of 10^1257.
Copy to Clipboard Toggle word wrap

图 31.13. 域模型

31.18. 旅行排放问题(TTP)

计划在 n 个团队数量之间匹配。

硬限制:

  • 每个团队对其他团队都会执行两次:家家后,一旦离开一次。
  • 每个团队每次都有一次匹配。
  • 团队必须连续只有三个连续的主页或连续三个匹配项。
  • 无重复者:没有两个连续地匹配这两个两个不同团队。

软限制:

  • 最小化所有团队所旅行的总距离。

Michael Trick 的网站(包含全球记录) 上定义了问题。

问题大小

1-nl04     has  6 days,  4 teams and   12 matches with a search space of    10^5.
1-nl06     has 10 days,  6 teams and   30 matches with a search space of   10^19.
1-nl08     has 14 days,  8 teams and   56 matches with a search space of   10^43.
1-nl10     has 18 days, 10 teams and   90 matches with a search space of   10^79.
1-nl12     has 22 days, 12 teams and  132 matches with a search space of  10^126.
1-nl14     has 26 days, 14 teams and  182 matches with a search space of  10^186.
1-nl16     has 30 days, 16 teams and  240 matches with a search space of  10^259.
2-bra24    has 46 days, 24 teams and  552 matches with a search space of  10^692.
3-nfl16    has 30 days, 16 teams and  240 matches with a search space of  10^259.
3-nfl18    has 34 days, 18 teams and  306 matches with a search space of  10^346.
3-nfl20    has 38 days, 20 teams and  380 matches with a search space of  10^447.
3-nfl22    has 42 days, 22 teams and  462 matches with a search space of  10^562.
3-nfl24    has 46 days, 24 teams and  552 matches with a search space of  10^692.
3-nfl26    has 50 days, 26 teams and  650 matches with a search space of  10^838.
3-nfl28    has 54 days, 28 teams and  756 matches with a search space of  10^999.
3-nfl30    has 58 days, 30 teams and  870 matches with a search space of 10^1175.
3-nfl32    has 62 days, 32 teams and  992 matches with a search space of 10^1367.
4-super04  has  6 days,  4 teams and   12 matches with a search space of    10^5.
4-super06  has 10 days,  6 teams and   30 matches with a search space of   10^19.
4-super08  has 14 days,  8 teams and   56 matches with a search space of   10^43.
4-super10  has 18 days, 10 teams and   90 matches with a search space of   10^79.
4-super12  has 22 days, 12 teams and  132 matches with a search space of  10^126.
4-super14  has 26 days, 14 teams and  182 matches with a search space of  10^186.
5-galaxy04 has  6 days,  4 teams and   12 matches with a search space of    10^5.
5-galaxy06 has 10 days,  6 teams and   30 matches with a search space of   10^19.
5-galaxy08 has 14 days,  8 teams and   56 matches with a search space of   10^43.
5-galaxy10 has 18 days, 10 teams and   90 matches with a search space of   10^79.
5-galaxy12 has 22 days, 12 teams and  132 matches with a search space of  10^126.
5-galaxy14 has 26 days, 14 teams and  182 matches with a search space of  10^186.
5-galaxy16 has 30 days, 16 teams and  240 matches with a search space of  10^259.
5-galaxy18 has 34 days, 18 teams and  306 matches with a search space of  10^346.
5-galaxy20 has 38 days, 20 teams and  380 matches with a search space of  10^447.
5-galaxy22 has 42 days, 22 teams and  462 matches with a search space of  10^562.
5-galaxy24 has 46 days, 24 teams and  552 matches with a search space of  10^692.
5-galaxy26 has 50 days, 26 teams and  650 matches with a search space of  10^838.
5-galaxy28 has 54 days, 28 teams and  756 matches with a search space of  10^999.
5-galaxy30 has 58 days, 30 teams and  870 matches with a search space of 10^1175.
5-galaxy32 has 62 days, 32 teams and  992 matches with a search space of 10^1367.
5-galaxy34 has 66 days, 34 teams and 1122 matches with a search space of 10^1576.
5-galaxy36 has 70 days, 36 teams and 1260 matches with a search space of 10^1801.
5-galaxy38 has 74 days, 38 teams and 1406 matches with a search space of 10^2042.
5-galaxy40 has 78 days, 40 teams and 1560 matches with a search space of 10^2301.
Copy to Clipboard Toggle word wrap

31.19. 更便宜的时间调度

以时间和计算机上计划所有任务,以最大程度降低功耗。电源价格因时间不同。这是 作业跃点调度的一种形式

硬限制:

  • 开始时间限制:每个任务都必须在其最早启动和最新的开始限制之间启动。
  • 最大容量:不得超过每台机器的最大资源容量。
  • 启动和关闭:每台机器必须在为其分配任务的期间内处于活跃状态。在任务间,允许闲置以避免启动和关闭成本。

中型限制:

  • 电源成本:最小化整个计划的总功耗。

    • 机器电源成本:每个活动或空闲计算机都会消耗电源,这推断了电源成本(取决于该时间的电源价格)。
    • 任务电源成本:每个任务消耗电源,从而推断出了电源成本(取决于其时间的电源价格)。
    • 机器启动和关闭成本:每次机器启动或关机时都会产生额外的成本。

软限制(在原始问题定义中添加):

  • 早开始: 首选启动一个任务,而不是在以后启动。

问题由 ICON 挑战 定义。

问题大小

sample01   has 3 resources,   2 machines, 288 periods and   25 tasks with a search space of    10^53.
sample02   has 3 resources,   2 machines, 288 periods and   50 tasks with a search space of   10^114.
sample03   has 3 resources,   2 machines, 288 periods and  100 tasks with a search space of   10^226.
sample04   has 3 resources,   5 machines, 288 periods and  100 tasks with a search space of   10^266.
sample05   has 3 resources,   2 machines, 288 periods and  250 tasks with a search space of   10^584.
sample06   has 3 resources,   5 machines, 288 periods and  250 tasks with a search space of   10^673.
sample07   has 3 resources,   2 machines, 288 periods and 1000 tasks with a search space of  10^2388.
sample08   has 3 resources,   5 machines, 288 periods and 1000 tasks with a search space of  10^2748.
sample09   has 4 resources,  20 machines, 288 periods and 2000 tasks with a search space of  10^6668.
instance00 has 1 resources,  10 machines, 288 periods and  200 tasks with a search space of   10^595.
instance01 has 1 resources,  10 machines, 288 periods and  200 tasks with a search space of   10^599.
instance02 has 1 resources,  10 machines, 288 periods and  200 tasks with a search space of   10^599.
instance03 has 1 resources,  10 machines, 288 periods and  200 tasks with a search space of   10^591.
instance04 has 1 resources,  10 machines, 288 periods and  200 tasks with a search space of   10^590.
instance05 has 2 resources,  25 machines, 288 periods and  200 tasks with a search space of   10^667.
instance06 has 2 resources,  25 machines, 288 periods and  200 tasks with a search space of   10^660.
instance07 has 2 resources,  25 machines, 288 periods and  200 tasks with a search space of   10^662.
instance08 has 2 resources,  25 machines, 288 periods and  200 tasks with a search space of   10^651.
instance09 has 2 resources,  25 machines, 288 periods and  200 tasks with a search space of   10^659.
instance10 has 2 resources,  20 machines, 288 periods and  500 tasks with a search space of  10^1657.
instance11 has 2 resources,  20 machines, 288 periods and  500 tasks with a search space of  10^1644.
instance12 has 2 resources,  20 machines, 288 periods and  500 tasks with a search space of  10^1637.
instance13 has 2 resources,  20 machines, 288 periods and  500 tasks with a search space of  10^1659.
instance14 has 2 resources,  20 machines, 288 periods and  500 tasks with a search space of  10^1643.
instance15 has 3 resources,  40 machines, 288 periods and  500 tasks with a search space of  10^1782.
instance16 has 3 resources,  40 machines, 288 periods and  500 tasks with a search space of  10^1778.
instance17 has 3 resources,  40 machines, 288 periods and  500 tasks with a search space of  10^1764.
instance18 has 3 resources,  40 machines, 288 periods and  500 tasks with a search space of  10^1769.
instance19 has 3 resources,  40 machines, 288 periods and  500 tasks with a search space of  10^1778.
instance20 has 3 resources,  50 machines, 288 periods and 1000 tasks with a search space of  10^3689.
instance21 has 3 resources,  50 machines, 288 periods and 1000 tasks with a search space of  10^3678.
instance22 has 3 resources,  50 machines, 288 periods and 1000 tasks with a search space of  10^3706.
instance23 has 3 resources,  50 machines, 288 periods and 1000 tasks with a search space of  10^3676.
instance24 has 3 resources,  50 machines, 288 periods and 1000 tasks with a search space of  10^3681.
instance25 has 3 resources,  60 machines, 288 periods and 1000 tasks with a search space of  10^3774.
instance26 has 3 resources,  60 machines, 288 periods and 1000 tasks with a search space of  10^3737.
instance27 has 3 resources,  60 machines, 288 periods and 1000 tasks with a search space of  10^3744.
instance28 has 3 resources,  60 machines, 288 periods and 1000 tasks with a search space of  10^3731.
instance29 has 3 resources,  60 machines, 288 periods and 1000 tasks with a search space of  10^3746.
instance30 has 4 resources,  70 machines, 288 periods and 2000 tasks with a search space of  10^7718.
instance31 has 4 resources,  70 machines, 288 periods and 2000 tasks with a search space of  10^7740.
instance32 has 4 resources,  70 machines, 288 periods and 2000 tasks with a search space of  10^7686.
instance33 has 4 resources,  70 machines, 288 periods and 2000 tasks with a search space of  10^7672.
instance34 has 4 resources,  70 machines, 288 periods and 2000 tasks with a search space of  10^7695.
instance35 has 4 resources,  80 machines, 288 periods and 2000 tasks with a search space of  10^7807.
instance36 has 4 resources,  80 machines, 288 periods and 2000 tasks with a search space of  10^7814.
instance37 has 4 resources,  80 machines, 288 periods and 2000 tasks with a search space of  10^7764.
instance38 has 4 resources,  80 machines, 288 periods and 2000 tasks with a search space of  10^7736.
instance39 has 4 resources,  80 machines, 288 periods and 2000 tasks with a search space of  10^7783.
instance40 has 4 resources,  90 machines, 288 periods and 4000 tasks with a search space of 10^15976.
instance41 has 4 resources,  90 machines, 288 periods and 4000 tasks with a search space of 10^15935.
instance42 has 4 resources,  90 machines, 288 periods and 4000 tasks with a search space of 10^15887.
instance43 has 4 resources,  90 machines, 288 periods and 4000 tasks with a search space of 10^15896.
instance44 has 4 resources,  90 machines, 288 periods and 4000 tasks with a search space of 10^15885.
instance45 has 4 resources, 100 machines, 288 periods and 5000 tasks with a search space of 10^20173.
instance46 has 4 resources, 100 machines, 288 periods and 5000 tasks with a search space of 10^20132.
instance47 has 4 resources, 100 machines, 288 periods and 5000 tasks with a search space of 10^20126.
instance48 has 4 resources, 100 machines, 288 periods and 5000 tasks with a search space of 10^20110.
instance49 has 4 resources, 100 machines, 288 periods and 5000 tasks with a search space of 10^20078.
Copy to Clipboard Toggle word wrap

31.20. 投资资产类分配(Portfolio Optimization)

决定对每个资产类进行投资的相对数量。

硬限制:

  • 风险最大值:标准开发总数不能高于标准偏差的最大值。

  • 地区最大值:每个地区具有最大数量。
  • 扇区最大值:每个扇区具有最大数量。

软限制:

  • 最大化预期收益。

问题大小

de_smet_1 has 1 regions, 3 sectors and 11 asset classes with a search space of 10^4.
irrinki_1 has 2 regions, 3 sectors and 6 asset classes with a search space of 10^3.
Copy to Clipboard Toggle word wrap

大型数据集尚未创建或测试,但不应造成问题。良好的数据源是 此资产修正网站

31.21. 会议调度

为每个会议分配上机时间和房间。Timeslots 可能会重叠。从使用 libreoffice 或 Excel 编辑的 *.xlsx 文件中读取和写入。

硬限制:

  • talk of timeslot: 一个讨论的类型必须与 timeslot 的讨论类型匹配。
  • 房间不可用:在对话期间,必须有机房可用。
  • 房间冲突:两个对话在重叠期间无法使用同一空间。
  • speaker unavailable timeslots:每个对话的发言人都必须在对话期间可用。
  • speaker 冲突:两个对话在重叠时无法共享发言人。
  • 通用目的次数和房间标签:

    • speaker required timeslot tag:如果发言人具有所需的 timeslot 标签,则必须将其所有或她的对话分配给具有该标签的时间。
    • speaker prohibited timeslot 标签:如果发言人有禁止性差标签,则所有其或她的对话都不能分配给具有该标签的时间。
    • 对话所需的 timeslot 标签:如果对话具有所需的 timeslot 标签,则必须将其分配给具有该标签的时间。
    • prohibited timeslot 标签:如果通信有禁止性标签,则无法将其分配给具有该标签的 timeslot。
    • speaker required room tag:如果发言人具有所需的房间标签,则必须将所有或她的对话分配到具有该标签的房间。
    • speaker prohibited room标签:如果发言人有禁止的房间标签,则所有或她都无法分配给具有该标签的房间。
    • 对话所需的房间标签:如果对话具有所需的房间标签,则必须将其分配到具有该标签的房间。
    • Insecure room tag:如果对话有禁止的房间标签,则无法将其分配给具有该标签的房间。
  • talk mutually-exclusive-talks tag: Talks, share a such a tag not be scheduled in overlapping timests.
  • 对话前提条件:必须在所有先决条件对话后调度对话。

软限制:

  • 主题跟踪冲突:减少在重叠期间共享主题标签的对话数量。
  • 扇区冲突:减少在重叠期间共享相同扇区标签的讨论数量。
  • 内容受众级别流程违反情况:对于每一个内容标签,请计划在高级对话之前进行介绍。
  • 受众级别多元化:对于每倍,将讨论数量最大化,让不同受众水平最大化。
  • 语言多样性:对于每家来说,使用不同语言最大程度提高对话的数量。
  • 通用目的次数和房间标签:

    • speaker preferredlot 标签:如果发言人有首选 timeslot 标签,则所有他或她的所有对话都应分配给具有该标签的时间。
    • speaker undesired timeslot 标签:如果 speaker 具有不需要的 timeslot 标签,则其任何或她的任何对话都不应分配给具有该标签的时间。
    • 发生首选 timeslot 标签:如果通信具有首选差差标签,则应该将其分配给具有该标签的时间。
    • 排除不需要的 timeslot 标签:如果通信具有不需要的 timeslot 标签,则不应将其分配给具有该标签的 timeslot。
    • speaker preferred room tag:如果发言人有首选空间标签,则所有他的所有对话都应分配给具有该标签的房间。
    • speaker undesired room tag:如果发言人有不需要的房间标签,则不应向具有该标签的房间分配任何人。
    • 对话首选房间标签:如果对话具有首选房间标签,则应将其分配到具有该标签的房间。
    • 讨论不需要的房间标签:如果对话具有不需要的房间标签,则不应将其分配给具有该标签的房间。
  • 同一天讨论:所有共享主题标签或内容标签都应以最小天数(通常在同一天)内调度。

图 31.14. 价值定位

问题大小

18talks-6timeslots-5rooms    has  18 talks,  6 timeslots and  5 rooms with a search space of  10^26.
36talks-12timeslots-5rooms   has  36 talks, 12 timeslots and  5 rooms with a search space of  10^64.
72talks-12timeslots-10rooms  has  72 talks, 12 timeslots and 10 rooms with a search space of 10^149.
108talks-18timeslots-10rooms has 108 talks, 18 timeslots and 10 rooms with a search space of 10^243.
216talks-18timeslots-20rooms has 216 talks, 18 timeslots and 20 rooms with a search space of 10^552.
Copy to Clipboard Toggle word wrap

31.22. rock Tur

从 show to show 驱动 rock 银行总线,但时间表仅在可用天显示。

硬限制:

  • 计划每个所需显示。
  • 计划尽可能多显示。

中型限制:

  • 最大化收入机会。
  • 尽量缩短驱动时间。
  • 比以后更早访问.

软限制:

  • 避免长时间驱动时间。

问题大小

47shows has 47 shows with a search space of 10^59.
Copy to Clipboard Toggle word wrap

31.23. flight crew 调度

为试验和上机分配交通。

硬限制:

  • 所需技能:每个员工都有所需的技能。例如,flight AB0001 需要 2 个试验和 3 个机票。
  • 交通冲突:每个员工可以同时参加一个交通
  • 在两个交易之间传输:在两个交易之间,员工必须能够从 arrival airport 传达给下机场所。例如,Amsterdam 中的 Brussels 到达 上午 10:00,地址为 15:00。
  • 员工不可用:员工必须在交易之日可用。例如,An 代表上 1-Feb。

软限制:

  • 第一个分配从家中分离
  • 到达 home 的最后分配
  • 每个员工的负载均衡 flight 持续时间

问题大小

175flights-7days-Europe  has 2 skills, 50 airports, 150 employees, 175 flights and  875 flight assignments with a search space of  10^1904.
700flights-28days-Europe has 2 skills, 50 airports, 150 employees, 700 flights and 3500 flight assignments with a search space of  10^7616.
875flights-7days-Europe  has 2 skills, 50 airports, 750 employees, 875 flights and 4375 flight assignments with a search space of 10^12578.
175flights-7days-US      has 2 skills, 48 airports, 150 employees, 175 flights and  875 flight assignments with a search space of  10^1904.
Copy to Clipboard Toggle word wrap

第 32 章 下载红帽构建的 OptaPlanner 示例

您可以下载 Red Hat build of OptaPlanner 示例,作为红帽客户门户网站中提供的 Red Hat Process Automation Manager 附加组件软件包的一部分。

流程

  1. 导航到红帽客户门户网站中的 Software Downloads 页面(需要登录),然后从下拉菜单中选择产品和版本:

    • 产品:流程自动化管理器
    • Version: 7.12
  2. 下载 Red Hat Process Automation Manager 7.12 Add Ons
  3. 提取 rhpam-7.12.0-add-ons.zip 文件。提取 的附加组件文件夹包含 rhpam-7.12.0-planner-engine.zip 文件。
  4. 提取 rhpam-7.12.0-planner-engine.zip 文件。

结果

提取的 rhpam-7.12.0-planner-engine 目录包含以下子目录下的示例源代码:

  • examples/sources/src/main/java/org/optaplanner/examples
  • examples/sources/src/main/resources/org/optaplanner/examples

32.1. 运行 OptaPlanner 示例

红帽构建的 OptaPlanner 包括一些演示各种规划用例的示例。下载并使用示例来探索不同类型的规划解决方案。

先决条件

流程

  1. 要运行示例,在 rhpam-7.12.0-planner-engine/examples 目录中输入以下命令之一:

    Linux 或 Mac:

    $ ./runExamples.sh
    Copy to Clipboard Toggle word wrap

    Windows:

    $ runExamples.bat
    Copy to Clipboard Toggle word wrap

    OptaPlanner Examples 窗口将打开。

  2. 选择一个运行该示例的示例。
注意

红帽构建的 OptaPlanner 没有 GUI 依赖项。它还在服务器或移动 JVM 上运行,就像它在桌面上一样。

如果您使用集成的开发环境(IDE),如 IntelliJ、Eclipse 或 Netbeans,您可以在开发环境中运行下载的 OptaPlanner 示例。

先决条件

流程

  1. 以新项目形式打开 OptaPlanner 示例:

    1. 对于 IntelliJ 或 Netbeans,打开 example/sources/pom.xml 作为新项目。Maven 集成指导您完成其余安装。跳过此过程中的其余步骤。
    2. 对于 Eclipse,为 /examples/binaries 目录打开一个新项目,它位于 rhpam-7.12.0-planner-engine 目录下。
  2. 将所有位于 二进制 目录的 JAR 文件添加到 classpath 中,但 examples/binaries/optaplanner-examples-7.59.0.Final-redhat-00006.jar 文件除外。
  3. 添加 Java 源目录 src/main/java 和 Java 资源目录 src/main/resources,位于 rhpam-7.12.0-planner-engine/examples/sources/ 目录下。
  4. 创建运行配置:

    • 主类: org.optaplanner.examples.app.OptaPlannerExamplesApp
    • VM 参数(可选): -Xmx512M -server -Dorg.optaplanner.examples.dataDir=examples/sources/data
    • 工作目录: example/sources
  5. 运行运行配置。

您可以在 Business Central 中 构建和部署员工 示例项目。该项目演示了如何创建解决转型计划问题所需要的每个 Business Central 资产,并使用红帽构建 OptaPlanner 来查找最佳解决方案。

您可以在 Business Central 中部署预配置的 员工 -rostering 项目。或者,您可以使用 Business Central 自行创建项目。

注意

Business Central 中的 员工 示例项目不包括数据集。您必须使用 REST API 调用以 XML 格式提供数据集。

Business Central 包括多个示例项目,可用于熟悉产品及其功能。员工漫长示例项目旨在并创建来演示红帽构建 OptaPlanner 的转变激情用例。使用以下流程在 Business Central 中部署和运行员工名词示例。

先决条件

  • Red Hat Process Automation Manager 已下载并安装。有关安装选项,请参阅 规划 Red Hat Process Automation Manager 安装
  • 您已按照安装文档启动 Red Hat Process Automation Manager,并以具有 admin 权限的用户身份登录到 Business Central。

流程

  1. 在 Business Central 中,点 MenuDesignProjects
  2. 在预配置的 MySpace 空间中,单击 Try Samples
  3. 从示例项目列表中选择 employee-rostering,再单击右上角的 Ok 以导入项目。
  4. 编译资产列表后,点 Build & Deploy 来部署员工名录示例。

本文档的其余部分解释了每个项目资产及其配置。

33.2. 重新创建员工示例项目

员工示例项目是 Business Central 中提供的预配置项目。您可以在 第 33.1 节 “在 Business Central 中部署员工漫长示例项目” 中了解如何部署此项目。

您可以创建员工对示例"从零开始"。您可以使用本例中的工作流在 Business Central 中创建您自己的类似项目。

33.2.1. 设置员工漫长项目

要在 Business Central 中开始开发解决者,您必须设置该项目。

先决条件

  • Red Hat Process Automation Manager 已下载并安装。
  • 您已部署了 Business Central,并使用具有 admin 角色的用户登录。

流程

  1. MenuDesignProjectsAdd Project,在 Business Central 中创建一个新项目。
  2. Add Project 窗口中填写以下字段:

    • 名称employee-rostering
    • 描述(可选):使用 OptaPlanner 扩大问题优化。根据自身技能,分配员工进行转变。

    可选:点 Configure Advanced Options 来填充 组 IDArtifact IDVersion 信息。

    • 组 ID :员工
    • 工件 ID :员工
    • Version:1.0.0-SNAPSHOT
  3. 单击 Add,将项目添加到 Business Central 项目存储库中。

33.2.2. 问题事实和规划实体

员工规划问题中的每个域类都归类为以下之一:

  • 一个不相关的类:不被分数限制使用。从规划的角度来看,这个数据已过时。
  • 问题事实 类:分数约束使用但在规划过程中不会改变(只要问题保持不变),例如 ShiftEmployee。问题类的所有属性都是问题属性。
  • 计划实体类:在规划 过程中分数约束和更改使用,例如 ShiftAssignment。计划期间更改的属性正在 规划变量。其他属性是问题属性。

    请您提出以下问题:

  • 计划期间发生了哪些类变化?
  • 哪个类具有我想要 更改 的变量?

    该类是计划实体。

    计划实体类需要使用 @PlanningEntity 注释标注,或者在 Business Central 中定义,并在域设计程序中使用红帽构建 OptaPlanner dock。

    每个计划实体类均有一个或多个 计划变量,并且必须具有一个或多个定义属性。

    大多数用例只有一个规划实体类,每个计划实体类都只有一个计划变量。

33.2.3. 为员工漫长项目创建数据模型

使用本节创建在 Business Central 中运行员工名录示例项目所需的数据对象。

先决条件

流程

  1. 使用新项目,点项目视角中的 Data Object,或者点击 Add AssetData Object 来创建新数据对象。
  2. 将第一个数据对象 time slot 命名为,然后选择 employeerostering.employeerostering 作为 软件包

    确定

  3. Data Objects 视角中,点 +add 字段Timeslot data 对象添加字段。
  4. id 字段中,键入 endTime
  5. 单击 Type 旁边的下拉菜单,再选择 LocalDateTime
  6. Create and continue 添加另一个字段。
  7. 使用 id startTimeType LocalDateTime 添加另一个字段。
  8. Create
  9. 点右上角的 Save,以保存 Timeslot 数据对象。
  10. 单击右上角的 x 以关闭 Data Objects 透视图,并返回到 Assets 菜单。
  11. 使用前面的步骤,创建以下数据对象及其属性:

    Expand
    表 33.1. 技能
    id类型

    name

    字符串

    Expand
    表 33.2. 员工
    id类型

    name

    字符串

    skills

    employeerostering.employeerostering.Skill[List]

    Expand
    表 33.3. 变动
    id类型

    requiredSkill

    employeerostering.employeerostering.Skill

    timeslot

    employeerostering.employeerostering.Timeslot

    Expand
    表 33.4. DayOffRequest
    id类型

    date

    LocalDate

    employee

    employeerostering.employeerostering.Employee

    Expand
    表 33.5. ShiftAssignment
    id类型

    employee

    employeerostering.employeerostering.Employee

    shift

    employeerostering.employeerostering.Shift

有关创建数据对象的更多示例,请参阅开始使用决策服务

33.2.3.1. 创建员工规划实体

为了解决员工对规划问题,您必须创建一个规划实体和解决者。计划实体使用红帽构建的 OptaPlanner dock 中提供的属性在域设计人员中定义。

使用以下步骤将 ShiftAssignment 数据对象定义为员工 rostering 的规划实体。

先决条件

流程

  1. 在项目 资产 菜单中,打开 ShiftAssignment data 对象。
  2. Data Objects 视角中,点右侧的 OptaPlanner icon 来打开 OptaPlanner dock。
  3. 选择 Planning Entity
  4. ShiftAssignment 数据对象下的字段列表中选择 employee
  5. 在 OptaPlanner dock 中,选择 Planning Variable

    Value Range Id 输入字段中,键入 employeeRange。这会将 @ValueRangeProvider 注释添加到计划实体,您可以通过单击设计程序中的 Source 选项卡来查看该注释。

    计划变量的值范围通过 @ValueRangeProvider 注释来定义。@ValueRangeProvider 注释始终具有属性 id,它被 @PlanningVariable 属性 valueRangeProviderRefs 引用。

  6. 关闭 dock 并点 Save 保存数据对象。
33.2.3.2. 创建员工规划解决方案

员工 roster 问题依赖于定义的规划解决方案。计划解决方案通过使用红帽构建的 OptaPlanner dock 中提供的属性在域设计人员中定义。

先决条件

流程

  1. 使用标识符 EmployeeRoster 创建新数据对象。
  2. 创建以下字段:

    Expand
    表 33.6. EmployeeRoster
    id类型

    dayOffRequestList

    employeerostering.employeerostering.DayOffRequest[List]

    shiftAssignmentList

    employeerostering.employeerostering.ShiftAssignment[List]

    shiftList

    employeerostering.employeerostering.Shift[List]

    skillList

    employeerostering.employeerostering.Skill[List]

    timeslotList

    employeerostering.employeerostering.Timeslot[List]

  3. Data Objects 视角中,点右侧的 OptaPlanner icon 来打开 OptaPlanner dock。
  4. 选择规划解决方案
  5. 将默认的硬 软分数 保留为 解决方案分数类型。这会在 EmployeeRoster 数据对象中自动生成 分数 字段,其解决方案分数作为类型。
  6. 使用以下属性添加新字段:

    Expand
    id类型

    employeeList

    employeerostering.employeerostering.Employee[List]

  7. 选择 employeeList 字段后,打开 OptaPlanner dock,然后选择 planning Value Range Provider 框。

    id 字段中,键入 employeeRange。关闭 dock。

  8. 单击右上角的 Save 以保存资产。

33.2.4. 员工划分限制

员工名列是规划问题。所有规划问题均包括必须满足的约束才能找到最佳解决方案。

Business Central 中的员工漫长示例项目包括以下硬和软限制:

硬约束
  • 每天仅分配一次变化。
  • 所有需要特定员工技能的改变都被分配了具有该特定技能的员工。
软限制
  • 所有员工都分配有变化。
  • 如果员工每天没有请求,则会将其转移重新分配给另一个员工。

使用自由格式 DRL 设计程序或使用指导规则在 Business Central 中定义硬和软限制。

33.2.4.1. DRL (Drools 规则语言)规则

DRL (Drools 规则语言)规则是您直接在 .drl 文本文件中定义的业务规则。这些 DRL 文件是最终呈现 Business Central 中所有其他规则资产的源。您可以在 Business Central 界面中创建和管理 DRL 文件,或使用 Red Hat CodeReady Studio 或其他集成开发环境(IDE)作为 Maven 或 Java 项目的一部分创建它们。DRL 文件可以包含一个或多个规则,它们至少定义规则条件(何时)和操作(然后)。Business Central 中的 DRL 设计程序提供了 Java、DRL 和 XML 的语法高亮显示。

DRL 文件由以下组件组成:

DRL 文件中的组件

package

import

function  // Optional

query  // Optional

declare   // Optional

global   // Optional

rule "rule name"
    // Attributes
    when
        // Conditions
    then
        // Actions
end

rule "rule2 name"

...
Copy to Clipboard Toggle word wrap

以下示例 DRL 规则决定了 loan 应用程序决策服务中的年龄限制:

loan 应用程序年龄限制的规则示例

rule "Underage"
  salience 15
  agenda-group "applicationGroup"
  when
    $application : LoanApplication()
    Applicant( age < 21 )
  then
    $application.setApproved( false );
    $application.setExplanation( "Underage" );
end
Copy to Clipboard Toggle word wrap

DRL 文件可包含一个或多个规则、查询和功能,并可定义您的规则和查询分配的资源声明,如导入、全局和属性。DRL 软件包必须列在 DRL 文件的顶部,并且规则通常会最后一个列出。所有其他 DRL 组件都可以遵循任何顺序。

每个规则必须在规则软件包中都有一个唯一名称。如果您在软件包中的任何 DRL 文件中使用相同的规则名称多次,则规则无法编译。始终使用双引号(规则"rule name")括起规则名称以防止可能的编译错误,特别是在规则名称中使用空格。

与 DRL 规则相关的所有数据对象都必须与 Business Central 中的 DRL 文件位于同一个项目中。默认情况下,同一软件包中的资产会导入。其他软件包中现有的资产可使用 DRL 规则导入。

33.2.4.2. 使用 DRL 设计程序定义员工的约束

您可以使用 Business Central 中的自由格式 DRL 设计程序为员工漫长示例创建约束定义。

使用这个流程创建一个 硬约束,其中没有员工被分配时间超过 10 小时的改变。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects,再单击项目名称。
  2. Add AssetDRL 文件
  3. DRL file name 字段中,键入 ComplexScoreRules
  4. 选择 employeerostering.employeerostering 软件包。
  5. 单击 +Ok 以创建 DRL 文件。
  6. 在 DRL 设计器的 Model 选项卡中,将 Employee10HourShiftSpace 规则定义为 DRL 文件:

    package employeerostering.employeerostering;
    
    rule "Employee10HourShiftSpace"
        when
            $shiftAssignment : ShiftAssignment( $employee : employee != null, $shiftEndDateTime : shift.timeslot.endTime)
            ShiftAssignment( this != $shiftAssignment, $employee == employee, $shiftEndDateTime <= shift.timeslot.endTime,
                    $shiftEndDateTime.until(shift.timeslot.startTime, java.time.temporal.ChronoUnit.HOURS) <10)
        then
            scoreHolder.addHardConstraintMatch(kcontext, -1);
    end
    Copy to Clipboard Toggle word wrap
  7. Save 保存 DRL 文件。

有关创建 DRL 文件的更多信息,请参阅使用 DRL 规则设计决策服务

33.2.5. 使用指导规则为员工划分创建规则

您可以使用 Business Central 中的指导规则设计人员创建硬和软约束。

33.2.5.1. 指导规则

指导规则是在 Business Central 中的基于 UI 的引导规则设计程序中创建的业务规则,引导您通过规则创建流程。指导规则设计程序根据所定义的规则的数据对象提供可接受的输入字段和选项。您定义的指导规则被编译到 Drools 规则语言(DRL)规则中,与所有其他规则资产一样。

与指导规则相关的所有数据对象都必须与指导规则位于同一个项目中。默认情况下,同一软件包中的资产会导入。创建必要的数据对象和指导规则后,您可以使用指导规则设计器的 Data Objects 选项卡来验证所有所需的数据对象是否都已列出或导入其他现有 的数据对象

33.2.5.2. 创建指导规则来平衡员工的改变数字

BalanceEmployeesShiftNumber 指导规则创建一个软约束,以确保按尽可能平均平衡的方式分配到员工。它通过创建一个在变换发行版时增加的分数损失来达到此目的。分数公式由规则实施,以更均衡的方式替换 Solver 分发变化。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects,再单击项目名称。
  2. Add AssetGuided Rule
  3. 输入 BalanceEmployeesShiftNumber 作为" 指导规则名称",然后选择 employeerostering.employeerostering Package
  4. Ok 创建规则资产。
  5. WHEN 字段中的 5686 来添加 WHEN 条件。
  6. Add a condition to the rule 窗口中选择 Employee。单击 +Ok
  7. Employee 条件来修改约束,并添加变量名称 $employee
  8. 累积 中添加 WHEN 条件

    1. 在 From A umulate 条件 上方,单击添加模式,然后从下拉列表中选择 Number 作为事实类型。
    2. 将变量名称 $shiftCount 添加到 Number 条件。
    3. From Accumulate 条件下,单击添加模式,然后从下拉列表中选择 ShiftAssignment 事实类型。
    4. 将变量名称 $shiftAssignment 添加到 ShiftAssignment 类型。
    5. 再次单击 ShiftAssignment 条件,然后从 字段下拉列表中的 Add a limit,选择 employee
    6. 员工 约束旁边的下拉列表中,选择 等于
    7. 点击下拉按钮旁的 edit 图标添加变量,然后点击 Field value 窗口中的 Bound 变量
    8. 从下拉列表中选择 $employee
    9. Function 框中,类型 count ($shiftAssignment)
  9. wordpress N 字段中的 5686 来添加 wordpressN 条件。
  10. Add a new action 窗口中选择 Modify Soft Score。单击 +Ok

    1. 在框中键入以下表达式: -($shiftCount.intValue ()*$shiftCount.intValue ())
  11. 单击右上角的 Validate,以检查所有规则条件是否有效。如果规则验证失败,请解决错误消息中描述的任何问题,检查规则中的所有组件,然后再次尝试验证规则,直到规则通过为止。
  12. 单击 Save 以保存规则。

有关创建指导规则的更多信息,请参阅使用指导规则设计决策服务

33.2.5.3. 创建一个指导规则,每天不多于一个

OneEmployeeShiftPerDay 指导规则创建硬约束,使员工不会每天分配多个变化。在 employee rostering 示例中,这个约束使用指导规则设计程序创建。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects,再单击项目名称。
  2. Add AssetGuided Rule
  3. 输入 OneEmployeeShiftPerDay 作为" 指导规则名称",然后选择 employeerostering.employeerostering Package
  4. Ok 创建规则资产。
  5. WHEN 字段中的 5686 来添加 WHEN 条件。
  6. Add a condition to the rule 窗口中选择 Free form DRL
  7. 在 free 表单 DRL 框中,输入以下条件:

    $shiftAssignment : ShiftAssignment( employee != null )
    		ShiftAssignment( this != $shiftAssignment , employee == $shiftAssignment.employee , shift.timeslot.startTime.toLocalDate() == $shiftAssignment.shift.timeslot.startTime.toLocalDate() )
    Copy to Clipboard Toggle word wrap

    此条件指出,无法分配给已经在同一天有另一个转移的员工。

  8. wordpress N 字段中的 5686 来添加 wordpressN 条件。
  9. Add a new action 窗口中选择 Add free form DRL
  10. 在 free 表单 DRL 框中,输入以下条件:

    scoreHolder.addHardConstraintMatch(kcontext, -1);
    Copy to Clipboard Toggle word wrap
  11. 单击右上角的 Validate,以检查所有规则条件是否有效。如果规则验证失败,请解决错误消息中描述的任何问题,检查规则中的所有组件,然后再次尝试验证规则,直到规则通过为止。
  12. 单击 Save 以保存规则。

有关创建指导规则的更多信息,请参阅使用指导规则设计决策服务

33.2.5.4. 创建指导规则来匹配转换要求

ShiftReqiredSkillsAreMet 指导规则会创建一个硬约束,确保为员工分配有正确技能集的员工。在 employee rostering 示例中,这个约束使用指导规则设计程序创建。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects,再单击项目名称。
  2. Add AssetGuided Rule
  3. 输入 ShiftReqiredSkillsAreMet 作为 指导规则 名称,然后选择 employeerostering.employeerostering Package
  4. Ok 创建规则资产。
  5. WHEN 字段中的 5686 来添加 WHEN 条件。
  6. Add a condition to the rule 窗口中选择 ShiftAssignment。单击 +Ok
  7. 单击 ShiftAssignment 条件,然后从 Add a limits on a field 下拉列表中选择 employee。
  8. 在设计人员中,单击 员工 旁边的下拉列表,然后选择 is not null
  9. 单击 ShiftAssignment 条件,然后单击 Expression 编辑器

    1. 在设计人员中,单击 [not bound] 以打开 Expression 编辑器,并将表达式绑定到变量 $requiredSkill。点 Set
    2. 在设计过程中,在 $requiredSkill 旁边,从第一个下拉列表中选择 切换,然后从下一个下拉列表中选择 requiredSkill
  10. 单击 ShiftAssignment 条件,然后单击 Expression 编辑器

    1. 在设计人员中,在 [not bound] 旁边,从第一个下拉列表中选择 employee,然后从下一下拉列表中选择 skills
    2. 将下一个下拉列表保留为 Choose
    3. 在下一个下拉菜单中,将 please choose 改为 excludes
    4. 点击 排除edit 图标,在 Field value 窗口中点击 New formula 按钮。
    5. 在公式框中键入 $requiredSkill
  11. wordpress N 字段中的 5686 来添加 wordpressN 条件。
  12. Add a new action 窗口中选择 Modify Hard Score。单击 +Ok
  13. 在分数操作框中键入 -1
  14. 单击右上角的 Validate,以检查所有规则条件是否有效。如果规则验证失败,请解决错误消息中描述的任何问题,检查规则中的所有组件,然后再次尝试验证规则,直到规则通过为止。
  15. 单击 Save 以保存规则。

有关创建指导规则的更多信息,请参阅使用指导规则设计决策服务

33.2.5.5. 创建指导规则来管理一天

DayOffRequest 指导规则创建一个软约束。通过这个约束,当最初分配该转换的员工不再能够工作时,可以将转换重新分配给另一个员工。在 employee rostering 示例中,这个约束使用指导规则设计程序创建。

流程

  1. 在 Business Central 中,前往 MenuDesignProjects,再单击项目名称。
  2. Add AssetGuided Rule
  3. 输入 DayOffRequest 作为" 指导规则名称",然后选择 employeerostering.employeerostering 软件包
  4. Ok 创建规则资产。
  5. WHEN 字段中的 5686 来添加 WHEN 条件。
  6. Add a condition to the rule 窗口中选择 Free form DRL
  7. 在 free 表单 DRL 框中,输入以下条件:

    $dayOffRequest : DayOffRequest( )
    		ShiftAssignment( employee == $dayOffRequest.employee , shift.timeslot.startTime.toLocalDate() == $dayOffRequest.date )
    Copy to Clipboard Toggle word wrap

    此条件表示,如果将转换分配给制定一天的员工,则员工可以取消分配该日期的转变。

  8. wordpress N 字段中的 5686 来添加 wordpressN 条件。
  9. Add a new action 窗口中选择 Add free form DRL
  10. 在 free 表单 DRL 框中,输入以下条件:

    scoreHolder.addSoftConstraintMatch(kcontext, -100);
    Copy to Clipboard Toggle word wrap
  11. 单击右上角的 Validate,以检查所有规则条件是否有效。如果规则验证失败,请解决错误消息中描述的任何问题,检查规则中的所有组件,然后再次尝试验证规则,直到规则通过为止。
  12. 单击 Save 以保存规则。

有关创建指导规则的更多信息,请参阅使用指导规则设计决策服务

33.2.6. 为员工名电创建解决者配置

您可以在 Business Central 中创建和编辑 Solver 配置。Solver 配置设计程序会创建一个解析器配置,可在部署项目后运行。

先决条件

  • Red Hat Process Automation Manager 已下载并安装。
  • 您已为员工漫长示例创建并配置了所有相关资产。

流程

  1. 在 Business Central 中,点 MenuProjects,然后点击您的项目来打开它。
  2. Assets 视角中,点 Add AssetSolver configuration
  3. Create new Solver configuration 窗口中,为您的 Solver 输入名称 EmployeeRosteringSolverConfig,然后点 Ok

    这将打开 Solv er 配置设计 程序。

  4. Score Director Factory 配置部分中,定义一个包含 scoring 规则定义的 KIE 基础。员工示例项目使用 defaultKieBase

    1. 选择在 KIE 库中定义的 KIE 会话之一。员工漫长示例项目使用 defaultKieSession
  5. 单击右上角的 Validate,以检查 Score Director Factory 配置是否正确。如果验证失败,请解决错误消息中描述的任何问题,然后重试验证,直到配置通过为止。
  6. Save 保存 Solver 配置。

33.2.7. 为员工排班项目配置 Solver 终止

您可以在指定时间后将 Solver 配置为终止。默认情况下,计划引擎会提供无限时间段来解决问题实例。

员工示例项目设置为运行 30 秒。

先决条件

流程

  1. Assets 视角打开 EmployeeRosteringSolverConfig。这将打开 Solv er 配置设计 程序。
  2. Termination 部分中,单击 Add 在所选逻辑组中创建新的 termination 元素。
  3. 从下拉列表中选择所用的 终止类型。这在终止配置中作为输入字段添加。
  4. 使用时间元素旁边的箭头将时间调整为 30 秒。
  5. 单击右上角的 Validate,以检查 Score Director Factory 配置是否正确。如果验证失败,请解决错误消息中描述的任何问题,然后重试验证,直到配置通过为止。
  6. Save 保存 Solver 配置。

33.3. 使用 REST API 访问解析器

在部署或重新创建示例解析程序后,您可以使用 REST API 访问它。

您必须使用 REST API 注册 solver 实例。然后,您可以提供数据集并检索优化的解决方案。

先决条件

33.3.1. 使用 REST API 注册 Solver

您必须使用 REST API 注册 solver 实例,然后才能使用 solver。

每个解决器实例都可以一次优化一个计划问题。

流程

  1. 使用以下标头创建 HTTP 请求:

    authorization: admin:admin
    X-KIE-ContentType: xstream
    content-type: application/xml
    Copy to Clipboard Toggle word wrap
  2. 使用以下请求注册 Solver :

    PUT
    http://localhost:8080/kie-server/services/rest/server/containers/employeerostering_1.0.0-SNAPSHOT/solvers/EmployeeRosteringSolver
    请求正文
    <solver-instance>
      <solver-config-file>employeerostering/employeerostering/EmployeeRosteringSolverConfig.solver.xml</solver-config-file>
    </solver-instance>
    Copy to Clipboard Toggle word wrap

33.3.2. 使用 REST API 调用 Solver

在注册解决程序实例后,您可以使用 REST API 向 solver 提交数据集并检索优化的解决方案。

流程

  1. 使用以下标头创建 HTTP 请求:

    authorization: admin:admin
    X-KIE-ContentType: xstream
    content-type: application/xml
    Copy to Clipboard Toggle word wrap
  2. 使用数据集向 Solver 提交请求,如下例所示:

    POST
    http://localhost:8080/kie-server/services/rest/server/containers/employeerostering_1.0.0-SNAPSHOT/solvers/EmployeeRosteringSolver/state/solving
    请求正文
    <employeerostering.employeerostering.EmployeeRoster>
      <employeeList>
        <employeerostering.employeerostering.Employee>
          <name>John</name>
          <skills>
            <employeerostering.employeerostering.Skill>
              <name>reading</name>
            </employeerostering.employeerostering.Skill>
          </skills>
        </employeerostering.employeerostering.Employee>
        <employeerostering.employeerostering.Employee>
          <name>Mary</name>
          <skills>
            <employeerostering.employeerostering.Skill>
              <name>writing</name>
            </employeerostering.employeerostering.Skill>
          </skills>
        </employeerostering.employeerostering.Employee>
        <employeerostering.employeerostering.Employee>
          <name>Petr</name>
          <skills>
            <employeerostering.employeerostering.Skill>
              <name>speaking</name>
            </employeerostering.employeerostering.Skill>
          </skills>
        </employeerostering.employeerostering.Employee>
      </employeeList>
      <shiftList>
        <employeerostering.employeerostering.Shift>
          <timeslot>
            <startTime>2017-01-01T00:00:00</startTime>
            <endTime>2017-01-01T01:00:00</endTime>
          </timeslot>
          <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
        </employeerostering.employeerostering.Shift>
        <employeerostering.employeerostering.Shift>
          <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
          <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
        </employeerostering.employeerostering.Shift>
        <employeerostering.employeerostering.Shift>
          <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
          <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
        </employeerostering.employeerostering.Shift>
      </shiftList>
      <skillList>
        <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
        <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
        <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
      </skillList>
      <timeslotList>
        <employeerostering.employeerostering.Timeslot reference="../../shiftList/employeerostering.employeerostering.Shift/timeslot"/>
      </timeslotList>
      <dayOffRequestList/>
      <shiftAssignmentList>
        <employeerostering.employeerostering.ShiftAssignment>
          <shift reference="../../../shiftList/employeerostering.employeerostering.Shift"/>
        </employeerostering.employeerostering.ShiftAssignment>
        <employeerostering.employeerostering.ShiftAssignment>
          <shift reference="../../../shiftList/employeerostering.employeerostering.Shift[3]"/>
        </employeerostering.employeerostering.ShiftAssignment>
        <employeerostering.employeerostering.ShiftAssignment>
          <shift reference="../../../shiftList/employeerostering.employeerostering.Shift[2]"/>
        </employeerostering.employeerostering.ShiftAssignment>
      </shiftAssignmentList>
    </employeerostering.employeerostering.EmployeeRoster>
    Copy to Clipboard Toggle word wrap
  3. 向规划问题请求最佳解决方案:

    GET

    http://localhost:8080/kie-server/services/rest/server/containers/employeerostering_1.0.0-SNAPSHOT/solvers/EmployeeRosteringSolver/bestsolution

    响应示例

    <solver-instance>
      <container-id>employee-rostering</container-id>
      <solver-id>solver1</solver-id>
      <solver-config-file>employeerostering/employeerostering/EmployeeRosteringSolverConfig.solver.xml</solver-config-file>
      <status>NOT_SOLVING</status>
      <score scoreClass="org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore">0hard/0soft</score>
      <best-solution class="employeerostering.employeerostering.EmployeeRoster">
        <employeeList>
          <employeerostering.employeerostering.Employee>
            <name>John</name>
            <skills>
              <employeerostering.employeerostering.Skill>
                <name>reading</name>
              </employeerostering.employeerostering.Skill>
            </skills>
          </employeerostering.employeerostering.Employee>
          <employeerostering.employeerostering.Employee>
            <name>Mary</name>
            <skills>
              <employeerostering.employeerostering.Skill>
                <name>writing</name>
              </employeerostering.employeerostering.Skill>
            </skills>
          </employeerostering.employeerostering.Employee>
          <employeerostering.employeerostering.Employee>
            <name>Petr</name>
            <skills>
              <employeerostering.employeerostering.Skill>
                <name>speaking</name>
              </employeerostering.employeerostering.Skill>
            </skills>
          </employeerostering.employeerostering.Employee>
        </employeeList>
        <shiftList>
          <employeerostering.employeerostering.Shift>
            <timeslot>
              <startTime>2017-01-01T00:00:00</startTime>
              <endTime>2017-01-01T01:00:00</endTime>
            </timeslot>
            <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
          </employeerostering.employeerostering.Shift>
          <employeerostering.employeerostering.Shift>
            <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
            <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
          </employeerostering.employeerostering.Shift>
          <employeerostering.employeerostering.Shift>
            <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
            <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
          </employeerostering.employeerostering.Shift>
        </shiftList>
        <skillList>
          <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
          <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
          <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
        </skillList>
        <timeslotList>
          <employeerostering.employeerostering.Timeslot reference="../../shiftList/employeerostering.employeerostering.Shift/timeslot"/>
        </timeslotList>
        <dayOffRequestList/>
        <shiftAssignmentList/>
        <score>0hard/0soft</score>
      </best-solution>
    </solver-instance>
    Copy to Clipboard Toggle word wrap

第 34 章 OptaPlanner 和 Quarkus 入门

您可以使用 https://code.quarkus.redhat.com 网站生成红帽构建的 OptaPlanner Quarkus Maven 项目,并自动配置要在应用程序中使用的扩展。然后您可以下载 Quarkus Maven 存储库,或将在线 Maven 存储库用于您的项目。

34.1. Apache Maven 和红帽构建的 Quarkus

Apache Maven 是 Java 应用程序开发中使用的分布式构建自动化工具,用于创建、管理和构建软件项目。Maven 使用名为 Project Object Model(POM)文件的标准配置文件来定义项目并管理构建流程。POM 文件描述了使用 XML 文件生成的项目打包和输出的模块和组件依赖项、构建顺序和目标。这可确保以正确、一致的方式构建项目。

Maven 存储库

Maven 存储库存储 Java 库、插件和其他构建构件。默认公共存储库是 Maven 2 Central Repository,但存储库可以是私有的,也可以是公司内部的存储库,以在开发团队之间共享通用的工件。也可从第三方获得存储库。

您可以将在线 Maven 存储库与 Quarkus 项目一起使用,也可以下载红帽构建的 Quarkus Maven 存储库。

Maven 插件

Maven 插件是 POM 文件的定义部分,可实现一个或多个目标。Quarkus 应用程序使用以下 Maven 插件:

  • Quarkus Maven 插件(quarkus-maven-plugin):启用 Maven 创建 Quarkus 项目,支持 uber-JAR 文件的生成,并提供开发模式。
  • Maven Surefire 插件(maven-surefire-plugin):在构建生命周期的测试阶段使用,用于在您的应用程序上执行单元测试。插件生成包含测试报告的文本和 XML 文件。

34.1.1. 为在线存储库配置 Maven settings.xml 文件

您可以通过配置用户 settings.xml 文件,在 Maven 项目中使用在线 Maven 存储库。这是推荐的方法。与共享服务器上的存储库管理器或存储库一起使用的 Maven 设置提供更好的项目控制和管理。

注意

当您修改 Maven settings.xml 文件来配置存储库时,更改适用于所有 Maven 项目。

流程

  1. 在文本编辑器或集成开发环境(IDE)中打开 Maven ~/.m2/settings.xml 文件。

    注意

    如果 ~/.m2/ 目录中没有 settings.xml 文件,请将 $MAVEN_HOME/.m2/conf/ 目录中的 settings.xml 文件复制到 ~/.m2/ 目录中。

  2. settings.xml 文件的 <profiles > 元素中添加以下行:

    <!-- Configure the Maven repository -->
    <profile>
      <id>red-hat-enterprise-maven-repository</id>
      <repositories>
        <repository>
          <id>red-hat-enterprise-maven-repository</id>
          <url>https://maven.repository.redhat.com/ga/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>red-hat-enterprise-maven-repository</id>
          <url>https://maven.repository.redhat.com/ga/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    Copy to Clipboard Toggle word wrap
  3. settings.xml 文件的 <activeProfiles > 元素中添加以下行,并保存文件。

    <activeProfile>red-hat-enterprise-maven-repository</activeProfile>
    Copy to Clipboard Toggle word wrap

34.1.2. 下载并配置 Quarkus Maven 存储库

如果您不想使用在线 Maven 存储库,您可以下载并配置 Quarkus Maven 存储库,以使用 Maven 创建 Quarkus 应用。Quarkus Maven 存储库包含 Java 开发人员通常用来构建应用程序的许多要求。此流程描述了如何编辑 settings.xml 文件来配置 Quarkus Maven 存储库。

注意

当您修改 Maven settings.xml 文件来配置存储库时,更改适用于所有 Maven 项目。

流程

  1. 从红帽客户门户的软件 下载页面 (需要登录)下载 Quarkus Maven 存储库 ZIP 文件。
  2. 展开下载的存档。
  3. 将目录更改到 ~/.m2/ 目录,并在文本编辑器或集成开发环境(IDE)中打开 Maven settings.xml 文件。
  4. 将以下行添加到 settings.xml 文件的 & lt;profiles > 元素中,其中 QUARKUS_MAVEN_REPOSITORY 是您下载的 Quarkus Maven 存储库的路径。QUARKUS_MAVEN_REPOSITORY 的格式必须是 file://$PATH,例如 file:///home/userX/rh-quarkus-2.2.3.GA-maven-repository/maven-repository

    <!-- Configure the Quarkus Maven repository -->
    <profile>
      <id>red-hat-enterprise-maven-repository</id>
      <repositories>
        <repository>
          <id>red-hat-enterprise-maven-repository</id>
          <url>QUARKUS_MAVEN_REPOSITORY</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>red-hat-enterprise-maven-repository</id>
          <url>QUARKUS_MAVEN_REPOSITORY</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    Copy to Clipboard Toggle word wrap
  5. settings.xml 文件的 <activeProfiles > 元素中添加以下行,并保存文件。

    <activeProfile>red-hat-enterprise-maven-repository</activeProfile>
    Copy to Clipboard Toggle word wrap
重要

如果您的 Maven 存储库包含过时的工件,则构建或部署项目时可能会遇到以下 Maven 错误消息之一,其中 ARTIFACT_NAME 是缺少的工件的名称,PROJECT_NAME 是您要构建的项目的名称:

  • 缺少工件 PROJECT_NAME
  • [ERROR] Failed to execute goal on project ARTIFACT_NAME; Could not resolve dependencies for PROJECT_NAME

要解决这个问题,请删除位于 ~/.m2/repository 目录中的本地存储库的缓存版本,以强制下载最新的 Maven 工件。

您可以使用 Apache Maven 和 Quarkus Maven 插件,通过红帽构建的 OptaPlanner 和 Quarkus 应用程序来获取和运行。

先决条件

  • OpenJDK 11 或更高版本已安装。红帽构建的 Open JDK 可从红帽客户门户中的 Software Downloads 页面获得(需要登录)。
  • 已安装 Apache Maven 3.6 或更高版本。Maven 可从 Apache Maven Project 网站获取。

流程

  1. 在命令终端中,输入以下命令来验证 Maven 是否使用 JDK 11,并且 Maven 版本是否为 3.6 或更高版本:

    mvn --version
    Copy to Clipboard Toggle word wrap
  2. 如果前面的命令没有返回 JDK 11,请将到 JDK 11 的路径添加到 PATH 环境变量中,然后再次输入前面的命令。
  3. 要生成 Quarkus OptaPlanner quickstart 项目,请输入以下命令:

    mvn com.redhat.quarkus.platform:quarkus-maven-plugin:2.2.3.Final-redhat-00013:create \
        -DprojectGroupId=com.example \
        -DprojectArtifactId=optaplanner-quickstart  \
        -Dextensions="resteasy,resteasy-jackson,optaplanner-quarkus,optaplanner-quarkus-jackson" \
        -DplatformGroupId=com.redhat.quarkus.platform
        -DplatformVersion=2.2.3.Final-redhat-00013 \
        -DnoExamples
    Copy to Clipboard Toggle word wrap

    这个命令在 ./optaplanner-quickstart 目录中创建以下元素:

    • Maven 结构
    • src/main/docker中的 Dockerfile 文件示例
    • 应用程序配置文件

      Expand
      表 34.1. mvn io.quarkus:quarkus-maven-plugin:2.2.3.Final-redhat-00013:create 命令中使用的属性
      属性描述

      projectGroupId

      项目的组 ID。

      projectArtifactId

      项目的工件 ID。

      extensions

      以逗号分隔的 Quarkus 扩展列表,用于此项目。如需 Quarkus 扩展的完整列表,请在命令行中输入 mvn quarkus:list-extensions

      noExamples

      创建一个具有项目结构的项目,但没有测试或类。

      projectGroupIDprojectArtifactID 属性的值用于生成项目版本。默认项目版本为 1.0.0-SNAPSHOT

  4. 要查看您的 OptaPlanner 项目,将目录改为 OptaPlanner Quickstarts 目录:

    cd optaplanner-quickstart
    Copy to Clipboard Toggle word wrap
  5. 检查 pom.xml 文件。内容应类似以下示例:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>io.quarkus.platform</groupId>
          <artifactId>quarkus-bom</artifactId>
          <version>2.2.3.Final-redhat-00013</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
        <dependency>
          <groupId>io.quarkus.platform</groupId>
          <artifactId>quarkus-optaplanner-bom</artifactId>
          <version>2.2.3.Final-redhat-00013</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy</artifactId>
      </dependency>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy-jackson</artifactId>
      </dependency>
      <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-quarkus</artifactId>
      </dependency>
      <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-quarkus-jackson</artifactId>
      </dependency>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-junit5</artifactId>
        <scope>test</scope>
      </dependency>
    </dependencies>
    Copy to Clipboard Toggle word wrap

您可以使用 code.quarkus.redhat.com 网站来生成红帽构建的 OptaPlanner Quarkus Maven 项目,并自动添加并配置要在应用程序中使用的扩展。此外,code.quarkus.redhat.com 会自动管理将项目编译到原生可执行文件所需的配置参数。

本节介绍了生成 OptaPlanner Maven 项目的过程,并包括以下主题:

  • 指定应用程序的基本详情。
  • 选择您要包含在项目中的扩展。
  • 使用您的项目文件生成可下载的存档。
  • 使用自定义命令编译并启动您的应用程序。

先决条件

  • 您有一个 Web 浏览器。

流程

  1. 在您的浏览器中打开 https://code.quarkus.redhat.com
  2. 指定项目详情:
  3. 输入项目的组名称。名称格式遵循 Java 软件包命名约定,例如 com.example
  4. 输入您要用于项目生成的 Maven 工件的名称,如 code-with-quarkus
  5. 选择 Build Tool > Maven 以指定您要创建 Maven 项目。您选择的构建工具决定了项目:

    • 生成项目的目录结构
    • 生成项目中使用的配置文件的格式
    • 在生成项目后,自定义构建脚本和命令用于编译并启动 code.quarkus.redhat.com 的应用程序

      注意

      红帽提供了对使用 code.quarkus.redhat.com 的支持,来仅创建 OptaPlanner Maven 项目。红帽不支持生成 Gradle 项目。

  6. 输入要在项目生成的工件中使用的版本。此字段的默认值为 1.0.0-SNAPSHOT。建议使用 语义版本,但如果愿意,您可以使用不同类型的版本。
  7. 输入构建工具在软件包项目时生成的工件的软件包名称。

    根据 Java 软件包命名约定,软件包名称应与项目的组名称匹配,但您可以指定不同的名称。

    注意

    code.quarkus.redhat.com 网站自动使用 OptaPlanner 的最新版本。在生成项目后,您可以手动更改 pom.xml 文件中的 BOM 版本。

  8. 选择以下扩展以包含在依赖项中:

    • RESTEasy JAX-RS (quarkus-resteasy)
    • RESTEasy Jackson (quarkus-resteasy-jackson)
    • OptaPlanner AI constraint solver(optaplanner-quarkus)
    • OptaPlanner Jackson (optaplanner-quarkus-jackson)

      红帽为列表上的单个扩展提供不同级别的支持,这些扩展由每个扩展名称旁的标签表示:

      • 红帽完全支持 SUPPORTED 扩展,以便在生产环境中的企业应用程序中使用。
      • 在" 技术预览 "扩展方面,红帽在 功能支持范围下,受红帽的支持限制
      • 红帽不支持 DEV-SUPPORT 扩展以供红帽在生产环境中使用,但红帽开发人员为开发新应用程序提供支持的核心功能。
      • DEPRECATED 扩展计划被替换为提供相同功能的较新技术或实施。

        红帽不支持未标记的扩展以用于生产环境。

  9. 选择 Generate your application 来确认您的选择,并使用包含您生成的项目的存档的下载链接显示覆盖屏幕。覆盖屏幕还显示可用于编译和启动应用程序的自定义命令。
  10. 选择 Download the ZIP 将存档与生成的项目文件保存到您的系统中。
  11. 提取存档的内容。
  12. 进入包含您提取的项目文件的目录:

    cd <directory_name>
    Copy to Clipboard Toggle word wrap
  13. 以开发模式编译并启动应用程序:

    ./mvnw compile quarkus:dev
    Copy to Clipboard Toggle word wrap

您可以使用 Quarkus 命令行界面(CLI)创建一个 Quarkus OptaPlanner 项目。

先决条件

流程

  1. 创建 Quarkus 应用程序:

    quarkus create app -P io.quarkus:quarkus-bom:2.2.3.Final-redhat-00013
    Copy to Clipboard Toggle word wrap
  2. 要查看可用的扩展,请输入以下命令:

    quarkus ext -i
    Copy to Clipboard Toggle word wrap

    这个命令返回以下扩展:

    optaplanner-quarkus
    optaplanner-quarkus-benchmark
    optaplanner-quarkus-jackson
    optaplanner-quarkus-jsonb
    Copy to Clipboard Toggle word wrap
  3. 输入以下命令在项目的 pom.xml 文件中添加扩展:

    quarkus ext add resteasy-jackson
    quarkus ext add optaplanner-quarkus
    quarkus ext add optaplanner-quarkus-jackson
    Copy to Clipboard Toggle word wrap
  4. 在文本编辑器中打开 pom.xml 文件。文件的内容应类似以下示例:

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.acme</groupId>
      <artifactId>code-with-quarkus-optaplanner</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <properties>
    	<compiler-plugin.version>3.8.1</compiler-plugin.version>
    	<maven.compiler.parameters>true</maven.compiler.parameters>
    	<maven.compiler.source>11</maven.compiler.source>
    	<maven.compiler.target>11</maven.compiler.target>
    	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    	<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    	<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    	<quarkus.platform.version>2.2.3.Final-redhat-00013</quarkus.platform.version>
    	<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
      </properties>
      <dependencyManagement>
    	<dependencies>
      	<dependency>
        	<groupId>${quarkus.platform.group-id}</groupId>
        	<artifactId>${quarkus.platform.artifact-id}</artifactId>
        	<version>${quarkus.platform.version}</version>
        	<type>pom</type>
        	<scope>import</scope>
      	</dependency>
      	<dependency>
        	<groupId>io.quarkus.platform</groupId>
        	<artifactId>optaplanner-quarkus</artifactId>
        	<version>2.2.2.Final</version>
        	<type>pom</type>
        	<scope>import</scope>
      	</dependency>
    	</dependencies>
      </dependencyManagement>
      <dependencies>
    	<dependency>
      	<groupId>io.quarkus</groupId>
      	<artifactId>quarkus-arc</artifactId>
    	</dependency>
    	<dependency>
      	<groupId>io.quarkus</groupId>
      	<artifactId>quarkus-resteasy</artifactId>
    	</dependency>
    	<dependency>
      	<groupId>org.optaplanner</groupId>
      	<artifactId>optaplanner-quarkus</artifactId>
    	</dependency>
    	<dependency>
      	<groupId>org.optaplanner</groupId>
      	<artifactId>optaplanner-quarkus-jackson</artifactId>
    	</dependency>
    	<dependency>
      	<groupId>io.quarkus</groupId>
      	<artifactId>quarkus-resteasy-jackson</artifactId>
    	</dependency>
    	<dependency>
      	<groupId>io.quarkus</groupId>
      	<artifactId>quarkus-junit5</artifactId>
      	<scope>test</scope>
    	</dependency>
    	<dependency>
      	<groupId>io.rest-assured</groupId>
      	<artifactId>rest-assured</artifactId>
      	<scope>test</scope>
    	</dependency>
      </dependencies>
      <build>
    	<plugins>
      	<plugin>
        	<groupId>${quarkus.platform.group-id}</groupId>
        	<artifactId>quarkus-maven-plugin</artifactId>
        	<version>${quarkus.platform.version}</version>
        	<extensions>true</extensions>
        	<executions>
          	<execution>
            	<goals>
              	<goal>build</goal>
              	<goal>generate-code</goal>
              	<goal>generate-code-tests</goal>
            	</goals>
          	</execution>
        	</executions>
      	</plugin>
      	<plugin>
        	<artifactId>maven-compiler-plugin</artifactId>
        	<version>${compiler-plugin.version}</version>
        	<configuration>
          	<parameters>${maven.compiler.parameters}</parameters>
        	</configuration>
      	</plugin>
      	<plugin>
        	<artifactId>maven-surefire-plugin</artifactId>
        	<version>${surefire-plugin.version}</version>
        	<configuration>
          	<systemPropertyVariables>
            	<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            	<maven.home>${maven.home}</maven.home>
          	</systemPropertyVariables>
        	</configuration>
      	</plugin>
    	</plugins>
      </build>
      <profiles>
    	<profile>
      	<id>native</id>
      	<activation>
        	<property>
          	<name>native</name>
        	</property>
      	</activation>
      	<build>
        	<plugins>
          	<plugin>
            	<artifactId>maven-failsafe-plugin</artifactId>
            	<version>${surefire-plugin.version}</version>
            	<executions>
              	<execution>
                	<goals>
                  	<goal>integration-test</goal>
                  	<goal>verify</goal>
                	</goals>
                	<configuration>
                  	<systemPropertyVariables>
                    	<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    	<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    	<maven.home>${maven.home}</maven.home>
                  	</systemPropertyVariables>
                	</configuration>
              	</execution>
            	</executions>
          	</plugin>
        	</plugins>
      	</build>
      	<properties>
        	<quarkus.package.type>native</quarkus.package.type>
      	</properties>
    	</profile>
      </profiles>
    </project>
    Copy to Clipboard Toggle word wrap

附录 A. 版本控制信息

文档最新更新于 2023 年 2 月 1 日(周三)。

附录 B. 联系信息

Red Hat Process Automation Manager 文档团队: brms-docs@redhat.com

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部