5

I am trying to implement some AI planning algorithms in C, but got stuck with the basic concept :)
Before jumping to the main problem, I tried implementing some small framework that would support propositional logic:

FORMULA f = PROPOSITION(a + 3 > 0);
FORMULA g = PROPOSITION(is_smaller_than(b, c));
f = AND(NOT(f), g);

Now, the problem is that I would like not to evaluate the expressions like 'a + 3 > 0' at the moment of defining the formula, but in some later phase:

bool res = EVALUATE(f);

I guess closures would have been handy in this case, but unfortunately I also like to stick to C99.

Any idea ?
How about extending this to predicate logic ?

The final goal (ideally) would be to build an AI planning library, which can be directly plugged-in to the application, and not to receive the problem as STRIPS program strings.

Thanks

pmilosev
  • 932
  • 8
  • 20
  • Hmmm, I guess I would need to make some restrictions. My next try would be to actually represent the propositions as a structure holding the data and some method pointer(s). In this case the complete context required for evaluating the proposition would be handled with this structure. – pmilosev Sep 06 '11 at 20:40
  • That is generally the way to go at it. Keep in your structure both the data you need to work on, and the operations you need to do on that data, and `EVALUATE` will look at those and act accordingly. – Eran Zimmerman Gonen Sep 27 '11 at 14:26

1 Answers1

1

OK,

As commented above I have solved the issue by using a structure with method pointer and data in it. This is the most common way of simulating closures in C.

My implementation is available here: https://github.com/pmilosev/clumsy

pmilosev
  • 932
  • 8
  • 20