Main Page | Class Hierarchy | Class List | File List | Class Members

Filter.h

00001 // Filter.h -- The interface to the super class of all CSP filters.
00002 
00003 /*
00004  * Copyright (C) 1997, 1998 Tudor Hulubei <tudor@hulubei.net>.
00005  *
00006  * This library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2, or (at
00009  * your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00019  * 02111-1307, USA.
00020  */
00021 
00022 /*
00023  * NOTE: This is an interal header file.
00024  * You should not attempt to use it directly.
00025  */
00026 
00027 // $Id: Filter_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00028 
00029 #ifndef _CSP_KERNEL_Filter_H
00030 #define _CSP_KERNEL_Filter_H
00031 
00032 
00033 CSP_NAMESPACE_BEGIN(csp);
00034 
00035 
00036 class CSP_API Retraction;
00037 
00038 
00042 class CSP_API Filter
00043 {
00044   public:
00052     Filter(
00053         const wstring& fullName,
00054         const wstring& shortName,
00055         Problem& problem,
00056         Retraction& retraction) :
00057         m_fullName(fullName),
00058         m_shortName(shortName),
00059         m_problem(problem),
00060         m_retraction(retraction) {}
00061 
00062     virtual ~Filter() {}
00063 
00065     const wstring name() const {
00066         return m_fullName + L" (" + m_shortName + L")"; }
00067 
00069     const wstring& fullName() const { return m_fullName; }
00070 
00072     const wstring& shortName() const { return m_shortName; }
00073 
00075     const Problem& problem() const { return m_problem; }
00076 
00078     Problem& problem() { return m_problem; }
00079 
00084     const Retraction& retraction() const { return m_retraction; }
00085 
00090     Retraction& retraction() { return m_retraction; }
00091 
00098     void recordDomainChange(
00099         Variable& victim,
00100         Variable& aggressor);
00101 
00110     void recordFailure(
00111         Constraint& constraint,
00112         Variable& victim,
00113         Variable& aggressor);
00114 
00123     void updateValueFailures(Domain& diffs);
00124 
00168     virtual bool restoresArcConsistency() const = 0;
00169 
00177     bool subProblemIsArcConsistent(bool debugging) const;
00178 
00184     virtual bool isDummy() const { return false; }
00185 
00236     virtual bool propagate(
00237         const vlist_type& uninstantiatedVariables,
00238         const vlist_type& modifiedVariables,
00239         const bool keepChanges = true) = 0;
00240 
00248     const hash_set<const Variable*>& prunedVariables() const
00249     {
00250         return m_prunedVariables;
00251     }
00252 
00264     virtual bool init(
00265         const vlist_type& /*uninstantiatedVariables*/,
00266         bool /*propagate*/ = true)
00267     {
00268         return true;
00269     }
00270 
00277     virtual void done() {}
00278 
00287     virtual void restrict(const vlist_type& /*variables*/) {}
00288 
00293     virtual void unrestrict() {}
00294 
00301     virtual wostream& print(wostream& wos) const
00302     {
00303         return wos << L"Filter: " << name() << endl;
00304     }
00305 
00306     friend CSP_API wostream& operator<<(wostream& wos, const Filter& filter)
00307     {
00308         return filter.print(wos);
00309     }
00310 
00319     static void saveState(const list<Variable*>& variables);
00320 
00329     static void restoreState(const list<Variable*>& variables);
00330 
00339     static void postponeState(const list<Variable*>& variables);
00340 
00341   private:
00343     const wstring m_fullName;
00344 
00346     const wstring m_shortName;
00347 
00348   protected:
00350     Problem& m_problem;
00351 
00353     Retraction& m_retraction;
00354 
00356     void clearPrunedVariables() { m_prunedVariables.clear(); }
00357 
00358   private:
00360     Filter(const Filter&);
00361 
00363     Filter& operator=(const Filter&);
00364 
00369     hash_set<const Variable*> m_prunedVariables;
00370 };
00371 
00372 
00373 CSP_NAMESPACE_END(csp);
00374 
00375 
00376 #endif // _CSP_KERNEL_Filter_H
00377 
00378 // Local Variables:
00379 // mode: C++
00380 // End:

Generated on Wed May 25 12:21:14 2005 for csp.kdevelop by  doxygen 1.3.9.1