Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Gecode-demo using trace
- //
- #include <iostream>
- #include <gecode/int.hh>
- #include <gecode/minimodel.hh>
- #include <gecode/search.hh>
- using namespace Gecode;
- class DistinctList : public Space {
- protected:
- IntVarArray l;
- public:
- DistinctList(void) : l(*this, 3, 0, 5) {
- distinct(*this, l);
- trace(*this, l);
- branch(*this, l, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
- }
- DistinctList(bool share, DistinctList& s) : Space(share, s) {
- l.update(*this, share, s.l);
- }
- Space* copy(bool share) {
- return new DistinctList(share, *this);
- }
- void print(void) const {
- std::cout << l << std::endl;
- }
- };
- int main(int argc, char* argv[])
- {
- DistinctList* m = new DistinctList;
- std::cout << "The contents of the space before search begins" << std::endl;
- m->print();
- // We initialise and get ready for search - search has not yet begun
- // DFS = depth first search
- DFS<DistinctList> e(m);
- delete m;
- // We loop through all solutions to the constraint problem
- int count = 0;
- while (DistinctList* s = e.next()) {
- s->print(); delete s;
- count++;
- }
- std::cout << "Number of elements: " << count << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement