Generated on Thu Apr 11 13:59:22 2019 for Gecode by doxygen 1.6.3

mm-rel.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2008
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include "test/int.hh"
00035 
00036 #include <gecode/minimodel.hh>
00037 
00038 namespace Test { namespace Int {
00039 
00041    namespace MiniModel {
00042 
00048 
00049      class IntLex : public Test {
00050      protected:
00052        Gecode::IntRelType irt;
00053      public:
00055        IntLex(Gecode::IntRelType irt0)
00056          : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
00058        virtual bool solution(const Assignment& x) const {
00059          int n=x.size() >> 1;
00060          for (int i=0; i<n; i++)
00061            if (x[i] != x[n+i])
00062              return cmp(x[i],irt,x[n+i]);
00063          return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00064                  (irt == Gecode::IRT_EQ));
00065          GECODE_NEVER;
00066          return false;
00067        }
00069        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00070          using namespace Gecode;
00071          int n=x.size() >> 1;
00072          IntVarArgs y(n); IntVarArgs z(n);
00073          for (int i=0; i<n; i++) {
00074            y[i]=x[i]; z[i]=x[n+i];
00075          }
00076          lex(home, y, irt, z);
00077        }
00078      };
00079 
00081      class BoolLex : public Test {
00082      protected:
00084        Gecode::IntRelType irt;
00085      public:
00087        BoolLex(Gecode::IntRelType irt0)
00088          : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
00090        virtual bool solution(const Assignment& x) const {
00091          int n=x.size() >> 1;
00092          for (int i=0; i<n; i++)
00093            if (x[i] != x[n+i])
00094              return cmp(x[i],irt,x[n+i]);
00095          return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00096                  (irt == Gecode::IRT_EQ));
00097          GECODE_NEVER;
00098          return false;
00099        }
00101        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00102          using namespace Gecode;
00103          int n=x.size() >> 1;
00104          BoolVarArgs y(n); BoolVarArgs z(n);
00105          for (int i=0; i<n; i++) {
00106            y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
00107          }
00108          lex(home, y, irt, z);
00109        }
00110      };
00111 
00113      class Create {
00114      public:
00116        Create(void) {
00117          using namespace Gecode;
00118          for (IntRelTypes irts; irts(); ++irts) {
00119            (void) new IntLex(irts.irt());
00120            (void) new BoolLex(irts.irt());
00121          }
00122        }
00123      };
00124 
00125      Create c;
00127 
00128    }
00129 
00130 }}
00131 
00132 // STATISTICS: test-minimodel