libCSP--/doc/html/csp_09_09_8h_source.html
2010-05-19 03:21:35 +02:00

157 lines
14 KiB
HTML

<!-- 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++.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++.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++.h</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Description: </span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * Version: 1.0</span>
<a name="l00009"></a>00009 <span class="comment"> * Created: 16/05/2010 23:16:42</span>
<a name="l00010"></a>00010 <span class="comment"> * Revision: none</span>
<a name="l00011"></a>00011 <span class="comment"> * Compiler: gcc</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * Author: BlackLight (http://0x00.ath.cx), &lt;blacklight@autistici.org&gt;</span>
<a name="l00014"></a>00014 <span class="comment"> * Company: lulz</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * =====================================================================================</span>
<a name="l00017"></a>00017 <span class="comment"> */</span>
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;exception&gt;</span>
<a name="l00021"></a>00021
<a name="l00022"></a>00022 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00023"></a><a class="code" href="structCSPvariable.html">00023</a> <span class="keyword">struct </span><a class="code" href="structCSPvariable.html">CSPvariable</a> {
<a name="l00024"></a>00024 <span class="keywordtype">int</span> index;
<a name="l00025"></a>00025 T value;
<a name="l00026"></a>00026 std::vector&lt;T&gt; domain;
<a name="l00027"></a>00027 };
<a name="l00028"></a>00028
<a name="l00033"></a><a class="code" href="classCSPexception.html">00033</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="l00034"></a>00034 <span class="keyword">const</span> <span class="keywordtype">char</span>* message;
<a name="l00035"></a>00035
<a name="l00036"></a>00036 <span class="keyword">public</span>:
<a name="l00037"></a>00037 <a class="code" href="classCSPexception.html" title="Class for managing exception in CSP.">CSPexception</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *m) {
<a name="l00038"></a>00038 message = m;
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040
<a name="l00041"></a>00041 <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* what() {
<a name="l00042"></a>00042 <span class="keywordflow">return</span> message;
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044 };
<a name="l00045"></a>00045
<a name="l00050"></a>00050 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00051"></a><a class="code" href="classCSP.html">00051</a> <span class="keyword">class </span><a class="code" href="classCSP.html" title="Main class for managing a CSP.">CSP</a> {
<a name="l00052"></a>00052 <span class="keyword">private</span>:
<a name="l00053"></a>00053 <span class="keyword">template</span>&lt;<span class="keyword">class</span> TT&gt;
<a name="l00054"></a>00054 <span class="keyword">struct </span>arc {
<a name="l00055"></a>00055 <a class="code" href="structCSPvariable.html">CSPvariable&lt;TT&gt;</a> var[2];
<a name="l00056"></a>00056 TT value[2];
<a name="l00057"></a>00057 };
<a name="l00058"></a>00058
<a name="l00059"></a>00059 std::vector&lt;bool&gt; fixed;
<a name="l00060"></a>00060 std::vector&lt; CSPvariable&lt;T&gt; &gt; variables;
<a name="l00061"></a>00061 std::vector&lt; bool (*)(std::vector&lt; CSPvariable&lt;T&gt; &gt;) &gt; constraints;
<a name="l00062"></a>00062 <span class="preprocessor"> #define constraint constraints[0]</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>
<a name="l00064"></a>00064 std::vector&lt; std::vector&lt;T&gt; &gt; __default_domains;
<a name="l00065"></a>00065 T __default_value;
<a name="l00066"></a>00066 <span class="keywordtype">bool</span> __has_default_value;
<a name="l00067"></a>00067 <span class="keyword">static</span> <span class="keywordtype">bool</span> __default_constraint ( std::vector&lt; <a class="code" href="structCSPvariable.html">CSPvariable&lt;T&gt;</a> &gt; v ) { <span class="keywordflow">return</span> <span class="keyword">true</span>; }
<a name="l00068"></a>00068 <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">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00069"></a>00069 <span class="keywordtype">void</span> restoreDomains ( <span class="keywordtype">void</span> );
<a name="l00070"></a>00070
<a name="l00071"></a>00071 <span class="keyword">public</span>:
<a name="l00081"></a>00081 <a class="code" href="classCSP.html#ad49548121582cc2d59e0d7f100092b75" title="Class constructor.">CSP</a> ( <span class="keywordtype">int</span> n, <span class="keywordtype">bool</span> (*c)(std::vector&lt; <a class="code" href="structCSPvariable.html">CSPvariable&lt;T&gt;</a> &gt;) = __default_constraint );
<a name="l00082"></a>00082
<a name="l00096"></a>00096 <a class="code" href="classCSP.html#ad49548121582cc2d59e0d7f100092b75" title="Class constructor.">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">CSPvariable&lt;T&gt;</a> &gt;) = __default_constraint );
<a name="l00097"></a>00097
<a name="l00104"></a>00104 <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; domain );
<a name="l00105"></a>00105
<a name="l00113"></a>00113 <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 domain[], <span class="keywordtype">int</span> size );
<a name="l00114"></a>00114
<a name="l00120"></a>00120 <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">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00121"></a>00121
<a name="l00128"></a>00128 <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">CSPvariable&lt;T&gt;</a> &gt;) &gt; c );
<a name="l00129"></a>00129
<a name="l00135"></a>00135 <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="l00136"></a>00136
<a name="l00142"></a>00142 <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">CSPvariable&lt;T&gt;</a> &gt;) );
<a name="l00143"></a>00143
<a name="l00148"></a>00148 <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="l00149"></a>00149
<a name="l00156"></a>00156 std::vector&lt;T&gt; <a class="code" href="classCSP.html#a2a9a7d8072613f6984795d5495373847" title="Get the domain of the i-th variable.">getDomain</a> ( <span class="keywordtype">size_t</span> index );
<a name="l00157"></a>00157
<a name="l00163"></a>00163 <span class="keywordtype">size_t</span> <a class="code" href="classCSP.html#a91a0e89bc1882d39b88122bee392c5f3" title="Get the number of variables in the current CSP.">getSize</a> ( <span class="keywordtype">void</span> );
<a name="l00164"></a>00164
<a name="l00171"></a>00171 <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 value );
<a name="l00172"></a>00172
<a name="l00181"></a>00181 <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="l00182"></a>00182
<a name="l00188"></a>00188 <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="l00189"></a>00189
<a name="l00190"></a>00190
<a name="l00198"></a>00198 <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="l00199"></a>00199 };
<a name="l00200"></a>00200
</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></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue May 18 19:03:23 2010 for libCSP++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>