[gecode-users] Simple example (x<2)

Christian Schulte schulte at imit.kth.se
Wed Apr 19 21:28:34 CEST 2006


In principle yes, the only main difference is that you also have to have a
constructor and a virtual member function that takes care of copying the
variables you have created. Again, much of the structure will become clear
if you look to the examples that come with Gecode!

But also, maybe Grégoire can chip in his two cents how to best deal with
variables to be created on the fly.

Christian

--
Christian Schulte, http://web.imit.kth.se/~schulte/




-----Original Message-----
From: Giuseppe Di Guglielmo [mailto:diguglielmo at sci.univr.it] 
Sent: Wednesday, April 19, 2006 6:01 PM
To: schulte at imit.kth.se; users at gecode.org
Subject: R: [gecode-users] Simple example (x<2)


> 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