R: [gecode-users] Simple example (x<2)
Giuseppe Di Guglielmo
diguglielmo at sci.univr.it
Wed Apr 19 18:00:30 CEST 2006
> Please find attached a basic example that does what you want.
> However, I would like to mention that Gecode is not really a
> system meant for learning constraint programming as all of
> its documentation already assumes a thorough knowledge of
> connstraint programming.
Ok, I'm using ECLiPSe C++ API, but due some its bugs I need to change CLP
enviroment.
Other question:
can I procede in this way with Gecode:
1. declaring some variable
2. post one or more constraints
3. retrieve the results
as in the following ECLiPSe example?
Can you post a Gecode equivalent slice of code?
#include <iostream>
#include <eclipseclass.h>
//[...]
int main(int argc, char* argv[]) {
//[...]
// configuring some ECLiPSe variables
char* ECLIPSE_HOME = getenv("ECLIPSE_HOME");
ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, (void *)ECLIPSE_HOME);
ec_set_option_int(EC_OPTION_LOCALSIZE, 128*1024*1024);
ec_set_option_int(EC_OPTION_GLOBALSIZE, 128*1024*1024);
ec_init();
EC_atom fail = EC_atom("fail");
EC_atom random = EC_atom("random");
post_goal("lib(ic)");
EC_ref Search;
// [1.]
////////////////////////////////////////////////////////////////////////
// declare a variable (ECLiPSe type)
EC_ref X_e;
long X;
// setting variable range
post_goal(set_bounds(X_e, 0, 100));
post_goal(term(EC_functor("indomain",2), X_e, random));
////////////////////////////////////////////////////////////////////////////
////
// [2.]
////////////////////////////////////////////////////////////////////////
// posting constraints
// x < 50
post_goal(less_e(X_e,50));
// x >= 30
post_goal(geq_e(X_e,30));
////////////////////////////////////////////////////////////////////////////
///
// [3.]
////////////////////////////////////////////////////////////////////////
// retrieve the results
while (EC_succeed == EC_resume(Search)) {
if ((EC_word(X_e).is_long(&X) == EC_succeed)) {
cout << "X : " << X << endl;
} else {
cout << "ERROR" << endl;
return 1;
}
Search.cut_to();
post_goal(fail);
}
ec_cleanup();
return 0;
}
[...]
More information about the gecode-users
mailing list