5

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. I came across CLIPS as a good rules engine.

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.

Question

  1. My application is developed on Linux/AIX/HP and Mingw (for windows). Can we develop rules engine in CLIPS and get it integrated to C++ application on all these platforms? 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. 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?

Update 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. 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). 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.

PS: The critical code related to increment/decrement/query are all in optimized c code. Some wrappers are in C++ code. So I am checking for rules engine to do it for me which can be invoked from my platform/application (in C/C++ code).

kumar_m_kiran
  • 3,982
  • 4
  • 47
  • 72

1 Answers1

3

The easiest way to integrate CLIPS with C++ is to use the compiler option (if available) to compile the C code as C++ code. From Section 1.2, C++ Compatibility, of the Advanced Programming Guide (http://clipsrules.sourceforge.net/documentation/v624/apg.htm):

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.

Optionally you can try using something like clipsmm (http://sourceforge.net/projects/clipsmm/) which is a C++ interface to the CLIPS library.

Gary Riley
  • 10,130
  • 2
  • 19
  • 34