Generated on Wed Jan 4 17:49:09 2006 for Gecode by doxygen 1.4.6

view.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2005
00007  *
00008  *  Last modified:
00009  *     $Date: 2005-10-31 13:17:08 +0100 (Mon, 31 Oct 2005) $ by $Author: schulte $
00010  *     $Revision: 2435 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "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 "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 
00341       void subscribe(Space* home, Propagator* p, PropCond pc);
00343       void cancel(Propagator* p, PropCond pc);
00345 
00347 
00348 
00349       void update(Space* home, bool share, MinusView& x);
00351     };
00352 
00353   }
00354 
00359 
00360   bool same(const Int::MinusView& x, const Int::MinusView& y);
00362   bool before(const Int::MinusView& x, const Int::MinusView& y);
00364 
00371   template<>
00372   class ViewVarTraits<Int::MinusView> {
00373   public:
00375     typedef Int::IntVarImp Var;
00376   };
00377 
00378 
00379   namespace Int {
00380 
00389     class OffsetView : public DerivedViewBase<IntView> {
00390     protected:
00392       int c;
00393       using DerivedViewBase<IntView>::view;
00394     public:
00396 
00397 
00398       OffsetView(void);
00400       OffsetView(const IntView& x, int c);
00402       void init(const IntView& x, int c);
00404       int offset(void) const;
00406 
00408 
00409 
00410       int min(void) const;
00412       int max(void) const;
00414       int med(void) const;
00416       int val(void) const;
00417 
00419       unsigned int size(void) const;
00421       unsigned int width(void) const;
00423       unsigned int regret_min(void) const;
00425       unsigned int regret_max(void) const;
00427 
00429 
00430 
00431       bool range(void) const;
00433       bool assigned(void) const;
00434 
00436       bool in(int n) const;
00438       bool in(double n) const;
00440 
00442 
00443 
00444       ModEvent lq(Space* home, int n); 
00446       ModEvent lq(Space* home, double n);
00448       ModEvent le(Space* home, int n); 
00450       ModEvent le(Space* home, double n);
00452       ModEvent gq(Space* home, int n); 
00454       ModEvent gq(Space* home, double n);
00456       ModEvent gr(Space* home, int n); 
00458       ModEvent gr(Space* home, double n);
00460       ModEvent nq(Space* home, int n); 
00462       ModEvent nq(Space* home, double n);
00464       ModEvent eq(Space* home, int n); 
00466       ModEvent eq(Space* home, double n);
00468 
00470 
00471 
00472       template <class I> ModEvent narrow(Space* home, I& i);
00474       template <class I> ModEvent inter(Space* home, I& i);
00476       template <class I> ModEvent minus(Space* home, I& i);
00478 
00480 
00481 
00482       static ModEvent     pme(const Propagator* p);
00484       static PropModEvent pme(ModEvent me);
00486 
00488 
00489 
00490       void subscribe(Space* home, Propagator* p, PropCond pc);
00492       void cancel(Propagator* p, PropCond pc);
00494 
00496 
00497 
00498       void update(Space* home, bool share, OffsetView& x);
00500     };
00501 
00502   }
00503 
00508 
00509   bool same(const Int::OffsetView& x, const Int::OffsetView& y);
00511   bool before(const Int::OffsetView& x, const Int::OffsetView& y);
00513 
00520   template<>
00521   class ViewVarTraits<Int::OffsetView> {
00522   public:
00524     typedef Int::IntVarImp Var;
00525   };
00526 
00527 
00528 
00529   namespace Int {
00530 
00556     template <class Val, class UnsVal>
00557     class ScaleView : public DerivedViewBase<IntView> {
00558     protected:
00560       int a;
00561       using DerivedViewBase<IntView>::view;
00562 
00564 
00565 
00566       int floor_div(double x);
00568       int ceil_div(double x);
00570       int exact_div(double x, bool& exact);
00571 #if GECODE_INT_RND_TWDS_ZERO
00572 
00573       int floor_div(int);
00575       int ceil_div(int);
00577       int exact_div(int, bool&);
00578 #endif
00579 
00580 
00581     public:
00583 
00584 
00585       ScaleView(void);
00587       ScaleView(int b, const IntView& y);
00589       void init(int b, const IntView& y);
00591       int scale(void) const;
00593 
00594 
00596 
00597 
00598       Val min(void) const;
00600       Val max(void) const;
00602       Val med(void) const;
00604       Val val(void) const;
00605 
00607       UnsVal size(void) const;
00609       UnsVal width(void) const;
00611       UnsVal regret_min(void) const;
00613       UnsVal regret_max(void) const;
00615 
00617 
00618 
00619       bool range(void) const;
00621       bool assigned(void) const;
00623       bool in(Val n) const;
00625 
00627 
00628 
00629       ModEvent lq(Space* home, Val n); 
00631       ModEvent le(Space* home, Val n); 
00633       ModEvent gq(Space* home, Val n); 
00635       ModEvent gr(Space* home, Val n); 
00637       ModEvent nq(Space* home, Val n); 
00639       ModEvent eq(Space* home, Val n); 
00641 
00643 
00644 
00645       static ModEvent     pme(const Propagator* p);
00647       static PropModEvent pme(ModEvent me);
00649 
00651 
00652 
00653       void subscribe(Space* home, Propagator* p, PropCond pc);
00655       void cancel(Propagator* p, PropCond pc);
00657 
00659 
00660 
00661       void update(Space* home, bool share, ScaleView<Val,UnsVal>& x);
00663     };
00664 
00669     typedef ScaleView<int,unsigned int> IntScaleView;
00670 
00675     typedef ScaleView<double,double> DoubleScaleView;
00676 
00677   }
00678 
00683 
00684   template <class Val, class UnsVal>
00685   bool same(const Int::ScaleView<Val,UnsVal>& x, 
00686             const Int::ScaleView<Val,UnsVal>& y);
00688   template <class Val, class UnsVal>
00689   bool before(const Int::ScaleView<Val,UnsVal>& x, 
00690               const Int::ScaleView<Val,UnsVal>& y);
00692 
00693 
00700   template <class Val, class UnsVal>
00701   class ViewVarTraits<Int::ScaleView<Val,UnsVal> > {
00702   public:
00704     typedef Int::IntVarImp Var;
00705   };
00706 
00707 
00708 
00709   namespace Int {
00710 
00718     class ConstIntView : public ConstantViewBase {
00719     protected:
00720       int x;
00721     public:
00723 
00724 
00725       ConstIntView(void);
00727       ConstIntView(int n);
00729       void init(int n);
00731 
00733 
00734 
00735       int min(void) const;
00737       int max(void) const;
00739       int med(void) const;
00741       int val(void) const;
00742 
00744       unsigned int size(void) const;
00746       unsigned int width(void) const;
00748       unsigned int regret_min(void) const;
00750       unsigned int regret_max(void) const;
00752 
00754 
00755 
00756       bool range(void) const;
00758       bool assigned(void) const;
00759 
00761       bool in(int n) const;
00763       bool in(double n) const;
00765 
00767 
00768 
00769       ModEvent lq(Space* home, int n); 
00771       ModEvent lq(Space* home, double n);
00773       ModEvent le(Space* home, int n); 
00775       ModEvent le(Space* home, double n);
00777       ModEvent gq(Space* home, int n); 
00779       ModEvent gq(Space* home, double n);
00781       ModEvent gr(Space* home, int n); 
00783       ModEvent gr(Space* home, double n);
00785       ModEvent nq(Space* home, int n); 
00787       ModEvent nq(Space* home, double n);
00789       ModEvent eq(Space* home, int n); 
00791       ModEvent eq(Space* home, double n);
00793 
00795 
00796 
00797       template <class I> ModEvent narrow(Space* home, I& i);
00799       template <class I> ModEvent inter(Space* home, I& i);
00801       template <class I> ModEvent minus(Space* home, I& i);
00803 
00805 
00806 
00807       static ModEvent     pme(const Propagator* p);
00809       static PropModEvent pme(ModEvent me);
00811 
00813 
00814 
00815       void subscribe(Space* home, Propagator* p, PropCond pc);
00817       void cancel(Propagator* p, PropCond pc);
00819 
00821 
00822 
00823       void update(Space* home, bool share, ConstIntView& x);
00825     };
00826 
00827   }
00828 
00834 
00835   bool same(const Int::ConstIntView& x, const Int::ConstIntView& y);
00837   template <class View, unsigned int n>
00838   bool before(const Int::ConstIntView& x, const Int::ConstIntView& y);
00840 
00847   template<>
00848   class ViewVarTraits<Int::ConstIntView> {
00849   public:
00851     typedef VarBase Var;
00852   };
00853 
00854   namespace Int {
00855 
00862     class BoolView : public IntView {
00864       friend class ViewArray<BoolView>;
00865     public:
00867 
00868 
00869       BoolView(void);
00871       BoolView(const BoolVar& b);
00872     private:
00878       BoolView(const IntVar& b);
00879     public:
00881       explicit BoolView(const IntView& x);
00883 
00885 
00886 
00887       bool zero(void) const;
00889       bool one(void) const;
00891       bool none(void) const;
00893 
00895 
00896 
00897       ModEvent t_one(Space* home);  
00899       ModEvent t_zero(Space* home);
00901       void t_one_none(Space* home); 
00903       void t_zero_none(Space* home);
00905 
00906     };
00907 
00908   }
00909 
00916   template<>
00917   class ViewVarTraits<Int::BoolView> {
00918   public:
00920     typedef Int::IntVarImp Var;
00921   };
00922 
00923   namespace Int {
00924 
00933     class NegBoolView : public DerivedViewBase<BoolView> {
00934     protected:
00935       using DerivedViewBase<BoolView>::view;
00936     public:
00938 
00939 
00940       NegBoolView(void);
00942       NegBoolView(const BoolView& b);
00944       void init(const BoolView& b);
00946 
00948 
00949 
00950       bool zero(void) const;
00952       bool one(void) const;
00954       bool none(void) const;
00956 
00958 
00959 
00960       ModEvent t_one(Space* home);  
00962       ModEvent t_zero(Space* home);
00964       void t_one_none(Space* home); 
00966       void t_zero_none(Space* home);
00968 
00970 
00971 
00972       int min(void) const;
00974       int max(void) const;
00976       int val(void) const;
00978 
00980 
00981 
00982       bool assigned(void) const;
00984 
00986 
00987 
00988       static ModEvent     pme(const Propagator* p);
00990       static PropModEvent pme(ModEvent me);
00992 
00994 
00995 
00996       void subscribe(Space* home, Propagator* p, PropCond pc);
00998       void cancel(Propagator* p, PropCond pc);
01000 
01002 
01003 
01004       void update(Space* home, bool share, NegBoolView& x);
01006     };
01007 
01012     enum BoolTest {
01013       BT_NONE, 
01014       BT_SAME, 
01015       BT_COMP  
01016     };
01017 
01023 
01024     BoolTest bool_test(const BoolView& b0, const BoolView& b1);
01026     BoolTest bool_test(const BoolView& b0, const NegBoolView& b1);
01028     BoolTest bool_test(const NegBoolView& b0, const BoolView& b1);
01030     BoolTest bool_test(const NegBoolView& b0, const NegBoolView& b1);
01032 
01033   }
01034 
01039 
01040   bool same(const Int::NegBoolView& x, const Int::NegBoolView& y);
01042   bool before(const Int::NegBoolView& x, const Int::NegBoolView& y);
01044 
01051   template<>
01052   class ViewVarTraits<Int::NegBoolView> {
01053   public:
01055     typedef Int::IntVarImp Var;
01056   };
01057 
01058 }
01059 
01060 #include "int/var/int.icc"
01061 #include "int/var/bool.icc"
01062 
01063 #include "int/view/int.icc"
01064 #include "int/view/bool.icc"
01065 
01066 #include "int/view/constint.icc"
01067 
01068 #include "int/view/minus.icc"
01069 #include "int/view/offset.icc"
01070 #include "int/view/scale.icc"
01071 
01076 GECODE_INT_EXPORT std::ostream&
01077 operator<<(std::ostream&, const Gecode::Int::IntView&);
01082 GECODE_INT_EXPORT std::ostream&
01083 operator<<(std::ostream&, const Gecode::Int::MinusView&);
01088 GECODE_INT_EXPORT std::ostream&
01089 operator<<(std::ostream&, const Gecode::Int::OffsetView&);
01094 GECODE_INT_EXPORT std::ostream&
01095 operator<<(std::ostream&, const Gecode::Int::ConstIntView&);
01100 GECODE_INT_EXPORT std::ostream&
01101 operator<<(std::ostream&, const Gecode::Int::IntScaleView&);
01106 GECODE_INT_EXPORT std::ostream&
01107 operator<<(std::ostream&, const Gecode::Int::DoubleScaleView&);
01112 GECODE_INT_EXPORT std::ostream&
01113 operator<<(std::ostream&, const Gecode::Int::NegBoolView&);
01114 
01115 
01116 inline std::ostream&
01117 operator<<(std::ostream& os, const Gecode::IntVar& x) {
01118   Gecode::Int::IntView vx(x);
01119   return os << vx;
01120 }
01121 
01122 namespace Gecode { 
01123 
01124   namespace Int {
01125 
01132 
01133     enum RelTest {
01134       RT_FALSE = 0, 
01135       RT_MAYBE = 1, 
01136       RT_TRUE  = 2   
01137     };
01138 
01140     template <class View> RelTest rtest_eq_bnd(View x, View y);
01142     template <class View> RelTest rtest_eq_dom(View x, View y);
01144     template <class View> RelTest rtest_eq_bnd(View x, int n);
01146     template <class View> RelTest rtest_eq_dom(View x, int n);
01147     
01149     template <class View> RelTest rtest_nq_bnd(View x, View y);
01151     template <class View> RelTest rtest_nq_dom(View x, View y);
01153     template <class View> RelTest rtest_nq_bnd(View x, int n);
01155     template <class View> RelTest rtest_nq_dom(View x, int n);
01156     
01158     template <class View> RelTest rtest_lq(View x, View y);
01160     template <class View> RelTest rtest_lq(View x, int n);
01161     
01163     template <class View> RelTest rtest_le(View x, View y);
01165     template <class View> RelTest rtest_le(View x, int n);
01166     
01168     template <class View> RelTest rtest_gq(View x, View y);
01170     template <class View> RelTest rtest_gq(View x, int n);
01171     
01173     template <class View> RelTest rtest_gr(View x, View y);
01175     template <class View> RelTest rtest_gr(View x, int n);
01177 
01178   }
01179 
01180 }
01181 
01182 #include "int/view/rtest.icc"
01183 
01184 // STATISTICS: int-var