Generated on Tue May 22 09:40:12 2018 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  *  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 <algorithm>
00039 #include <gecode/search.hh>
00040 
00041 namespace Gecode { namespace Search {
00042 
00043   unsigned long int
00044   CutoffConstant::operator ()(void) const {
00045     return c;
00046   }
00047   unsigned long int
00048   CutoffConstant::operator ++(void) {
00049     return c;
00050   }
00051 
00052 
00053   unsigned long int
00054   CutoffLinear::operator ()(void) const {
00055     return n;
00056   }
00057   unsigned long int
00058   CutoffLinear::operator ++(void) {
00059     n += scale;
00060     return n;
00061   }
00062 
00063 
00064   unsigned long int
00065   CutoffLuby::start[CutoffLuby::n_start] = {
00066     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,
00067     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
00068   };
00069   unsigned long int
00070   CutoffLuby::operator ()(void) const {
00071     return scale*luby(i);
00072   }
00073   unsigned long int
00074   CutoffLuby::operator ++(void) {
00075     return scale*luby(i++);
00076   }
00077 
00078 
00079   unsigned long int
00080   CutoffGeometric::operator ()(void) const {
00081     return static_cast<unsigned long int>(scale * n);
00082   }
00083   unsigned long int
00084   CutoffGeometric::operator ++(void) {
00085     n *= base;
00086     return static_cast<unsigned long int>(scale * n);
00087   }
00088 
00089 
00090   unsigned long int
00091   CutoffRandom::operator ++(void) {
00092     cur = min+step*rnd(n);
00093     return cur;
00094   }
00095   unsigned long int
00096   CutoffRandom::operator ()(void) const {
00097     return cur;
00098   }
00099 
00100 
00101   unsigned long int
00102   CutoffAppend::operator ()(void) const {
00103     if (n > 0) {
00104       return (*c1)();
00105     } else {
00106       return (*c2)();
00107     }
00108   }
00109   unsigned long int
00110   CutoffAppend::operator ++(void) {
00111     if (n > 0) {
00112       n--;
00113       return ++(*c1);
00114     } else {
00115       return ++(*c2);
00116     }
00117   }
00118 
00119 
00120   unsigned long int
00121   CutoffMerge::operator ()(void) const {
00122     return (*c1)();
00123   }
00124   unsigned long int
00125   CutoffMerge::operator ++(void) {
00126     (void) ++(*c1);
00127     std::swap(c1,c2);
00128     return (*c1)();
00129   }
00130 
00131 
00132   unsigned long int
00133   CutoffRepeat::operator ()(void) const {
00134     return cutoff;
00135   }
00136   unsigned long int
00137   CutoffRepeat::operator ++(void) {
00138     i++;
00139     if (i == n) {
00140       cutoff = (*c)();
00141       i = 0;
00142     }
00143     return cutoff;
00144   }
00145 
00146 
00147   Cutoff*
00148   Cutoff::constant(unsigned long int scale) {
00149     return new CutoffConstant(scale);
00150   }
00151   Cutoff*
00152   Cutoff::linear(unsigned long int scale) {
00153     return new CutoffLinear(scale);
00154   }
00155   Cutoff*
00156   Cutoff::luby(unsigned long int scale) {
00157     return new CutoffLuby(scale);
00158   }
00159   Cutoff*
00160   Cutoff::geometric(unsigned long int base, double scale) {
00161     return new CutoffGeometric(base,scale);
00162   }
00163   Cutoff*
00164   Cutoff::rnd(unsigned int seed,
00165               unsigned long int min,
00166               unsigned long int max,
00167               unsigned long int n) {
00168     return new CutoffRandom(seed,min,max,n);
00169   }
00170   Cutoff*
00171   Cutoff::append(Cutoff* c1, unsigned long int n, Cutoff* c2) {
00172     return new CutoffAppend(c1,n,c2);
00173   }
00174   Cutoff*
00175   Cutoff::merge(Cutoff* c1, Cutoff* c2) {
00176     return new CutoffMerge(c1,c2);
00177   }
00178   Cutoff*
00179   Cutoff::repeat(Cutoff* c, unsigned long int n) {
00180   return new CutoffRepeat(c,n);
00181   }
00182 
00183 }}
00184 
00185 // STATISTICS: search-other