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

variables/SolutionProbability.h

00001 // SolutionProbability.h -- The `minimum/maximum solution probability'
00002 // variable ordering heuristic interface.
00003 
00004 /*
00005  * Copyright (C) 2004 Tudor Hulubei <tudor@hulubei.net>.
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as
00009  * published by the Free Software Foundation; either version 2, or (at
00010  * your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00020  * 02111-1307, USA.
00021  */
00022 
00023 // $Id: variables_2SolutionProbability_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00024 
00025 #ifndef _CSP_HEURISTICS_VARIABLE_SolutionProbability_H
00026 #define _CSP_HEURISTICS_VARIABLE_SolutionProbability_H
00027 
00028 
00029 #include "../../caches/DomainSizes.h"
00030 
00031 
00032 //#define SP_VAR_LOOK_AROUND 1
00033 
00034 
00035 #ifdef SP_VAR_LOOK_AROUND
00036 #include <gmpxx.h>
00037 #endif
00038 
00039 
00040 CSP_NAMESPACE_BEGIN(csp);
00041 CSP_NAMESPACE_BEGIN(heuristics);
00042 CSP_NAMESPACE_BEGIN(variables);
00043 
00044 
00045 /*
00046  * This variable ordering heuristic should select the variables that,
00047  * when instantiated, maximizes the probability of finding a solution
00048  * in the remaining subproblem.  The heuristic works by computing the
00049  * set of active constraints in which the problem's uninstantiated
00050  * variables are involved, and multiplying their probabilities of
00051  * being satisfied, either based on the initial set of allowed tuples
00052  * or the current one (in the dynamic version).  This computation is
00053  * performed n times (with n the number of uninstantiated variables),
00054  * each time with a different variable and its constraints being taken
00055  * out of the set, so that we can calculate the probability of finding
00056  * a solution in the remaining problem.  Obviously, both the static
00057  * and the dynamic version of this heuristic are very expensive.
00058  */
00059 class CSP_API SolutionProbability :
00060     public VariableOH
00061 {
00062   public:
00063 #ifdef SP_VAR_LOOK_AROUND
00064     typedef mpf_class Real;
00065 #else
00066     typedef long double Real;
00067 #endif
00068 
00069     enum Preference
00070     {
00072         Minimum,
00073 
00075         Maximum
00076     };
00077 
00090     SolutionProbability(
00091         Decomposition& decomposition,
00092         const vector<pair<double, double> >& intervals,
00093         double quality = 1,
00094         Preference preference = Minimum,
00095         bool dynamic = false);
00096 
00104     virtual void select(vlist_type& selectable, vlist_type& selected);
00105 
00106   private:
00108     SolutionProbability(const SolutionProbability&);
00109 
00111     SolutionProbability& operator=(const SolutionProbability&);
00112 
00120     ulonglong maxTuples(const Constraint& constraint);
00121 
00128     Real constraintProbability(const Constraint& constraint);
00129 
00137     void computeProbabilities(
00138         const Decomposition::ActiveConstraintsSet& acs,
00139         const Decomposition::ActiveVariablesSet& avs);
00140 
00146     void computeMaxTuples(
00147         const Decomposition::ActiveConstraintsSet& acs);
00148 
00155     void computeValueProbabilities(
00156         const Decomposition::ActiveVariablesSet& avs);
00157 
00159     void clearCaches();
00160 
00168     Real subproblemSolutionProbability(
00169         const Decomposition::ActiveConstraintsSet& acs) const;
00170 
00178     Real multiplyProbabilities(const Variable& variable) const;
00179 
00181     typedef hash_map<const Constraint*, Real> cp_type;
00182 
00184     typedef hash_map<const Constraint*, ulonglong> mt_type;
00185 
00187     typedef hash_map<const Value*, Real> vp_type;
00188 
00190     typedef hash_map<const Variable*, vp_type*> vs_type;
00191 
00193     cp_type m_constraintProbabilities;
00194 
00196     mt_type m_maxTuples;
00197 
00199     vs_type m_valueProbabilities;
00200 
00202     caches::DomainSizes m_domainSizes;
00203 
00205     Preference m_preference;
00206 
00211     bool m_dynamic;
00212 
00218     Real m_precision;
00219 };
00220 
00221 
00222 CSP_NAMESPACE_END(variables);
00223 CSP_NAMESPACE_END(heuristics);
00224 CSP_NAMESPACE_END(csp);
00225 
00226 
00227 #endif // _CSP_HEURISTICS_VARIABLE_SolutionProbability_H
00228 
00229 // Local Variables:
00230 // mode: C++
00231 // End:

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