lds.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, 2004, 2016 00008 * 00009 * Bugfixes provided by: 00010 * Stefano Gualandi 00011 * 00012 * Last modified: 00013 * $Date: 2016-09-22 16:19:20 +0200 (Thu, 22 Sep 2016) $ by $Author: schulte $ 00014 * $Revision: 15169 $ 00015 * 00016 * This file is part of Gecode, the generic constraint 00017 * development environment: 00018 * http://www.gecode.org 00019 * 00020 * Permission is hereby granted, free of charge, to any person obtaining 00021 * a copy of this software and associated documentation files (the 00022 * "Software"), to deal in the Software without restriction, including 00023 * without limitation the rights to use, copy, modify, merge, publish, 00024 * distribute, sublicense, and/or sell copies of the Software, and to 00025 * permit persons to whom the Software is furnished to do so, subject to 00026 * the following conditions: 00027 * 00028 * The above copyright notice and this permission notice shall be 00029 * included in all copies or substantial portions of the Software. 00030 * 00031 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00032 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00033 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00034 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00035 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00036 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00037 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00038 * 00039 */ 00040 00041 #include <gecode/search/sequential/lds.hh> 00042 00043 namespace Gecode { namespace Search { namespace Sequential { 00044 00045 /* 00046 * The probing engine: computes all solutions with 00047 * exact number of discrepancies (solutions with 00048 * fewer discrepancies are discarded) 00049 * 00050 */ 00051 Space* 00052 LDS::next(void) { 00053 while (true) { 00054 Space* s = e.next(opt); 00055 if (s != NULL) 00056 return s; 00057 if (((s == NULL) && e.stopped()) || (++d > opt.d_l) || e.done()) 00058 break; 00059 if (d == opt.d_l) { 00060 if (root != NULL) 00061 e.reset(root,d); 00062 root = NULL; 00063 } else if (root != NULL) { 00064 e.reset(root->clone(),d); 00065 } 00066 } 00067 return NULL; 00068 } 00069 00070 bool 00071 LDS::stopped(void) const { 00072 return e.stopped(); 00073 } 00074 00075 Statistics 00076 LDS::statistics(void) const { 00077 return e.statistics(); 00078 } 00079 00080 LDS::~LDS(void) { 00081 delete root; 00082 } 00083 00084 }}} 00085 00086 // STATISTICS: search-sequential