c++ - CLIPS 和与 C++ 的集成

标签 c++ rule-engine clips

我正在开发一个相当复杂的规则引擎。所以我决定借助任何 GNU 规则引擎并将其与我的应用程序集成。我遇到了CLIPS作为一个好的规则引擎。

现在,我的应用程序是用 C++ 编写的,我想要一个示例方法(一种 Hello world 类程序),从中我可以学习如何将 .clp 规则引擎集成到我的 C++ 应用程序中。

问题

  1. 我的应用程序是在 Linux/AIX/HP 和 Mingw(适用于 Windows)上开发的。我们能否在 CLIPS 中开发规则引擎并将其集成到所有这些平台上的 C++ 应用程序中?您能否分享有关如何集成的链接。
  2. 使用规则引擎的根本原因是,我体验到在我的 C/C++ 应用程序中“构建”的规则会占用大量内存/CPU。我的印象是,通过使用规则引擎,我可以以更优化(更好的资源利用)的方式实现相同的目的。 CLIPS 可以帮助我实现这一目标吗?

更新 1:

  • 您正在开发哪种应用程序?
    总而言之,我正在开发一个基于过滤器匹配的计数器。用户可以增加(NetworkID=XYZ,增量计数 = 7),(NetworkID = MNO,增量计数=934)...等。现在您得到一个 NetworkID=X* 的查询,然后我需要提供来自 XAA 的所有计数。 ..XZZ。它在跨不同节点(分布式环境)的多进程、多线程中更新。

  • 为什么里面会有专家系统规则,是什么规则?
    现在,我的平台/应用程序在 C++ 中(用户在其中进行递增/递减/查询)。现在我想使用规则引擎来帮助我完成这些工作。用 C/C++ 代码编写逻辑似乎会杀死更多需要的资源。

PS:自增/自减/查询相关的关键代码均在优化后的c代码中。一些包装器在 C++ 代码中。所以我正在检查规则引擎来为我做这件事,它可以从我的平台/应用程序(在 C/C++ 代码中)调用。

最佳答案

将 CLIPS 与 C++ 集成的最简单方法是使用编译器选项(如果可用)将 C 代码编译为 C++ 代码。来自高级编程指南 (http://clipsrules.sourceforge.net/documentation/v624/apg.htm) 的第 1.2 节,C++ 兼容性:

The CLIPS source code can now be compiled using either an ANSI C or C++ compiler. Minimally, non-ANSI C compilers must support full ANSI style function prototypes and the void data type in order to compile CLIPS. If you want to make CLIPS API calls from a C++ program, it is usually easier to do the integration by compiling the CLIPS source files as C++ files. This removes the need to make an extern "C" declaration in your C++ program for the CLIPS APIs. Some programming environments allow you to specify the whether a file should be compiled as C or C++ code based on the file extension. Other environments allow you to explicitly specify which compiler to use regardless of the extension (e.g. in gcc the option “-x c++” will compile .c files as C++ files). In some environments, the same compiler is used to compile both C and C++ programs and the compiler uses the file extension to determine whether the file should be compiled as a C or C++ program. In this situation, changing the .c extension of the CLIPS source files to .cpp usually allows the source to be compiled as a C++ program.

您可以选择尝试使用类似 clipsmm ( http://sourceforge.net/projects/clipsmm/ ) 的东西,它是 CLIPS 库的 C++ 接口(interface)。

关于c++ - CLIPS 和与 C++ 的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667628/

相关文章:

CLIPS 从文件加载和运行程序

java - 有没有办法使不同语言的这两个值保持一致?

c++ - header 包含的嵌套深度是否有限制?

c++ - Boost::Asio - 读还是读到?

java - 在推断模型上使用 Jena 规则文件为本体创建 validator

Prolog/ASP(Clingo) 到 CLIPS 翻译器

c++ - 指向特征数据 `std::list` 的指针

java - 为什么我们不能用 Java 文件而不是 .drl 文件来编写业务规则?

scala - Apache Flink:使用keyBy/connect维护流中的消息输入顺序

python - 如何使用 Clipspy 撤回事实