Generated on Tue Apr 18 10:22:09 2017 for Gecode by doxygen 1.6.3

cutoff.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2013
00011  *     Guido Tack, 2013
00012  *
00013  *  Last modified:
00014  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00015  *     $Revision: 14967 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #include <algorithm>
00043 #include <gecode/search.hh>
00044 
00045 namespace Gecode { namespace Search {
00046 
00047   unsigned long int
00048   CutoffConstant::operator ()(void) const {
00049     return c;
00050   }
00051   unsigned long int
00052   CutoffConstant::operator ++(void) {
00053     return c;
00054   }
00055 
00056 
00057   unsigned long int
00058   CutoffLinear::operator ()(void) const {
00059     return n;
00060   }
00061   unsigned long int
00062   CutoffLinear::operator ++(void) {
00063     n += scale;
00064     return n;
00065   }
00066 
00067 
00068   unsigned long int
00069   CutoffLuby::start[CutoffLuby::n_start] = {
00070     1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,
00071     1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,32
00072   };
00073   unsigned long int
00074   CutoffLuby::operator ()(void) const {
00075     return scale*luby(i);
00076   }
00077   unsigned long int
00078   CutoffLuby::operator ++(void) {
00079     return scale*luby(i++);
00080   }
00081 
00082 
00083   unsigned long int
00084   CutoffGeometric::operator ()(void) const {
00085     return static_cast<unsigned long int>(scale * n);
00086   }
00087   unsigned long int
00088   CutoffGeometric::operator ++(void) {
00089     n *= base;
00090     return static_cast<unsigned long int>(scale * n);
00091   }
00092 
00093 
00094   unsigned long int
00095   CutoffRandom::operator ++(void) {
00096     cur = min+step*rnd(n);
00097     return cur;
00098   }
00099   unsigned long int
00100   CutoffRandom::operator ()(void) const {
00101     return cur;
00102   }
00103 
00104 
00105   unsigned long int
00106   CutoffAppend::operator ()(void) const {
00107     if (n > 0) {
00108       return (*c1)();
00109     } else {
00110       return (*c2)();
00111     }
00112   }
00113   unsigned long int
00114   CutoffAppend::operator ++(void) {
00115     if (n > 0) {
00116       n--;
00117       return ++(*c1);
00118     } else {
00119       return ++(*c2);
00120     }
00121   }
00122 
00123 
00124   unsigned long int
00125   CutoffMerge::operator ()(void) const {
00126     return (*c1)();
00127   }
00128   unsigned long int
00129   CutoffMerge::operator ++(void) {
00130     (void) ++(*c1);
00131     std::swap(c1,c2);
00132     return (*c1)();
00133   }
00134 
00135 
00136   unsigned long int
00137   CutoffRepeat::operator ()(void) const {
00138     return cutoff;
00139   }
00140   unsigned long int
00141   CutoffRepeat::operator ++(void) {
00142     i++;
00143     if (i == n) {
00144       cutoff = (*c)();
00145       i = 0;
00146     }
00147     return cutoff;
00148   }
00149 
00150 
00151   Cutoff*
00152   Cutoff::constant(unsigned long int scale) {
00153     return new CutoffConstant(scale);
00154   }
00155   Cutoff*
00156   Cutoff::linear(unsigned long int scale) {
00157     return new CutoffLinear(scale);
00158   }
00159   Cutoff*
00160   Cutoff::luby(unsigned long int scale) {
00161     return new CutoffLuby(scale);
00162   }
00163   Cutoff*
00164   Cutoff::geometric(unsigned long int base, double scale) {
00165     return new CutoffGeometric(base,scale);
00166   }
00167   Cutoff*
00168   Cutoff::rnd(unsigned int seed,
00169               unsigned long int min,
00170               unsigned long int max,
00171               unsigned long int n) {
00172     return new CutoffRandom(seed,min,max,n);
00173   }
00174   Cutoff*
00175   Cutoff::append(Cutoff* c1, unsigned long int n, Cutoff* c2) {
00176     return new CutoffAppend(c1,n,c2);
00177   }
00178   Cutoff*
00179   Cutoff::merge(Cutoff* c1, Cutoff* c2) {
00180     return new CutoffMerge(c1,c2);
00181   }
00182   Cutoff*
00183   Cutoff::repeat(Cutoff* c, unsigned long int n) {
00184   return new CutoffRepeat(c,n);
00185   }
00186 
00187 }}
00188 
00189 // STATISTICS: search-other