Generated on Thu Apr 11 13:58:55 2019 for Gecode by doxygen 1.6.3

float.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00006  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00007  *
00008  *  Copyright:
00009  *     Christian Schulte, 2005
00010  *     Mikael Lagerkvist, 2006
00011  *     Vincent Barichard, 2012
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #ifndef __GECODE_TEST_FLOAT_HH__
00039 #define __GECODE_TEST_FLOAT_HH__
00040 
00041 #include "test/test.hh"
00042 
00043 #include <gecode/float.hh>
00044 
00045 namespace Test {
00046 
00048   namespace Float {
00049 
00051     enum MaybeType {
00052       MT_FALSE = 0, //< Does hold
00053       MT_TRUE,      //< Does not hold
00054       MT_MAYBE      //< Might or might not hold
00055     };
00056 
00058     MaybeType operator &(MaybeType a, MaybeType b);
00059 
00061     enum AssignmentType {
00062       CPLT_ASSIGNMENT = 0,
00063       RANDOM_ASSIGNMENT,
00064       EXTEND_ASSIGNMENT
00065     };
00066 
00067     class Test;
00068 
00079 
00080     class Assignment {
00081     protected:
00082       int n;              
00083       Gecode::FloatVal d; 
00084     public:
00086       Assignment(int n0, const Gecode::FloatVal& d0);
00088       virtual bool operator()(void) const = 0;
00090       virtual void operator++(void) = 0;
00092       virtual Gecode::FloatVal operator[](int i) const = 0;
00094       virtual void set(int i, const Gecode::FloatVal& val) = 0;
00096       int size(void) const;
00098       virtual ~Assignment(void);
00099     };
00100 
00102     class CpltAssignment : public Assignment {
00103     protected:
00104       Gecode::FloatVal* dsv; 
00105       Gecode::FloatNum step; 
00106     public:
00108       CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s);
00110       virtual bool operator()(void) const;
00112       virtual void operator++(void);
00114       virtual Gecode::FloatVal operator[](int i) const;
00116       virtual void set(int i, const Gecode::FloatVal& val);
00118       virtual ~CpltAssignment(void);
00119     };
00120 
00122     class ExtAssignment : public Assignment {
00123     protected:
00124       const Test* curPb;     
00125       Gecode::FloatVal* dsv; 
00126       Gecode::FloatNum step; 
00127     public:
00129       ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
00131       virtual bool operator()(void) const;
00133       virtual void operator++(void);
00135       virtual Gecode::FloatVal operator[](int i) const;
00137       virtual void set(int i, const Gecode::FloatVal& val);
00139       virtual ~ExtAssignment(void);
00140     };
00141 
00142 
00144     class RandomAssignment : public Assignment {
00145     protected:
00146       Gecode::FloatVal* vals; 
00147       int  a;                 
00148 
00149       Gecode::FloatNum randval(void);
00150     public:
00152       RandomAssignment(int n, const Gecode::FloatVal& d, int a);
00154       virtual bool operator()(void) const;
00156       virtual void operator++(void);
00158       virtual Gecode::FloatVal operator[](int i) const;
00160       virtual void set(int i, const Gecode::FloatVal& val);
00162       virtual ~RandomAssignment(void);
00163     };
00164 
00166     class TestSpace : public Gecode::Space {
00167     public:
00169       Gecode::FloatVal d;
00171       Gecode::FloatNum step;
00173       Gecode::FloatVarArray x;
00175       Gecode::Reify r;
00177       Test* test;
00179       bool reified;
00180 
00188       TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t);
00196       TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t,
00197                 Gecode::ReifyMode rm);
00199       TestSpace(TestSpace& s);
00201       virtual Gecode::Space* copy(void);
00203       virtual void dropUntil(const Assignment& a);
00205       bool assigned(void) const;
00207       bool matchAssignment(const Assignment& a) const;
00209       void post(void);
00211       bool failed(void);
00213       void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
00215       void rel(bool sol);
00219       void assign(const Assignment& a, MaybeType& sol, bool skip=false);
00221       void bound(void);
00225       Gecode::FloatNum cut(int* cutDirections);
00227       void prune(int i);
00229       void prune(void);
00231       bool prune(const Assignment& a, bool testfix);
00233       void disable(void);
00235       void enable(void);
00237       unsigned int propagators(void);
00238     };
00239 
00244     class Test : public Base {
00245     protected:
00247       int arity;
00249       Gecode::FloatVal dom;
00251       Gecode::FloatNum step;
00253       AssignmentType assigmentType;
00255       bool reified;
00257       int rms;
00259       bool testsearch;
00261       bool testfix;
00263       bool testsubsumed;
00265 
00266 
00267       bool eqv(void) const;
00269       bool imp(void) const;
00271       bool pmi(void) const;
00273     public:
00281       Test(const std::string& s, int a, const Gecode::FloatVal& d,
00282            Gecode::FloatNum st, AssignmentType at,
00283            bool r);
00291       Test(const std::string& s, int a,
00292            Gecode::FloatNum min, Gecode::FloatNum max,
00293            Gecode::FloatNum st, AssignmentType at,
00294            bool r);
00296       virtual Assignment* assignment(void) const;
00299       virtual bool extendAssignement(Assignment& a) const;
00301       virtual MaybeType solution(const Assignment&) const = 0;
00304       bool subsumed(const TestSpace& ts) const;
00306       virtual bool ignore(const Assignment& a) const;
00308       virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
00310       virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00311                         Gecode::Reify r);
00313       virtual bool run(void);
00315 
00316 
00317       static std::string str(Gecode::FloatRelType frt);
00319       static std::string str(Gecode::FloatNum f);
00321       static std::string str(Gecode::FloatVal f);
00323       static std::string str(const Gecode::FloatValArgs& f);
00325 
00326 
00327 
00328       static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r,
00329                            Gecode::FloatVal y);
00331       static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
00333       bool flip(void);
00335     };
00337 
00339     class FloatRelTypes {
00340     private:
00342       static const Gecode::FloatRelType frts[6];
00344       int i;
00345     public:
00347       FloatRelTypes(void);
00349       void reset(void);
00351       bool operator()(void) const;
00353       void operator++(void);
00355       Gecode::FloatRelType frt(void) const;
00356     };
00357 
00358   }
00359 }
00360 
00365 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
00366 
00367 #include "test/float.hpp"
00368 
00369 #endif
00370 
00371 // STATISTICS: test-float
00372