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

CBJ.h

00001 // CBJ.h -- The `conflict-directed back jumping' retraction 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: CBJ_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00023 
00024 #ifndef _CSP_RETRACTIONS_CBJ_H
00025 #define _CSP_RETRACTIONS_CBJ_H
00026 
00027 
00028 CSP_NAMESPACE_BEGIN(csp);
00029 CSP_NAMESPACE_BEGIN(retractions);
00030 
00031 
00035 class CSP_API CBJ :
00036     public Retraction
00037 {
00038   public:
00039     CBJ(Problem& problem) :
00040         Retraction(L"Conflict Directed Backjumping", problem),
00041         m_success(true) {}
00042     virtual ~CBJ() {}
00043 
00044     virtual void init() { m_gcs.clear(); m_jumps.clear(); }
00045     virtual void done() { m_gcs.clear(); }
00046     virtual void start();
00047     virtual void stop();
00048 
00058     virtual void recordDomainChange(
00059         Variable& victim,
00060         Variable& aggressor);
00061 
00069     virtual void recordFailure(
00070         Constraint& constraint,
00071         Variable& victim,
00072         Variable& aggressor);
00073 
00080     virtual int computeJump(bool chronological = true) const;
00081 
00089     virtual void unifyConflictSets(int jumpDepth);
00090 
00098     virtual void eraseConflictSets(int jumpDepth);
00099 
00106     virtual wostream& print(wostream& wos) const;
00107 
00108   private:
00109     // This is how we represent a conflict set.
00110     typedef set<const Variable*, id_less<const Variable*> > cs_type;
00111 
00112     /* This is set to `false' if recordDomainFailure() gets called
00113        (i.e. the filter failed).  Otherwise it is `true'.  */
00114     bool m_success;
00115 
00116     // The global conflict sets (each variable has one).
00117     hash_map<id_t, cs_type> m_gcs;
00118 
00119     // The local conflict sets (each variable has one).
00120     hash_map<id_t, cs_type> m_lcs;
00121 
00122     // Used as a temp object for unions, for optimization.
00123     cs_type m_ucs;
00124 
00125     /* Keep track of the number of x-levels jumps, for reporting
00126        purposes.  */
00127     mutable vector<int> m_jumps;
00128 
00136     void unify(const Variable& src, const Variable& dest);
00137 
00144     void updateStatistics(int currentDepth, int jumpDepth) const;
00145 };
00146 
00147 
00148 CSP_NAMESPACE_END(retractions);
00149 CSP_NAMESPACE_END(csp);
00150 
00151 
00152 #endif // _CSP_RETRACTIONS_CBJ_H
00153 
00154 // Local Variables:
00155 // mode: C++
00156 // End:

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