【发布时间】:2011-08-03 00:03:02
【问题描述】:
我有一个班级作业是使用 Drools 作为推理机来创建一个机器人。但是,我的大多数规则都表现得很奇怪,因为它们不是为类而触发,而是为它的超类而触发。像这样的:
我的规则:
import the.manifested.Robotonikku;
import the.manifested.Strategy;
import the.manifested.Action;
import robocode.TeamRobot;
rule "One"
when
Robotonikku();
then
System.out.println("roboto is present");
end
rule "Two"
when
not Robotonikku();
then
System.out.println("roboto is not present");
end
rule "Three"
when
TeamRobot();
then
System.out.println("robot is present");
end
rule "Four"
when
not TeamRobot();
then
System.out.println("robot is not present");
end
和预期的一样
public class Robotonikku extends TeamRobot
在 Robocode 的模拟器调用的 Robotonikku 的 run() 方法中,我将实例作为事实插入:
ksession.insert(this)
我希望规则一和三应该触发,但规则二和三被触发。为什么它将实例识别为 TeamRobot 而不是 Robotonikku?
提前致谢。
加载代码:
String ficheroReglas = System.getProperty("robot.reglas", RobotDrools.FICHERO_REGLAS);
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(ficheroReglas, RobotDrools.class), ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.err.println(kbuilder.getErrors().toString());
}
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
ksession = kbase.newStatefulKnowledgeSession();
【问题讨论】:
-
它可能是由同一件事引起的。当我使用 Query 从 Drools 检索某些内容并尝试将其转换为 java 中的正确类时,它给了我(类加载器如何工作?drools 和 robocode 可以使用不同的类加载器吗?):异常:java.lang.ClassCastException:drools_robocode。动作不能转换为 drools_robocode.Action
-
能否请您包含显示您如何创建知识库和会话的代码。因为我使用您描述的基本类和规则一和三按预期触发了您的 DRL。
-
你好 Perception,在某些机器上它可以工作。我们无法找出区别(相同的 drools、jdk、jre 和 robocode 版本号),除了工作的是 32 位和不工作的是 64 位。不确定是不是这样。