c++ - 无法在剪辑嵌入式应用程序中断言事实

标签 c++ clips expert-system

我试图在嵌入式应用程序中声明 CLIPS 中的一个新事实。 我尝试了两种方法: - 第一个使用断言,如高级编程指南第 74 页中的示例所示。 - 第二种方法是使用 assert-string。 我单独尝试了每种方式,也尝试了两种方式。

我正在使用 RUN_TIME 模块。我的代码输出了正确的结构(defrules 和 deftemplates),但新的事实没有断言。只有初始事实在那里。我不知道为什么!

这是我的代码:

#include "clips.h"

int main()
{
    void *theEnv, *newFact, *templatePtr;
    DATA_OBJECT theValue;

    extern void *InitCImage_1();
    theEnv = InitCImage_1();

    EnvReset(theEnv);

    // One way
    templatePtr = EnvFindDeftemplate(theEnv, "Navigation");
    newFact = EnvCreateFact(theEnv, templatePtr);
    if (newFact == NULL) return -1;

    theValue.type = SYMBOL;
    theValue.value = EnvAddSymbol(theEnv, "Auto");
    EnvPutFactSlot(theEnv, newFact, "FlightStatus", &theValue);

    EnvAssert(theEnv, newFact);

    // The other way
    EnvAssertString(theEnv, "(Navigation (FlightStatus Auto))");

    EnvRun(theEnv,-1);

    EnvListDeftemplates(theEnv, "stdout", NULL);
    EnvListDefrules(theEnv, "stdout", NULL);
    EnvListDeffacts(theEnv, "stdout", NULL);
}

我的代码有什么问题?

最佳答案

使用:

EnvFacts(theEnv,"stdout",NULL,-1,-1,-1);

而不是:

EnvListDeffacts(theEnv, "stdout", NULL);

Defacts 是定义在执行(重置)命令时要断言的事实列表的结构。有一个预定义的 initial-facts defacts 在执行重置时断言 (initial-fact)。这就是您在调用 EnvListDefacts 时看到的列表。您想调用 EnvFacts 来查看实际已断言的事实(无论是在重置后由 deffacts 创建还是直接使用断言)。

关于c++ - 无法在剪辑嵌入式应用程序中断言事实,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219835/

相关文章:

c++ - 我正在编写代码以使用数组将小写字母转换为大写字母

Clips-小程序

machine-learning - 什么机器学习算法适合这种情况

c# - 动态调度系统使用什么算法?

prolog 规则作为参数

c++ - 从 C++ 中的符号、指数和尾数部分创建 NaN 浮点值

c++ - 头文件与源文件中的外部函数

c++ - boost::multi_array reshape() 函数的复杂性

testing - 使用多文件设置设计一个单元测试框架,用于在 CLIPS 中为 CLIPS 规则编写自定义测试