Generated on Tue Apr 18 10:21:38 2017 for Gecode by doxygen 1.6.3

channel.cpp

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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2006
00009  *     Vincent Barichard, 2012
00010  *
00011  *  Last modified:
00012  *     $Date: 2016-06-27 20:51:18 +0200 (Mon, 27 Jun 2016) $ by $Author: schulte $
00013  *     $Revision: 15132 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include "test/float.hh"
00041 
00042 #include <gecode/minimodel.hh>
00043 
00044 namespace Test { namespace Float {
00045 
00047    namespace Channel {
00048 
00050      class Int : public Test {
00051      public:
00053        Int(Gecode::FloatNum st)
00054          : Test("Channel::Int",2,-1,2,st,CPLT_ASSIGNMENT,false) {}
00056        virtual MaybeType solution(const Assignment& x) const {
00057          Gecode::FloatNum tmp;
00058          return (((modf(x[0].min(),&tmp)==0) ||
00059                   (modf(x[0].max(),&tmp)==0))
00060                  && (x[0]==x[1])) ? MT_TRUE : MT_FALSE;
00061        }
00063        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00064          using namespace Gecode;
00065          IntVar iv(home,-1000,1000);
00066          channel(home, x[0], iv);
00067          channel(home, iv, x[1]);
00068        }
00069      };
00070 
00072      class Bool : public Test {
00073      public:
00075        Bool(Gecode::FloatNum st)
00076          : Test("Channel::Bool",2,0,1,st,CPLT_ASSIGNMENT,false) {}
00078        virtual MaybeType solution(const Assignment& x) const {
00079          Gecode::FloatNum tmp;
00080          return (((modf(x[0].min(),&tmp)==0) ||
00081                   (modf(x[0].max(),&tmp)==0))
00082                  && (x[0]==x[1])) ? MT_TRUE : MT_FALSE;
00083        }
00085        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00086          using namespace Gecode;
00087          BoolVar bv(home,0,1);
00088          channel(home, x[0], bv);
00089          channel(home, bv, x[1]);
00090        }
00091      };
00092 
00093      Gecode::FloatNum step1 = 0.7;
00094      Gecode::FloatNum step2 = 0.1;
00095 
00096      Int ci(step1);
00097      Bool cb(step2);
00099 
00100    }
00101 }}
00102 
00103 // STATISTICS: test-float
00104