Generated on Mon May 10 06:46:44 2010 for Gecode by doxygen 1.6.3

unary.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, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
00011  *     $Revision: 10684 $
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 #include "test/int.hh"
00039 
00040 #include <gecode/minimodel.hh>
00041 #include <gecode/scheduling.hh>
00042 
00043 namespace Test { namespace Int {
00044 
00046    namespace Unary {
00047 
00053 
00054      class ManFixUnary : public Test {
00055      protected:
00057        Gecode::IntArgs p;
00059        static int st(const Gecode::IntArgs& p) {
00060          int t = 0;
00061          for (int i=p.size(); i--; )
00062            t += p[i];
00063          return t;
00064        }
00065      public:
00067        ManFixUnary(const Gecode::IntArgs& p0, int o)
00068          : Test("Scheduling::Unary::Man::Fix::"+str(o)+"::"+str(p0),
00069                 p0.size(),o,o+st(p0)), 
00070            p(p0) {
00071          testsearch = false;
00072          contest = CTL_NONE;
00073        }
00075        virtual Assignment* assignment(void) const {
00076          return new RandomAssignment(arity,dom,500);
00077        }
00079        virtual bool solution(const Assignment& x) const {
00080          for (int i=0; i<x.size(); i++)
00081            for (int j=i+1; j<x.size(); j++)
00082              if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00083                return false;
00084          return true;
00085        }
00087        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00088          Gecode::unary(home, x, p);
00089        }
00090      };
00091 
00093      class OptFixUnary : public Test {
00094      protected:
00096        Gecode::IntArgs p;
00098        int l;
00100        static int st(const Gecode::IntArgs& p) {
00101          int t = 0;
00102          for (int i=p.size(); i--; )
00103            t += p[i];
00104          return t;
00105        }
00106      public:
00108        OptFixUnary(const Gecode::IntArgs& p0, int o)
00109          : Test("Scheduling::Unary::Opt::Fix::"+str(o)+"::"+str(p0),
00110                 2*p0.size(),o,o+st(p0)), p(p0), l(o+st(p)/2) {
00111          testsearch = false;
00112          contest = CTL_NONE;
00113        }
00115        virtual Assignment* assignment(void) const {
00116          return new RandomAssignment(arity,dom,500);
00117        }
00119        virtual bool solution(const Assignment& x) const {
00120          int n = x.size() / 2;
00121          for (int i=0; i<n; i++)
00122            if (x[n+i] > l)
00123              for (int j=i+1; j<n; j++)
00124                if(x[n+j] > l)
00125                  if ((x[i]+p[i] > x[j]) && (x[j]+p[j] > x[i]))
00126                    return false;
00127          return true;
00128        }
00130        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00131          int n=x.size() / 2;
00132          Gecode::IntVarArgs s(n);
00133          Gecode::BoolVarArgs m(n);
00134          for (int i=0; i<n; i++) {
00135            s[i]=x[i];
00136            m[i]=Gecode::post(home, ~(x[n+i] > l));
00137          }
00138          Gecode::unary(home, s, p, m);
00139        }
00140      };
00141 
00142      Gecode::IntArgs p1(4, 2,2,2,2);
00143      ManFixUnary mfu10(p1,0);
00144      ManFixUnary mfu1i(p1,Gecode::Int::Limits::min);
00145      OptFixUnary ofu10(p1,0);
00146      OptFixUnary ofu1i(p1,Gecode::Int::Limits::min);
00147 
00148      Gecode::IntArgs p10(5, 2,2,0,2,2);
00149      ManFixUnary mfu010(p10,0);
00150      ManFixUnary mfu01i(p10,Gecode::Int::Limits::min);
00151      OptFixUnary ofu010(p10,0);
00152      OptFixUnary ofu01i(p10,Gecode::Int::Limits::min);
00153 
00154      Gecode::IntArgs p2(4, 4,3,3,5);
00155      ManFixUnary mfu20(p2,0);
00156      ManFixUnary mfu2i(p2,Gecode::Int::Limits::min);
00157      OptFixUnary ofu20(p2,0);
00158      OptFixUnary ofu2i(p2,Gecode::Int::Limits::min);
00159 
00160      Gecode::IntArgs p20(6, 4,0,3,3,0,5);
00161      ManFixUnary mfu020(p20,0);
00162      ManFixUnary mfu02i(p20,Gecode::Int::Limits::min);
00163      OptFixUnary ofu020(p20,0);
00164      OptFixUnary ofu02i(p20,Gecode::Int::Limits::min);
00165 
00166      Gecode::IntArgs p3(6, 4,2,9,3,7,5);
00167      ManFixUnary mfu30(p3,0);
00168      ManFixUnary mfu3i(p3,Gecode::Int::Limits::min);
00169      OptFixUnary ofu30(p3,0);
00170      OptFixUnary ofu3i(p3,Gecode::Int::Limits::min);
00171 
00172      Gecode::IntArgs p30(8, 4,0,2,9,3,7,5,0);
00173      ManFixUnary mfu030(p30,0);
00174      ManFixUnary mfu03i(p30,Gecode::Int::Limits::min);
00175      OptFixUnary ofu030(p30,0);
00176      OptFixUnary ofu03i(p30,Gecode::Int::Limits::min);
00177 
00179 
00180    }
00181 }}
00182 
00183 // STATISTICS: test-int