Drools 创建自定义乐谱

发布于 2024-11-19 05:55:33 字数 298 浏览 10 评论 0原文

所以我在 drools: 中创建了一个自定义分数

public interface MyScore extends Score<MyScore>

并实现了它。但是我不知道如何使用分数。该配置有一个

<scoreDefinition>

标签,但将除 SIMPLE 或 HARD_AND_SOFT 之外的任何内容放入其中都会产生错误。

如何配置求解器以使用我创建的分数,文档似乎暗示这是可能的,但没有详细说明。

So I've created a custom score in drools:

public interface MyScore extends Score<MyScore>

and have implemented it. However I can't see how to use the score. The config has a

<scoreDefinition>

tag but putting anything inside this other than SIMPLE or HARD_AND_SOFT produces an error.

How can I configure the solver to use the score I've created, the docs seem to imply this is possible but doesn't go into any detail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶舞 2024-11-26 05:55:33

这原本是可能的(也是一种正常的做法),但存在一个障碍。

我刚刚添加了此文档:

实现自定义分数

要实现自定义分数,您还需要实现自定义 ScoreDefinition。扩展 AbstractScoreDefinition(最好通过复制粘贴 HardAndSoftScoreDefinition 或 SimpleScoreDefinition)并从那里开始。

接下来,在 SolverConfig.xml 中挂钩自定义 ScoreDefinition:

<scoreDefinition>
    <scoreDefinitionClass>org.drools.planner.examples.my.score.definition.MyScoreDefinition</scoreDefinitionClass>
</scoreDefinition>

障碍

我将针对 5.3 或 5.4 修复一个障碍:

ScoreDefinitionConfig 有以下代码:

/**
 * @TODO score-in-solution refactor
 */
public ScoreCalculator buildScoreCalculator() {
    if (scoreDefinitionType != null) {
        switch (scoreDefinitionType) {
            case SIMPLE:
                return new SimpleScoreCalculator();
            case SIMPLE_DOUBLE:
                return new SimpleDoubleScoreCalculator();
            case HARD_AND_SOFT:
                return new DefaultHardAndSoftConstraintScoreCalculator();
            default:
                throw new IllegalStateException("The scoreDefinitionType (" + scoreDefinitionType
                        + ") is not implemented");
        }
    } else {
        return new SimpleScoreCalculator();
    }
}

解决该问题的一种方法是扩展 ScoreDefinitionConfig 并覆盖该方法,如手册中使用自定义选择器、接受器或觅食器部分中所述。

This was meant to be possible (and a normal practice), but there's a roadblock.

I just added this documentation:

Implementing a custom Score

To implement a custom Score, you 'll also need to implement a custom ScoreDefinition. Extend AbstractScoreDefinition (preferable by copy pasting HardAndSoftScoreDefinition or SimpleScoreDefinition) and start from there.

Next, hook you custom ScoreDefinition in your SolverConfig.xml:

<scoreDefinition>
    <scoreDefinitionClass>org.drools.planner.examples.my.score.definition.MyScoreDefinition</scoreDefinitionClass>
</scoreDefinition>

The Roadblock

There's a roadblock that I 'll fix for 5.3 or 5.4:

ScoreDefinitionConfig has this code:

/**
 * @TODO score-in-solution refactor
 */
public ScoreCalculator buildScoreCalculator() {
    if (scoreDefinitionType != null) {
        switch (scoreDefinitionType) {
            case SIMPLE:
                return new SimpleScoreCalculator();
            case SIMPLE_DOUBLE:
                return new SimpleDoubleScoreCalculator();
            case HARD_AND_SOFT:
                return new DefaultHardAndSoftConstraintScoreCalculator();
            default:
                throw new IllegalStateException("The scoreDefinitionType (" + scoreDefinitionType
                        + ") is not implemented");
        }
    } else {
        return new SimpleScoreCalculator();
    }
}

One way to deal with that is to extend ScoreDefinitionConfig and overwrite that method, as described in the manual in the section using a custom Selector, Acceptor or Forager.

野生奥特曼 2024-11-26 05:55:33

据我所知,可能不支持自定义分数,这很遗憾......
我检查了 ScoreDefinitionConfig 类,我看到了这个:

                   switch (scoreDefinitionType) {
                case SIMPLE:
                    return new SimpleScoreDefinition();
                case HARD_AND_SOFT:
                    return new HardAndSoftScoreDefinition();
                default:
                    throw new IllegalStateException("scoreDefinitionType ("
                            + scoreDefinitionType + ") not implemented");

那么,除了 SIMPLE 和 HARD_AND_SOFT 之外的任何东西都不能削减它......

对此有什么见解吗?

克罗恩,
路易斯

For what I could see, there could be no support for custom scores, which is a shame...
I checked the ScoreDefinitionConfig class and I saw this:

                   switch (scoreDefinitionType) {
                case SIMPLE:
                    return new SimpleScoreDefinition();
                case HARD_AND_SOFT:
                    return new HardAndSoftScoreDefinition();
                default:
                    throw new IllegalStateException("scoreDefinitionType ("
                            + scoreDefinitionType + ") not implemented");

So, anything other than SIMPLE and HARD_AND_SOFT doesn't cut it...

Any insights on this?

KR,
Luis

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文