[gecode-users] Simple example (x<2)
Christian Schulte
schulte at imit.kth.se
Wed Apr 19 16:11:20 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.
Christian
--
Christian Schulte, http://www.imit.kth.se/~schulte/
-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Giuseppe Di Guglielmo
Sent: Wednesday, April 19, 2006 3:13 PM
To: users at gecode.org
Subject: [gecode-users] Simple example (x<2)
Hi, I'm searching for a small example to solving this constraint
(X<10) with X in [0..100]
Can you help me, I'll use it as starting point.
Thanks
--
--------------------------------------------------------------------------
Giuseppe Di Guglielmo
Department of Computer Science - University of Verona
Strada le Grazie, 15 - 37134 Verona - Italy
email: diguglielmo at sci.univr.it
tel: +39 045 8027049
fax: +39 045 8027068
--------------------------------------------------------------------------
_______________________________________________
Gecode users mailing list
users at gecode.org https://www.gecode.org/mailman/listinfo/gecode-users
-------------- next part --------------
/*
* Main authors:
* Christian Schulte <schulte at gecode.org>
*
* Copyright:
* Christian Schulte, 2001
*
*/
#include <iostream>
#include "gecode/int.hh"
#include "gecode/search.hh"
using namespace Gecode;
/// Define class to host problem
class Simple : public Space {
protected:
/// Single variable x
IntVar x;
public:
/// Actual model
Simple(void) : x(this,0,100) {
rel(this, x, IRT_LE, 10);
}
/// Constructor for cloning \a s
Simple(bool share, Simple& s) : Space(share,s) {
x.update(this, share, s.x);
}
/// Copy during cloning
virtual Space*
copy(bool share) {
return new Simple(share,*this);
}
/// Print solution
virtual void
print(void) {
std::cout << "x = " << x << std::endl;
}
};
/** \brief Main-function
* \relates Simple
*/
int
main(int, char**) {
/// Create space for simple
Simple* s = new Simple;
/// Create depth-first search engine
DFS<Simple> e(s);
/// Iterate over all solutions
while (Simple* sol = e.next()) {
sol->print(); delete sol;
}
delete s;
return 0;
}
More information about the gecode-users
mailing list