Generated on Sun Aug 26 2012 08:43:19 for Gecode by doxygen 1.8.1.1
set.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  * Christian Schulte <schulte@gecode.org>
6  *
7  * Contributing authors:
8  * Gabor Szokoli <szokoli@gecode.org>
9  *
10  * Copyright:
11  * Guido Tack, 2004
12  * Christian Schulte, 2004
13  * Gabor Szokoli, 2004
14  *
15  * Last modified:
16  * $Date: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
17  * $Revision: 12346 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #ifndef __GECODE_SET_HH__
45 #define __GECODE_SET_HH__
46 
47 #include <gecode/kernel.hh>
48 #include <gecode/int.hh>
49 #include <gecode/iter.hh>
50 
51 /*
52  * Configure linking
53  *
54  */
55 #if !defined(GECODE_STATIC_LIBS) && \
56  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
57 
58 #ifdef GECODE_BUILD_SET
59 #define GECODE_SET_EXPORT __declspec( dllexport )
60 #else
61 #define GECODE_SET_EXPORT __declspec( dllimport )
62 #endif
63 
64 #else
65 
66 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
67 #define GECODE_SET_EXPORT __attribute__ ((visibility("default")))
68 #else
69 #define GECODE_SET_EXPORT
70 #endif
71 
72 #endif
73 
74 // Configure auto-linking
75 #ifndef GECODE_BUILD_SET
76 #define GECODE_LIBRARY_NAME "Set"
78 #endif
79 
80 
92 #include <gecode/set/exception.hpp>
93 
94 namespace Gecode { namespace Set {
95 
97  namespace Limits {
99  const int max = (Gecode::Int::Limits::max / 2) - 1;
101  const int min = -max;
103  const unsigned int card = max-min+1;
105  void check(int n, const char* l);
107  void check(unsigned int n, const char* l);
109  void check(const IntSet& s, const char* l);
110  }
111 
112 }}
113 
114 #include <gecode/set/limits.hpp>
115 
116 #include <gecode/set/var-imp.hpp>
117 
118 namespace Gecode {
119 
120  namespace Set {
121  class SetView;
122  }
123 
129  class SetVar : public VarImpVar<Set::SetVarImp> {
130  friend class SetVarArray;
131  friend class SetVarArgs;
133  public:
135 
136 
137  SetVar(void);
139  SetVar(const SetVar& y);
141  SetVar(const Set::SetView& y);
142 
145 
164  SetVar(Space& home,int glbMin,int glbMax,int lubMin,int lubMax,
165  unsigned int cardMin = 0,
166  unsigned int cardMax = Set::Limits::card);
167 
185  SetVar(Space& home,const IntSet& glbD,int lubMin,int lubMax,
186  unsigned int cardMin = 0,
187  unsigned int cardMax = Set::Limits::card);
188 
207  SetVar(Space& home,int glbMin,int glbMax,const IntSet& lubD,
208  unsigned int cardMin = 0,
209  unsigned int cardMax = Set::Limits::card);
210 
229  SetVar(Space& home,const IntSet& glbD,const IntSet& lubD,
230  unsigned int cardMin = 0,
231  unsigned int cardMax = Set::Limits::card);
233 
235 
236 
237  unsigned int glbSize(void) const;
239  unsigned int lubSize(void) const;
241  unsigned int unknownSize(void) const;
243  unsigned int cardMin(void) const;
245  unsigned int cardMax(void) const;
247  int lubMin(void) const;
249  int lubMax(void) const;
251  int glbMin(void) const;
253  int glbMax(void) const;
255 
257 
258 
259  bool contains(int i) const;
261  bool notContains(int i) const;
263  };
264 
270 
273  private:
275  public:
277 
278 
279  SetVarGlbRanges(void);
281  SetVarGlbRanges(const SetVar& x);
283 
285 
286 
287  bool operator ()(void) const;
289  void operator ++(void);
291 
293 
294 
295  int min(void) const;
297  int max(void) const;
299  unsigned int width(void) const;
301  };
302 
305  private:
307  public:
309 
310 
311  SetVarLubRanges(void);
313  SetVarLubRanges(const SetVar& x);
315 
317 
318 
319  bool operator ()(void) const;
321  void operator ++(void);
323 
325 
326 
327  int min(void) const;
329  int max(void) const;
331  unsigned int width(void) const;
333  };
334 
337  private:
339  public:
341 
342 
343  SetVarUnknownRanges(void);
345  SetVarUnknownRanges(const SetVar& x);
347 
349 
350 
351  bool operator ()(void) const;
353  void operator ++(void);
355 
357 
358 
359  int min(void) const;
361  int max(void) const;
363  unsigned int width(void) const;
365  };
366 
369  private:
371  public:
373 
374 
375  SetVarGlbValues(void);
377  SetVarGlbValues(const SetVar& x);
379 
381 
382 
383  bool operator ()(void) const;
385  void operator ++(void);
387 
389 
390 
391  int val(void) const;
393  };
394 
397  private:
399  public:
401 
402 
403  SetVarLubValues(void);
405  SetVarLubValues(const SetVar& x);
407 
409 
410 
411  bool operator ()(void) const;
413  void operator ++(void);
415 
417 
418 
419  int val(void) const;
421  };
422 
425  private:
427  public:
429 
430 
431  SetVarUnknownValues(void);
433  SetVarUnknownValues(const SetVar& x);
435 
437 
438 
439  bool operator ()(void) const;
441  void operator ++(void);
443 
445 
446 
447  int val(void) const;
449  };
450 
452 
457  template<class Char, class Traits>
458  std::basic_ostream<Char,Traits>&
459  operator <<(std::basic_ostream<Char,Traits>& os, const SetVar& x);
460 
461 }
462 
463 #include <gecode/set/view.hpp>
464 
465 namespace Gecode {
475 
476 }
477 
479 
480 namespace Gecode {
481 
490  class SetVarArgs : public VarArgArray<SetVar> {
491  public:
493 
494 
495  SetVarArgs(void) {}
497  explicit SetVarArgs(int n) : VarArgArray<SetVar>(n) {}
509  SetVarArgs(Space& home,int n,int glbMin,int glbMax,
510  int lubMin,int lubMax,
511  unsigned int minCard = 0,
512  unsigned int maxCard = Set::Limits::card);
520  SetVarArgs(Space& home,int n,const IntSet& glb,
521  int lubMin, int lubMax,
522  unsigned int minCard = 0,
523  unsigned int maxCard = Set::Limits::card);
531  SetVarArgs(Space& home,int n,int glbMin,int glbMax,
532  const IntSet& lub,
533  unsigned int minCard = 0,
534  unsigned int maxCard = Set::Limits::card);
542  SetVarArgs(Space& home,int n,
543  const IntSet& glb,const IntSet& lub,
544  unsigned int minCard = 0,
545  unsigned int maxCard = Set::Limits::card);
547  };
549 
565  class SetVarArray : public VarArray<SetVar> {
566  public:
568 
569 
570  SetVarArray(void);
572  SetVarArray(const SetVarArray&);
574  SetVarArray(Space& home, const SetVarArgs&);
576  GECODE_SET_EXPORT SetVarArray(Space& home, int n);
584  SetVarArray(Space& home,int n,int glbMin,int glbMax,int lubMin,int lubMax,
585  unsigned int minCard = 0,
586  unsigned int maxCard = Set::Limits::card);
594  SetVarArray(Space& home,int n,const IntSet& glb, int lubMin, int lubMax,
595  unsigned int minCard = 0,
596  unsigned int maxCard = Set::Limits::card);
604  SetVarArray(Space& home,int n,int glbMin,int glbMax,const IntSet& lub,
605  unsigned int minCard = 0,
606  unsigned int maxCard = Set::Limits::card);
614  SetVarArray(Space& home,int n,
615  const IntSet& glb,const IntSet& lub,
616  unsigned int minCard = 0,
617  unsigned int maxCard = Set::Limits::card);
619  };
620 
621 }
622 
623 #include <gecode/set/array.hpp>
624 
625 namespace Gecode {
626 
638  enum SetRelType {
649  };
650 
655  enum SetOpType {
660  };
661 
669 
671  GECODE_SET_EXPORT void
672  dom(Home home, SetVar x, SetRelType r, int i);
673 
675  GECODE_SET_EXPORT void
676  dom(Home home, SetVar x, SetRelType r, int i, int j);
677 
679  GECODE_SET_EXPORT void
680  dom(Home home, SetVar x, SetRelType r, const IntSet& s);
681 
683  GECODE_SET_EXPORT void
684  dom(Home home, SetVar x, SetRelType r, int i, BoolVar b);
685 
687  GECODE_SET_EXPORT void
688  dom(Home home, SetVar x, SetRelType r, int i, int j, BoolVar b);
689 
691  GECODE_SET_EXPORT void
692  dom(Home home, SetVar x, SetRelType r, const IntSet& s, BoolVar b);
693 
695  GECODE_SET_EXPORT void
696  cardinality(Home home, SetVar x, unsigned int i, unsigned int j);
697 
699 
700 
708 
710  GECODE_SET_EXPORT void
711  rel(Home home, SetVar x, SetRelType r, SetVar y);
712 
714  GECODE_SET_EXPORT void
715  rel(Home home, SetVar x, SetRelType r, SetVar y, BoolVar b);
716 
718  GECODE_SET_EXPORT void
719  rel(Home home, SetVar s, SetRelType r, IntVar x);
720 
722  GECODE_SET_EXPORT void
723  rel(Home home, IntVar x, SetRelType r, SetVar s);
724 
726  GECODE_SET_EXPORT void
727  rel(Home home, SetVar s, SetRelType r, IntVar x, BoolVar b);
728 
730  GECODE_SET_EXPORT void
731  rel(Home home, IntVar x, SetRelType r, SetVar s, BoolVar b);
732 
734  GECODE_SET_EXPORT void
735  rel(Home home, SetVar s, IntRelType r, IntVar x);
736 
738  GECODE_SET_EXPORT void
739  rel(Home home, IntVar x, IntRelType r, SetVar s);
740 
742 
750 
752  GECODE_SET_EXPORT void
753  rel(Home home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z);
754 
756  GECODE_SET_EXPORT void
757  rel(Home home, SetOpType op, const SetVarArgs& x, SetVar y);
758 
760  GECODE_SET_EXPORT void
761  rel(Home home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y);
762 
764  GECODE_SET_EXPORT void
765  rel(Home home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y);
766 
768  GECODE_SET_EXPORT void
769  rel(Home home, SetOpType op, const IntVarArgs& x, SetVar y);
770 
772  GECODE_SET_EXPORT void
773  rel(Home home, const IntSet& x, SetOpType op, SetVar y,
774  SetRelType r, SetVar z);
775 
777  GECODE_SET_EXPORT void
778  rel(Home home, SetVar x, SetOpType op, const IntSet& y,
779  SetRelType r, SetVar z);
780 
782  GECODE_SET_EXPORT void
783  rel(Home home, SetVar x, SetOpType op, SetVar y,
784  SetRelType r, const IntSet& z);
785 
787  GECODE_SET_EXPORT void
788  rel(Home home, const IntSet& x, SetOpType op, SetVar y, SetRelType r,
789  const IntSet& z);
790 
792  GECODE_SET_EXPORT void
793  rel(Home home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
794  const IntSet& z);
795 
797 
798 
805 
807  GECODE_SET_EXPORT void
808  convex(Home home, SetVar x);
809 
811  GECODE_SET_EXPORT void
812  convex(Home home, SetVar x, SetVar y);
813 
815 
822 
824  GECODE_SET_EXPORT void
825  sequence(Home home, const SetVarArgs& x);
826 
828  GECODE_SET_EXPORT void
829  sequence(Home home, const SetVarArgs& y, SetVar x);
830 
832 
839 
840 
842  GECODE_SET_EXPORT void
843  atmostOne(Home home, const SetVarArgs& x, unsigned int c);
844 
846 
854 
857  GECODE_SET_EXPORT void
858  min(Home home, SetVar s, IntVar x);
859 
862  GECODE_SET_EXPORT void
863  notMin(Home home, SetVar s, IntVar x);
864 
867  GECODE_SET_EXPORT void
868  min(Home home, SetVar s, IntVar x, BoolVar b);
869 
872  GECODE_SET_EXPORT void
873  max(Home home, SetVar s, IntVar x);
874 
877  GECODE_SET_EXPORT void
878  notMax(Home home, SetVar s, IntVar x);
879 
882  GECODE_SET_EXPORT void
883  max(Home home, SetVar s, IntVar x, BoolVar b);
884 
886  GECODE_SET_EXPORT void
887  channelSorted(Home home, const IntVarArgs& x, SetVar y);
888 
890  GECODE_SET_EXPORT void
891  channel(Home home, const IntVarArgs& x,const SetVarArgs& y);
892 
894  GECODE_SET_EXPORT void
895  channel(Home home, const BoolVarArgs& x, SetVar y);
896 
898  GECODE_SET_EXPORT void
899  cardinality(Home home, SetVar s, IntVar x);
900 
901 
912  GECODE_SET_EXPORT void
913  weights(Home home, IntSharedArray elements, IntSharedArray weights,
914  SetVar x, IntVar y);
915 
917 
929  GECODE_SET_EXPORT void
930  precede(Home home, const SetVarArgs& x, int s, int t);
934  GECODE_SET_EXPORT void
935  precede(Home home, const SetVarArgs& x, const IntArgs& c);
936 
950 
960  GECODE_SET_EXPORT void
961  element(Home home, SetOpType op, const SetVarArgs& x, SetVar y, SetVar z,
962  const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
963 
973  GECODE_SET_EXPORT void
974  element(Home home, SetOpType op, const IntVarArgs& x, SetVar y, SetVar z,
975  const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
976 
986  GECODE_SET_EXPORT void
987  element(Home home, SetOpType op, const IntSetArgs& x, SetVar y, SetVar z,
988  const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
989 
999  GECODE_SET_EXPORT void
1000  element(Home home, SetOpType op, const IntArgs& x, SetVar y, SetVar z,
1001  const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
1002 
1008  GECODE_SET_EXPORT void
1009  element(Home home, const SetVarArgs& x, IntVar y, SetVar z);
1010 
1016  GECODE_SET_EXPORT void
1017  element(Home home, const IntSetArgs& s, IntVar y, SetVar z);
1018 
1024  GECODE_SET_EXPORT void
1025  element(Home home, const IntSetArgs& a,
1026  IntVar x, int w, IntVar y, int h, SetVar z);
1032  GECODE_SET_EXPORT void
1033  element(Home home, const SetVarArgs& a,
1034  IntVar x, int w, IntVar y, int h, SetVar z);
1036 
1047 
1048  GECODE_SET_EXPORT void
1049  wait(Home home, SetVar x, void (*c)(Space& home));
1051  GECODE_SET_EXPORT void
1052  wait(Home home, const SetVarArgs& x, void (*c)(Space& home));
1054 
1061 
1079  };
1080 
1091  };
1092 
1094  GECODE_SET_EXPORT void
1095  branch(Home home, const SetVarArgs& x,
1096  SetVarBranch vars, SetValBranch vals,
1097  const VarBranchOptions& o_vars = VarBranchOptions::def,
1098  const ValBranchOptions& o_vals = ValBranchOptions::def);
1100  GECODE_SET_EXPORT void
1101  branch(Home home, const SetVarArgs& x,
1102  const TieBreakVarBranch<SetVarBranch>& vars, SetValBranch vals,
1103  const TieBreakVarBranchOptions& o_vars = TieBreakVarBranchOptions::def,
1104  const ValBranchOptions& o_vals = ValBranchOptions::def);
1106  GECODE_SET_EXPORT void
1107  branch(Home home, SetVar x, SetValBranch vals,
1108  const ValBranchOptions& o_vals = ValBranchOptions::def);
1110 
1116 
1117  enum SetAssign {
1126  };
1127 
1129  GECODE_SET_EXPORT void
1130  assign(Home home, const SetVarArgs& x, SetAssign vals,
1131  const ValBranchOptions& o_vals = ValBranchOptions::def);
1133  GECODE_SET_EXPORT void
1134  assign(Home home, SetVar x, SetAssign vals,
1135  const ValBranchOptions& o_vals = ValBranchOptions::def);
1136 
1138 
1139 }
1140 
1141 #endif
1142 
1143 // IFDEF: GECODE_HAS_SET_VARS
1144 // STATISTICS: set-post