00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <iostream>
00039
00040 #if (-17 / 7) == -2
00041 #define GECODE_INT_RND_TWDS_ZERO 1
00042 #else
00043 #define GECODE_INT_RND_TWDS_ZERO 0
00044 #endif
00045
00046 namespace Gecode { namespace Int {
00047
00059 template<class View>
00060 class ViewRanges {
00061 public:
00063
00064
00065 ViewRanges(void);
00067 ViewRanges(const View& x);
00069 void init(const View& x);
00071
00073
00074
00075 bool operator ()(void) const;
00077 void operator ++(void);
00079
00081
00082
00083 int min(void) const;
00085 int max(void) const;
00087 unsigned int width(void) const;
00089 };
00090
00099 template<class View>
00100 class ViewValues : public Iter::Ranges::ToValues<ViewRanges<View> > {
00101 public:
00103
00104
00105 ViewValues(void);
00107 ViewValues(const View& x);
00109 void init(const View& x);
00111 };
00112
00113 }}
00114
00115 #include <gecode/int/view/iter.hpp>
00116
00117 namespace Gecode { namespace Int {
00118
00135 class IntView : public VarImpView<IntVar> {
00136 protected:
00137 using VarImpView<IntVar>::x;
00138 public:
00140
00141
00142 IntView(void);
00144 IntView(const IntVar& y);
00146 IntView(IntVarImp* y);
00148
00150
00151
00152 int min(void) const;
00154 int max(void) const;
00156 int med(void) const;
00158 int val(void) const;
00159
00161 unsigned int size(void) const;
00163 unsigned int width(void) const;
00165 unsigned int regret_min(void) const;
00167 unsigned int regret_max(void) const;
00169
00171
00172
00173 bool range(void) const;
00174
00176 bool in(int n) const;
00178 bool in(double n) const;
00180
00182
00183
00184 ModEvent lq(Space& home, int n);
00186 ModEvent lq(Space& home, double n);
00187
00189 ModEvent le(Space& home, int n);
00191 ModEvent le(Space& home, double n);
00192
00194 ModEvent gq(Space& home, int n);
00196 ModEvent gq(Space& home, double n);
00197
00199 ModEvent gr(Space& home, int n);
00201 ModEvent gr(Space& home, double n);
00203 ModEvent nq(Space& home, int n);
00205 ModEvent nq(Space& home, double n);
00206
00208 ModEvent eq(Space& home, int n);
00210 ModEvent eq(Space& home, double n);
00212
00228
00229 template<class I>
00230 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00232 template<class I>
00233 ModEvent inter_r(Space& home, I& i, bool depends=true);
00235 template<class I>
00236 ModEvent minus_r(Space& home, I& i, bool depends=true);
00238 template<class I>
00239 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00241 template<class I>
00242 ModEvent inter_v(Space& home, I& i, bool depends=true);
00244 template<class I>
00245 ModEvent minus_v(Space& home, I& i, bool depends=true);
00247
00249
00250
00251 int min(const Delta& d) const;
00253 int max(const Delta& d) const;
00255 bool any(const Delta& d) const;
00257
00259
00260
00261 static ModEventDelta med(ModEvent me);
00263 };
00264
00269 template<class Char, class Traits>
00270 std::basic_ostream<Char,Traits>&
00271 operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x);
00272
00273
00281 class MinusView : public DerivedView<IntView> {
00282 protected:
00283 using DerivedView<IntView>::x;
00284 public:
00286
00287
00288 MinusView(void);
00290 explicit MinusView(const IntView& y);
00292
00294
00295
00296 int min(void) const;
00298 int max(void) const;
00300 int med(void) const;
00302 int val(void) const;
00303
00305 unsigned int size(void) const;
00307 unsigned int width(void) const;
00309 unsigned int regret_min(void) const;
00311 unsigned int regret_max(void) const;
00313
00315
00316
00317 bool range(void) const;
00318
00320 bool in(int n) const;
00322 bool in(double n) const;
00324
00326
00327
00328 ModEvent lq(Space& home, int n);
00330 ModEvent lq(Space& home, double n);
00332 ModEvent le(Space& home, int n);
00334 ModEvent le(Space& home, double n);
00336 ModEvent gq(Space& home, int n);
00338 ModEvent gq(Space& home, double n);
00340 ModEvent gr(Space& home, int n);
00342 ModEvent gr(Space& home, double n);
00344 ModEvent nq(Space& home, int n);
00346 ModEvent nq(Space& home, double n);
00348 ModEvent eq(Space& home, int n);
00350 ModEvent eq(Space& home, double n);
00352
00368
00369 template<class I>
00370 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00372 template<class I>
00373 ModEvent inter_r(Space& home, I& i, bool depends=true);
00375 template<class I>
00376 ModEvent minus_r(Space& home, I& i, bool depends=true);
00378 template<class I>
00379 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00381 template<class I>
00382 ModEvent inter_v(Space& home, I& i, bool depends=true);
00384 template<class I>
00385 ModEvent minus_v(Space& home, I& i, bool depends=true);
00387
00389
00390
00391 static ModEventDelta med(ModEvent me);
00393
00395
00396
00397 int min(const Delta& d) const;
00399 int max(const Delta& d) const;
00401 bool any(const Delta& d) const;
00403 };
00404
00409 template<class Char, class Traits>
00410 std::basic_ostream<Char,Traits>&
00411 operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x);
00412
00413
00422 class OffsetView : public DerivedView<IntView> {
00423 protected:
00425 int c;
00426 using DerivedView<IntView>::x;
00427 public:
00429
00430
00431 OffsetView(void);
00433 OffsetView(const IntView& y, int c);
00435
00437
00438
00439 int offset(void) const;
00441 void offset(int n);
00443 int min(void) const;
00445 int max(void) const;
00447 int med(void) const;
00449 int val(void) const;
00450
00452 unsigned int size(void) const;
00454 unsigned int width(void) const;
00456 unsigned int regret_min(void) const;
00458 unsigned int regret_max(void) const;
00460
00462
00463
00464 bool range(void) const;
00465
00467 bool in(int n) const;
00469 bool in(double n) const;
00471
00473
00474
00475 ModEvent lq(Space& home, int n);
00477 ModEvent lq(Space& home, double n);
00479 ModEvent le(Space& home, int n);
00481 ModEvent le(Space& home, double n);
00483 ModEvent gq(Space& home, int n);
00485 ModEvent gq(Space& home, double n);
00487 ModEvent gr(Space& home, int n);
00489 ModEvent gr(Space& home, double n);
00491 ModEvent nq(Space& home, int n);
00493 ModEvent nq(Space& home, double n);
00495 ModEvent eq(Space& home, int n);
00497 ModEvent eq(Space& home, double n);
00499
00515
00516 template<class I>
00517 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00519 template<class I>
00520 ModEvent inter_r(Space& home, I& i, bool depends=true);
00522 template<class I>
00523 ModEvent minus_r(Space& home, I& i, bool depends=true);
00525 template<class I>
00526 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00528 template<class I>
00529 ModEvent inter_v(Space& home, I& i, bool depends=true);
00531 template<class I>
00532 ModEvent minus_v(Space& home, I& i, bool depends=true);
00534
00536
00537
00538 static ModEventDelta med(ModEvent me);
00540
00542
00543
00544 int min(const Delta& d) const;
00546 int max(const Delta& d) const;
00548 bool any(const Delta& d) const;
00550
00552
00553
00554 void update(Space& home, bool share, OffsetView& y);
00556 };
00557
00562 template<class Char, class Traits>
00563 std::basic_ostream<Char,Traits>&
00564 operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x);
00565
00570
00571 bool same(const OffsetView& x, const OffsetView& y);
00573 bool before(const OffsetView& x, const OffsetView& y);
00575
00576
00602 template<class Val, class UnsVal>
00603 class ScaleView : public DerivedView<IntView> {
00604 protected:
00605 using DerivedView<IntView>::x;
00607 int a;
00609
00610
00611 int floor_div(double y) const;
00613 int ceil_div(double y) const;
00615 int exact_div(double y, bool& exact) const;
00616 #if GECODE_INT_RND_TWDS_ZERO
00617
00618 int floor_div(int y) const;
00620 int ceil_div(int y) const;
00622 int exact_div(int y, bool& exact) const;
00623 #endif
00624
00625
00626 public:
00628
00629
00630 ScaleView(void);
00632 ScaleView(int b, const IntView& y);
00634
00636
00637
00638 int scale(void) const;
00640 Val min(void) const;
00642 Val max(void) const;
00644 Val med(void) const;
00646 Val val(void) const;
00647
00649 UnsVal size(void) const;
00651 UnsVal width(void) const;
00653 UnsVal regret_min(void) const;
00655 UnsVal regret_max(void) const;
00657
00659
00660
00661 bool range(void) const;
00663 bool in(Val n) const;
00665
00667
00668
00669 ModEvent lq(Space& home, Val n);
00671 ModEvent le(Space& home, Val n);
00673 ModEvent gq(Space& home, Val n);
00675 ModEvent gr(Space& home, Val n);
00677 ModEvent nq(Space& home, Val n);
00679 ModEvent eq(Space& home, Val n);
00681
00683
00684
00685 static ModEventDelta med(ModEvent me);
00687
00689
00690
00691 Val min(const Delta& d) const;
00693 Val max(const Delta& d) const;
00695 bool any(const Delta& d) const;
00697
00699
00700
00701 void update(Space& home, bool share, ScaleView<Val,UnsVal>& y);
00703 };
00704
00709 typedef ScaleView<int,unsigned int> IntScaleView;
00710
00715 typedef ScaleView<double,double> DoubleScaleView;
00716
00721 template<class Char, class Traits>
00722 std::basic_ostream<Char,Traits>&
00723 operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x);
00724
00729 template<class Char, class Traits>
00730 std::basic_ostream<Char,Traits>&
00731 operator <<(std::basic_ostream<Char,Traits>& os, const DoubleScaleView& x);
00732
00737
00738 template<class Val, class UnsVal>
00739 bool same(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y);
00741 template<class Val, class UnsVal>
00742 bool before(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y);
00744
00745
00746
00754 class ConstIntView : public ConstView<IntView> {
00755 protected:
00756 int x;
00757 public:
00759
00760
00761 ConstIntView(void);
00763 ConstIntView(int n);
00765
00767
00768
00769 int min(void) const;
00771 int max(void) const;
00773 int med(void) const;
00775 int val(void) const;
00776
00778 unsigned int size(void) const;
00780 unsigned int width(void) const;
00782 unsigned int regret_min(void) const;
00784 unsigned int regret_max(void) const;
00786
00788
00789
00790 bool range(void) const;
00792 bool in(int n) const;
00794 bool in(double n) const;
00796
00798
00799
00800 ModEvent lq(Space& home, int n);
00802 ModEvent lq(Space& home, double n);
00804 ModEvent le(Space& home, int n);
00806 ModEvent le(Space& home, double n);
00808 ModEvent gq(Space& home, int n);
00810 ModEvent gq(Space& home, double n);
00812 ModEvent gr(Space& home, int n);
00814 ModEvent gr(Space& home, double n);
00816 ModEvent nq(Space& home, int n);
00818 ModEvent nq(Space& home, double n);
00820 ModEvent eq(Space& home, int n);
00822 ModEvent eq(Space& home, double n);
00824
00840
00841 template<class I>
00842 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00844 template<class I>
00845 ModEvent inter_r(Space& home, I& i, bool depends=true);
00847 template<class I>
00848 ModEvent minus_r(Space& home, I& i, bool depends=true);
00850 template<class I>
00851 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00853 template<class I>
00854 ModEvent inter_v(Space& home, I& i, bool depends=true);
00856 template<class I>
00857 ModEvent minus_v(Space& home, I& i, bool depends=true);
00859
00861
00862
00863 int min(const Delta& d) const;
00865 int max(const Delta& d) const;
00867 bool any(const Delta& d) const;
00869
00871
00872
00873 void update(Space& home, bool share, ConstIntView& y);
00875 };
00876
00881 template<class Char, class Traits>
00882 std::basic_ostream<Char,Traits>&
00883 operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x);
00884
00890
00891 bool same(const ConstIntView& x, const ConstIntView& y);
00893 bool before(const ConstIntView& x, const ConstIntView& y);
00895
00896
00904 class ZeroIntView : public ConstView<IntView> {
00905 public:
00907
00908
00909 ZeroIntView(void);
00911
00913
00914
00915 int min(void) const;
00917 int max(void) const;
00919 int med(void) const;
00921 int val(void) const;
00922
00924 unsigned int size(void) const;
00926 unsigned int width(void) const;
00928 unsigned int regret_min(void) const;
00930 unsigned int regret_max(void) const;
00932
00934
00935
00936 bool range(void) const;
00938 bool in(int n) const;
00940 bool in(double n) const;
00942
00944
00945
00946 ModEvent lq(Space& home, int n);
00948 ModEvent lq(Space& home, double n);
00950 ModEvent le(Space& home, int n);
00952 ModEvent le(Space& home, double n);
00954 ModEvent gq(Space& home, int n);
00956 ModEvent gq(Space& home, double n);
00958 ModEvent gr(Space& home, int n);
00960 ModEvent gr(Space& home, double n);
00962 ModEvent nq(Space& home, int n);
00964 ModEvent nq(Space& home, double n);
00966 ModEvent eq(Space& home, int n);
00968 ModEvent eq(Space& home, double n);
00970
00986
00987 template<class I>
00988 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00990 template<class I>
00991 ModEvent inter_r(Space& home, I& i, bool depends=true);
00993 template<class I>
00994 ModEvent minus_r(Space& home, I& i, bool depends=true);
00996 template<class I>
00997 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00999 template<class I>
01000 ModEvent inter_v(Space& home, I& i, bool depends=true);
01002 template<class I>
01003 ModEvent minus_v(Space& home, I& i, bool depends=true);
01005
01007
01008
01009 int min(const Delta& d) const;
01011 int max(const Delta& d) const;
01013 bool any(const Delta& d) const;
01015 };
01016
01021 template<class Char, class Traits>
01022 std::basic_ostream<Char,Traits>&
01023 operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView& x);
01024
01030
01031 bool same(const ZeroIntView& x, const ZeroIntView& y);
01033
01034
01035
01042 class BoolView : public VarImpView<BoolVar> {
01043 protected:
01044 using VarImpView<BoolVar>::x;
01045 public:
01047
01048
01049 BoolView(void);
01051 BoolView(const BoolVar& y);
01053 BoolView(BoolVarImp* y);
01055
01057
01058
01059 static const int BITS = BoolVarImp::BITS;
01061 static const BoolStatus ZERO = BoolVarImp::ZERO;
01063 static const BoolStatus ONE = BoolVarImp::ONE;
01065 static const BoolStatus NONE = BoolVarImp::NONE;
01067 BoolStatus status(void) const;
01069
01071
01072
01073 int min(void) const;
01075 int max(void) const;
01077 int med(void) const;
01079 int val(void) const;
01080
01082 unsigned int size(void) const;
01084 unsigned int width(void) const;
01086 unsigned int regret_min(void) const;
01088 unsigned int regret_max(void) const;
01090
01092
01093
01094 bool range(void) const;
01096 bool in(int n) const;
01098 bool in(double n) const;
01100
01102
01103
01104 bool zero(void) const;
01106 bool one(void) const;
01108 bool none(void) const;
01110
01112
01113
01114 ModEvent one(Space& home);
01116 ModEvent zero(Space& home);
01118 ModEvent one_none(Space& home);
01120 ModEvent zero_none(Space& home);
01122
01124
01125
01126 ModEvent lq(Space& home, int n);
01128 ModEvent lq(Space& home, double n);
01129
01131 ModEvent le(Space& home, int n);
01133 ModEvent le(Space& home, double n);
01134
01136 ModEvent gq(Space& home, int n);
01138 ModEvent gq(Space& home, double n);
01139
01141 ModEvent gr(Space& home, int n);
01143 ModEvent gr(Space& home, double n);
01144
01146 ModEvent nq(Space& home, int n);
01148 ModEvent nq(Space& home, double n);
01149
01151 ModEvent eq(Space& home, int n);
01153 ModEvent eq(Space& home, double n);
01155
01171
01172 template<class I>
01173 ModEvent narrow_r(Space& home, I& i, bool depends=true);
01175 template<class I>
01176 ModEvent inter_r(Space& home, I& i, bool depends=true);
01178 template<class I>
01179 ModEvent minus_r(Space& home, I& i, bool depends=true);
01181 template<class I>
01182 ModEvent narrow_v(Space& home, I& i, bool depends=true);
01184 template<class I>
01185 ModEvent inter_v(Space& home, I& i, bool depends=true);
01187 template<class I>
01188 ModEvent minus_v(Space& home, I& i, bool depends=true);
01190
01192
01193
01194 int min(const Delta& d) const;
01196 int max(const Delta& d) const;
01198 bool any(const Delta& d) const;
01200 static bool zero(const Delta& d);
01202 static bool one(const Delta& d);
01204
01206
01207
01208 static ModEventDelta med(ModEvent me);
01210 };
01211
01216 template<class Char, class Traits>
01217 std::basic_ostream<Char,Traits>&
01218 operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x);
01219
01220
01221
01230 class NegBoolView : public DerivedView<BoolView> {
01231 protected:
01232 using DerivedView<BoolView>::x;
01233 public:
01235
01236
01237 NegBoolView(void);
01239 explicit NegBoolView(const BoolView& y);
01241
01243
01244
01245 static const int BITS = BoolView::BITS;
01247 static const BoolStatus ZERO = BoolView::ONE;
01249 static const BoolStatus ONE = BoolView::ZERO;
01251 static const BoolStatus NONE = BoolView::NONE;
01253 BoolStatus status(void) const;
01255
01257
01258
01259 bool zero(void) const;
01261 bool one(void) const;
01263 bool none(void) const;
01265
01267
01268
01269 ModEvent one(Space& home);
01271 ModEvent zero(Space& home);
01273 ModEvent one_none(Space& home);
01275 ModEvent zero_none(Space& home);
01277
01279
01280
01281 int min(void) const;
01283 int max(void) const;
01285 int val(void) const;
01287
01289
01290
01291 int min(const Delta& d) const;
01293 int max(const Delta& d) const;
01295 bool any(const Delta& d) const;
01297 static bool zero(const Delta& d);
01299 static bool one(const Delta& d);
01301 };
01302
01307 template<class Char, class Traits>
01308 std::basic_ostream<Char,Traits>&
01309 operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x);
01310
01311 }}
01312
01313 #include <gecode/int/var/int.hpp>
01314 #include <gecode/int/var/bool.hpp>
01315
01316 #include <gecode/int/view/int.hpp>
01317
01318 #include <gecode/int/view/constint.hpp>
01319 #include <gecode/int/view/zero.hpp>
01320 #include <gecode/int/view/minus.hpp>
01321 #include <gecode/int/view/offset.hpp>
01322 #include <gecode/int/view/scale.hpp>
01323
01324 #include <gecode/int/view/bool.hpp>
01325
01326 #include <gecode/int/view/neg-bool.hpp>
01327
01328 #include <gecode/int/view/print.hpp>
01329 #include <gecode/int/var/print.hpp>
01330
01331 namespace Gecode { namespace Int {
01332
01339
01340 enum RelTest {
01341 RT_FALSE = 0,
01342 RT_MAYBE = 1,
01343 RT_TRUE = 2
01344 };
01345
01347 template<class View> RelTest rtest_eq_bnd(View x, View y);
01349 template<class View> RelTest rtest_eq_dom(View x, View y);
01351 template<class View> RelTest rtest_eq_bnd(View x, int n);
01353 template<class View> RelTest rtest_eq_dom(View x, int n);
01354
01356 template<class View> RelTest rtest_nq_bnd(View x, View y);
01358 template<class View> RelTest rtest_nq_dom(View x, View y);
01360 template<class View> RelTest rtest_nq_bnd(View x, int n);
01362 template<class View> RelTest rtest_nq_dom(View x, int n);
01363
01365 template<class View> RelTest rtest_lq(View x, View y);
01367 template<class View> RelTest rtest_lq(View x, int n);
01368
01370 template<class View> RelTest rtest_le(View x, View y);
01372 template<class View> RelTest rtest_le(View x, int n);
01373
01375 template<class View> RelTest rtest_gq(View x, View y);
01377 template<class View> RelTest rtest_gq(View x, int n);
01378
01380 template<class View> RelTest rtest_gr(View x, View y);
01382 template<class View> RelTest rtest_gr(View x, int n);
01384
01385
01390 enum BoolTest {
01391 BT_NONE,
01392 BT_SAME,
01393 BT_COMP
01394 };
01395
01401
01402 BoolTest bool_test(const BoolView& b0, const BoolView& b1);
01404 BoolTest bool_test(const BoolView& b0, const NegBoolView& b1);
01406 BoolTest bool_test(const NegBoolView& b0, const BoolView& b1);
01408 BoolTest bool_test(const NegBoolView& b0, const NegBoolView& b1);
01410
01411 }}
01412
01413 #include <gecode/int/view/rel-test.hpp>
01414 #include <gecode/int/view/bool-test.hpp>
01415
01416