Generated on Tue Oct 22 2013 00:49:07 for Gecode by doxygen 1.8.4
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  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
8  *
9  * Copyright:
10  * Christian Schulte, 2004
11  * Guido Tack, 2004
12  * Mikael Lagerkvist, 2005
13  * Vincent Barichard, 2012
14  *
15  * Last modified:
16  * $Date: 2013-04-17 17:43:48 +0200 (Wed, 17 Apr 2013) $ by $Author: schulte $
17  * $Revision: 13581 $
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_MINIMODEL_HH__
45 #define __GECODE_MINIMODEL_HH__
46 
47 #include <gecode/kernel.hh>
48 #include <gecode/int.hh>
49 #ifdef GECODE_HAS_SET_VARS
50 #include <gecode/set.hh>
51 #endif
52 #ifdef GECODE_HAS_FLOAT_VARS
53 #include <gecode/float.hh>
54 #endif
55 
57 
58 #include <iostream>
59 
60 /*
61  * Support for DLLs under Windows
62  *
63  */
64 
65 #if !defined(GECODE_STATIC_LIBS) && \
66  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
67 
68 #ifdef GECODE_BUILD_MINIMODEL
69 #define GECODE_MINIMODEL_EXPORT __declspec( dllexport )
70 #else
71 #define GECODE_MINIMODEL_EXPORT __declspec( dllimport )
72 #endif
73 
74 #else
75 
76 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
77 
78 #define GECODE_MINIMODEL_EXPORT __attribute__ ((visibility("default")))
79 
80 #else
81 
82 #define GECODE_MINIMODEL_EXPORT
83 
84 #endif
85 #endif
86 
87 // Configure auto-linking
88 #ifndef GECODE_BUILD_MINIMODEL
89 #define GECODE_LIBRARY_NAME "MiniModel"
91 #endif
92 
93 namespace Gecode {
94 
96  namespace MiniModel {}
97 
98  class LinIntRel;
99 #ifdef GECODE_HAS_SET_VARS
100  class SetExpr;
101 #endif
102 #ifdef GECODE_HAS_FLOAT_VARS
103  class LinFloatExpr;
104 #endif
105 
108  public:
110  virtual IntVar post(Home home, IntVar* ret, IntConLevel icl) const = 0;
112  virtual void post(Home home, IntRelType irt, int c,
113  IntConLevel icl) const = 0;
115  virtual void post(Home home, IntRelType irt, int c,
116  BoolVar b, IntConLevel icl) const = 0;
118  virtual ~NonLinIntExpr(void) {}
120  static IntVar result(Home home, IntVar* x) {
121  if (x==NULL)
123  return *x;
124  }
126  static IntVar result(Home home, IntVar* x, IntVar y) {
127  if (x!=NULL)
128  rel(home,*x,IRT_EQ,y);
129  return y;
130  }
132  void* operator new(size_t size) { return heap.ralloc(size); }
134  void operator delete(void* p, size_t) { heap.rfree(p); }
135  };
136 
138  class LinIntExpr {
139  friend class LinIntRel;
140 #ifdef GECODE_HAS_SET_VARS
141  friend class SetExpr;
142 #endif
143 #ifdef GECODE_HAS_FLOAT_VARS
144  friend class LinFloatExpr;
145 #endif
146  public:
148  enum NodeType {
158  };
159  private:
161  class Node;
162  Node* n;
163  public:
166  LinIntExpr(void);
169  LinIntExpr(int c);
172  LinIntExpr(const IntVar& x, int a=1);
175  LinIntExpr(const BoolVar& x, int a=1);
178  explicit LinIntExpr(const IntVarArgs& x);
181  LinIntExpr(const IntArgs& a, const IntVarArgs& x);
184  explicit LinIntExpr(const BoolVarArgs& x);
187  LinIntExpr(const IntArgs& a, const BoolVarArgs& x);
190  LinIntExpr(const LinIntExpr& e);
193  LinIntExpr(const LinIntExpr& e0, NodeType t, const LinIntExpr& e1);
196  LinIntExpr(const LinIntExpr& e0, NodeType t, int c);
199  LinIntExpr(int a, const LinIntExpr& e);
202  explicit LinIntExpr(NonLinIntExpr* e);
205  const LinIntExpr& operator =(const LinIntExpr& e);
208  void post(Home home, IntRelType irt, IntConLevel icl) const;
211  void post(Home home, IntRelType irt, const BoolVar& b,
212  IntConLevel icl) const;
215  IntVar post(Home home, IntConLevel icl) const;
218  NonLinIntExpr* nle(void) const;
221  ~LinIntExpr(void);
222  };
223 
224  class BoolExpr;
225 
227  class LinIntRel {
228  friend class BoolExpr;
229  private:
231  LinIntExpr e;
233  IntRelType irt;
235  static IntRelType neg(IntRelType irt);
237  LinIntRel(void);
238  public:
240  LinIntRel(const LinIntExpr& l, IntRelType irt, const LinIntExpr& r);
242  LinIntRel(const LinIntExpr& l, IntRelType irt, int r);
244  LinIntRel(int l, IntRelType irt, const LinIntExpr& r);
246  void post(Home home, bool t, IntConLevel icl) const;
248  void post(Home home, const BoolVar& b, bool t, IntConLevel icl) const;
249  };
250 
271  operator +(int, const IntVar&);
274  operator +(int, const BoolVar&);
277  operator +(int, const LinIntExpr&);
280  operator +(const IntVar&, int);
283  operator +(const BoolVar&, int);
286  operator +(const LinIntExpr&, int);
289  operator +(const IntVar&, const IntVar&);
292  operator +(const IntVar&, const BoolVar&);
295  operator +(const BoolVar&, const IntVar&);
298  operator +(const BoolVar&, const BoolVar&);
301  operator +(const IntVar&, const LinIntExpr&);
304  operator +(const BoolVar&, const LinIntExpr&);
307  operator +(const LinIntExpr&, const IntVar&);
310  operator +(const LinIntExpr&, const BoolVar&);
313  operator +(const LinIntExpr&, const LinIntExpr&);
314 
317  operator -(int, const IntVar&);
320  operator -(int, const BoolVar&);
323  operator -(int, const LinIntExpr&);
326  operator -(const IntVar&, int);
329  operator -(const BoolVar&, int);
332  operator -(const LinIntExpr&, int);
335  operator -(const IntVar&, const IntVar&);
338  operator -(const IntVar&, const BoolVar&);
341  operator -(const BoolVar&, const IntVar&);
344  operator -(const BoolVar&, const BoolVar&);
347  operator -(const IntVar&, const LinIntExpr&);
350  operator -(const BoolVar&, const LinIntExpr&);
353  operator -(const LinIntExpr&, const IntVar&);
356  operator -(const LinIntExpr&, const BoolVar&);
359  operator -(const LinIntExpr&, const LinIntExpr&);
360 
363  operator -(const IntVar&);
366  operator -(const BoolVar&);
369  operator -(const LinIntExpr&);
370 
373  operator *(int, const IntVar&);
376  operator *(int, const BoolVar&);
379  operator *(const IntVar&, int);
382  operator *(const BoolVar&, int);
385  operator *(const LinIntExpr&, int);
388  operator *(int, const LinIntExpr&);
389 
392  sum(const IntVarArgs& x);
395  sum(const IntArgs& a, const IntVarArgs& x);
398  sum(const BoolVarArgs& x);
401  sum(const IntArgs& a, const BoolVarArgs& x);
402 
405  operator ==(int l, const IntVar& r);
408  operator ==(int l, const BoolVar& r);
411  operator ==(int l, const LinIntExpr& r);
414  operator ==(const IntVar& l, int r);
417  operator ==(const BoolVar& l, int r);
420  operator ==(const LinIntExpr& l, int r);
423  operator ==(const IntVar& l, const IntVar& r);
426  operator ==(const IntVar& l, const BoolVar& r);
429  operator ==(const BoolVar& l, const IntVar& r);
432  operator ==(const BoolVar& l, const BoolVar& r);
435  operator ==(const IntVar& l, const LinIntExpr& r);
438  operator ==(const BoolVar& l, const LinIntExpr& r);
441  operator ==(const LinIntExpr& l, const IntVar& r);
444  operator ==(const LinIntExpr& l, const BoolVar& r);
447  operator ==(const LinIntExpr& l, const LinIntExpr& r);
448 
451  operator !=(int l, const IntVar& r);
454  operator !=(int l, const BoolVar& r);
457  operator !=(int l, const LinIntExpr& r);
460  operator !=(const IntVar& l, int r);
463  operator !=(const BoolVar& l, int r);
466  operator !=(const LinIntExpr& l, int r);
469  operator !=(const IntVar& l, const IntVar& r);
472  operator !=(const IntVar& l, const BoolVar& r);
475  operator !=(const BoolVar& l, const IntVar& r);
478  operator !=(const BoolVar& l, const BoolVar& r);
481  operator !=(const IntVar& l, const LinIntExpr& r);
484  operator !=(const BoolVar& l, const LinIntExpr& r);
487  operator !=(const LinIntExpr& l, const IntVar& r);
490  operator !=(const LinIntExpr& l, const BoolVar& r);
493  operator !=(const LinIntExpr& l, const LinIntExpr& r);
494 
497  operator <(int l, const IntVar& r);
500  operator <(int l, const BoolVar& r);
503  operator <(int l, const LinIntExpr& r);
506  operator <(const IntVar& l, int r);
509  operator <(const BoolVar& l, int r);
512  operator <(const LinIntExpr& l, int r);
515  operator <(const IntVar& l, const IntVar& r);
518  operator <(const IntVar& l, const BoolVar& r);
521  operator <(const BoolVar& l, const IntVar& r);
524  operator <(const BoolVar& l, const BoolVar& r);
527  operator <(const IntVar& l, const LinIntExpr& r);
530  operator <(const BoolVar& l, const LinIntExpr& r);
533  operator <(const LinIntExpr& l, const IntVar& r);
536  operator <(const LinIntExpr& l, const BoolVar& r);
539  operator <(const LinIntExpr& l, const LinIntExpr& r);
540 
543  operator <=(int l, const IntVar& r);
546  operator <=(int l, const BoolVar& r);
549  operator <=(int l, const LinIntExpr& r);
552  operator <=(const IntVar& l, int r);
555  operator <=(const BoolVar& l, int r);
558  operator <=(const LinIntExpr& l, int r);
561  operator <=(const IntVar& l, const IntVar& r);
564  operator <=(const IntVar& l, const BoolVar& r);
567  operator <=(const BoolVar& l, const IntVar& r);
570  operator <=(const BoolVar& l, const BoolVar& r);
573  operator <=(const IntVar& l, const LinIntExpr& r);
576  operator <=(const BoolVar& l, const LinIntExpr& r);
579  operator <=(const LinIntExpr& l, const IntVar& r);
582  operator <=(const LinIntExpr& l, const BoolVar& r);
585  operator <=(const LinIntExpr& l, const LinIntExpr& r);
586 
589  operator >(int l, const IntVar& r);
592  operator >(int l, const BoolVar& r);
595  operator >(int l, const LinIntExpr& r);
598  operator >(const IntVar& l, int r);
601  operator >(const BoolVar& l, int r);
604  operator >(const LinIntExpr& l, int r);
607  operator >(const IntVar& l, const IntVar& r);
610  operator >(const IntVar& l, const BoolVar& r);
613  operator >(const BoolVar& l, const IntVar& r);
616  operator >(const BoolVar& l, const BoolVar& r);
619  operator >(const IntVar& l, const LinIntExpr& r);
622  operator >(const BoolVar& l, const LinIntExpr& r);
625  operator >(const LinIntExpr& l, const IntVar& r);
628  operator >(const LinIntExpr& l, const BoolVar& r);
631  operator >(const LinIntExpr& l, const LinIntExpr& r);
632 
635  operator >=(int l, const IntVar& r);
638  operator >=(int l, const BoolVar& r);
641  operator >=(int l, const LinIntExpr& r);
644  operator >=(const IntVar& l, int r);
647  operator >=(const BoolVar& l, int r);
650  operator >=(const LinIntExpr& l, int r);
653  operator >=(const IntVar& l, const IntVar& r);
656  operator >=(const IntVar& l, const BoolVar& r);
659  operator >=(const BoolVar& l, const IntVar& r);
662  operator >=(const BoolVar& l, const BoolVar& r);
665  operator >=(const IntVar& l, const LinIntExpr& r);
668  operator >=(const BoolVar& l, const LinIntExpr& r);
671  operator >=(const LinIntExpr& l, const IntVar& r);
674  operator >=(const LinIntExpr& l, const BoolVar& r);
677  operator >=(const LinIntExpr& l, const LinIntExpr& r);
679 
680 #ifdef GECODE_HAS_FLOAT_VARS
681  class NonLinFloatExpr {
683  public:
685  virtual FloatVar post(Home home, FloatVar* ret) const = 0;
687  virtual void post(Home home, FloatRelType frt, FloatVal c) const = 0;
689  virtual void post(Home home, FloatRelType frt, FloatVal c,
690  BoolVar b) const = 0;
692  virtual ~NonLinFloatExpr(void) {}
694  static FloatVar result(Home home, FloatVar* x) {
695  if (x == NULL)
697  return *x;
698  }
700  static FloatVar result(Home home, FloatVar* x, FloatVar y) {
701  if (x!=NULL)
702  rel(home,*x,FRT_EQ,y);
703  return y;
704  }
706  void* operator new(size_t size) { return heap.ralloc(size); }
708  void operator delete(void* p, size_t) { heap.rfree(p); }
709  };
710 
712  class LinFloatExpr {
713  friend class LinFloatRel;
714  public:
716  enum NodeType {
724  };
725  private:
727  class Node;
728  Node* n;
729  public:
732  LinFloatExpr(void);
735  LinFloatExpr(const FloatVal& c);
738  LinFloatExpr(const FloatVar& x);
741  LinFloatExpr(const FloatVar& x, FloatVal a);
744  explicit LinFloatExpr(const FloatVarArgs& x);
747  LinFloatExpr(const FloatValArgs& a, const FloatVarArgs& x);
750  LinFloatExpr(const LinFloatExpr& e);
753  LinFloatExpr(const LinFloatExpr& e0, NodeType t, const LinFloatExpr& e1);
756  LinFloatExpr(const LinFloatExpr& e0, NodeType t, const FloatVal& c);
759  LinFloatExpr(FloatVal a, const LinFloatExpr& e);
762  explicit LinFloatExpr(NonLinFloatExpr* e);
765  const LinFloatExpr& operator =(const LinFloatExpr& e);
768  void post(Home home, FloatRelType frt) const;
771  void post(Home home, FloatRelType frt, const BoolVar& b) const;
774  FloatVar post(Home home) const;
777  NonLinFloatExpr* nlfe(void) const;
780  ~LinFloatExpr(void);
781  };
782 
783  class BoolExpr;
784 
786  class LinFloatRel {
787  friend class BoolExpr;
788  private:
790  LinFloatExpr e;
792  FloatRelType frt;
794  static FloatRelType neg(FloatRelType frt);
796  LinFloatRel(void);
797  public:
799  LinFloatRel(const LinFloatExpr& l, FloatRelType frt, const LinFloatExpr& r);
805  void post(Home home, bool t) const;
807  void post(Home home, const BoolVar& b, bool t) const;
808  };
809 
825  operator +(const FloatVal&, const FloatVar&);
828  operator +(const FloatVal&, const LinFloatExpr&);
831  operator +(const FloatVar&, const FloatVal&);
834  operator +(const LinFloatExpr&, const FloatVal&);
837  operator +(const FloatVar&, const FloatVar&);
840  operator +(const FloatVar&, const LinFloatExpr&);
843  operator +(const LinFloatExpr&, const FloatVar&);
846  operator +(const LinFloatExpr&, const LinFloatExpr&);
847 
850  operator -(const FloatVal&, const FloatVar&);
853  operator -(const FloatVal&, const LinFloatExpr&);
856  operator -(const FloatVar&, const FloatVal&);
859  operator -(const LinFloatExpr&, const FloatVal&);
862  operator -(const FloatVar&, const FloatVar&);
865  operator -(const FloatVar&, const LinFloatExpr&);
868  operator -(const LinFloatExpr&, const FloatVar&);
871  operator -(const LinFloatExpr&, const LinFloatExpr&);
872 
875  operator -(const FloatVar&);
878  operator -(const LinFloatExpr&);
879 
882  operator *(const FloatVal&, const FloatVar&);
885  operator *(const FloatVar&, const FloatVal&);
888  operator *(const LinFloatExpr&, const FloatVal&);
891  operator *(const FloatVal&, const LinFloatExpr&);
892 
895  sum(const FloatVarArgs& x);
898  sum(const FloatValArgs& a, const FloatVarArgs& x);
899 
902  operator ==(const FloatVal& l, const FloatVar& r);
905  operator ==(const FloatVal& l, const LinFloatExpr& r);
908  operator ==(const FloatVar& l, const FloatVal& r);
911  operator ==(const LinFloatExpr& l, const FloatVal& r);
914  operator ==(const FloatVar& l, const FloatVar& r);
917  operator ==(const FloatVar& l, const BoolVar& r);
920  operator ==(const FloatVar& l, const LinFloatExpr& r);
923  operator ==(const LinFloatExpr& l, const FloatVar& r);
926  operator ==(const LinFloatExpr& l, const BoolVar& r);
929  operator ==(const LinFloatExpr& l, const LinFloatExpr& r);
930 
933  operator !=(const FloatVal& l, const FloatVar& r);
936  operator !=(const FloatVal& l, const LinFloatExpr& r);
939  operator !=(const FloatVar& l, const FloatVal& r);
942  operator !=(const LinFloatExpr& l, const FloatVal& r);
945  operator !=(const FloatVar& l, const FloatVar& r);
948  operator !=(const FloatVar& l, const BoolVar& r);
951  operator !=(const FloatVar& l, const LinFloatExpr& r);
954  operator !=(const LinFloatExpr& l, const FloatVar& r);
957  operator !=(const LinFloatExpr& l, const BoolVar& r);
960  operator !=(const LinFloatExpr& l, const LinFloatExpr& r);
961 
964  operator <(const FloatVal& l, const FloatVar& r);
967  operator <(const FloatVal& l, const LinFloatExpr& r);
970  operator <(const FloatVar& l, const FloatVal& r);
973  operator <(const LinFloatExpr& l, const FloatVal& r);
976  operator <(const FloatVar& l, const FloatVar& r);
979  operator <(const FloatVar& l, const LinFloatExpr& r);
982  operator <(const LinFloatExpr& l, const FloatVar& r);
985  operator <(const LinFloatExpr& l, const LinFloatExpr& r);
986 
989  operator <=(const FloatVal& l, const FloatVar& r);
992  operator <=(const FloatVal& l, const LinFloatExpr& r);
995  operator <=(const FloatVar& l, const FloatVal& r);
998  operator <=(const LinFloatExpr& l, const FloatVal& r);
1001  operator <=(const FloatVar& l, const FloatVar& r);
1004  operator <=(const FloatVar& l, const LinFloatExpr& r);
1007  operator <=(const LinFloatExpr& l, const FloatVar& r);
1010  operator <=(const LinFloatExpr& l, const LinFloatExpr& r);
1011 
1014  operator >(const FloatVal& l, const FloatVar& r);
1017  operator >(const FloatVal& l, const LinFloatExpr& r);
1020  operator >(const FloatVar& l, const FloatVal& r);
1023  operator >(const LinFloatExpr& l, const FloatVal& r);
1026  operator >(const FloatVar& l, const FloatVar& r);
1029  operator >(const FloatVar& l, const LinFloatExpr& r);
1032  operator >(const LinFloatExpr& l, const FloatVar& r);
1035  operator >(const LinFloatExpr& l, const LinFloatExpr& r);
1036 
1039  operator >=(const FloatVal& l, const FloatVar& r);
1042  operator >=(const FloatVal& l, const LinFloatExpr& r);
1045  operator >=(const FloatVar& l, const FloatVal& r);
1048  operator >=(const LinFloatExpr& l, const FloatVal& r);
1051  operator >=(const FloatVar& l, const FloatVar& r);
1054  operator >=(const FloatVar& l, const LinFloatExpr& r);
1057  operator >=(const LinFloatExpr& l, const FloatVar& r);
1060  operator >=(const LinFloatExpr& l, const LinFloatExpr& r);
1062 #endif
1063 
1064 #ifdef GECODE_HAS_SET_VARS
1065  class SetExpr {
1067  public:
1069  enum NodeType {
1077  };
1079  class Node;
1080  private:
1082  Node* n;
1083  public:
1085  SetExpr(void);
1088  SetExpr(const SetExpr& e);
1091  SetExpr(const SetExpr& l, NodeType t, const SetExpr& r);
1094  SetExpr(const SetVar& x);
1097  explicit SetExpr(const LinIntExpr& x);
1100  SetExpr(const IntSet& s);
1103  SetExpr(const SetExpr& e, NodeType t);
1106  SetVar post(Home home) const;
1109  void post(Home home, SetRelType srt, const SetExpr& e) const;
1112  void post(Home home, BoolVar b, bool t,
1113  SetRelType srt, const SetExpr& e) const;
1116  const SetExpr& operator =(const SetExpr& e);
1119  ~SetExpr(void);
1120  };
1121 
1123  class SetCmpRel {
1124  public:
1132  SetCmpRel(const SetExpr& l, SetRelType srt, const SetExpr& r);
1133  };
1134 
1136  class SetRel {
1137  private:
1139  SetExpr _e0;
1141  SetRelType _srt;
1143  SetExpr _e1;
1144  public:
1146  SetRel(void);
1148  SetRel(const SetExpr& e0, SetRelType srt, const SetExpr& e1);
1150  SetRel(const SetCmpRel& r);
1152  void post(Home home, bool t) const;
1154  void post(Home home, BoolVar b, bool t) const;
1155  };
1156 
1169  singleton(const LinIntExpr&);
1172  operator -(const SetExpr&);
1175  operator &(const SetExpr&, const SetExpr&);
1178  operator |(const SetExpr&, const SetExpr&);
1181  operator +(const SetExpr&, const SetExpr&);
1184  operator -(const SetExpr&, const SetExpr&);
1185 
1188  inter(const SetVarArgs&);
1191  setunion(const SetVarArgs&);
1194  setdunion(const SetVarArgs&);
1195 
1198  cardinality(const SetExpr&);
1201  min(const SetExpr&);
1204  max(const SetExpr&);
1205 
1208  operator ==(const SetExpr&, const SetExpr&);
1211  operator !=(const SetExpr&, const SetExpr&);
1214  operator <=(const SetExpr&, const SetExpr&);
1217  operator <=(const SetCmpRel&, const SetExpr&);
1220  operator >=(const SetExpr&, const SetExpr&);
1223  operator >=(const SetCmpRel&, const SetExpr&);
1226  operator ||(const SetExpr&, const SetExpr&);
1228 #endif
1229 
1231  class BoolExpr {
1232  public:
1234  enum NodeType {
1244  };
1246  class MiscExpr {
1247  public:
1251  virtual void post(Space& home, BoolVar b, bool neg,
1252  IntConLevel icl) = 0;
1254  virtual GECODE_MINIMODEL_EXPORT ~MiscExpr(void);
1256  static void* operator new(size_t size);
1258  static void operator delete(void* p, size_t size);
1259  };
1261  class Node;
1262  private:
1264  Node* n;
1265  public:
1268  BoolExpr(void);
1271  BoolExpr(const BoolExpr& e);
1274  BoolExpr(const BoolExpr& l, NodeType t, const BoolExpr& r);
1277  BoolExpr(const BoolVar& x);
1280  BoolExpr(const BoolExpr& e, NodeType t);
1283  BoolExpr(const LinIntRel& rl);
1284 #ifdef GECODE_HAS_FLOAT_VARS
1287  BoolExpr(const LinFloatRel& rfl);
1288 #endif
1289 #ifdef GECODE_HAS_SET_VARS
1292  BoolExpr(const SetRel& rs);
1295  BoolExpr(const SetCmpRel& rs);
1296 #endif
1299  explicit BoolExpr(MiscExpr* m);
1302  BoolVar expr(Home home, IntConLevel icl) const;
1305  void rel(Home home, IntConLevel icl) const;
1308  const BoolExpr& operator =(const BoolExpr& e);
1311  ~BoolExpr(void);
1312  };
1313 
1326  operator !(const BoolExpr&);
1329  operator &&(const BoolExpr&, const BoolExpr&);
1332  operator ||(const BoolExpr&, const BoolExpr&);
1335  operator ^(const BoolExpr&, const BoolExpr&);
1336 
1339  operator !=(const BoolExpr&, const BoolExpr&);
1342  operator ==(const BoolExpr&, const BoolExpr&);
1345  operator >>(const BoolExpr&, const BoolExpr&);
1348  operator <<(const BoolExpr&, const BoolExpr&);
1349 
1351 
1360  expr(Home home, const LinIntExpr& e, IntConLevel icl=ICL_DEF);
1361 #ifdef GECODE_HAS_FLOAT_VARS
1364  expr(Home home, const LinFloatExpr& e);
1365 #endif
1366 #ifdef GECODE_HAS_SET_VARS
1369  expr(Home home, const SetExpr& e);
1370 #endif
1373  expr(Home home, const BoolExpr& e, IntConLevel icl=ICL_DEF);
1376  rel(Home home, const BoolExpr& e, IntConLevel icl=ICL_DEF);
1378 
1379 }
1380 
1386 
1387 namespace Gecode {
1388 
1389  namespace MiniModel {
1390  class ExpInfo;
1391  }
1392 
1399  friend class MiniModel::ExpInfo;
1400  private:
1402  class Exp;
1404  Exp* e;
1406  REG(Exp* e);
1407  public:
1409  REG(void);
1411  REG(int s);
1418  REG(const IntArgs& x);
1419 
1421  REG(const REG& r);
1423  const REG& operator =(const REG& r);
1424 
1426  REG operator +(const REG& r);
1428  REG& operator +=(const REG& r);
1430  REG operator |(const REG& r);
1432  REG& operator |=(const REG& r);
1434  REG operator *(void);
1436  REG operator +(void);
1438  REG operator ()(unsigned int n, unsigned int m);
1440  REG operator ()(unsigned int n);
1442  template<class Char, class Traits>
1443  std::basic_ostream<Char,Traits>&
1444  print(std::basic_ostream<Char,Traits>& os) const;
1446  operator DFA(void);
1448  ~REG(void);
1449  };
1450 
1454  template<class Char, class Traits>
1455  std::basic_ostream<Char,Traits>&
1456  operator <<(std::basic_ostream<Char,Traits>& os, const REG& r);
1457 
1458 
1467  abs(const LinIntExpr& e);
1470  min(const LinIntExpr& x, const LinIntExpr& y);
1473  min(const IntVarArgs& x);
1476  max(const LinIntExpr& x, const LinIntExpr& y);
1479  max(const IntVarArgs& x);
1480 #ifdef GECODE_HAS_FLOAT_VARS
1483  operator *(const FloatVar&, const FloatVar&);
1486  operator *(const FloatVar&, const LinFloatExpr&);
1489  operator *(const LinFloatExpr&, const FloatVar&);
1490 #endif
1493  operator *(const LinIntExpr& x, const LinIntExpr& y);
1496  operator /(const LinIntExpr& x, const LinIntExpr& y);
1499  operator %(const LinIntExpr& x, const LinIntExpr& y);
1502  sqr(const LinIntExpr& x);
1505  sqrt(const LinIntExpr& x);
1508  pow(const LinIntExpr& x, int n);
1511  nroot(const LinIntExpr& x, int n);
1514  element(const IntVarArgs& x, const LinIntExpr& y);
1517  element(const BoolVarArgs& x, const LinIntExpr& y);
1520  element(const IntArgs& x, const LinIntExpr& y);
1523  ite(const BoolExpr& b, const LinIntExpr& x, const LinIntExpr& y);
1525 
1526 #ifdef GECODE_HAS_FLOAT_VARS
1529  abs(const LinFloatExpr& e);
1532  min(const LinFloatExpr& x, const LinFloatExpr& y);
1535  min(const FloatVarArgs& x);
1538  max(const LinFloatExpr& x, const LinFloatExpr& y);
1541  max(const FloatVarArgs& x);
1544  operator *(const LinFloatExpr& x, const LinFloatExpr& y);
1547  operator /(const LinFloatExpr& x, const LinFloatExpr& y);
1550  sqr(const LinFloatExpr& x);
1553  sqrt(const LinFloatExpr& x);
1556  pow(const LinFloatExpr& x, int n);
1559  nroot(const LinFloatExpr& x, int n);
1561 
1562 #ifdef GECODE_HAS_MPFR
1563 
1571  exp(const LinFloatExpr& x);
1574  log(const LinFloatExpr& x);
1576 
1585  asin(const LinFloatExpr& x);
1588  sin(const LinFloatExpr& x);
1591  acos(const LinFloatExpr& x);
1594  cos(const LinFloatExpr& x);
1597  atan(const LinFloatExpr& x);
1600  tan(const LinFloatExpr& x);
1602 #endif
1603 #endif
1604 
1611  inline BoolVar
1614  IntConLevel icl=ICL_DEF) {
1615  (void) icl;
1616  BoolVar b(home,0,1); channel(home,b,x);
1617  return b;
1618  }
1620  inline IntVar
1622  IntConLevel icl=ICL_DEF) {
1623  (void) icl;
1624  IntVar x(home,0,1); channel(home,b,x);
1625  return x;
1626  }
1627 #ifdef GECODE_HAS_FLOAT_VARS
1628  inline IntVar
1630  channel(Home home, FloatVar f) {
1631  int min = static_cast<int>(std::max(static_cast<double>(Int::Limits::min),
1632  std::ceil(f.min())));
1633  int max = static_cast<int>(std::min(static_cast<double>(Int::Limits::max),
1634  std::floor(f.max())));
1635  IntVar x(home,min,max);
1636  channel(home,f,x);
1637  return x;
1638  }
1639 #endif
1640 #ifdef GECODE_HAS_SET_VARS
1641  inline SetVar
1644  (void) icl;
1646  rel(home,SOT_UNION,x,s);
1647  nvalues(home,x,IRT_EQ,expr(home,cardinality(s)));
1648  return s;
1649  }
1650 #endif
1651 
1652 
1653 }
1654 
1655 namespace Gecode {
1656 
1671  inline void
1672  atmost(Home home, const IntVarArgs& x, int n, int m,
1673  IntConLevel icl=ICL_DEF) {
1674  count(home,x,n,IRT_LQ,m,icl);
1675  }
1680  inline void
1681  atmost(Home home, const IntVarArgs& x, IntVar y, int m,
1682  IntConLevel icl=ICL_DEF) {
1683  count(home,x,y,IRT_LQ,m,icl);
1684  }
1692  inline void
1693  atmost(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1694  IntConLevel icl=ICL_DEF) {
1695  count(home,x,y,IRT_LQ,m,icl);
1696  }
1701  inline void
1702  atmost(Home home, const IntVarArgs& x, int n, IntVar z,
1703  IntConLevel icl=ICL_DEF) {
1704  count(home,x,n,IRT_LQ,z,icl);
1705  }
1710  inline void
1711  atmost(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1712  IntConLevel icl=ICL_DEF) {
1713  count(home,x,y,IRT_LQ,z,icl);
1714  }
1722  inline void
1723  atmost(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1724  IntConLevel icl=ICL_DEF) {
1725  count(home,x,y,IRT_LQ,z,icl);
1726  }
1727 
1732  inline void
1733  atleast(Home home, const IntVarArgs& x, int n, int m,
1734  IntConLevel icl=ICL_DEF) {
1735  count(home,x,n,IRT_GQ,m,icl);
1736  }
1741  inline void
1742  atleast(Home home, const IntVarArgs& x, IntVar y, int m,
1743  IntConLevel icl=ICL_DEF) {
1744  count(home,x,y,IRT_GQ,m,icl);
1745  }
1753  inline void
1754  atleast(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1755  IntConLevel icl=ICL_DEF) {
1756  count(home,x,y,IRT_GQ,m,icl);
1757  }
1762  inline void
1763  atleast(Home home, const IntVarArgs& x, int n, IntVar z,
1764  IntConLevel icl=ICL_DEF) {
1765  count(home,x,n,IRT_GQ,z,icl);
1766  }
1771  inline void
1772  atleast(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1773  IntConLevel icl=ICL_DEF) {
1774  count(home,x,y,IRT_GQ,z,icl);
1775  }
1783  inline void
1784  atleast(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1785  IntConLevel icl=ICL_DEF) {
1786  count(home,x,y,IRT_GQ,z,icl);
1787  }
1788 
1793  inline void
1794  exactly(Home home, const IntVarArgs& x, int n, int m,
1795  IntConLevel icl=ICL_DEF) {
1796  count(home,x,n,IRT_EQ,m,icl);
1797  }
1802  inline void
1803  exactly(Home home, const IntVarArgs& x, IntVar y, int m,
1804  IntConLevel icl=ICL_DEF) {
1805  count(home,x,y,IRT_EQ,m,icl);
1806  }
1814  inline void
1815  exactly(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1816  IntConLevel icl=ICL_DEF) {
1817  count(home,x,y,IRT_EQ,m,icl);
1818  }
1823  inline void
1824  exactly(Home home, const IntVarArgs& x, int n, IntVar z,
1825  IntConLevel icl=ICL_DEF) {
1826  count(home,x,n,IRT_EQ,z,icl);
1827  }
1832  inline void
1833  exactly(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1834  IntConLevel icl=ICL_DEF) {
1835  count(home,x,y,IRT_EQ,z,icl);
1836  }
1844  inline void
1845  exactly(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1846  IntConLevel icl=ICL_DEF) {
1847  count(home,x,y,IRT_EQ,z,icl);
1848  }
1851  inline void
1852  lex(Home home, const IntVarArgs& x, IntRelType r, const IntVarArgs& y,
1853  IntConLevel icl=ICL_DEF) {
1854  rel(home,x,r,y,icl);
1855  }
1858  inline void
1859  lex(Home home, const BoolVarArgs& x, IntRelType r, const BoolVarArgs& y,
1860  IntConLevel icl=ICL_DEF) {
1861  rel(home,x,r,y,icl);
1862  }
1865  inline void
1866  values(Home home, const IntVarArgs& x, IntSet y,
1867  IntConLevel icl=ICL_DEF) {
1868  dom(home,x,y,icl);
1869  nvalues(home,x,IRT_EQ,y.size(),icl);
1870  }
1871 
1873 
1874 #ifdef GECODE_HAS_SET_VARS
1875 
1890  inline void
1891  channel(Home home, const IntVarArgs& x, SetVar y) {
1892  rel(home,SOT_UNION,x,y);
1893  nvalues(home,x,IRT_EQ,expr(home,cardinality(y)));
1894  }
1895 
1898  inline void
1899  range(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1900  element(home,SOT_UNION,x,y,z);
1901  }
1902 
1908  inline void
1909  roots(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1910  SetVarArgs xiv(home,z.lubMax()+1,IntSet::empty,0,x.size()-1);
1911  channel(home,x,xiv);
1912  element(home,SOT_UNION,xiv,z,y);
1913  }
1914 
1916 #endif
1917 }
1918 
1919 namespace Gecode {
1920 
1921  template<class> class Matrix;
1922 
1930  template<class A>
1931  class Slice {
1932  public:
1935  private:
1936  ArgsType _r;
1937  unsigned int _fc,
1938  _tc,
1939  _fr,
1940  _tr;
1941  public:
1943  Slice(const Matrix<A>& a, int fc, int tc, int fr, int tr);
1947  Slice& reverse(void);
1949  operator ArgsType(void);
1951  operator Matrix<ArgsType>(void);
1952 
1954  operator const ArgsType(void) const;
1956  operator const Matrix<ArgsType>(void) const;
1957  };
1958 
1960  template<class A>
1961  typename Slice<A>::ArgsType
1962  operator+(const Slice<A>& x, const Slice<A>& y);
1963 
1965  template<class A>
1966  typename Slice<A>::ArgsType
1967  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ArgsType& y);
1968 
1970  template<class A>
1971  typename Slice<A>::ArgsType
1972  operator+(const typename ArrayTraits<A>::ArgsType& x, const Slice<A>& y);
1973 
1975  template<class A>
1976  typename Slice<A>::ArgsType
1977  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ValueType& y);
1978 
1980  template<class A>
1981  typename Slice<A>::ArgsType
1982  operator+(const typename ArrayTraits<A>::ValueType& x, const Slice<A>& y);
1983 
1994  template<class A>
1995  class Matrix {
1996  public:
2001 
2002  private:
2004  typedef typename ArrayTraits<A>::StorageType StorageType;
2005  StorageType _a;
2006  int _w;
2007  int _h;
2008 
2009  public:
2022  Matrix(A a, int w, int h);
2023 
2036  Matrix(A a, int n);
2037 
2039  int width(void) const;
2041  int height(void) const;
2043  ArgsType const get_array(void) const;
2044 
2050  ValueType& operator ()(int c, int r);
2051 
2057  const ValueType& operator ()(int c, int r) const;
2058 
2068  Slice<A> slice(int fc, int tc, int fr, int tr) const;
2069 
2071  Slice<A> row(int r) const;
2072 
2074  Slice<A> col(int c) const;
2075  };
2076 
2080  template<class Char, class Traits, class A>
2081  std::basic_ostream<Char,Traits>&
2082  operator <<(std::basic_ostream<Char,Traits>& os, const Matrix<A>& m);
2083 
2087  template<class Char, class Traits, class A>
2088  std::basic_ostream<Char,Traits>&
2089  operator <<(std::basic_ostream<Char,Traits>& os, const Slice<A>& s);
2090 
2097  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
2098  IntVar z, IntConLevel icl=ICL_DEF);
2105  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
2106  BoolVar z, IntConLevel icl=ICL_DEF);
2113  void element(Home home, const Matrix<IntVarArgs>& m, IntVar x, IntVar y,
2114  IntVar z, IntConLevel icl=ICL_DEF);
2121  void element(Home home, const Matrix<BoolVarArgs>& m, IntVar x, IntVar y,
2122  BoolVar z, IntConLevel icl=ICL_DEF);
2123 #ifdef GECODE_HAS_SET_VARS
2124 
2130  void element(Home home, const Matrix<IntSetArgs>& m, IntVar x, IntVar y,
2131  SetVar z);
2138  void element(Home home, const Matrix<SetVarArgs>& m, IntVar x, IntVar y,
2139  SetVar z);
2140 #endif
2141 
2145  template<class A>
2150  template<class A>
2155  template<class A>
2160  template<class A>
2167  template<class A>
2169 }
2170 
2171 #include <gecode/minimodel/matrix.hpp>
2172 #include <gecode/minimodel/ldsb.hpp>
2173 
2174 namespace Gecode {
2175 
2185  namespace MiniModel {
2186 
2188  template<IntRelType irt>
2189  class IntOptimizeSpace : public Space {
2190  public:
2192  IntOptimizeSpace(void);
2194  IntOptimizeSpace(bool share, IntOptimizeSpace& s);
2196  virtual void constrain(const Space& best);
2198  virtual IntVar cost(void) const = 0;
2199  };
2200 
2201 #ifdef GECODE_HAS_FLOAT_VARS
2202 
2204  template<FloatRelType frt>
2205  class FloatOptimizeSpace : public Space {
2206  public:
2208  FloatOptimizeSpace(void);
2210  FloatOptimizeSpace(bool share, FloatOptimizeSpace& s);
2212  virtual void constrain(const Space& best);
2214  virtual FloatVar cost(void) const = 0;
2215  };
2216 
2217 #endif
2218 
2219  }
2220 
2229 
2230 #ifdef GECODE_HAS_FLOAT_VARS
2231 
2236 
2237 #endif
2238 
2240 
2241 }
2242 
2244 
2245 #endif
2246 
2247 // IFDEF: GECODE_HAS_INT_VARS
2248 // STATISTICS: minimodel-any
2249