Česky
Kamil Dudka

Fast SAT Solver (C++, GAlib)

File detail

Name:DownloadGaSatSolver_8cpp-source.html [Download]
Location: fss > doc > api > html
Size:32.9 KB
Last modification:2022-09-09 13:06

Source code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Fast SAT Solver: GaSatSolver.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.4 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li><a href="annotated.html"><span>Classes</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
  </ul>
</div>
<h1>GaSatSolver.cpp</h1><a href="GaSatSolver_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2008 Kamil Dudka &lt;xdudka00@stud.fit.vutbr.cz&gt;</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This file is part of fss (Fast SAT Solver).</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * fss is free software: you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment"> * any later version.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * fss is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment"> * along with fss.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00018"></a>00018 <span class="comment"> */</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;ga/GA1DBinStrGenome.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;ga/GASimpleGA.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;ga/GAStatistics.h&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="fssIO_8h.html" title="I/O module.">fssIO.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="SatProblem_8h.html" title="SAT Problem representation.">SatProblem.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="GaSatSolver_8h.html" title="GaSatSolver class using GAlib library to solve SAT problem.">GaSatSolver.h</a>"</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="comment">//#include &lt;ga/GASStateGA.h&gt;</span>
<a name="l00029"></a>00029 <span class="comment">//#include &lt;ga/GAIncGA.h&gt;</span>
<a name="l00030"></a>00030 <span class="comment">//#include &lt;ga/GADemeGA.h&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a><a class="code" href="GaSatSolver_8cpp.html#9795659bc91c151a3ed460dfdb658e74">00032</a> <span class="keyword">typedef</span> GASimpleGA <a class="code" href="GaSatSolver_8cpp.html#9795659bc91c151a3ed460dfdb658e74">TGeneticAlgorithm</a>;
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">namespace </span>FastSatSolver {
<a name="l00035"></a>00035 
<a name="l00036"></a>00036   <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00037"></a>00037   <span class="comment">// GaSatItem implementation</span>
<a name="l00038"></a><a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html">00038</a>   <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html">GaSatItem::Private</a> {
<a name="l00039"></a><a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">00039</a>     GABinaryString <a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>;
<a name="l00040"></a>00040 
<a name="l00041"></a><a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#944f97fa8f0810643691dfdfc9f810e0">00041</a>     <a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#944f97fa8f0810643691dfdfc9f810e0">Private</a>(<span class="keywordtype">unsigned</span> size): <a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>(size) { }
<a name="l00042"></a>00042   };
<a name="l00043"></a><a class="code" href="classFastSatSolver_1_1GaSatItem.html#9a7f9bea9f7f2870c44d1692b989881e">00043</a>   <a class="code" href="classFastSatSolver_1_1GaSatItem.html#9a7f9bea9f7f2870c44d1692b989881e">GaSatItem::GaSatItem</a>(<span class="keyword">const</span> GABinaryString &amp;bs):
<a name="l00044"></a>00044     d(new <a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html">Private</a>(bs.size()))
<a name="l00045"></a>00045   {
<a name="l00046"></a>00046     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>.copy(bs);
<a name="l00047"></a>00047   }
<a name="l00048"></a><a class="code" href="classFastSatSolver_1_1GaSatItem.html#1ab756a0f3ce624a1d1c0f45cd9b4dde">00048</a>   GaSatItem::~GaSatItem() {
<a name="l00049"></a>00049     <span class="keyword">delete</span> d;
<a name="l00050"></a>00050   }
<a name="l00051"></a><a class="code" href="classFastSatSolver_1_1GaSatItem.html#f59b115e86eaeac1f15673766852e428">00051</a>   <span class="keywordtype">int</span> <a class="code" href="classFastSatSolver_1_1GaSatItem.html#f59b115e86eaeac1f15673766852e428" title="Returns count of bits (resp. variables) managed by object.">GaSatItem::getLength</a>()<span class="keyword"> const </span>{
<a name="l00052"></a>00052     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>.size();
<a name="l00053"></a>00053   }
<a name="l00054"></a><a class="code" href="classFastSatSolver_1_1GaSatItem.html#02914b181415dd30b58db5408487a8e1">00054</a>   <span class="keywordtype">bool</span> <a class="code" href="classFastSatSolver_1_1GaSatItem.html#02914b181415dd30b58db5408487a8e1" title="Returns value of desired bit (resp. variable).">GaSatItem::getBit</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const </span>{
<a name="l00055"></a>00055     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>.bit(index);
<a name="l00056"></a>00056   }
<a name="l00057"></a><a class="code" href="classFastSatSolver_1_1GaSatItem.html#be193dccd5bf6292787bda695498aace">00057</a>   <a class="code" href="classFastSatSolver_1_1GaSatItem.html" title="ISatItem implementation used by GaSatSolver.">GaSatItem</a>* <a class="code" href="classFastSatSolver_1_1GaSatItem.html#be193dccd5bf6292787bda695498aace" title="Returns clone of object&amp;#39;s instance.">GaSatItem::clone</a>()<span class="keyword"> const </span>{
<a name="l00058"></a>00058     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classFastSatSolver_1_1GaSatItem.html#9a7f9bea9f7f2870c44d1692b989881e">GaSatItem</a>(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatItem_1_1Private.html#05a5ce6bfc46e3e304f1df2217f59690">bs</a>);
<a name="l00059"></a>00059   }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061   <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00062"></a>00062   <span class="comment">// SatItemGalibAdatper implementation</span>
<a name="l00063"></a><a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#a16fa6f95b23e204bc8bd49a268e00f3">00063</a>   <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#a16fa6f95b23e204bc8bd49a268e00f3">SatItemGalibAdatper::SatItemGalibAdatper</a>(<span class="keyword">const</span> GABinaryString &amp;bs):
<a name="l00064"></a>00064     bs_(bs)
<a name="l00065"></a>00065   {
<a name="l00066"></a>00066   }
<a name="l00067"></a><a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#b3dfe49bcf358268bd5b67def3472e64">00067</a>   <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#b3dfe49bcf358268bd5b67def3472e64">SatItemGalibAdatper::~SatItemGalibAdatper</a>() { }
<a name="l00068"></a><a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#f59b115e86eaeac1f15673766852e428">00068</a>   <span class="keywordtype">int</span> <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#f59b115e86eaeac1f15673766852e428" title="Returns count of bits (resp. variables) managed by object.">SatItemGalibAdatper::getLength</a>()<span class="keyword"> const </span>{
<a name="l00069"></a>00069     <span class="keywordflow">return</span> bs_.size();
<a name="l00070"></a>00070   }
<a name="l00071"></a><a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#02914b181415dd30b58db5408487a8e1">00071</a>   <span class="keywordtype">bool</span> <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#02914b181415dd30b58db5408487a8e1" title="Returns value of desired bit (resp. variable).">SatItemGalibAdatper::getBit</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const </span>{
<a name="l00072"></a>00072     <span class="keywordflow">return</span> bs_.bit(index);
<a name="l00073"></a>00073   }
<a name="l00074"></a>00074   <span class="comment">// FIXME: There is no deep copy (optimalization)</span>
<a name="l00075"></a><a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#63bba39b2b1ae2152c70546532ffccc6">00075</a>   <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html" title="Leightweight, optimized ISatItem implementation used by GaSatSolver time-critical...">SatItemGalibAdatper</a>* <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#63bba39b2b1ae2152c70546532ffccc6" title="Returns clone of object&amp;#39;s instance.">SatItemGalibAdatper::clone</a>()<span class="keyword"> const </span>{
<a name="l00076"></a>00076     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html#a16fa6f95b23e204bc8bd49a268e00f3">SatItemGalibAdatper</a>(bs_);
<a name="l00077"></a>00077   }
<a name="l00078"></a>00078 
<a name="l00079"></a>00079   <span class="comment">// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00080"></a>00080   <span class="comment">// GaSatSolver implementation</span>
<a name="l00081"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html">00081</a>   <span class="keyword">struct </span><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html">GaSatSolver::Private</a> {
<a name="l00082"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#74a878161cb263331f8413b1502a482a">00082</a>     <a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a>                *problem;
<a name="l00083"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#a7592b04ea348c57b37a117ba1f9ffc2">00083</a>     <a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a>               *solver;
<a name="l00084"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">00084</a>     <span class="keywordtype">float</span>                     maxFitness;
<a name="l00085"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#2ff18683899bb37f7be06cddde88b13d">00085</a>     GA1DBinaryStringGenome    *genome;
<a name="l00086"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">00086</a>     <a class="code" href="GaSatSolver_8cpp.html#9795659bc91c151a3ed460dfdb658e74">TGeneticAlgorithm</a>         *ga;
<a name="l00087"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">00087</a>     <a class="code" href="classFastSatSolver_1_1SatItemSet.html" title="Associative array for ISatItem objects.">SatItemSet</a>                *resultSet;
<a name="l00088"></a>00088 
<a name="l00089"></a>00089     <span class="keyword">static</span> <span class="keywordtype">float</span> fitness(GAGenome &amp;);
<a name="l00090"></a>00090   };
<a name="l00091"></a>00091   <span class="comment">// protected</span>
<a name="l00092"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#5800d77805ee60252d59d43e4a786cdc">00092</a>   <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#5800d77805ee60252d59d43e4a786cdc" title="Non-public constructor. Use static method create() instead.">GaSatSolver::GaSatSolver</a> (<a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a> *problem, <span class="keyword">const</span> GAParameterList &amp;params):
<a name="l00093"></a>00093     d(new <a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html">Private</a>)
<a name="l00094"></a>00094   {
<a name="l00095"></a>00095     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#74a878161cb263331f8413b1502a482a">problem</a> = problem;
<a name="l00096"></a>00096     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#a7592b04ea348c57b37a117ba1f9ffc2">solver</a> = <span class="keyword">this</span>;
<a name="l00097"></a>00097     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = 0.0;
<a name="l00098"></a>00098     <span class="keyword">const</span> <span class="keywordtype">int</span> varsCount = problem-&gt;<a class="code" href="classFastSatSolver_1_1SatProblem.html#92e7e3731c3c44467cadeb9038dd4cb9" title="Returns total count of variables managed by SatProblem.">getVarsCount</a>();
<a name="l00099"></a>00099     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#2ff18683899bb37f7be06cddde88b13d">genome</a> = <span class="keyword">new</span> GA1DBinaryStringGenome(varsCount, <a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#69c383de18f3cd26911dff4a44bd5417">Private::fitness</a>, d);
<a name="l00100"></a>00100     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a> = <span class="keyword">new</span> <a class="code" href="GaSatSolver_8cpp.html#9795659bc91c151a3ed460dfdb658e74">TGeneticAlgorithm</a>(*(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#2ff18683899bb37f7be06cddde88b13d">genome</a>));
<a name="l00101"></a>00101     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;parameters(params);
<a name="l00102"></a>00102     <span class="keywordtype">bool</span> termUponConvergence = <span class="keyword">false</span>;
<a name="l00103"></a>00103     params.get(<span class="stringliteral">"term_upon_convergence"</span>, &amp;termUponConvergence);
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (termUponConvergence)
<a name="l00105"></a>00105       d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;terminator(GAGeneticAlgorithm::TerminateUponConvergence);
<a name="l00106"></a>00106       <span class="comment">//d-&gt;ga-&gt;terminator(GAGeneticAlgorithm::TerminateUponPopConvergence);</span>
<a name="l00107"></a>00107     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a> = <span class="keyword">new</span> <a class="code" href="classFastSatSolver_1_1SatItemSet.html" title="Associative array for ISatItem objects.">SatItemSet</a>;
<a name="l00108"></a>00108   }
<a name="l00109"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#85731baa47549065bff3846628f55e0f">00109</a>   <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#85731baa47549065bff3846628f55e0f">GaSatSolver::~GaSatSolver</a>() {
<a name="l00110"></a>00110     <span class="keyword">delete</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a>;
<a name="l00111"></a>00111     <span class="keyword">delete</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>;
<a name="l00112"></a>00112     <span class="keyword">delete</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#2ff18683899bb37f7be06cddde88b13d">genome</a>;
<a name="l00113"></a>00113     <span class="keyword">delete</span> d;
<a name="l00114"></a>00114   }
<a name="l00115"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#c162276cd1a753ecbba6e64f367fef60">00115</a>   <a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a>* <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#c162276cd1a753ecbba6e64f367fef60" title="Simple factory method.">GaSatSolver::create</a> (<a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a> *problem, <span class="keyword">const</span> GAParameterList &amp;params) {
<a name="l00116"></a>00116     <a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a> *obj = <span class="keyword">new</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#5800d77805ee60252d59d43e4a786cdc" title="Non-public constructor. Use static method create() instead.">GaSatSolver</a>(problem, params);
<a name="l00117"></a>00117     obj-&gt;<a class="code" href="classFastSatSolver_1_1GaSatSolver.html#25a40b6614565f755233080a384c35f1" title="Initialize process.">initialize</a>();
<a name="l00118"></a>00118     <span class="keywordflow">return</span> obj;
<a name="l00119"></a>00119   }
<a name="l00120"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#dfe44037a7f3a1f48e063707acca8c5e">00120</a>   <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#dfe44037a7f3a1f48e063707acca8c5e" title="Extends GAParameterList with GA-specific parameters.">GaSatSolver::registerDefaultParameters</a>(GAParameterList &amp;params) {
<a name="l00121"></a>00121     TGeneticAlgorithm::registerDefaultParameters(params);
<a name="l00122"></a>00122     <span class="keyword">const</span> <span class="keywordtype">bool</span> FALSE = <span class="keyword">false</span>;
<a name="l00123"></a>00123     params.add(<span class="stringliteral">"term_upon_convergence"</span>, <span class="stringliteral">"convterm"</span>, GAParameter::BOOLEAN, &amp;FALSE);
<a name="l00124"></a>00124   }
<a name="l00125"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#0f8b9a0b5b88a1091aee75779d1b7cb7">00125</a>   <a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a>* <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#0f8b9a0b5b88a1091aee75779d1b7cb7" title="Returns pointer to instance of SatProblem used by solver.">GaSatSolver::getProblem</a>() {
<a name="l00126"></a>00126     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#74a878161cb263331f8413b1502a482a">problem</a>;
<a name="l00127"></a>00127   }
<a name="l00128"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#a7b4044638ce63985c719e6f456a8ea5">00128</a>   <span class="keyword">const</span> GAStatistics&amp; <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#a7b4044638ce63985c719e6f456a8ea5" title="Returns useful statistic data managed by GAStatistics class.">GaSatSolver::getStatistics</a>()<span class="keyword"> const </span>{
<a name="l00129"></a>00129     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;statistics();
<a name="l00130"></a>00130   }
<a name="l00131"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#7b0abc45218a7539d5c842d0d23d1c2e">00131</a>   <span class="keywordtype">int</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#7b0abc45218a7539d5c842d0d23d1c2e" title="Returns current count solutions founded by solver.">GaSatSolver::getSolutionsCount</a>() {
<a name="l00132"></a>00132     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a>-&gt;<a class="code" href="classFastSatSolver_1_1SatItemSet.html#ab0d4bbd0884d04dbe281cc2b9d21206" title="Returns count of item managed by container.">getLength</a>();
<a name="l00133"></a>00133   }
<a name="l00134"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#afe4f04b889ee848eb52271ea1f4f9ef">00134</a>   <a class="code" href="classFastSatSolver_1_1SatItemVector.html" title="Linear storage container for ISatItem objects.">SatItemVector</a>* <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#afe4f04b889ee848eb52271ea1f4f9ef" title="Returns a set of solutions founded by solver.">GaSatSolver::getSolutionVector</a>() {
<a name="l00135"></a>00135     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a>-&gt;<a class="code" href="classFastSatSolver_1_1SatItemSet.html#1ec6a07165be87a359b04ee833c0a283" title="Export container&amp;#39;s content to SatItemVector.">createVector</a>();
<a name="l00136"></a>00136   }
<a name="l00137"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#3e12cbdb3e43385dc45fc10f703af769">00137</a>   <span class="keywordtype">float</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#3e12cbdb3e43385dc45fc10f703af769" title="Returns fitness of the Worst solution managed by solver.">GaSatSolver::minFitness</a>() {
<a name="l00138"></a>00138     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;statistics().offlineMin();
<a name="l00139"></a>00139   }
<a name="l00140"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#c38f955a6e6a313249883aa555ab36b6">00140</a>   <span class="keywordtype">float</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#c38f955a6e6a313249883aa555ab36b6" title="Returns average fitness computed by solver.">GaSatSolver::avgFitness</a>() {
<a name="l00141"></a>00141     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;statistics().offlineMax();
<a name="l00142"></a>00142   }
<a name="l00143"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#a4ff4f00ef1022a70f538e32d7a2e07b">00143</a>   <span class="keywordtype">float</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#a4ff4f00ef1022a70f538e32d7a2e07b" title="Returns the Best fitness founded by solver.">GaSatSolver::maxFitness</a>() {
<a name="l00144"></a>00144     <span class="keywordflow">return</span> d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a>;
<a name="l00145"></a>00145   }
<a name="l00146"></a>00146   <span class="comment">// protected</span>
<a name="l00147"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#25a40b6614565f755233080a384c35f1">00147</a>   <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#25a40b6614565f755233080a384c35f1" title="Initialize process.">GaSatSolver::initialize</a>() {
<a name="l00148"></a>00148     GARandomSeed();
<a name="l00149"></a>00149     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = 0.0;
<a name="l00150"></a>00150     d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>-&gt;initialize();
<a name="l00151"></a>00151     <span class="comment">// Now using incremental strategy</span>
<a name="l00152"></a>00152     <span class="comment">// d-&gt;resultSet-&gt;clear();</span>
<a name="l00153"></a>00153   }
<a name="l00154"></a>00154   <span class="comment">// protected</span>
<a name="l00155"></a><a class="code" href="classFastSatSolver_1_1GaSatSolver.html#931514cf013abbc0b9511a44c1f7fe48">00155</a>   <span class="keywordtype">void</span> <a class="code" href="classFastSatSolver_1_1GaSatSolver.html#931514cf013abbc0b9511a44c1f7fe48" title="Do one step of process.">GaSatSolver::doStep</a>() {
<a name="l00156"></a>00156     GAGeneticAlgorithm &amp;ga= *(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#089431747ac13c76d93b4687eab6e0a4">ga</a>);
<a name="l00157"></a>00157     ga.step();
<a name="l00158"></a>00158     <span class="keywordflow">if</span> (ga.done()) {
<a name="l00159"></a>00159       this-&gt;<a class="code" href="classFastSatSolver_1_1AbstractProcessWatched.html#8c528baf37154d347366083f0f816846" title="Stop currently executed process as soon as possible.">stop</a>();
<a name="l00160"></a>00160 <span class="preprocessor">#if 0//ndef NDEBUG</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span>      std::cerr &lt;&lt; <span class="stringliteral">"&gt;&gt;&gt; Stopped by GAlib terminator"</span> &lt;&lt; std::endl;
<a name="l00162"></a>00162 <span class="preprocessor">#endif // NDEBUG</span>
<a name="l00163"></a>00163 <span class="preprocessor"></span>    }
<a name="l00164"></a>00164   }
<a name="l00165"></a><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#69c383de18f3cd26911dff4a44bd5417">00165</a>   <span class="keywordtype">float</span> <a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#69c383de18f3cd26911dff4a44bd5417">GaSatSolver::Private::fitness</a>(GAGenome &amp;genome) {
<a name="l00166"></a>00166     <span class="comment">// Static to non-static binding</span>
<a name="l00167"></a>00167     <a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html">Private</a> *d = <span class="keyword">reinterpret_cast&lt;</span><a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html">Private</a> *<span class="keyword">&gt;</span>(genome.userData());
<a name="l00168"></a>00168     <a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a> *<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#74a878161cb263331f8413b1502a482a">problem</a> = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classFastSatSolver_1_1SatProblem.html" title="SAT Problem module&amp;#39;s facade.">SatProblem</a> *<span class="keyword">&gt;</span>(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#74a878161cb263331f8413b1502a482a">problem</a>);
<a name="l00169"></a>00169     <a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a> *<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#a7592b04ea348c57b37a117ba1f9ffc2">solver</a> = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classFastSatSolver_1_1GaSatSolver.html" title="Solver using GAlib library to solve SAT problem.">GaSatSolver</a> *<span class="keyword">&gt;</span>(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#a7592b04ea348c57b37a117ba1f9ffc2">solver</a>);
<a name="l00170"></a>00170     <span class="keyword">const</span> GABinaryString &amp;bs= <span class="keyword">dynamic_cast&lt;</span>GABinaryString &amp;<span class="keyword">&gt;</span>(genome);
<a name="l00171"></a>00171     <a class="code" href="classFastSatSolver_1_1SatItemSet.html" title="Associative array for ISatItem objects.">SatItemSet</a> *<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a>= <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classFastSatSolver_1_1SatItemSet.html" title="Associative array for ISatItem objects.">SatItemSet</a> *<span class="keyword">&gt;</span>(d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#7489b689bcc371cb84451df846096df1">resultSet</a>);
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="comment">// Compute fitness</span>
<a name="l00174"></a>00174     <a class="code" href="classFastSatSolver_1_1SatItemGalibAdatper.html" title="Leightweight, optimized ISatItem implementation used by GaSatSolver time-critical...">SatItemGalibAdatper</a> data(bs);
<a name="l00175"></a>00175     <span class="keyword">const</span> <span class="keywordtype">int</span> formulasCount = problem-&gt;<a class="code" href="classFastSatSolver_1_1SatProblem.html#fa9215848a08453610b67d1eb882c641" title="Returns total count of formulas managed by SatProblem.">getFormulasCount</a>();
<a name="l00176"></a>00176     <span class="keyword">const</span> <span class="keywordtype">int</span> satsCount = problem-&gt;<a class="code" href="classFastSatSolver_1_1SatProblem.html#3c6475887daf5925eadbc98109b8a3dc" title="Evaluate all formulas in container using given data and return satisfaction ratio...">getSatsCount</a>(&amp;data);
<a name="l00177"></a>00177     <span class="keywordtype">float</span> <a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#69c383de18f3cd26911dff4a44bd5417">fitness</a> = <span class="keyword">static_cast&lt;</span><span class="keywordtype">float</span><span class="keyword">&gt;</span>(satsCount)/formulasCount;
<a name="l00178"></a>00178     <span class="keywordflow">if</span> (fitness &gt; d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a>) {
<a name="l00179"></a>00179       d-&gt;<a class="code" href="structFastSatSolver_1_1GaSatSolver_1_1Private.html#c1dfa1e4f4ce3522765951e4bb1c8902">maxFitness</a> = fitness;
<a name="l00180"></a>00180       solver-&gt;<a class="code" href="classFastSatSolver_1_1AbstractSubject.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Send notification to all observers (listeners).">notify</a>();
<a name="l00181"></a>00181     }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     <span class="keywordflow">if</span> (formulasCount==satsCount) {
<a name="l00184"></a>00184       resultSet-&gt;<a class="code" href="classFastSatSolver_1_1SatItemSet.html#e50e61bb65bb3328f6afbd8e005cb96f" title="Add item to container, if it hasn&amp;#39;t been there before.">addItem</a>(<span class="keyword">new</span> <a class="code" href="classFastSatSolver_1_1GaSatItem.html" title="ISatItem implementation used by GaSatSolver.">GaSatItem</a>(bs));
<a name="l00185"></a>00185       solver-&gt;<a class="code" href="classFastSatSolver_1_1AbstractSubject.html#7ff19734eb024bd6f3e2ad95647b1b27" title="Send notification to all observers (listeners).">notify</a>();
<a name="l00186"></a>00186     };
<a name="l00187"></a>00187 
<a name="l00188"></a>00188     <span class="comment">// TODO: scale fitness?</span>
<a name="l00189"></a>00189     <span class="keywordflow">return</span> fitness;
<a name="l00190"></a>00190   }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192 
<a name="l00193"></a>00193 } <span class="comment">// namespace FastSatSolver</span>
<a name="l00194"></a>00194 
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed Nov 5 22:30:21 2008 for Fast SAT Solver by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.4 </small></address>
</body>
</html>