optaplanner:如何强制执行计划变量值仅可使用一次 [英] optaplanner: how to enforce planning variables values to be used only once

查看:99
本文介绍了optaplanner:如何强制执行计划变量值仅可使用一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习optaplanner.作为一个学习项目,我正在尝试实现一个非常基本且简单的程序,该程序可以计算"魔方 ".

I am trying to learn optaplanner. And as a learning project I am trying to implement a very basic and simple program which calculates "magic squares".

基本上,我试图将数字"分配给在行和列中定义的框".

Basically I am trying to assign "Number"s to the "Box"es defined in rows and columns.

很抱歉不能直接从源代码复制/粘贴,我的开发机器无法连接到Internet,所以我将尝试手工写下类的重要部分.

Sorry for not copy/pasting directly from source code, my development machine can not connect to internet so I will try to write down important part of classes by hand.

我的域结构如下:

@PlanningSolution MagicSquareSolution

@PlanningSolution MagicSquareSolution

//facts
List<Column> columnList
List<Row> rowList
List<Number> numberList

//entity
List<Box> boxList


@valueRangeProvider (id="numberRange")
getNumberList()

@PlanningEntityCollectionProperty
getBoxList


@PlanningEntity 盒子

@PlanningEntity Box

Column column
Row row
Number number // planningVariable

@PlanningVariable(valueRangeProviderRefs="{numberRange}")
getNumber

我正在使用SIMPLE Java分数计算器类.

I am using a SIMPLE Java score calculator class.

在我的求解器配置xml中,我使用了FIRST_FIT和FIRST_NON_DETERIRATING_SCORE.

In my solver configuration xml I used FIRST_FIT and FIRST_NON_DETERIRATING_SCORE.

问题是;在我得到的解决方案中,数字被重复使用

The problem is; in the solution I got, numbers are reused like

7 5 3
1 5 9
7 5 3

在这里您可以看到行和列的总和等于15; 数字7,5和3多次使用. 如何强制计划变量的值范围内的所有值至少使用一次,并且只能使用一次.

Here you can see although the sum of rows and columns are equal to 15; Numbers 7,5 and 3 are used multiple times. How can I enforce the all the values in the value range for the planning variable is used at least once and only once.

谢谢.

Akif,

推荐答案

添加分数约束:

when
     Box($n : number, $id : id)
     Box(number == $n, $id > id)
then
     // -1 hard

这篇关于optaplanner:如何强制执行计划变量值仅可使用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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