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

AC3x.h

00001 // AC3x.h -- The AC-3x 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: AC3x_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00023 
00024 #ifndef _CSP_FILTERS_AC3X_H
00025 #define _CSP_FILTERS_AC3X_H
00026 
00027 
00028 CSP_NAMESPACE_BEGIN(csp);
00029 CSP_NAMESPACE_BEGIN(filters);
00030 
00031 
00035 class CSP_API AC3x :
00036     public Filter
00037 {
00038   public:
00039     AC3x(Problem& problem, Retraction& retraction, bool optimizeCC = false) :
00040         Filter(L"Arc Consistency 3x", L"AC-3x", problem, retraction) {
00041         m_optimizeCC = optimizeCC; }
00042     ~AC3x() {}
00043 
00044     virtual bool init(
00045         const vlist_type& uninstantiatedVariables,
00046         bool propagate = true);
00047     virtual void done() { Filter::done(); }
00048 
00049     virtual bool restoresArcConsistency() const { return true; }
00050 
00051     virtual bool propagate(
00052         const vlist_type& uninstantiatedVariables,
00053         const vlist_type& modifiedVariables,
00054         const bool keepChanges = true);
00055 
00056   private:
00061     void queueInit();
00062 
00064     void queueClear();
00065 
00067     void queueMaintain();
00068 
00070     void queuePush(Constraint& c);
00071 
00073     void queuePop();
00074 
00076     bool queueEmpty() const;
00077 
00079     Constraint& queueTop() const;
00080 
00082     Domain m_diffs;
00083 
00084     // The queue of constraints to be processed.
00085     vector<Constraint*> m_heap;
00086 
00087     // The queue of constraints to be processed.
00088     deque<Constraint*> m_queue;
00089 
00090     /* Depending on whether or not this is true, we use `m_heap' or
00091        `m_queue'.  The use of `m_heap' will cut down the number of
00092        constraint checks, but it is expensive and in practice it
00093        doesn't seem to be worth the trouble, which is why it is
00094        turned off.  */
00095     bool m_optimizeCC;
00096 
00097     // `true' for constraints already in the queue.
00098     hash_set<const Constraint*> m_inQueue;
00099 
00101     AC3x(const AC3x&);
00102 
00104     AC3x& operator=(const AC3x&);
00105 
00106     /* Return `true' if the unary constraint `constraint' can be
00107        satisfied.  */
00108     bool pruneUnaryConstraint(Constraint& constraint);
00109 
00110     /* Make sure the domains of all the variables involved in the
00111        given constraint have support.  Return `true' on succes (no dwo),
00112        `false' otherwise.  */
00113     bool pruneBinaryConstraint(Constraint& c);
00114 
00119     void addRelatedConstraints(Constraint& constraint, Variable& variable);
00120 
00128     void addActiveConstraints(const Variable& variable);
00129 };
00130 
00131 
00132 CSP_NAMESPACE_END(filters);
00133 CSP_NAMESPACE_END(csp);
00134 
00135 
00136 #endif // _CSP_FILTERS_AC3X_H
00137 
00138 // Local Variables:
00139 // mode: C++
00140 // End:

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