libCSP--/doc/html/csp_09_09-def_8h_source.html

182 lines
19 KiB
HTML
Raw Normal View History

2010-05-24 02:45:09 +02:00
<!-- This comment will put IE 6, 7 and 8 in quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libCSP++: csp++-def.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.6.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</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>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<img id="MSearchSelect" src="search/search.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</div>
</li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
</ul>
</div>
<h1>csp++-def.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * =====================================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Filename: csp++-def.h</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Description: Header file containing the CSP class definition. Never include this</span>
<a name="l00007"></a>00007 <span class="comment"> * file directly in your sources. Include csp++.h instead.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
2010-05-27 11:55:27 +02:00
<a name="l00009"></a>00009 <span class="comment"> * Version: 0.1</span>
2010-05-24 02:45:09 +02:00
<a name="l00010"></a>00010 <span class="comment"> * Created: 16/05/2010 23:16:42</span>
<a name="l00011"></a>00011 <span class="comment"> * Revision: none</span>
<a name="l00012"></a>00012 <span class="comment"> * Compiler: gcc</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * Author: BlackLight (http://0x00.ath.cx), &lt;blacklight@autistici.org&gt;</span>
2010-05-27 11:55:27 +02:00
<a name="l00015"></a>00015 <span class="comment"> * Licence: GNU GPL v.3</span>
<a name="l00016"></a>00016 <span class="comment"> * Company: lulz</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * =====================================================================================</span>
<a name="l00019"></a>00019 <span class="comment"> */</span>
<a name="l00020"></a>00020
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef __CSPPP_H</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define __CSPPP_H</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#ifndef __CSPPP_CPP</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#error &quot;csp++-def.h must not be included directly - include csp++.h instead&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <span class="preprocessor">#define __CSPPP_VERSION &quot;0.1&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;exception&gt;</span>
<a name="l00032"></a>00032
<a name="l00037"></a>00037 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00038"></a><a class="code" href="structCSPvariable.html">00038</a> <span class="keyword">struct </span><a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable</a> {
<a name="l00040"></a><a class="code" href="structCSPvariable.html#a1fb7622b0576133aa9a2445da22fddac">00040</a> <span class="keywordtype">int</span> <a class="code" href="structCSPvariable.html#a1fb7622b0576133aa9a2445da22fddac" title="Index of the variable.">index</a>;
2010-05-24 02:45:09 +02:00
<a name="l00041"></a>00041
2010-05-27 11:55:27 +02:00
<a name="l00043"></a><a class="code" href="structCSPvariable.html#a8e7a1cbd9af27e295508794f871dc599">00043</a> <span class="keywordtype">bool</span> <a class="code" href="structCSPvariable.html#a8e7a1cbd9af27e295508794f871dc599" title="If the value of the variable is set explicitely, this value is true.">fixed</a>;
2010-05-24 02:45:09 +02:00
<a name="l00044"></a>00044
2010-05-27 11:55:27 +02:00
<a name="l00046"></a><a class="code" href="structCSPvariable.html#acc2ff31b449351f04b1c3a2a096e584c">00046</a> T <a class="code" href="structCSPvariable.html#acc2ff31b449351f04b1c3a2a096e584c" title="The value of the variable.">value</a>;
<a name="l00047"></a>00047
<a name="l00049"></a><a class="code" href="structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2">00049</a> std::vector&lt;T&gt; <a class="code" href="structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2" title="Domain of the variable, declared as a vector.">domain</a>;
<a name="l00050"></a>00050 };
<a name="l00051"></a>00051
<a name="l00056"></a><a class="code" href="classCSPexception.html">00056</a> <span class="keyword">class </span><a class="code" href="classCSPexception.html" title="Class for managing exception in CSP.">CSPexception</a> : <span class="keyword">public</span> std::exception {
<a name="l00057"></a>00057 <span class="keyword">const</span> <span class="keywordtype">char</span>* message;
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <span class="keyword">public</span>:
<a name="l00064"></a><a class="code" href="classCSPexception.html#a810bcfbb11d2e35d7b95f1e2b11b408c">00064</a> <a class="code" href="classCSPexception.html#a810bcfbb11d2e35d7b95f1e2b11b408c" title="Constructor.">CSPexception</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *m) {
<a name="l00065"></a>00065 message = m;
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00071"></a><a class="code" href="classCSPexception.html#a7013e90a6c26ba4c15bc6fbc42be02ef">00071</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="classCSPexception.html#a7013e90a6c26ba4c15bc6fbc42be02ef" title="Return the description of the exception.">what</a>() {
<a name="l00072"></a>00072 <span class="keywordflow">return</span> message;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 };
<a name="l00075"></a>00075
<a name="l00080"></a>00080 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00081"></a><a class="code" href="classCSP.html">00081</a> <span class="keyword">class </span><a class="code" href="classCSP.html" title="Main class for managing a CSP.">CSP</a> {
<a name="l00082"></a>00082 <span class="keyword">private</span>:
<a name="l00083"></a>00083 <span class="keyword">template</span>&lt;<span class="keyword">class</span> TT&gt;
<a name="l00084"></a>00084 <span class="keyword">struct </span>arc {
<a name="l00085"></a>00085 <a class="code" href="structCSPvariable.html">CSPvariable&lt;TT&gt;</a> var[2];
<a name="l00086"></a>00086 TT <a class="code" href="classCSP.html#aafa5e1a65d6c5d80780437d8d684f32a" title="Get the value of the i-th variable of the CSP. Be careful: before using this function...">value</a>[2];
<a name="l00087"></a>00087 };
<a name="l00088"></a>00088
<a name="l00089"></a>00089 std::vector&lt; CSPvariable&lt;T&gt; &gt; variables;
<a name="l00090"></a>00090 std::vector&lt; bool (*)(std::vector&lt; CSPvariable&lt;T&gt; &gt;) &gt; constraints;
<a name="l00091"></a>00091 <span class="preprocessor"> #define constraint constraints[0]</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span>
<a name="l00093"></a>00093 std::vector&lt; std::vector&lt;T&gt; &gt; __default_domains;
<a name="l00094"></a>00094 T __default_value;
<a name="l00095"></a>00095 <span class="keywordtype">bool</span> __has_default_value;
<a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">bool</span> __default_constraint ( std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt; v ) { <span class="keywordflow">return</span> <span class="keyword">true</span>; }
<a name="l00097"></a>00097 <span class="keywordtype">void</span> __init ( <span class="keywordtype">int</span> n, <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00098"></a>00098 <span class="keywordtype">void</span> restoreDomains ( <span class="keywordtype">void</span> );
<a name="l00099"></a>00099
<a name="l00100"></a>00100 <span class="keyword">public</span>:
<a name="l00105"></a><a class="code" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a">00105</a> <a class="code" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a" title="Empty constructor - just do nothing, used for declaring an object and initialize...">CSP</a>() {}
<a name="l00106"></a>00106
<a name="l00116"></a>00116 <a class="code" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a" title="Empty constructor - just do nothing, used for declaring an object and initialize...">CSP</a> ( <span class="keywordtype">int</span> n, <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) = __default_constraint );
<a name="l00117"></a>00117
<a name="l00131"></a>00131 <a class="code" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a" title="Empty constructor - just do nothing, used for declaring an object and initialize...">CSP</a> ( <span class="keywordtype">int</span> n, T default_value, <span class="keywordtype">bool</span> set_variables = <span class="keyword">false</span>, <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) = __default_constraint );
<a name="l00132"></a>00132
<a name="l00138"></a>00138 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a4017c17aac9d3e96d0e821ebbe09da7b" title="Set the domain for the i-th variable.">setDomain</a> ( <span class="keywordtype">size_t</span> index, std::vector&lt;T&gt; <a class="code" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07" title="Get the domain of the i-th variable.">domain</a> );
<a name="l00139"></a>00139
<a name="l00146"></a>00146 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a4017c17aac9d3e96d0e821ebbe09da7b" title="Set the domain for the i-th variable.">setDomain</a> ( <span class="keywordtype">size_t</span> index, T <a class="code" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07" title="Get the domain of the i-th variable.">domain</a>[], <span class="keywordtype">int</span> <a class="code" href="classCSP.html#a125c7171c19b99e631926bbe011f127d" title="Get the number of variables in the current CSP.">size</a> );
<a name="l00147"></a>00147
<a name="l00152"></a>00152 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a534a0d9bd10fb544f94196bf3c386657" title="Apply the constraint to the CSP as a boolean function.">setConstraint</a> ( <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00153"></a>00153
<a name="l00159"></a>00159 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a534a0d9bd10fb544f94196bf3c386657" title="Apply the constraint to the CSP as a boolean function.">setConstraint</a> ( std::vector&lt; <span class="keywordtype">bool</span>(*)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) &gt; c );
<a name="l00160"></a>00160
<a name="l00165"></a>00165 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a0231b93bceae257f0e1c35041f8fe63f" title="Drops a constraint from the CSP.">dropConstraint</a> ( <span class="keywordtype">size_t</span> index );
<a name="l00166"></a>00166
<a name="l00171"></a>00171 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a8dc6aec6ca7e40d198e58b0ec14fee66" title="Append a constraint to the list of the constraint of the CSP.">appendConstraint</a> ( <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00172"></a>00172
<a name="l00178"></a>00178 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a466845256e638c5e258fd728b641359f" title="Updates the domains of the variables. Any constraint or node fixed value is applied...">refreshDomains</a> ( <span class="keywordtype">void</span> );
<a name="l00179"></a>00179
<a name="l00184"></a>00184 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a7ff61c379081881c21626926bdfd8733" title="Get, if it exists, the solution of the CSP, calling refreshDomains until a fixed...">solve</a> ( <span class="keywordtype">size_t</span> maxIterations = 0 );
<a name="l00185"></a>00185
<a name="l00191"></a>00191 std::vector&lt;T&gt; <a class="code" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07" title="Get the domain of the i-th variable.">domain</a> ( <span class="keywordtype">size_t</span> index );
<a name="l00192"></a>00192
<a name="l00197"></a>00197 <span class="keywordtype">size_t</span> <a class="code" href="classCSP.html#a125c7171c19b99e631926bbe011f127d" title="Get the number of variables in the current CSP.">size</a> ( <span class="keywordtype">void</span> );
<a name="l00198"></a>00198
<a name="l00204"></a>00204 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#ac25064c5b2d4e1020173b56913251ebd" title="Set the value of a variable as a constraint.">setValue</a> ( <span class="keywordtype">size_t</span> index, T <a class="code" href="classCSP.html#aafa5e1a65d6c5d80780437d8d684f32a" title="Get the value of the i-th variable of the CSP. Be careful: before using this function...">value</a> );
<a name="l00205"></a>00205
<a name="l00213"></a>00213 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#a4c0cae125a610f519dc22eaec255a0ae" title="Marks a variable as not set, and if a default value was assigned in the CSP constructor...">unsetValue</a> ( <span class="keywordtype">size_t</span> index );
<a name="l00214"></a>00214
<a name="l00219"></a>00219 <span class="keywordtype">bool</span> <a class="code" href="classCSP.html#a7ef9eb91c38815c9d82182696a6bd5d3" title="Check if the current CSP, with the applied constraints, is satisfiable.">isSatisfiable</a> ( <span class="keywordtype">void</span> );
<a name="l00220"></a>00220
<a name="l00227"></a>00227 <span class="keywordtype">bool</span> <a class="code" href="classCSP.html#ae96286c6c7dfb6fe077544e0d4af15f4" title="Check if the CSP, with the given variables, domains and constraints, admits a unique...">hasUniqueSolution</a> ( <span class="keywordtype">void</span> );
<a name="l00228"></a>00228
<a name="l00234"></a>00234 <span class="keywordtype">void</span> <a class="code" href="classCSP.html#ac74cb751589a58bf6f2815f6878d2213" title="Check if any of the variables in the CSP has a domain containing an only item. If...">assignUniqueDomains</a> ( <span class="keywordtype">void</span> );
<a name="l00240"></a>00240 <span class="keywordtype">bool</span> <a class="code" href="classCSP.html#a213dafc1aae7b1825371810a511eca4f" title="Check if the i-th variable in the CSP has a fixed value.">isSet</a> ( <span class="keywordtype">size_t</span> i );
<a name="l00241"></a>00241
<a name="l00251"></a>00251 T <a class="code" href="classCSP.html#aafa5e1a65d6c5d80780437d8d684f32a" title="Get the value of the i-th variable of the CSP. Be careful: before using this function...">value</a> ( <span class="keywordtype">size_t</span> i );
<a name="l00252"></a>00252 };
<a name="l00253"></a>00253
<a name="l00254"></a>00254 <span class="preprocessor">#endif</span>
<a name="l00255"></a>00255 <span class="preprocessor"></span>
2010-05-24 02:45:09 +02:00
</pre></div></div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&nbsp;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&nbsp;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&nbsp;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&nbsp;</span>Variables</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
2010-05-27 11:55:27 +02:00
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by&nbsp;
2010-05-24 02:45:09 +02:00
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>