Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //
  2. // Gecode-demo using trace
  3. //
  4. #include <iostream>
  5.  
  6. #include <gecode/int.hh>
  7. #include <gecode/minimodel.hh>
  8. #include <gecode/search.hh>
  9.  
  10. using namespace Gecode;
  11.  
  12. class DistinctList : public Space {
  13. protected:
  14. IntVarArray l;
  15.  
  16. public:
  17. DistinctList(void) : l(*this, 3, 0, 5) {
  18.  
  19. distinct(*this, l);
  20. trace(*this, l);
  21. branch(*this, l, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
  22. }
  23.  
  24. DistinctList(bool share, DistinctList& s) : Space(share, s) {
  25. l.update(*this, share, s.l);
  26. }
  27.  
  28. Space* copy(bool share) {
  29. return new DistinctList(share, *this);
  30. }
  31.  
  32. void print(void) const {
  33. std::cout << l << std::endl;
  34. }
  35.  
  36.  
  37. };
  38.  
  39.  
  40.  
  41. int main(int argc, char* argv[])
  42. {
  43. DistinctList* m = new DistinctList;
  44. std::cout << "The contents of the space before search begins" << std::endl;
  45. m->print();
  46.  
  47. // We initialise and get ready for search - search has not yet begun
  48. // DFS = depth first search
  49. DFS<DistinctList> e(m);
  50. delete m;
  51.  
  52. // We loop through all solutions to the constraint problem
  53. int count = 0;
  54. while (DistinctList* s = e.next()) {
  55. s->print(); delete s;
  56. count++;
  57. }
  58. std::cout << "Number of elements: " << count << std::endl;
  59. return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement