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

AC3.h

00001 // AC3.h -- The AC-3 filter interface.
00002 
00003 /*
00004  * Copyright (C) 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 // $Id: AC3_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00023 
00024 #ifndef _CSP_FILTERS_AC3_H
00025 #define _CSP_FILTERS_AC3_H
00026 
00027 
00028 CSP_NAMESPACE_BEGIN(csp);
00029 CSP_NAMESPACE_BEGIN(filters);
00030 
00031 
00035 class CSP_API AC3 :
00036     public Filter
00037 {
00038   public:
00039     AC3(Problem& problem, Retraction& retraction) :
00040         Filter(L"Arc Consistency 3", L"AC-3", problem, retraction) {}
00041     ~AC3() {}
00042 
00043     virtual bool init(
00044         const vlist_type& uninstantiatedVariables,
00045         bool propagate = true);
00046     virtual void done() { Filter::done(); }
00047 
00048     virtual bool restoresArcConsistency() const { return true; }
00049 
00050     virtual bool propagate(
00051         const vlist_type& uninstantiatedVariables,
00052         const vlist_type& modifiedVariables,
00053         const bool keepChanges = true);
00054 
00055     virtual wostream& print(wostream& wos) const;
00056 
00057   private:
00059     AC3(const AC3&);
00060 
00062     AC3& operator=(const AC3&);
00063 
00071     void insertInQueue(
00072         const Variable& variable0,
00073         const Variable& variable1,
00074         Constraint& constraint);
00075 
00083     void popFromQueue(
00084         const Variable& variable0,
00085         const Variable& variable1,
00086         const Constraint& constraint);
00087 
00096     bool isInQueue(
00097         const Variable& variable0,
00098         const Variable& variable1,
00099         const Constraint& constraint);
00100 
00105     void addRelatedConstraints(Variable& variable, const Constraint& unwanted);
00106 
00113     void addActiveConstraintPairs(const Variable& variable);
00114 
00116     Domain m_diffs;
00117 
00118     struct Edge
00119     {
00121         Constraint* m_constraint;
00122 
00124         bool m_reversed;
00125     };
00126 
00128     deque<Edge> m_queue;
00129 
00134     hash_set<const Constraint*> m_inQueueAsIJ;
00135 
00140     hash_set<const Constraint*> m_inQueueAsJI;
00141 };
00142 
00143 
00144 CSP_NAMESPACE_END(filters);
00145 CSP_NAMESPACE_END(csp);
00146 
00147 
00148 #endif // _CSP_FILTERS_AC3_H
00149 
00150 // Local Variables:
00151 // mode: C++
00152 // End:

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