Generated on Wed Sep 5 2012 18:52:04 for Gecode by doxygen 1.8.1.1
minimodel.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  * Guido Tack <tack@gecode.org>
6  * Mikael Lagerkvist <lagerkvist@gecode.org>
7  *
8  * Copyright:
9  * Christian Schulte, 2004
10  * Guido Tack, 2004
11  * Mikael Lagerkvist, 2005
12  *
13  * Last modified:
14  * $Date: 2012-02-22 16:04:20 +1100 (Wed, 22 Feb 2012) $ by $Author: tack $
15  * $Revision: 12537 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 #ifndef __GECODE_MINIMODEL_HH__
43 #define __GECODE_MINIMODEL_HH__
44 
45 #include <gecode/kernel.hh>
46 #include <gecode/int.hh>
47 #ifdef GECODE_HAS_SET_VARS
48 #include <gecode/set.hh>
49 #endif
50 #include <gecode/int/linear.hh>
51 
53 
54 #include <iostream>
55 
56 /*
57  * Support for DLLs under Windows
58  *
59  */
60 
61 #if !defined(GECODE_STATIC_LIBS) && \
62  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
63 
64 #ifdef GECODE_BUILD_MINIMODEL
65 #define GECODE_MINIMODEL_EXPORT __declspec( dllexport )
66 #else
67 #define GECODE_MINIMODEL_EXPORT __declspec( dllimport )
68 #endif
69 
70 #else
71 
72 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
73 
74 #define GECODE_MINIMODEL_EXPORT __attribute__ ((visibility("default")))
75 
76 #else
77 
78 #define GECODE_MINIMODEL_EXPORT
79 
80 #endif
81 #endif
82 
83 // Configure auto-linking
84 #ifndef GECODE_BUILD_MINIMODEL
85 #define GECODE_LIBRARY_NAME "MiniModel"
87 #endif
88 
89 namespace Gecode {
90 
92  namespace MiniModel {}
93 
94  class LinRel;
95 #ifdef GECODE_HAS_SET_VARS
96  class SetExpr;
97 #endif
98 
100  class NonLinExpr {
101  public:
103  virtual IntVar post(Home home, IntVar* ret, IntConLevel icl) const = 0;
105  virtual void post(Home home, IntRelType irt, int c,
106  IntConLevel icl) const = 0;
108  virtual void post(Home home, IntRelType irt, int c,
109  BoolVar b, IntConLevel icl) const = 0;
111  virtual ~NonLinExpr(void) {}
113  static IntVar result(Home home, IntVar* x) {
114  if (x==NULL)
116  return *x;
117  }
119  static IntVar result(Home home, IntVar* x, IntVar y) {
120  if (x!=NULL)
121  rel(home,*x,IRT_EQ,y);
122  return y;
123  }
125  void* operator new(size_t size) { return heap.ralloc(size); }
127  void operator delete(void* p, size_t) { heap.rfree(p); }
128  };
129 
131  class LinExpr {
132  friend class LinRel;
133 #ifdef GECODE_HAS_SET_VARS
134  friend class SetExpr;
135 #endif
136  public:
138  enum NodeType {
148  };
149  private:
151  class Node {
152  public:
154  unsigned int use;
156  int n_int;
158  int n_bool;
160  NodeType t;
162  Node *l, *r;
164  union {
170  NonLinExpr* ne;
171  } sum;
173  int a, c;
175  IntVar x_int;
177  BoolVar x_bool;
179  Node(void);
182  void fill(Home home, IntConLevel icl,
183  Int::Linear::Term<Int::IntView>*& ti,
184  Int::Linear::Term<Int::BoolView>*& tb,
185  double m, double& d) const;
187  int fill(Home home, IntConLevel icl,
188  Int::Linear::Term<Int::IntView>* ti,
189  Int::Linear::Term<Int::BoolView>* tb) const;
191  bool decrement(void);
193  ~Node(void);
195  static void* operator new(size_t size);
197  static void operator delete(void* p,size_t size);
198  };
199  Node* n;
200  public:
203  LinExpr(void);
206  LinExpr(int c);
209  LinExpr(const IntVar& x, int a=1);
212  LinExpr(const BoolVar& x, int a=1);
215  explicit LinExpr(const IntVarArgs& x);
218  LinExpr(const IntArgs& a, const IntVarArgs& x);
221  explicit LinExpr(const BoolVarArgs& x);
224  LinExpr(const IntArgs& a, const BoolVarArgs& x);
226  LinExpr(const LinExpr& e);
229  LinExpr(const LinExpr& e0, NodeType t, const LinExpr& e1);
232  LinExpr(const LinExpr& e0, NodeType t, int c);
235  LinExpr(int a, const LinExpr& e);
238  explicit LinExpr(NonLinExpr* e);
241  const LinExpr& operator =(const LinExpr& e);
243  void post(Home home, IntRelType irt, IntConLevel icl) const;
245  void post(Home home, IntRelType irt, const BoolVar& b,
246  IntConLevel icl) const;
248  IntVar post(Home home, IntConLevel icl) const;
250  NonLinExpr* nle(void) const;
253  ~LinExpr(void);
254  };
255 
256  class BoolExpr;
257 
259  class LinRel {
260  friend class BoolExpr;
261  private:
263  LinExpr e;
265  IntRelType irt;
267  static IntRelType neg(IntRelType irt);
269  LinRel(void);
270  public:
272  LinRel(const LinExpr& l, IntRelType irt, const LinExpr& r);
274  LinRel(const LinExpr& l, IntRelType irt, int r);
276  LinRel(int l, IntRelType irt, const LinExpr& r);
278  void post(Home home, bool t, IntConLevel icl) const;
280  void post(Home home, const BoolVar& b, bool t, IntConLevel icl) const;
281  };
282 
301 
303  operator +(int, const IntVar&);
306  operator +(int, const BoolVar&);
309  operator +(int, const LinExpr&);
312  operator +(const IntVar&, int);
315  operator +(const BoolVar&, int);
318  operator +(const LinExpr&, int);
321  operator +(const IntVar&, const IntVar&);
324  operator +(const IntVar&, const BoolVar&);
327  operator +(const BoolVar&, const IntVar&);
330  operator +(const BoolVar&, const BoolVar&);
333  operator +(const IntVar&, const LinExpr&);
336  operator +(const BoolVar&, const LinExpr&);
339  operator +(const LinExpr&, const IntVar&);
342  operator +(const LinExpr&, const BoolVar&);
345  operator +(const LinExpr&, const LinExpr&);
346 
349  operator -(int, const IntVar&);
352  operator -(int, const BoolVar&);
355  operator -(int, const LinExpr&);
358  operator -(const IntVar&, int);
361  operator -(const BoolVar&, int);
364  operator -(const LinExpr&, int);
367  operator -(const IntVar&, const IntVar&);
370  operator -(const IntVar&, const BoolVar&);
373  operator -(const BoolVar&, const IntVar&);
376  operator -(const BoolVar&, const BoolVar&);
379  operator -(const IntVar&, const LinExpr&);
382  operator -(const BoolVar&, const LinExpr&);
385  operator -(const LinExpr&, const IntVar&);
388  operator -(const LinExpr&, const BoolVar&);
391  operator -(const LinExpr&, const LinExpr&);
392 
395  operator -(const IntVar&);
398  operator -(const BoolVar&);
401  operator -(const LinExpr&);
402 
405  operator *(int, const IntVar&);
408  operator *(int, const BoolVar&);
411  operator *(const IntVar&, int);
414  operator *(const BoolVar&, int);
417  operator *(const LinExpr&, int);
420  operator *(int, const LinExpr&);
421 
424  sum(const IntVarArgs& x);
427  sum(const IntArgs& a, const IntVarArgs& x);
430  sum(const BoolVarArgs& x);
433  sum(const IntArgs& a, const BoolVarArgs& x);
434 
437  operator ==(int l, const IntVar& r);
440  operator ==(int l, const BoolVar& r);
443  operator ==(int l, const LinExpr& r);
446  operator ==(const IntVar& l, int r);
449  operator ==(const BoolVar& l, int r);
452  operator ==(const LinExpr& l, int r);
455  operator ==(const IntVar& l, const IntVar& r);
458  operator ==(const IntVar& l, const BoolVar& r);
461  operator ==(const BoolVar& l, const IntVar& r);
464  operator ==(const BoolVar& l, const BoolVar& r);
467  operator ==(const IntVar& l, const LinExpr& r);
470  operator ==(const BoolVar& l, const LinExpr& r);
473  operator ==(const LinExpr& l, const IntVar& r);
476  operator ==(const LinExpr& l, const BoolVar& r);
479  operator ==(const LinExpr& l, const LinExpr& r);
480 
483  operator !=(int l, const IntVar& r);
486  operator !=(int l, const BoolVar& r);
489  operator !=(int l, const LinExpr& r);
492  operator !=(const IntVar& l, int r);
495  operator !=(const BoolVar& l, int r);
498  operator !=(const LinExpr& l, int r);
501  operator !=(const IntVar& l, const IntVar& r);
504  operator !=(const IntVar& l, const BoolVar& r);
507  operator !=(const BoolVar& l, const IntVar& r);
510  operator !=(const BoolVar& l, const BoolVar& r);
513  operator !=(const IntVar& l, const LinExpr& r);
516  operator !=(const BoolVar& l, const LinExpr& r);
519  operator !=(const LinExpr& l, const IntVar& r);
522  operator !=(const LinExpr& l, const BoolVar& r);
525  operator !=(const LinExpr& l, const LinExpr& r);
526 
529  operator <(int l, const IntVar& r);
532  operator <(int l, const BoolVar& r);
535  operator <(int l, const LinExpr& r);
538  operator <(const IntVar& l, int r);
541  operator <(const BoolVar& l, int r);
544  operator <(const LinExpr& l, int r);
547  operator <(const IntVar& l, const IntVar& r);
550  operator <(const IntVar& l, const BoolVar& r);
553  operator <(const BoolVar& l, const IntVar& r);
556  operator <(const BoolVar& l, const BoolVar& r);
559  operator <(const IntVar& l, const LinExpr& r);
562  operator <(const BoolVar& l, const LinExpr& r);
565  operator <(const LinExpr& l, const IntVar& r);
568  operator <(const LinExpr& l, const BoolVar& r);
571  operator <(const LinExpr& l, const LinExpr& r);
572 
575  operator <=(int l, const IntVar& r);
578  operator <=(int l, const BoolVar& r);
581  operator <=(int l, const LinExpr& r);
584  operator <=(const IntVar& l, int r);
587  operator <=(const BoolVar& l, int r);
590  operator <=(const LinExpr& l, int r);
593  operator <=(const IntVar& l, const IntVar& r);
596  operator <=(const IntVar& l, const BoolVar& r);
599  operator <=(const BoolVar& l, const IntVar& r);
602  operator <=(const BoolVar& l, const BoolVar& r);
605  operator <=(const IntVar& l, const LinExpr& r);
608  operator <=(const BoolVar& l, const LinExpr& r);
611  operator <=(const LinExpr& l, const IntVar& r);
614  operator <=(const LinExpr& l, const BoolVar& r);
617  operator <=(const LinExpr& l, const LinExpr& r);
618 
621  operator >(int l, const IntVar& r);
624  operator >(int l, const BoolVar& r);
627  operator >(int l, const LinExpr& r);
630  operator >(const IntVar& l, int r);
633  operator >(const BoolVar& l, int r);
636  operator >(const LinExpr& l, int r);
639  operator >(const IntVar& l, const IntVar& r);
642  operator >(const IntVar& l, const BoolVar& r);
645  operator >(const BoolVar& l, const IntVar& r);
648  operator >(const BoolVar& l, const BoolVar& r);
651  operator >(const IntVar& l, const LinExpr& r);
654  operator >(const BoolVar& l, const LinExpr& r);
657  operator >(const LinExpr& l, const IntVar& r);
660  operator >(const LinExpr& l, const BoolVar& r);
663  operator >(const LinExpr& l, const LinExpr& r);
664 
667  operator >=(int l, const IntVar& r);
670  operator >=(int l, const BoolVar& r);
673  operator >=(int l, const LinExpr& r);
676  operator >=(const IntVar& l, int r);
679  operator >=(const BoolVar& l, int r);
682  operator >=(const LinExpr& l, int r);
685  operator >=(const IntVar& l, const IntVar& r);
688  operator >=(const IntVar& l, const BoolVar& r);
691  operator >=(const BoolVar& l, const IntVar& r);
694  operator >=(const BoolVar& l, const BoolVar& r);
697  operator >=(const IntVar& l, const LinExpr& r);
700  operator >=(const BoolVar& l, const LinExpr& r);
703  operator >=(const LinExpr& l, const IntVar& r);
706  operator >=(const LinExpr& l, const BoolVar& r);
709  operator >=(const LinExpr& l, const LinExpr& r);
711 
712 #ifdef GECODE_HAS_SET_VARS
713 
714  class SetExpr {
715  public:
717  enum NodeType {
725  };
727  static bool same(NodeType t0, NodeType t1);
729  class Node {
730  public:
732  unsigned int use;
734  int same;
738  Node *l, *r;
745 
747  Node(void);
750  bool decrement(void);
752  static void* operator new(size_t size);
754  static void operator delete(void* p, size_t size);
755  };
757  class NNF {
758  public:
762  int p;
764  int n;
766  union {
768  struct {
770  NNF* l;
772  NNF* r;
773  } b;
775  struct {
777  Node* x;
778  } a;
779  } u;
781  bool neg;
784  static NNF* nnf(Region& r, Node* n, bool neg);
787  void post(Home home, NodeType t, SetVarArgs& b, int& i) const;
790  void post(Home home, SetRelType srt, SetVar s) const;
793  void post(Home home, SetRelType srt, SetVar s, BoolVar b) const;
796  void post(Home home, SetRelType srt, const NNF* n) const;
799  void post(Home home, BoolVar b, bool t, SetRelType srt,
800  const NNF* n) const;
802  static void* operator new(size_t s, Region& r);
804  static void operator delete(void*);
806  static void operator delete(void*, Region&);
807  };
808  private:
810  Node* n;
811  public:
814  SetExpr(void);
816  SetExpr(const SetExpr& e);
819  SetExpr(const SetExpr& l, NodeType t, const SetExpr& r);
822  SetExpr(const SetVar& x);
825  explicit SetExpr(const LinExpr& x);
828  SetExpr(const IntSet& s);
831  SetExpr(const SetExpr& e, NodeType t);
833  SetVar post(Home home) const;
835  void post(Home home, SetRelType srt, const SetExpr& e) const;
837  void post(Home home, BoolVar b, bool t,
838  SetRelType srt, const SetExpr& e) const;
841  const SetExpr& operator =(const SetExpr& e);
844  ~SetExpr(void);
845  };
846 
848  class SetCmpRel {
849  public:
857  SetCmpRel(const SetExpr& l, SetRelType srt, const SetExpr& r);
858  };
859 
861  class SetRel {
862  private:
864  SetExpr _e0;
866  SetRelType _srt;
868  SetExpr _e1;
869  public:
871  SetRel(void);
873  SetRel(const SetExpr& e0, SetRelType srt, const SetExpr& e1);
875  SetRel(const SetCmpRel& r);
877  void post(Home home, bool t) const;
879  void post(Home home, BoolVar b, bool t) const;
880  };
881 
892 
894  singleton(const LinExpr&);
897  operator -(const SetExpr&);
900  operator &(const SetExpr&, const SetExpr&);
903  operator |(const SetExpr&, const SetExpr&);
906  operator +(const SetExpr&, const SetExpr&);
909  operator -(const SetExpr&, const SetExpr&);
910 
913  inter(const SetVarArgs&);
916  setunion(const SetVarArgs&);
919  setdunion(const SetVarArgs&);
920 
923  cardinality(const SetExpr&);
926  min(const SetExpr&);
929  max(const SetExpr&);
930 
933  operator ==(const SetExpr&, const SetExpr&);
936  operator !=(const SetExpr&, const SetExpr&);
939  operator <=(const SetExpr&, const SetExpr&);
942  operator <=(const SetCmpRel&, const SetExpr&);
945  operator >=(const SetExpr&, const SetExpr&);
948  operator >=(const SetCmpRel&, const SetExpr&);
951  operator ||(const SetExpr&, const SetExpr&);
953 #endif
954 
956  class BoolExpr {
957  public:
959  enum NodeType {
968  };
970  class MiscExpr {
971  public:
975  virtual void post(Space& home, BoolVar b, bool neg,
976  IntConLevel icl) = 0;
978  virtual GECODE_MINIMODEL_EXPORT ~MiscExpr(void);
980  static void* operator new(size_t size);
982  static void operator delete(void* p, size_t size);
983  };
985  class Node {
986  public:
988  unsigned int use;
990  int same;
994  Node *l, *r;
999 #ifdef GECODE_HAS_SET_VARS
1000 
1002 #endif
1003 
1005 
1007  Node(void);
1009  ~Node(void);
1012  bool decrement(void);
1014  static void* operator new(size_t size);
1016  static void operator delete(void* p, size_t size);
1017  };
1019  class NNF {
1020  public:
1024  int p;
1026  int n;
1028  union {
1030  struct {
1032  NNF* l;
1034  NNF* r;
1035  } b;
1037  struct {
1039  bool neg;
1042  } a;
1043  } u;
1046  static NNF* nnf(Region& r, Node* n, bool neg);
1049  void post(Home home, NodeType t,
1050  BoolVarArgs& bp, BoolVarArgs& bn,
1051  int& ip, int& in,
1052  IntConLevel icl) const;
1055  BoolVar expr(Home home, IntConLevel icl) const;
1058  void rel(Home home, IntConLevel icl) const;
1060  static void* operator new(size_t s, Region& r);
1062  static void operator delete(void*);
1064  static void operator delete(void*, Region&);
1065  };
1066  private:
1068  Node* n;
1069  public:
1072  BoolExpr(void);
1074  BoolExpr(const BoolExpr& e);
1077  BoolExpr(const BoolExpr& l, NodeType t, const BoolExpr& r);
1080  BoolExpr(const BoolVar& x);
1083  BoolExpr(const BoolExpr& e, NodeType t);
1086  BoolExpr(const LinRel& rl);
1087 #ifdef GECODE_HAS_SET_VARS
1088 
1090  BoolExpr(const SetRel& rs);
1093  BoolExpr(const SetCmpRel& rs);
1094 #endif
1095 
1097  explicit BoolExpr(MiscExpr* m);
1099  BoolVar expr(Home home, IntConLevel icl) const;
1101  void rel(Home home, IntConLevel icl) const;
1104  const BoolExpr& operator =(const BoolExpr& e);
1107  ~BoolExpr(void);
1108  };
1109 
1120 
1121  GECODE_MINIMODEL_EXPORT BoolExpr
1122  operator !(const BoolExpr&);
1124  GECODE_MINIMODEL_EXPORT BoolExpr
1125  operator &&(const BoolExpr&, const BoolExpr&);
1127  GECODE_MINIMODEL_EXPORT BoolExpr
1128  operator ||(const BoolExpr&, const BoolExpr&);
1130  GECODE_MINIMODEL_EXPORT BoolExpr
1131  operator ^(const BoolExpr&, const BoolExpr&);
1132 
1134  GECODE_MINIMODEL_EXPORT BoolExpr
1135  operator !=(const BoolExpr&, const BoolExpr&);
1137  GECODE_MINIMODEL_EXPORT BoolExpr
1138  operator ==(const BoolExpr&, const BoolExpr&);
1140  GECODE_MINIMODEL_EXPORT BoolExpr
1141  operator >>(const BoolExpr&, const BoolExpr&);
1143  GECODE_MINIMODEL_EXPORT BoolExpr
1144  operator <<(const BoolExpr&, const BoolExpr&);
1145 
1147 
1154 
1155  GECODE_MINIMODEL_EXPORT IntVar
1156  expr(Home home, const LinExpr& e, IntConLevel icl=ICL_DEF);
1157 #ifdef GECODE_HAS_SET_VARS
1158 
1160  expr(Home home, const SetExpr& e);
1161 #endif
1162 
1163  GECODE_MINIMODEL_EXPORT BoolVar
1164  expr(Home home, const BoolExpr& e, IntConLevel icl=ICL_DEF);
1167  rel(Home home, const BoolExpr& e, IntConLevel icl=ICL_DEF);
1169 
1170 }
1171 
1177 
1178 namespace Gecode {
1179 
1180  namespace MiniModel {
1181  class ExpInfo;
1182  }
1183 
1190  friend class MiniModel::ExpInfo;
1191  private:
1193  class Exp;
1195  Exp* e;
1197  REG(Exp* e);
1198  public:
1200  REG(void);
1202  REG(int s);
1209  REG(const IntArgs& x);
1210 
1212  REG(const REG& r);
1214  const REG& operator =(const REG& r);
1215 
1217  REG operator +(const REG& r);
1219  REG& operator +=(const REG& r);
1221  REG operator |(const REG& r);
1223  REG& operator |=(const REG& r);
1225  REG operator *(void);
1227  REG operator +(void);
1229  REG operator ()(unsigned int n, unsigned int m);
1231  REG operator ()(unsigned int n);
1233  template<class Char, class Traits>
1234  std::basic_ostream<Char,Traits>&
1235  print(std::basic_ostream<Char,Traits>& os) const;
1237  operator DFA(void);
1239  ~REG(void);
1240  };
1241 
1245  template<class Char, class Traits>
1246  std::basic_ostream<Char,Traits>&
1247  operator <<(std::basic_ostream<Char,Traits>& os, const REG& r);
1248 
1249 
1256 
1258  abs(const LinExpr& e);
1261  min(const LinExpr& x, const LinExpr& y);
1264  min(const IntVarArgs& x);
1267  max(const LinExpr& x, const LinExpr& y);
1270  max(const IntVarArgs& x);
1273  operator *(const LinExpr& x, const LinExpr& y);
1276  operator /(const LinExpr& x, const LinExpr& y);
1279  operator %(const LinExpr& x, const LinExpr& y);
1282  sqr(const LinExpr& x);
1285  sqrt(const LinExpr& x);
1288  element(const IntVarArgs& x, const LinExpr& y);
1291  element(const BoolVarArgs& x, const LinExpr& y);
1294  element(const IntArgs& x, const LinExpr& y);
1296 
1303 
1304  inline BoolVar
1306  IntConLevel icl=ICL_DEF) {
1307  (void) icl;
1308  BoolVar b(home,0,1); channel(home,b,x);
1309  return b;
1310  }
1312  inline IntVar
1314  IntConLevel icl=ICL_DEF) {
1315  (void) icl;
1316  IntVar x(home,0,1); channel(home,b,x);
1317  return x;
1318  }
1319 #ifdef GECODE_HAS_SET_VARS
1320 
1321  inline SetVar
1322  channel(Home home, const IntVarArgs& x, IntConLevel icl=ICL_DEF) {
1323  (void) icl;
1325  rel(home,SOT_UNION,x,s);
1326  nvalues(home,x,IRT_EQ,expr(home,cardinality(s)));
1327  return s;
1328  }
1329 #endif
1330 
1331 
1332 }
1333 
1334 namespace Gecode {
1335 
1350  inline void
1351  atmost(Home home, const IntVarArgs& x, int n, int m,
1352  IntConLevel icl=ICL_DEF) {
1353  count(home,x,n,IRT_LQ,m,icl);
1354  }
1359  inline void
1360  atmost(Home home, const IntVarArgs& x, IntVar y, int m,
1361  IntConLevel icl=ICL_DEF) {
1362  count(home,x,y,IRT_LQ,m,icl);
1363  }
1371  inline void
1372  atmost(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1373  IntConLevel icl=ICL_DEF) {
1374  count(home,x,y,IRT_LQ,m,icl);
1375  }
1380  inline void
1381  atmost(Home home, const IntVarArgs& x, int n, IntVar z,
1382  IntConLevel icl=ICL_DEF) {
1383  count(home,x,n,IRT_LQ,z,icl);
1384  }
1389  inline void
1390  atmost(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1391  IntConLevel icl=ICL_DEF) {
1392  count(home,x,y,IRT_LQ,z,icl);
1393  }
1401  inline void
1402  atmost(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1403  IntConLevel icl=ICL_DEF) {
1404  count(home,x,y,IRT_LQ,z,icl);
1405  }
1406 
1411  inline void
1412  atleast(Home home, const IntVarArgs& x, int n, int m,
1413  IntConLevel icl=ICL_DEF) {
1414  count(home,x,n,IRT_GQ,m,icl);
1415  }
1420  inline void
1421  atleast(Home home, const IntVarArgs& x, IntVar y, int m,
1422  IntConLevel icl=ICL_DEF) {
1423  count(home,x,y,IRT_GQ,m,icl);
1424  }
1432  inline void
1433  atleast(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1434  IntConLevel icl=ICL_DEF) {
1435  count(home,x,y,IRT_GQ,m,icl);
1436  }
1441  inline void
1442  atleast(Home home, const IntVarArgs& x, int n, IntVar z,
1443  IntConLevel icl=ICL_DEF) {
1444  count(home,x,n,IRT_GQ,z,icl);
1445  }
1450  inline void
1451  atleast(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1452  IntConLevel icl=ICL_DEF) {
1453  count(home,x,y,IRT_GQ,z,icl);
1454  }
1462  inline void
1463  atleast(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1464  IntConLevel icl=ICL_DEF) {
1465  count(home,x,y,IRT_GQ,z,icl);
1466  }
1467 
1472  inline void
1473  exactly(Home home, const IntVarArgs& x, int n, int m,
1474  IntConLevel icl=ICL_DEF) {
1475  count(home,x,n,IRT_EQ,m,icl);
1476  }
1481  inline void
1482  exactly(Home home, const IntVarArgs& x, IntVar y, int m,
1483  IntConLevel icl=ICL_DEF) {
1484  count(home,x,y,IRT_EQ,m,icl);
1485  }
1493  inline void
1494  exactly(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1495  IntConLevel icl=ICL_DEF) {
1496  count(home,x,y,IRT_EQ,m,icl);
1497  }
1502  inline void
1503  exactly(Home home, const IntVarArgs& x, int n, IntVar z,
1504  IntConLevel icl=ICL_DEF) {
1505  count(home,x,n,IRT_EQ,z,icl);
1506  }
1511  inline void
1512  exactly(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1513  IntConLevel icl=ICL_DEF) {
1514  count(home,x,y,IRT_EQ,z,icl);
1515  }
1523  inline void
1524  exactly(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1525  IntConLevel icl=ICL_DEF) {
1526  count(home,x,y,IRT_EQ,z,icl);
1527  }
1530  inline void
1531  lex(Home home, const IntVarArgs& x, IntRelType r, const IntVarArgs& y,
1532  IntConLevel icl=ICL_DEF) {
1533  rel(home,x,r,y,icl);
1534  }
1537  inline void
1538  lex(Home home, const BoolVarArgs& x, IntRelType r, const BoolVarArgs& y,
1539  IntConLevel icl=ICL_DEF) {
1540  rel(home,x,r,y,icl);
1541  }
1544  inline void
1545  values(Home home, const IntVarArgs& x, IntSet y,
1546  IntConLevel icl=ICL_DEF) {
1547  dom(home,x,y,icl);
1548  nvalues(home,x,IRT_EQ,y.size(),icl);
1549  }
1550 
1552 
1553 #ifdef GECODE_HAS_SET_VARS
1554 
1569  inline void
1570  channel(Home home, const IntVarArgs& x, SetVar y) {
1571  rel(home,SOT_UNION,x,y);
1572  nvalues(home,x,IRT_EQ,expr(home,cardinality(y)));
1573  }
1574 
1577  inline void
1578  range(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1579  element(home,SOT_UNION,x,y,z);
1580  }
1581 
1587  inline void
1588  roots(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1589  SetVarArgs xiv(home,z.lubMax()+1,IntSet::empty,0,x.size()-1);
1590  channel(home,x,xiv);
1591  element(home,SOT_UNION,xiv,z,y);
1592  }
1593 
1595 #endif
1596 
1597 }
1598 
1599 namespace Gecode {
1600 
1601  template<class> class Matrix;
1602 
1610  template<class A>
1611  class Slice {
1612  public:
1615  private:
1616  ArgsType _r;
1617  unsigned int _fc,
1618  _tc,
1619  _fr,
1620  _tr;
1621  public:
1623  Slice(const Matrix<A>& a, int fc, int tc, int fr, int tr);
1627  Slice& reverse(void);
1629  operator ArgsType(void);
1631  operator Matrix<ArgsType>(void);
1632 
1634  operator const ArgsType(void) const;
1636  operator const Matrix<ArgsType>(void) const;
1637  };
1638 
1640  template<class A>
1641  typename Slice<A>::ArgsType
1642  operator+(const Slice<A>& x, const Slice<A>& y);
1643 
1645  template<class A>
1646  typename Slice<A>::ArgsType
1647  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ArgsType& y);
1648 
1650  template<class A>
1651  typename Slice<A>::ArgsType
1652  operator+(const typename ArrayTraits<A>::ArgsType& x, const Slice<A>& y);
1653 
1655  template<class A>
1656  typename Slice<A>::ArgsType
1657  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ValueType& y);
1658 
1660  template<class A>
1661  typename Slice<A>::ArgsType
1662  operator+(const typename ArrayTraits<A>::ValueType& x, const Slice<A>& y);
1663 
1674  template<class A>
1675  class Matrix {
1676  public:
1681 
1682  private:
1684  typedef typename ArrayTraits<A>::StorageType StorageType;
1685  StorageType _a;
1686  int _w;
1687  int _h;
1688 
1689  public:
1702  Matrix(A a, int w, int h);
1703 
1716  Matrix(A a, int n);
1717 
1719  int width(void) const;
1721  int height(void) const;
1723  ArgsType const get_array(void) const;
1724 
1730  ValueType& operator ()(int c, int r);
1731 
1737  const ValueType& operator ()(int c, int r) const;
1738 
1748  Slice<A> slice(int fc, int tc, int fr, int tr) const;
1749 
1751  Slice<A> row(int r) const;
1752 
1754  Slice<A> col(int c) const;
1755  };
1756 
1760  template<class Char, class Traits, class A>
1761  std::basic_ostream<Char,Traits>&
1762  operator <<(std::basic_ostream<Char,Traits>& os, const Matrix<A>& m);
1763 
1767  template<class Char, class Traits, class A>
1768  std::basic_ostream<Char,Traits>&
1769  operator <<(std::basic_ostream<Char,Traits>& os, const Slice<A>& s);
1770 
1777  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
1778  IntVar z, IntConLevel icl=ICL_DEF);
1785  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
1786  BoolVar z, IntConLevel icl=ICL_DEF);
1793  void element(Home home, const Matrix<IntVarArgs>& m, IntVar x, IntVar y,
1794  IntVar z, IntConLevel icl=ICL_DEF);
1801  void element(Home home, const Matrix<BoolVarArgs>& m, IntVar x, IntVar y,
1802  BoolVar z, IntConLevel icl=ICL_DEF);
1803 #ifdef GECODE_HAS_SET_VARS
1804 
1810  void element(Home home, const Matrix<IntSetArgs>& m, IntVar x, IntVar y,
1811  SetVar z);
1818  void element(Home home, const Matrix<SetVarArgs>& m, IntVar x, IntVar y,
1819  SetVar z);
1820 #endif
1821 
1822 }
1823 
1824 #include <gecode/minimodel/matrix.hpp>
1825 
1826 namespace Gecode {
1827 
1837  namespace MiniModel {
1838 
1840  template<IntRelType irt>
1841  class OptimizeSpace : public Space {
1842  public:
1844  OptimizeSpace(void);
1846  OptimizeSpace(bool share, OptimizeSpace& s);
1848  virtual void constrain(const Space& best);
1850  virtual IntVar cost(void) const = 0;
1851  };
1852 
1853  }
1854 
1857 
1861 
1862 }
1863 
1865 
1866 #endif
1867 
1868 // IFDEF: GECODE_HAS_INT_VARS
1869 // STATISTICS: minimodel-any
1870