Generated on Sat May 25 2013 18:00:40 for Gecode by doxygen 1.8.3.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  * 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-03-08 01:36:33 +0100 (Fri, 08 Mar 2013) $ by $Author: tack $
17  * $Revision: 13470 $
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 
269 
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 
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 
823 
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 
1066  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 
1167 
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
1285 
1287  BoolExpr(const LinFloatRel& rfl);
1288 #endif
1289 #ifdef GECODE_HAS_SET_VARS
1290 
1292  BoolExpr(const SetRel& rs);
1295  BoolExpr(const SetCmpRel& rs);
1296 #endif
1297 
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 
1324 
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 
1358 
1360  expr(Home home, const LinIntExpr& e, IntConLevel icl=ICL_DEF);
1361 #ifdef GECODE_HAS_FLOAT_VARS
1362 
1364  expr(Home home, const LinFloatExpr& e);
1365 #endif
1366 #ifdef GECODE_HAS_SET_VARS
1367 
1369  expr(Home home, const SetExpr& e);
1370 #endif
1371 
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 
1465 
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
1481 
1483  operator *(const FloatVar&, const FloatVar&);
1486  operator *(const FloatVar&, const LinFloatExpr&);
1489  operator *(const LinFloatExpr&, const FloatVar&);
1490 #endif
1491 
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);
1522 
1523 #ifdef GECODE_HAS_FLOAT_VARS
1524 
1526  abs(const LinFloatExpr& e);
1529  min(const LinFloatExpr& x, const LinFloatExpr& y);
1532  min(const FloatVarArgs& x);
1535  max(const LinFloatExpr& x, const LinFloatExpr& y);
1538  max(const FloatVarArgs& x);
1541  operator *(const LinFloatExpr& x, const LinFloatExpr& y);
1544  operator /(const LinFloatExpr& x, const LinFloatExpr& y);
1547  sqr(const LinFloatExpr& x);
1550  sqrt(const LinFloatExpr& x);
1553  pow(const LinFloatExpr& x, int n);
1556  nroot(const LinFloatExpr& x, int n);
1558 
1559 #ifdef GECODE_HAS_MPFR
1560 
1566 
1568  exp(const LinFloatExpr& x);
1571  log(const LinFloatExpr& x);
1573 
1580 
1582  asin(const LinFloatExpr& x);
1585  sin(const LinFloatExpr& x);
1588  acos(const LinFloatExpr& x);
1591  cos(const LinFloatExpr& x);
1594  atan(const LinFloatExpr& x);
1597  tan(const LinFloatExpr& x);
1599 #endif
1600 #endif
1601 
1608 
1609  inline BoolVar
1611  IntConLevel icl=ICL_DEF) {
1612  (void) icl;
1613  BoolVar b(home,0,1); channel(home,b,x);
1614  return b;
1615  }
1617  inline IntVar
1619  IntConLevel icl=ICL_DEF) {
1620  (void) icl;
1621  IntVar x(home,0,1); channel(home,b,x);
1622  return x;
1623  }
1624 #ifdef GECODE_HAS_FLOAT_VARS
1625 
1626  inline IntVar
1627  channel(Home home, FloatVar f) {
1628  int min = static_cast<int>(std::max(static_cast<double>(Int::Limits::min),
1629  std::ceil(f.min())));
1630  int max = static_cast<int>(std::min(static_cast<double>(Int::Limits::max),
1631  std::floor(f.max())));
1632  IntVar x(home,min,max);
1633  channel(home,f,x);
1634  return x;
1635  }
1636 #endif
1637 #ifdef GECODE_HAS_SET_VARS
1638 
1639  inline SetVar
1641  (void) icl;
1643  rel(home,SOT_UNION,x,s);
1644  nvalues(home,x,IRT_EQ,expr(home,cardinality(s)));
1645  return s;
1646  }
1647 #endif
1648 
1649 
1650 }
1651 
1652 namespace Gecode {
1653 
1668  inline void
1669  atmost(Home home, const IntVarArgs& x, int n, int m,
1670  IntConLevel icl=ICL_DEF) {
1671  count(home,x,n,IRT_LQ,m,icl);
1672  }
1677  inline void
1678  atmost(Home home, const IntVarArgs& x, IntVar y, int m,
1679  IntConLevel icl=ICL_DEF) {
1680  count(home,x,y,IRT_LQ,m,icl);
1681  }
1689  inline void
1690  atmost(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1691  IntConLevel icl=ICL_DEF) {
1692  count(home,x,y,IRT_LQ,m,icl);
1693  }
1698  inline void
1699  atmost(Home home, const IntVarArgs& x, int n, IntVar z,
1700  IntConLevel icl=ICL_DEF) {
1701  count(home,x,n,IRT_LQ,z,icl);
1702  }
1707  inline void
1708  atmost(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1709  IntConLevel icl=ICL_DEF) {
1710  count(home,x,y,IRT_LQ,z,icl);
1711  }
1719  inline void
1720  atmost(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1721  IntConLevel icl=ICL_DEF) {
1722  count(home,x,y,IRT_LQ,z,icl);
1723  }
1724 
1729  inline void
1730  atleast(Home home, const IntVarArgs& x, int n, int m,
1731  IntConLevel icl=ICL_DEF) {
1732  count(home,x,n,IRT_GQ,m,icl);
1733  }
1738  inline void
1739  atleast(Home home, const IntVarArgs& x, IntVar y, int m,
1740  IntConLevel icl=ICL_DEF) {
1741  count(home,x,y,IRT_GQ,m,icl);
1742  }
1750  inline void
1751  atleast(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1752  IntConLevel icl=ICL_DEF) {
1753  count(home,x,y,IRT_GQ,m,icl);
1754  }
1759  inline void
1760  atleast(Home home, const IntVarArgs& x, int n, IntVar z,
1761  IntConLevel icl=ICL_DEF) {
1762  count(home,x,n,IRT_GQ,z,icl);
1763  }
1768  inline void
1769  atleast(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1770  IntConLevel icl=ICL_DEF) {
1771  count(home,x,y,IRT_GQ,z,icl);
1772  }
1780  inline void
1781  atleast(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1782  IntConLevel icl=ICL_DEF) {
1783  count(home,x,y,IRT_GQ,z,icl);
1784  }
1785 
1790  inline void
1791  exactly(Home home, const IntVarArgs& x, int n, int m,
1792  IntConLevel icl=ICL_DEF) {
1793  count(home,x,n,IRT_EQ,m,icl);
1794  }
1799  inline void
1800  exactly(Home home, const IntVarArgs& x, IntVar y, int m,
1801  IntConLevel icl=ICL_DEF) {
1802  count(home,x,y,IRT_EQ,m,icl);
1803  }
1811  inline void
1812  exactly(Home home, const IntVarArgs& x, const IntArgs& y, int m,
1813  IntConLevel icl=ICL_DEF) {
1814  count(home,x,y,IRT_EQ,m,icl);
1815  }
1820  inline void
1821  exactly(Home home, const IntVarArgs& x, int n, IntVar z,
1822  IntConLevel icl=ICL_DEF) {
1823  count(home,x,n,IRT_EQ,z,icl);
1824  }
1829  inline void
1830  exactly(Home home, const IntVarArgs& x, IntVar y, IntVar z,
1831  IntConLevel icl=ICL_DEF) {
1832  count(home,x,y,IRT_EQ,z,icl);
1833  }
1841  inline void
1842  exactly(Home home, const IntVarArgs& x, const IntArgs& y, IntVar z,
1843  IntConLevel icl=ICL_DEF) {
1844  count(home,x,y,IRT_EQ,z,icl);
1845  }
1848  inline void
1849  lex(Home home, const IntVarArgs& x, IntRelType r, const IntVarArgs& y,
1850  IntConLevel icl=ICL_DEF) {
1851  rel(home,x,r,y,icl);
1852  }
1855  inline void
1856  lex(Home home, const BoolVarArgs& x, IntRelType r, const BoolVarArgs& y,
1857  IntConLevel icl=ICL_DEF) {
1858  rel(home,x,r,y,icl);
1859  }
1862  inline void
1863  values(Home home, const IntVarArgs& x, IntSet y,
1864  IntConLevel icl=ICL_DEF) {
1865  dom(home,x,y,icl);
1866  nvalues(home,x,IRT_EQ,y.size(),icl);
1867  }
1868 
1870 
1871 #ifdef GECODE_HAS_SET_VARS
1872 
1887  inline void
1888  channel(Home home, const IntVarArgs& x, SetVar y) {
1889  rel(home,SOT_UNION,x,y);
1890  nvalues(home,x,IRT_EQ,expr(home,cardinality(y)));
1891  }
1892 
1895  inline void
1896  range(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1897  element(home,SOT_UNION,x,y,z);
1898  }
1899 
1905  inline void
1906  roots(Home home, const IntVarArgs& x, SetVar y, SetVar z) {
1907  SetVarArgs xiv(home,z.lubMax()+1,IntSet::empty,0,x.size()-1);
1908  channel(home,x,xiv);
1909  element(home,SOT_UNION,xiv,z,y);
1910  }
1911 
1913 #endif
1914 }
1915 
1916 namespace Gecode {
1917 
1918  template<class> class Matrix;
1919 
1927  template<class A>
1928  class Slice {
1929  public:
1932  private:
1933  ArgsType _r;
1934  unsigned int _fc,
1935  _tc,
1936  _fr,
1937  _tr;
1938  public:
1940  Slice(const Matrix<A>& a, int fc, int tc, int fr, int tr);
1944  Slice& reverse(void);
1946  operator ArgsType(void);
1948  operator Matrix<ArgsType>(void);
1949 
1951  operator const ArgsType(void) const;
1953  operator const Matrix<ArgsType>(void) const;
1954  };
1955 
1957  template<class A>
1958  typename Slice<A>::ArgsType
1959  operator+(const Slice<A>& x, const Slice<A>& y);
1960 
1962  template<class A>
1963  typename Slice<A>::ArgsType
1964  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ArgsType& y);
1965 
1967  template<class A>
1968  typename Slice<A>::ArgsType
1969  operator+(const typename ArrayTraits<A>::ArgsType& x, const Slice<A>& y);
1970 
1972  template<class A>
1973  typename Slice<A>::ArgsType
1974  operator+(const Slice<A>& x, const typename ArrayTraits<A>::ValueType& y);
1975 
1977  template<class A>
1978  typename Slice<A>::ArgsType
1979  operator+(const typename ArrayTraits<A>::ValueType& x, const Slice<A>& y);
1980 
1991  template<class A>
1992  class Matrix {
1993  public:
1998 
1999  private:
2001  typedef typename ArrayTraits<A>::StorageType StorageType;
2002  StorageType _a;
2003  int _w;
2004  int _h;
2005 
2006  public:
2019  Matrix(A a, int w, int h);
2020 
2033  Matrix(A a, int n);
2034 
2036  int width(void) const;
2038  int height(void) const;
2040  ArgsType const get_array(void) const;
2041 
2047  ValueType& operator ()(int c, int r);
2048 
2054  const ValueType& operator ()(int c, int r) const;
2055 
2065  Slice<A> slice(int fc, int tc, int fr, int tr) const;
2066 
2068  Slice<A> row(int r) const;
2069 
2071  Slice<A> col(int c) const;
2072  };
2073 
2077  template<class Char, class Traits, class A>
2078  std::basic_ostream<Char,Traits>&
2079  operator <<(std::basic_ostream<Char,Traits>& os, const Matrix<A>& m);
2080 
2084  template<class Char, class Traits, class A>
2085  std::basic_ostream<Char,Traits>&
2086  operator <<(std::basic_ostream<Char,Traits>& os, const Slice<A>& s);
2087 
2094  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
2095  IntVar z, IntConLevel icl=ICL_DEF);
2102  void element(Home home, const Matrix<IntArgs>& m, IntVar x, IntVar y,
2103  BoolVar z, IntConLevel icl=ICL_DEF);
2110  void element(Home home, const Matrix<IntVarArgs>& m, IntVar x, IntVar y,
2111  IntVar z, IntConLevel icl=ICL_DEF);
2118  void element(Home home, const Matrix<BoolVarArgs>& m, IntVar x, IntVar y,
2119  BoolVar z, IntConLevel icl=ICL_DEF);
2120 #ifdef GECODE_HAS_SET_VARS
2121 
2127  void element(Home home, const Matrix<IntSetArgs>& m, IntVar x, IntVar y,
2128  SetVar z);
2135  void element(Home home, const Matrix<SetVarArgs>& m, IntVar x, IntVar y,
2136  SetVar z);
2137 #endif
2138 
2142  template<class A>
2147  template<class A>
2152  template<class A>
2157  template<class A>
2164  template<class A>
2166 }
2167 
2168 #include <gecode/minimodel/matrix.hpp>
2169 #include <gecode/minimodel/ldsb.hpp>
2170 
2171 namespace Gecode {
2172 
2182  namespace MiniModel {
2183 
2185  template<IntRelType irt>
2186  class OptimizeSpace : public Space {
2187  public:
2189  OptimizeSpace(void);
2191  OptimizeSpace(bool share, OptimizeSpace& s);
2193  virtual void constrain(const Space& best);
2195  virtual IntVar cost(void) const = 0;
2196  };
2197 
2198  }
2199 
2202 
2206 
2207 }
2208 
2210 
2211 #endif
2212 
2213 // IFDEF: GECODE_HAS_INT_VARS
2214 // STATISTICS: minimodel-any
2215