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

view-values.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, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2012-09-18 18:07:37 +0200 (Tue, 18 Sep 2012) $ by $Author: schulte $
00011  *     $Revision: 13101 $
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/int/branch.hh>
00039 
00040 namespace Gecode { namespace Int { namespace Branch {
00041 
00042   PosValuesChoice::PosValuesChoice(const Brancher& b, const Pos& p, IntView x)
00043     : PosChoice(b,x.size(),p), n(0) {
00044     for (ViewRanges<IntView> r(x); r(); ++r)
00045       n++;
00046     pm = heap.alloc<PosMin>(n+1);
00047     unsigned int w=0;
00048     int i=0;
00049     for (ViewRanges<IntView> r(x); r(); ++r) {
00050       pm[i].min = r.min();
00051       pm[i].pos = w;
00052       w += r.width(); i++;
00053     }
00054     pm[i].pos = w;
00055   }
00056 
00057   PosValuesChoice::PosValuesChoice(const Brancher& b, unsigned int a, Pos p,
00058                                    Archive& e)
00059     : PosChoice(b,a,p) {
00060     e >> n;
00061     pm = heap.alloc<PosMin>(n+1);
00062     for (unsigned int i=0; i<n+1; i++) {
00063       e >> pm[i].pos;
00064       e >> pm[i].min;
00065     }
00066   }
00067 
00068   size_t
00069   PosValuesChoice::size(void) const {
00070     return sizeof(PosValuesChoice)+(n+1)*sizeof(PosMin);
00071   }
00072 
00073   PosValuesChoice::~PosValuesChoice(void) {
00074     heap.free<PosMin>(pm,n+1);
00075   }
00076 
00077   forceinline void
00078   PosValuesChoice::archive(Archive& e) const {
00079     PosChoice::archive(e);
00080     e << this->alternatives() << n;
00081     for (unsigned int i=0; i<n+1; i++) {
00082       e << pm[i].pos;
00083       e << pm[i].min;
00084     }
00085   }
00086 
00087 }}}
00088 
00089 // STATISTICS: int-branch