Generated on Fri Mar 20 15:56:22 2015 for Gecode by doxygen 1.6.3

brancher-handle.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, 2013
00008  *
00009  *  Last modified:
00010  *     $Date: 2013-02-25 21:43:24 +0100 (Mon, 25 Feb 2013) $ by $Author: schulte $
00011  *     $Revision: 13406 $
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 <gecode/kernel.hh>
00039 #include <gecode/int.hh>
00040 
00041 #include "test/test.hh"
00042 
00043 namespace Test {
00044 
00046   class BrancherHandle : public Test::Base {
00047   protected:
00049     class TestSpace : public Gecode::Space {
00050     protected:
00052       Gecode::IntVarArray x;
00053     public:
00055       TestSpace(void) : x(*this,2,0,10) {}
00057       TestSpace(bool share, TestSpace& s) : Space(share,s) {
00058         x.update(*this,share,s.x);
00059       }
00061       Gecode::BrancherHandle post(void) {
00062         using namespace Gecode;
00063         return Gecode::branch(*this, x, INT_VAR_NONE(), INT_VAL_MIN());
00064       }
00066       virtual Space* copy(bool share) {
00067         return new TestSpace(share,*this);
00068       }
00069     };
00071     static const int n_b = 1024;
00073     int index(void) {
00074       //      return rand(n);
00075       return 4;
00076     }
00077   public:
00079     BrancherHandle(void) : Test::Base("BrancherHandle") {}
00081     bool run(void) {
00082       using namespace Gecode;
00083       TestSpace* s = new TestSpace;
00084       
00085       // Create and immediately delete
00086       for (int i=0; i<n_b; i++) {
00087         Gecode::BrancherHandle b(s->post());
00088         if (!b(*s)) return false;
00089         b.kill(*s);
00090         if (b(*s)) return false;
00091       }
00092 
00093       if (s->status() != SS_SOLVED)
00094         return false;
00095 
00096       // Array of handles for tests
00097       Gecode::BrancherHandle bs[n_b];
00098 
00099       // Create and delete
00100       for (int i=0; i<n_b; i++) {
00101         Gecode::BrancherHandle b(s->post());
00102         if (!b(*s)) return false;
00103         bs[i] = b;
00104       }
00105       for (int i=0; i<n_b; i++) {
00106         bs[i].kill(*s);
00107         if (bs[i](*s)) return false;
00108       }
00109       if (s->status() != SS_SOLVED)
00110         return false;
00111 
00112       // Create and delete in inverse order
00113       for (int i=0; i<n_b; i++) {
00114         Gecode::BrancherHandle b(s->post());
00115         if (!b(*s)) return false;
00116         bs[i] = b;
00117       }
00118       for (int i=n_b; i--; ) {
00119         bs[i].kill(*s);
00120         if (bs[i](*s)) return false;
00121       }
00122       if (s->status() != SS_SOLVED)
00123         return false;
00124       
00125       // Create and delete randomly
00126       for (int i=0; i<n_b; i++) {
00127         Gecode::BrancherHandle b(s->post());
00128         if (!b(*s)) return false;
00129         bs[i] = b;
00130       }
00131       int a = n_b;
00132       while (a > 0) {
00133         int i = rand(n_b);
00134         if (bs[i](*s)) {
00135           bs[i].kill(*s); a--;
00136         }
00137       }
00138       if (s->status() != SS_SOLVED)
00139         return false;
00140 
00141       return true;
00142     }
00143   };
00144 
00145   BrancherHandle bh;
00146 
00147 }
00148 
00149 // STATISTICS: test-core