00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gecode/iter.hh"
00023
00024 #include <iostream>
00025
00026 #if (-17 / 7) == -2
00027 #define GECODE_INT_RND_TWDS_ZERO 1
00028 #else
00029 #define GECODE_INT_RND_TWDS_ZERO 0
00030 #endif
00031
00032 namespace Gecode { namespace Int {
00033
00045 template <class View>
00046 class ViewRanges {
00047 public:
00049
00050
00051 ViewRanges(void);
00053 ViewRanges(const View& x);
00055 void init(const View& x);
00057
00059
00060
00061 bool operator()(void) const;
00063 void operator++(void);
00065
00067
00068
00069 int min(void) const;
00071 int max(void) const;
00073 unsigned int width(void) const;
00075 };
00076
00085 template <class View>
00086 class ViewValues
00087 : public Iter::Ranges::ToValues<ViewRanges<View> > {
00088 public:
00090
00091
00092 ViewValues(void);
00094 ViewValues(const View& x);
00096 void init(const View& x);
00098 };
00099
00100 }}
00101
00102 #include "gecode/int/view/iter.icc"
00103
00104 namespace Gecode {
00105
00106 namespace Int {
00107
00124 class IntView : public VariableViewBase<IntVarImp> {
00125 protected:
00126 using VariableViewBase<IntVarImp>::var;
00127 public:
00129
00130
00131 IntView(void);
00133 IntView(const IntVar& x);
00135
00137
00138
00139 int min(void) const;
00141 int max(void) const;
00143 int med(void) const;
00145 int val(void) const;
00146
00148 unsigned int size(void) const;
00150 unsigned int width(void) const;
00152 unsigned int regret_min(void) const;
00154 unsigned int regret_max(void) const;
00156
00158
00159
00160 bool range(void) const;
00162 bool assigned(void) const;
00163
00165 bool in(int n) const;
00167 bool in(double n) const;
00169
00171
00172
00173 ModEvent lq(Space* home, int n);
00175 ModEvent lq(Space* home, double n);
00176
00178 ModEvent le(Space* home, int n);
00180 ModEvent le(Space* home, double n);
00181
00183 ModEvent gq(Space* home, int n);
00185 ModEvent gq(Space* home, double n);
00186
00188 ModEvent gr(Space* home, int n);
00190 ModEvent gr(Space* home, double n);
00191
00193 ModEvent nq(Space* home, int n);
00195 ModEvent nq(Space* home, double n);
00196
00198 ModEvent eq(Space* home, int n);
00200 ModEvent eq(Space* home, double n);
00202
00204
00205
00206 template <class I> ModEvent narrow(Space* home, I& i);
00208 template <class I> ModEvent inter(Space* home, I& i);
00210 template <class I> ModEvent minus(Space* home, I& i);
00212
00214
00215
00216 void update(Space* home, bool share, IntView& x);
00218 };
00219
00220 }
00221
00228 template<>
00229 class ViewVarTraits<Int::IntView> {
00230 public:
00232 typedef Int::IntVarImp Var;
00233 };
00234
00235 namespace Int {
00236
00244 class MinusView : public DerivedViewBase<IntView> {
00245 protected:
00246 using DerivedViewBase<IntView>::view;
00247 public:
00249
00250
00251 MinusView(void);
00253 MinusView(const IntView& x);
00255 void init(const IntView& x);
00257
00259
00260
00261 int min(void) const;
00263 int max(void) const;
00265 int med(void) const;
00267 int val(void) const;
00268
00270 unsigned int size(void) const;
00272 unsigned int width(void) const;
00274 unsigned int regret_min(void) const;
00276 unsigned int regret_max(void) const;
00278
00280
00281
00282 bool range(void) const;
00284 bool assigned(void) const;
00285
00287 bool in(int n) const;
00289 bool in(double n) const;
00291
00293
00294
00295 ModEvent lq(Space* home, int n);
00297 ModEvent lq(Space* home, double n);
00299 ModEvent le(Space* home, int n);
00301 ModEvent le(Space* home, double n);
00303 ModEvent gq(Space* home, int n);
00305 ModEvent gq(Space* home, double n);
00307 ModEvent gr(Space* home, int n);
00309 ModEvent gr(Space* home, double n);
00311 ModEvent nq(Space* home, int n);
00313 ModEvent nq(Space* home, double n);
00315 ModEvent eq(Space* home, int n);
00317 ModEvent eq(Space* home, double n);
00319
00321
00322
00323 template <class I> ModEvent narrow(Space* home, I& i);
00325 template <class I> ModEvent inter(Space* home, I& i);
00327 template <class I> ModEvent minus(Space* home, I& i);
00329
00331
00332
00333 static ModEvent pme(const Propagator* p);
00335 static PropModEvent pme(ModEvent me);
00337
00339
00340
00347 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00349 void cancel(Space* home, Propagator* p, PropCond pc);
00351
00353
00354
00355 void update(Space* home, bool share, MinusView& x);
00357 };
00358
00359 }
00360
00365
00366 bool same(const Int::MinusView& x, const Int::MinusView& y);
00368 bool before(const Int::MinusView& x, const Int::MinusView& y);
00370
00377 template<>
00378 class ViewVarTraits<Int::MinusView> {
00379 public:
00381 typedef Int::IntVarImp Var;
00382 };
00383
00384
00385 namespace Int {
00386
00395 class OffsetView : public DerivedViewBase<IntView> {
00396 protected:
00398 int c;
00399 using DerivedViewBase<IntView>::view;
00400 public:
00402
00403
00404 OffsetView(void);
00406 OffsetView(const IntView& x, int c);
00408 void init(const IntView& x, int c);
00410 int offset(void) const;
00412
00414
00415
00416 int min(void) const;
00418 int max(void) const;
00420 int med(void) const;
00422 int val(void) const;
00423
00425 unsigned int size(void) const;
00427 unsigned int width(void) const;
00429 unsigned int regret_min(void) const;
00431 unsigned int regret_max(void) const;
00433
00435
00436
00437 bool range(void) const;
00439 bool assigned(void) const;
00440
00442 bool in(int n) const;
00444 bool in(double n) const;
00446
00448
00449
00450 ModEvent lq(Space* home, int n);
00452 ModEvent lq(Space* home, double n);
00454 ModEvent le(Space* home, int n);
00456 ModEvent le(Space* home, double n);
00458 ModEvent gq(Space* home, int n);
00460 ModEvent gq(Space* home, double n);
00462 ModEvent gr(Space* home, int n);
00464 ModEvent gr(Space* home, double n);
00466 ModEvent nq(Space* home, int n);
00468 ModEvent nq(Space* home, double n);
00470 ModEvent eq(Space* home, int n);
00472 ModEvent eq(Space* home, double n);
00474
00476
00477
00478 template <class I> ModEvent narrow(Space* home, I& i);
00480 template <class I> ModEvent inter(Space* home, I& i);
00482 template <class I> ModEvent minus(Space* home, I& i);
00484
00486
00487
00488 static ModEvent pme(const Propagator* p);
00490 static PropModEvent pme(ModEvent me);
00492
00494
00495
00502 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00504 void cancel(Space* home, Propagator* p, PropCond pc);
00506
00508
00509
00510 void update(Space* home, bool share, OffsetView& x);
00512 };
00513
00514 }
00515
00520
00521 bool same(const Int::OffsetView& x, const Int::OffsetView& y);
00523 bool before(const Int::OffsetView& x, const Int::OffsetView& y);
00525
00532 template<>
00533 class ViewVarTraits<Int::OffsetView> {
00534 public:
00536 typedef Int::IntVarImp Var;
00537 };
00538
00539
00540
00541 namespace Int {
00542
00568 template <class Val, class UnsVal>
00569 class ScaleView : public DerivedViewBase<IntView> {
00570 protected:
00572 int a;
00573 using DerivedViewBase<IntView>::view;
00574
00576
00577
00578 int floor_div(double x) const;
00580 int ceil_div(double x) const;
00582 int exact_div(double x, bool& exact) const;
00583 #if GECODE_INT_RND_TWDS_ZERO
00584
00585 int floor_div(int) const;
00587 int ceil_div(int) const;
00589 int exact_div(int, bool&) const;
00590 #endif
00591
00592
00593 public:
00595
00596
00597 ScaleView(void);
00599 ScaleView(int b, const IntView& y);
00601 void init(int b, const IntView& y);
00603 int scale(void) const;
00605
00606
00608
00609
00610 Val min(void) const;
00612 Val max(void) const;
00614 Val med(void) const;
00616 Val val(void) const;
00617
00619 UnsVal size(void) const;
00621 UnsVal width(void) const;
00623 UnsVal regret_min(void) const;
00625 UnsVal regret_max(void) const;
00627
00629
00630
00631 bool range(void) const;
00633 bool assigned(void) const;
00635 bool in(Val n) const;
00637
00639
00640
00641 ModEvent lq(Space* home, Val n);
00643 ModEvent le(Space* home, Val n);
00645 ModEvent gq(Space* home, Val n);
00647 ModEvent gr(Space* home, Val n);
00649 ModEvent nq(Space* home, Val n);
00651 ModEvent eq(Space* home, Val n);
00653
00655
00656
00657 static ModEvent pme(const Propagator* p);
00659 static PropModEvent pme(ModEvent me);
00661
00663
00664
00671 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00673 void cancel(Space* home, Propagator* p, PropCond pc);
00675
00677
00678
00679 void update(Space* home, bool share, ScaleView<Val,UnsVal>& x);
00681 };
00682
00687 typedef ScaleView<int,unsigned int> IntScaleView;
00688
00693 typedef ScaleView<double,double> DoubleScaleView;
00694
00695 }
00696
00701
00702 template <class Val, class UnsVal>
00703 bool same(const Int::ScaleView<Val,UnsVal>& x,
00704 const Int::ScaleView<Val,UnsVal>& y);
00706 template <class Val, class UnsVal>
00707 bool before(const Int::ScaleView<Val,UnsVal>& x,
00708 const Int::ScaleView<Val,UnsVal>& y);
00710
00711
00718 template <class Val, class UnsVal>
00719 class ViewVarTraits<Int::ScaleView<Val,UnsVal> > {
00720 public:
00722 typedef Int::IntVarImp Var;
00723 };
00724
00725
00726
00727 namespace Int {
00728
00736 class ConstIntView : public ConstantViewBase {
00737 protected:
00738 int x;
00739 public:
00741
00742
00743 ConstIntView(void);
00745 ConstIntView(int n);
00747 void init(int n);
00749
00751
00752
00753 int min(void) const;
00755 int max(void) const;
00757 int med(void) const;
00759 int val(void) const;
00760
00762 unsigned int size(void) const;
00764 unsigned int width(void) const;
00766 unsigned int regret_min(void) const;
00768 unsigned int regret_max(void) const;
00770
00772
00773
00774 bool range(void) const;
00776 bool assigned(void) const;
00777
00779 bool in(int n) const;
00781 bool in(double n) const;
00783
00785
00786
00787 ModEvent lq(Space* home, int n);
00789 ModEvent lq(Space* home, double n);
00791 ModEvent le(Space* home, int n);
00793 ModEvent le(Space* home, double n);
00795 ModEvent gq(Space* home, int n);
00797 ModEvent gq(Space* home, double n);
00799 ModEvent gr(Space* home, int n);
00801 ModEvent gr(Space* home, double n);
00803 ModEvent nq(Space* home, int n);
00805 ModEvent nq(Space* home, double n);
00807 ModEvent eq(Space* home, int n);
00809 ModEvent eq(Space* home, double n);
00811
00813
00814
00815 template <class I> ModEvent narrow(Space* home, I& i);
00817 template <class I> ModEvent inter(Space* home, I& i);
00819 template <class I> ModEvent minus(Space* home, I& i);
00821
00823
00824
00825 static ModEvent pme(const Propagator* p);
00827 static PropModEvent pme(ModEvent me);
00829
00831
00832
00839 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00841 void cancel(Space* home, Propagator* p, PropCond pc);
00843
00845
00846
00847 void update(Space* home, bool share, ConstIntView& x);
00849 };
00850
00851 }
00852
00858
00859 bool same(const Int::ConstIntView& x, const Int::ConstIntView& y);
00861 template <class View, unsigned int n>
00862 bool before(const Int::ConstIntView& x, const Int::ConstIntView& y);
00864
00871 template<>
00872 class ViewVarTraits<Int::ConstIntView> {
00873 public:
00875 typedef VarBase Var;
00876 };
00877
00878 namespace Int {
00879
00886 class BoolView : public IntView {
00888 friend class ViewArray<BoolView>;
00889 public:
00891
00892
00893 BoolView(void);
00895 BoolView(const BoolVar& b);
00896 private:
00902 BoolView(const IntVar& b);
00903 public:
00905 explicit BoolView(const IntView& x);
00907
00909
00910
00911 bool zero(void) const;
00913 bool one(void) const;
00915 bool none(void) const;
00917
00919
00920
00921 ModEvent t_one(Space* home);
00923 ModEvent t_zero(Space* home);
00925 void t_one_none(Space* home);
00927 void t_zero_none(Space* home);
00929
00931
00932
00933 void update(Space* home, bool share, BoolView& x);
00935 };
00936
00937 }
00938
00945 template<>
00946 class ViewVarTraits<Int::BoolView> {
00947 public:
00949 typedef Int::IntVarImp Var;
00950 };
00951
00952 namespace Int {
00953
00962 class NegBoolView : public DerivedViewBase<BoolView> {
00963 protected:
00964 using DerivedViewBase<BoolView>::view;
00965 public:
00967
00968
00969 NegBoolView(void);
00971 NegBoolView(const BoolView& b);
00973 void init(const BoolView& b);
00975
00977
00978
00979 bool zero(void) const;
00981 bool one(void) const;
00983 bool none(void) const;
00985
00987
00988
00989 ModEvent t_one(Space* home);
00991 ModEvent t_zero(Space* home);
00993 void t_one_none(Space* home);
00995 void t_zero_none(Space* home);
00997
00999
01000
01001 int min(void) const;
01003 int max(void) const;
01005 int val(void) const;
01007
01009
01010
01011 bool assigned(void) const;
01013
01015
01016
01017 static ModEvent pme(const Propagator* p);
01019 static PropModEvent pme(ModEvent me);
01021
01023
01024
01031 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
01033 void cancel(Space* home, Propagator* p, PropCond pc);
01035
01037
01038
01039 void update(Space* home, bool share, NegBoolView& x);
01041 };
01042
01047 enum BoolTest {
01048 BT_NONE,
01049 BT_SAME,
01050 BT_COMP
01051 };
01052
01058
01059 BoolTest bool_test(const BoolView& b0, const BoolView& b1);
01061 BoolTest bool_test(const BoolView& b0, const NegBoolView& b1);
01063 BoolTest bool_test(const NegBoolView& b0, const BoolView& b1);
01065 BoolTest bool_test(const NegBoolView& b0, const NegBoolView& b1);
01067
01068 }
01069
01074
01075 bool same(const Int::NegBoolView& x, const Int::NegBoolView& y);
01077 bool before(const Int::NegBoolView& x, const Int::NegBoolView& y);
01079
01086 template<>
01087 class ViewVarTraits<Int::NegBoolView> {
01088 public:
01090 typedef Int::IntVarImp Var;
01091 };
01092
01093 }
01094
01095 #include "gecode/int/var/int.icc"
01096 #include "gecode/int/var/bool.icc"
01097
01098 #include "gecode/int/view/int.icc"
01099 #include "gecode/int/view/bool.icc"
01100
01101 #include "gecode/int/view/constint.icc"
01102
01103 #include "gecode/int/view/minus.icc"
01104 #include "gecode/int/view/offset.icc"
01105 #include "gecode/int/view/scale.icc"
01106
01111 GECODE_INT_EXPORT std::ostream&
01112 operator<<(std::ostream&, const Gecode::Int::IntView&);
01117 GECODE_INT_EXPORT std::ostream&
01118 operator<<(std::ostream&, const Gecode::Int::MinusView&);
01123 GECODE_INT_EXPORT std::ostream&
01124 operator<<(std::ostream&, const Gecode::Int::OffsetView&);
01129 GECODE_INT_EXPORT std::ostream&
01130 operator<<(std::ostream&, const Gecode::Int::ConstIntView&);
01135 GECODE_INT_EXPORT std::ostream&
01136 operator<<(std::ostream&, const Gecode::Int::IntScaleView&);
01141 GECODE_INT_EXPORT std::ostream&
01142 operator<<(std::ostream&, const Gecode::Int::DoubleScaleView&);
01147 GECODE_INT_EXPORT std::ostream&
01148 operator<<(std::ostream&, const Gecode::Int::NegBoolView&);
01149
01150
01151 inline std::ostream&
01152 operator<<(std::ostream& os, const Gecode::IntVar& x) {
01153 Gecode::Int::IntView vx(x);
01154 return os << vx;
01155 }
01156
01157 namespace Gecode {
01158
01159 namespace Int {
01160
01167
01168 enum RelTest {
01169 RT_FALSE = 0,
01170 RT_MAYBE = 1,
01171 RT_TRUE = 2
01172 };
01173
01175 template <class View> RelTest rtest_eq_bnd(View x, View y);
01177 template <class View> RelTest rtest_eq_dom(View x, View y);
01179 template <class View> RelTest rtest_eq_bnd(View x, int n);
01181 template <class View> RelTest rtest_eq_dom(View x, int n);
01182
01184 template <class View> RelTest rtest_nq_bnd(View x, View y);
01186 template <class View> RelTest rtest_nq_dom(View x, View y);
01188 template <class View> RelTest rtest_nq_bnd(View x, int n);
01190 template <class View> RelTest rtest_nq_dom(View x, int n);
01191
01193 template <class View> RelTest rtest_lq(View x, View y);
01195 template <class View> RelTest rtest_lq(View x, int n);
01196
01198 template <class View> RelTest rtest_le(View x, View y);
01200 template <class View> RelTest rtest_le(View x, int n);
01201
01203 template <class View> RelTest rtest_gq(View x, View y);
01205 template <class View> RelTest rtest_gq(View x, int n);
01206
01208 template <class View> RelTest rtest_gr(View x, View y);
01210 template <class View> RelTest rtest_gr(View x, int n);
01212
01213 }
01214
01215 }
01216
01217 #include "gecode/int/view/rtest.icc"
01218
01219