简体   繁体   English

CLIPS和与C ++的集成

[英]CLIPS and integration with C++

I am in the process of developing a fairly complex rules engine. 我正在开发一个相当复杂的规则引擎。 So I decided to take help of any GNU rules engine and get it integrated with my application. 因此,我决定寻求任何GNU规则引擎的帮助,并将其与我的应用程序集成。 I came across CLIPS as a good rules engine. 我遇到了CLIPS,这是一个很好的规则引擎。

Now, My application is in C++ and I want a sample way (a Hello world kind of program) from which I can learn how to integrate the .clp rules engine to my C++ application. 现在,我的应用程序是C ++,我想要一个示例方法(Hello world程序),从中我可以学习如何将.clp规则引擎集成到我的C ++应用程序中。

Question

  1. My application is developed on Linux/AIX/HP and Mingw (for windows). 我的应用程序是在Linux / AIX / HP和Mingw(用于Windows)上开发的。 Can we develop rules engine in CLIPS and get it integrated to C++ application on all these platforms? 我们可以在CLIPS中开发规则引擎并将其集成到所有这些平台上的C ++应用程序中吗? Can you please share a link on how to integrate. 您能否分享一个有关如何集成的链接。
  2. The fundamental reason for going into an rules engine is that, I have experienced that rules "built" within my C/C++ application takes huge memory/CPU. 进入规则引擎的根本原因是,我已经体验到在我的C / C ++应用程序中“内置”的规则会占用大量内存/ CPU。 I am under the impression that by using a rules engine, I can achieve the same in a more optimized (better resource utilization) way. 我的印象是,通过使用规则引擎,我可以以更优化(更好地利用资源)的方式实现相同的目标。 Can CLIPS help me achieve that? CLIPS可以帮助我实现这一目标吗?

Update 1: 更新1:

  • What kind of application are you developing? 您正在开发哪种应用程序?
    To put it in a line,I am developing a filter match based counter. 总而言之,我正在开发基于过滤器匹配的计数器。 User may increment (NetworkID=XYZ, Increment count = 7), (NetworkID = MNO, Increment count=934)... etc. Now you get a query for NetworkID=X*, then I need to provide all count from XAA...XZZ. 用户可以增加(NetworkID = XYZ,增加计数= 7),(NetworkID = MNO,增加计数= 934)...等等。现在您获得了NetworkID = X *的查询,那么我需要提供XAA的所有计数。 ..XZZ。 It is updated in multiple process, multiple thread across different node (distributed environment). 它在多进程,跨不同节点(分布式环境)的多线程中更新。

  • Why do you have expert system rules inside, and what kind of rules? 为什么您内部有专家系统规则,以及什么样的规则?
    Now, My platform/application is in C++ (where user does increment/decrement/query). 现在,我的平台/应用程序是C ++(用户在其中进行递增/递减/查询)。 Now I want to use a rules engine to aid me in these. 现在,我想使用规则引擎来帮助我。 Writing the logic in C/C++ code seems to kill more resource that needed. 用C / C ++代码编写逻辑似乎会浪费更多的资源。

PS: The critical code related to increment/decrement/query are all in optimized c code. PS:与增量/减量/查询相关的关键代码全部在优化的c代码中。 Some wrappers are in C++ code. 一些包装器使用C ++代码。 So I am checking for rules engine to do it for me which can be invoked from my platform/application (in C/C++ code). 因此,我正在检查可以为我做的规则引擎,可以从我的平台/应用程序(使用C / C ++代码)中调用它。

The easiest way to integrate CLIPS with C++ is to use the compiler option (if available) to compile the C code as C++ code. 将CLIPS与C ++集成的最简单方法是使用编译器选项(如果有)将C代码编译为C ++代码。 From Section 1.2, C++ Compatibility, of the Advanced Programming Guide ( http://clipsrules.sourceforge.net/documentation/v624/apg.htm ): 从《高级编程指南》( 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. 现在可以使用ANSI C或C ++编译器来编译CLIPS源代码。 Minimally, non-ANSI C compilers must support full ANSI style function prototypes and the void data type in order to compile CLIPS. 至少,非ANSI C编译器必须支持完整的ANSI样式函数原型和void数据类型才能编译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. 如果要从C ++程序进行CLIPS API调用,通常通过将CLIPS源文件编译为C ++文件来进行集成更容易。 This removes the need to make an extern "C" declaration in your C++ program for the CLIPS APIs. 这消除了在C ++程序中为CLIPS API做出外部“ C”声明的需要。 Some programming environments allow you to specify the whether a file should be compiled as C or C++ code based on the file extension. 某些编程环境允许您根据文件扩展名指定是将文件编译为C还是C ++代码。 Other environments allow you to explicitly specify which compiler to use regardless of the extension (eg in gcc the option “-x c++” will compile .c files as C++ files). 其他环境允许您明确指定使用哪个编译器而不管扩展名如何(例如,在gcc中,选项“ -x c ++”会将.c文件编译为C ++文件)。 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. 在某些环境中,使用同一编译器来编译C和C ++程序,并且该编译器使用文件扩展名来确定是将文件编译为C还是C ++程序。 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. 在这种情况下,将CLIPS源文件的.c扩展名更改为.cpp通常可以将源代码编译为C ++程序。

Optionally you can try using something like clipsmm ( http://sourceforge.net/projects/clipsmm/ ) which is a C++ interface to the CLIPS library. (可选)您可以尝试使用clipsmm( http://sourceforge.net/projects/clipsmm/ )之类的东西,它是CLIPS库的C ++接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM