mirror of
https://github.com/BlackLight/libCSP--.git
synced 2024-12-26 18:55:11 +01:00
Release 0.1.1
This commit is contained in:
parent
3c58a73e53
commit
1f678b2bc2
28 changed files with 416 additions and 305 deletions
|
@ -6,7 +6,7 @@
|
|||
* Description: Header file containing the CSP class definition. Never include this
|
||||
* file directly in your sources. Include csp++.h instead.
|
||||
*
|
||||
* Version: 0.1
|
||||
* Version: 0.1.1
|
||||
* Created: 16/05/2010 23:16:42
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
|
@ -25,7 +25,7 @@
|
|||
#error "csp++-def.h must not be included directly - include csp++.h instead"
|
||||
#endif
|
||||
|
||||
#define __CSPPP_VERSION "0.1"
|
||||
#define __CSPPP_VERSION "0.1.1"
|
||||
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
|
@ -172,21 +172,29 @@ public:
|
|||
|
||||
/**
|
||||
* \brief Updates the domains of the variables. Any constraint or node fixed value is applied
|
||||
* \param max_iterations Maximum number of iterations, after which the function will quit. This
|
||||
* can be used to break endless loops in domains assignations.
|
||||
*/
|
||||
void refreshDomains( void );
|
||||
void refreshDomains ( void );
|
||||
|
||||
/**
|
||||
* \brief Get, if it exists, the solution of the CSP, calling refreshDomains until a fixed point
|
||||
* is reached
|
||||
*/
|
||||
void solve ( size_t maxIterations = 0 );
|
||||
|
||||
/**
|
||||
* \brief Get the domain of the i-th variable
|
||||
* \param index Variable for which we're going to get the domain
|
||||
* \return The domain of the i-th variable as a vector of T
|
||||
*/
|
||||
std::vector<T> getDomain ( size_t index );
|
||||
std::vector<T> domain ( size_t index );
|
||||
|
||||
/**
|
||||
* \brief Get the number of variables in the current CSP
|
||||
* \return Size of the CSP
|
||||
*/
|
||||
size_t getSize ( void );
|
||||
size_t size ( void );
|
||||
|
||||
/**
|
||||
* \brief Set the value of a variable as a constraint
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 0.1
|
||||
* Version: 0.1.1
|
||||
* Created: 17/05/2010 09:17:13
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
|
@ -209,7 +209,7 @@ CSP<T>::refreshDomains ( void )
|
|||
|
||||
template<class T>
|
||||
std::vector<T>
|
||||
CSP<T>::getDomain ( size_t index )
|
||||
CSP<T>::domain ( size_t index )
|
||||
{
|
||||
if (index >= variables.size())
|
||||
throw CSPexception("Index out of range");
|
||||
|
@ -219,7 +219,7 @@ CSP<T>::getDomain ( size_t index )
|
|||
|
||||
template<class T>
|
||||
size_t
|
||||
CSP<T>::getSize( void )
|
||||
CSP<T>::size( void )
|
||||
{
|
||||
return variables.size();
|
||||
}
|
||||
|
@ -275,9 +275,9 @@ template<class T>
|
|||
void
|
||||
CSP<T>::assignUniqueDomains ( void )
|
||||
{
|
||||
for ( int i=0; i < getSize(); i++ ) {
|
||||
if (getDomain(i).size() == 1)
|
||||
setValue( i, getDomain(i)[0] );
|
||||
for ( int i=0; i < size(); i++ ) {
|
||||
if (domain(i).size() == 1)
|
||||
setValue( i, domain(i)[0] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,3 +301,41 @@ CSP<T>::value ( size_t index )
|
|||
return variables[index].value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
CSP<T>::solve ( size_t max_iterations )
|
||||
{
|
||||
bool changed = false;
|
||||
size_t steps = 1;
|
||||
vector< vector<T> > oldDomains(size());
|
||||
|
||||
do {
|
||||
if (max_iterations != 0) {
|
||||
if (steps++ > max_iterations)
|
||||
break;
|
||||
}
|
||||
|
||||
for ( size_t i=0; i < size(); i++ ) {
|
||||
oldDomains[i] = variables[i].domain;
|
||||
}
|
||||
|
||||
refreshDomains();
|
||||
assignUniqueDomains();
|
||||
|
||||
if (hasUniqueSolution())
|
||||
break;
|
||||
|
||||
changed = false;
|
||||
|
||||
for ( size_t i=0; i < size(); i++ ) {
|
||||
if (domain(i).size() != oldDomains[i].size())
|
||||
changed = true;
|
||||
|
||||
for ( size_t j=0; j < domain(i).size() && !changed; j++ ) {
|
||||
if ( domain(i)[j] != oldDomains[i][j] )
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} while (changed);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 0.1
|
||||
* Version: 0.1.1
|
||||
* Created: 23/05/2010 23:27:43
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
|
|
|
@ -63,7 +63,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -49,9 +49,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<tr class="memlist"><td><a class="el" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a">CSP</a>()</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#ad49548121582cc2d59e0d7f100092b75">CSP</a>(int n, bool(*c)(std::vector< CSPvariable< T > >)=__default_constraint)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a734bb08d8f45394a2acfc8822981a6d0">CSP</a>(int n, T default_value, bool set_variables=false, bool(*c)(std::vector< CSPvariable< T > >)=__default_constraint)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07">domain</a>(size_t index)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a0231b93bceae257f0e1c35041f8fe63f">dropConstraint</a>(size_t index)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a2a9a7d8072613f6984795d5495373847">getDomain</a>(size_t index)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a91a0e89bc1882d39b88122bee392c5f3">getSize</a>(void)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#ae96286c6c7dfb6fe077544e0d4af15f4">hasUniqueSolution</a>(void)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a7ef9eb91c38815c9d82182696a6bd5d3">isSatisfiable</a>(void)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a213dafc1aae7b1825371810a511eca4f">isSet</a>(size_t i)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
|
@ -61,6 +60,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<tr class="memlist"><td><a class="el" href="classCSP.html#a4017c17aac9d3e96d0e821ebbe09da7b">setDomain</a>(size_t index, std::vector< T > domain)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a65518e67e33e31bff1b5f9aabdf80a01">setDomain</a>(size_t index, T domain[], int size)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#ac25064c5b2d4e1020173b56913251ebd">setValue</a>(size_t index, T value)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a125c7171c19b99e631926bbe011f127d">size</a>(void)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a7ff61c379081881c21626926bdfd8733">solve</a>(size_t maxIterations=0)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#a4c0cae125a610f519dc22eaec255a0ae">unsetValue</a>(size_t index)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
<tr class="memlist"><td><a class="el" href="classCSP.html#aafa5e1a65d6c5d80780437d8d684f32a">value</a>(size_t i)</td><td><a class="el" href="classCSP.html">CSP< T ></a></td><td><code> [inline]</code></td></tr>
|
||||
</table></div>
|
||||
|
@ -78,7 +79,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -73,13 +73,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Drops a constraint from the <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. <a href="#a0231b93bceae257f0e1c35041f8fe63f"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a8dc6aec6ca7e40d198e58b0ec14fee66">appendConstraint</a> (bool(*c)(std::vector< <a class="el" href="structCSPvariable.html">CSPvariable</a>< T > >))</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Append a constraint to the list of the constraint of the <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. <a href="#a8dc6aec6ca7e40d198e58b0ec14fee66"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a466845256e638c5e258fd728b641359f"></a><!-- doxytag: member="CSP::refreshDomains" ref="a466845256e638c5e258fd728b641359f" args="(void)" -->
|
||||
void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a466845256e638c5e258fd728b641359f">refreshDomains</a> (void)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Updates the domains of the variables. Any constraint or node fixed value is applied. <br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">std::vector< T > </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a2a9a7d8072613f6984795d5495373847">getDomain</a> (size_t index)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the domain of the i-th variable. <a href="#a2a9a7d8072613f6984795d5495373847"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a91a0e89bc1882d39b88122bee392c5f3">getSize</a> (void)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the number of variables in the current <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. <a href="#a91a0e89bc1882d39b88122bee392c5f3"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a466845256e638c5e258fd728b641359f">refreshDomains</a> (void)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Updates the domains of the variables. Any constraint or node fixed value is applied. <a href="#a466845256e638c5e258fd728b641359f"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a7ff61c379081881c21626926bdfd8733"></a><!-- doxytag: member="CSP::solve" ref="a7ff61c379081881c21626926bdfd8733" args="(size_t maxIterations=0)" -->
|
||||
void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a7ff61c379081881c21626926bdfd8733">solve</a> (size_t maxIterations=0)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get, if it exists, the solution of the <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>, calling refreshDomains until a fixed point is reached. <br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">std::vector< T > </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07">domain</a> (size_t index)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the domain of the i-th variable. <a href="#ae9db774b971c480cbef66168b9b6cf07"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a125c7171c19b99e631926bbe011f127d">size</a> (void)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the number of variables in the current <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. <a href="#a125c7171c19b99e631926bbe011f127d"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#ac25064c5b2d4e1020173b56913251ebd">setValue</a> (size_t index, T value)</td></tr>
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the value of a variable as a constraint. <a href="#ac25064c5b2d4e1020173b56913251ebd"></a><br/></td></tr>
|
||||
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classCSP.html#a4c0cae125a610f519dc22eaec255a0ae">unsetValue</a> (size_t index)</td></tr>
|
||||
|
@ -219,6 +221,35 @@ template<class T > </div>
|
|||
</dd>
|
||||
</dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="ae9db774b971c480cbef66168b9b6cf07"></a><!-- doxytag: member="CSP::domain" ref="ae9db774b971c480cbef66168b9b6cf07" args="(size_t index)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">std::vector< T > <a class="el" href="classCSP.html">CSP</a>< T >::domain </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">size_t </td>
|
||||
<td class="paramname"> <em>index</em></td>
|
||||
<td> ) </td>
|
||||
<td><code> [inline]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>Get the domain of the i-th variable. </p>
|
||||
<dl><dt><b>Parameters:</b></dt><dd>
|
||||
<table border="0" cellspacing="2" cellpadding="0">
|
||||
<tr><td valign="top"></td><td valign="top"><em>index</em> </td><td>Variable for which we're going to get the domain </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="return"><dt><b>Returns:</b></dt><dd>The domain of the i-th variable as a vector of T </dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a0231b93bceae257f0e1c35041f8fe63f"></a><!-- doxytag: member="CSP::dropConstraint" ref="a0231b93bceae257f0e1c35041f8fe63f" args="(size_t index)" -->
|
||||
|
@ -247,58 +278,6 @@ template<class T > </div>
|
|||
</dd>
|
||||
</dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a2a9a7d8072613f6984795d5495373847"></a><!-- doxytag: member="CSP::getDomain" ref="a2a9a7d8072613f6984795d5495373847" args="(size_t index)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">std::vector< T > <a class="el" href="classCSP.html">CSP</a>< T >::getDomain </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">size_t </td>
|
||||
<td class="paramname"> <em>index</em></td>
|
||||
<td> ) </td>
|
||||
<td><code> [inline]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>Get the domain of the i-th variable. </p>
|
||||
<dl><dt><b>Parameters:</b></dt><dd>
|
||||
<table border="0" cellspacing="2" cellpadding="0">
|
||||
<tr><td valign="top"></td><td valign="top"><em>index</em> </td><td>Variable for which we're going to get the domain </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="return"><dt><b>Returns:</b></dt><dd>The domain of the i-th variable as a vector of T </dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a91a0e89bc1882d39b88122bee392c5f3"></a><!-- doxytag: member="CSP::getSize" ref="a91a0e89bc1882d39b88122bee392c5f3" args="(void)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">size_t <a class="el" href="classCSP.html">CSP</a>< T >::getSize </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">void </td>
|
||||
<td class="paramname"></td>
|
||||
<td> ) </td>
|
||||
<td><code> [inline]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>Get the number of variables in the current <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. </p>
|
||||
<dl class="return"><dt><b>Returns:</b></dt><dd>Size of the <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a> </dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="ae96286c6c7dfb6fe077544e0d4af15f4"></a><!-- doxytag: member="CSP::hasUniqueSolution" ref="ae96286c6c7dfb6fe077544e0d4af15f4" args="(void)" -->
|
||||
|
@ -374,6 +353,34 @@ template<class T > </div>
|
|||
</dl>
|
||||
<dl class="return"><dt><b>Returns:</b></dt><dd>true if the i-th variable has a fixed value, false otherwise </dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a466845256e638c5e258fd728b641359f"></a><!-- doxytag: member="CSP::refreshDomains" ref="a466845256e638c5e258fd728b641359f" args="(void)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">void <a class="el" href="classCSP.html">CSP</a>< T >::refreshDomains </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">void </td>
|
||||
<td class="paramname"></td>
|
||||
<td> ) </td>
|
||||
<td><code> [inline]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>Updates the domains of the variables. Any constraint or node fixed value is applied. </p>
|
||||
<dl><dt><b>Parameters:</b></dt><dd>
|
||||
<table border="0" cellspacing="2" cellpadding="0">
|
||||
<tr><td valign="top"></td><td valign="top"><em>max_iterations</em> </td><td>Maximum number of iterations, after which the function will quit. This can be used to break endless loops in domains assignations. </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a457e1df05d4ec16be00118bda22fd882"></a><!-- doxytag: member="CSP::setConstraint" ref="a457e1df05d4ec16be00118bda22fd882" args="(std::vector< bool(*)(std::vector< CSPvariable< T > >) > c)" -->
|
||||
|
@ -551,6 +558,29 @@ template<class T > </div>
|
|||
</dd>
|
||||
</dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a125c7171c19b99e631926bbe011f127d"></a><!-- doxytag: member="CSP::size" ref="a125c7171c19b99e631926bbe011f127d" args="(void)" -->
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">size_t <a class="el" href="classCSP.html">CSP</a>< T >::size </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">void </td>
|
||||
<td class="paramname"></td>
|
||||
<td> ) </td>
|
||||
<td><code> [inline]</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="memdoc">
|
||||
|
||||
<p>Get the number of variables in the current <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a>. </p>
|
||||
<dl class="return"><dt><b>Returns:</b></dt><dd>Size of the <a class="el" href="classCSP.html" title="Main class for managing a CSP.">CSP</a> </dd></dl>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a class="anchor" id="a4c0cae125a610f519dc22eaec255a0ae"></a><!-- doxytag: member="CSP::unsetValue" ref="a4c0cae125a610f519dc22eaec255a0ae" args="(size_t index)" -->
|
||||
|
@ -629,7 +659,7 @@ template<class T > </div>
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -61,7 +61,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -105,7 +105,7 @@ virtual const char * </td><td class="memItemRight" valign="bottom"><a class
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -62,7 +62,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -48,112 +48,117 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<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>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Version: 1.0</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Version: 0.1</span>
|
||||
<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), <blacklight@autistici.org></span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * Company: lulz</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * =====================================================================================</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> */</span>
|
||||
<a name="l00019"></a>00019
|
||||
<a name="l00020"></a>00020 <span class="preprocessor">#ifndef __CSPPP_H</span>
|
||||
<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define __CSPPP_H</span>
|
||||
<a name="l00022"></a>00022 <span class="preprocessor"></span>
|
||||
<a name="l00023"></a>00023 <span class="preprocessor">#ifndef __CSPPP_CPP</span>
|
||||
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#error "csp++-def.h must not be included directly - include csp++.h instead"</span>
|
||||
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
||||
<a name="l00026"></a>00026 <span class="preprocessor"></span>
|
||||
<a name="l00027"></a>00027 <span class="preprocessor">#include <vector></span>
|
||||
<a name="l00028"></a>00028 <span class="preprocessor">#include <exception></span>
|
||||
<a name="l00029"></a>00029
|
||||
<a name="l00034"></a>00034 <span class="keyword">template</span><<span class="keyword">class</span> T>
|
||||
<a name="l00035"></a><a class="code" href="structCSPvariable.html">00035</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="l00037"></a><a class="code" href="structCSPvariable.html#a1fb7622b0576133aa9a2445da22fddac">00037</a> <span class="keywordtype">int</span> <a class="code" href="structCSPvariable.html#a1fb7622b0576133aa9a2445da22fddac" title="Index of the variable.">index</a>;
|
||||
<a name="l00038"></a>00038
|
||||
<a name="l00040"></a><a class="code" href="structCSPvariable.html#a8e7a1cbd9af27e295508794f871dc599">00040</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>;
|
||||
<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 "csp++-def.h must not be included directly - include csp++.h instead"</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 "0.1"</span>
|
||||
<a name="l00029"></a>00029 <span class="preprocessor"></span>
|
||||
<a name="l00030"></a>00030 <span class="preprocessor">#include <vector></span>
|
||||
<a name="l00031"></a>00031 <span class="preprocessor">#include <exception></span>
|
||||
<a name="l00032"></a>00032
|
||||
<a name="l00037"></a>00037 <span class="keyword">template</span><<span class="keyword">class</span> T>
|
||||
<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>;
|
||||
<a name="l00041"></a>00041
|
||||
<a name="l00043"></a><a class="code" href="structCSPvariable.html#acc2ff31b449351f04b1c3a2a096e584c">00043</a> T <a class="code" href="structCSPvariable.html#acc2ff31b449351f04b1c3a2a096e584c" title="The value of the variable.">value</a>;
|
||||
<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>;
|
||||
<a name="l00044"></a>00044
|
||||
<a name="l00046"></a><a class="code" href="structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2">00046</a> std::vector<T> <a class="code" href="structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2" title="Domain of the variable, declared as a vector.">domain</a>;
|
||||
<a name="l00047"></a>00047 };
|
||||
<a name="l00048"></a>00048
|
||||
<a name="l00053"></a><a class="code" href="classCSPexception.html">00053</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="l00054"></a>00054 <span class="keyword">const</span> <span class="keywordtype">char</span>* message;
|
||||
<a name="l00055"></a>00055
|
||||
<a name="l00056"></a>00056 <span class="keyword">public</span>:
|
||||
<a name="l00061"></a><a class="code" href="classCSPexception.html#a810bcfbb11d2e35d7b95f1e2b11b408c">00061</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="l00062"></a>00062 message = m;
|
||||
<a name="l00063"></a>00063 }
|
||||
<a name="l00064"></a>00064
|
||||
<a name="l00068"></a><a class="code" href="classCSPexception.html#a7013e90a6c26ba4c15bc6fbc42be02ef">00068</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="l00069"></a>00069 <span class="keywordflow">return</span> message;
|
||||
<a name="l00070"></a>00070 }
|
||||
<a name="l00071"></a>00071 };
|
||||
<a name="l00072"></a>00072
|
||||
<a name="l00077"></a>00077 <span class="keyword">template</span><<span class="keyword">class</span> T>
|
||||
<a name="l00078"></a><a class="code" href="classCSP.html">00078</a> <span class="keyword">class </span><a class="code" href="classCSP.html" title="Main class for managing a CSP.">CSP</a> {
|
||||
<a name="l00079"></a>00079 <span class="keyword">private</span>:
|
||||
<a name="l00080"></a>00080 <span class="keyword">template</span><<span class="keyword">class</span> TT>
|
||||
<a name="l00081"></a>00081 <span class="keyword">struct </span>arc {
|
||||
<a name="l00082"></a>00082 <a class="code" href="structCSPvariable.html">CSPvariable<TT></a> var[2];
|
||||
<a name="l00083"></a>00083 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="l00084"></a>00084 };
|
||||
<a name="l00085"></a>00085
|
||||
<a name="l00086"></a>00086 std::vector< CSPvariable<T> > variables;
|
||||
<a name="l00087"></a>00087 std::vector< bool (*)(std::vector< CSPvariable<T> >) > constraints;
|
||||
<a name="l00088"></a>00088 <span class="preprocessor"> #define constraint constraints[0]</span>
|
||||
<a name="l00089"></a>00089 <span class="preprocessor"></span>
|
||||
<a name="l00090"></a>00090 std::vector< std::vector<T> > __default_domains;
|
||||
<a name="l00091"></a>00091 T __default_value;
|
||||
<a name="l00092"></a>00092 <span class="keywordtype">bool</span> __has_default_value;
|
||||
<a name="l00093"></a>00093 <span class="keyword">static</span> <span class="keywordtype">bool</span> __default_constraint ( std::vector< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> > v ) { <span class="keywordflow">return</span> <span class="keyword">true</span>; }
|
||||
<a name="l00094"></a>00094 <span class="keywordtype">void</span> __init ( <span class="keywordtype">int</span> n, <span class="keywordtype">bool</span> (*c)(std::vector< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<a name="l00095"></a>00095 <span class="keywordtype">void</span> restoreDomains ( <span class="keywordtype">void</span> );
|
||||
<a name="l00096"></a>00096
|
||||
<a name="l00097"></a>00097 <span class="keyword">public</span>:
|
||||
<a name="l00102"></a><a class="code" href="classCSP.html#a3a4c1cfab4f5c2376b5f9da588e73f5a">00102</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="l00103"></a>00103
|
||||
<a name="l00113"></a>00113 <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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) = __default_constraint );
|
||||
<a name="l00114"></a>00114
|
||||
<a name="l00128"></a>00128 <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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) = __default_constraint );
|
||||
<a name="l00129"></a>00129
|
||||
<a name="l00135"></a>00135 <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<T> domain );
|
||||
<a name="l00136"></a>00136
|
||||
<a name="l00143"></a>00143 <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="l00144"></a>00144
|
||||
<a name="l00149"></a>00149 <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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<a name="l00150"></a>00150
|
||||
<a name="l00156"></a>00156 <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< <span class="keywordtype">bool</span>(*)(std::vector< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) > c );
|
||||
<a name="l00157"></a>00157
|
||||
<a name="l00162"></a>00162 <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="l00163"></a>00163
|
||||
<a name="l00168"></a>00168 <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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<a name="l00169"></a>00169
|
||||
<a name="l00173"></a>00173 <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="l00174"></a>00174
|
||||
<a name="l00180"></a>00180 std::vector<T> <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="l00181"></a>00181
|
||||
<a name="l00186"></a>00186 <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="l00187"></a>00187
|
||||
<a name="l00193"></a>00193 <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="l00194"></a>00194
|
||||
<a name="l00202"></a>00202 <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="l00203"></a>00203
|
||||
<a name="l00208"></a>00208 <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="l00209"></a>00209
|
||||
<a name="l00216"></a>00216 <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="l00217"></a>00217
|
||||
<a name="l00223"></a>00223 <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="l00229"></a>00229 <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="l00230"></a>00230
|
||||
<a name="l00240"></a>00240 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="l00241"></a>00241 };
|
||||
<a name="l00242"></a>00242
|
||||
<a name="l00243"></a>00243 <span class="preprocessor">#endif</span>
|
||||
<a name="l00244"></a>00244 <span class="preprocessor"></span>
|
||||
<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<T> <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><<span class="keyword">class</span> T>
|
||||
<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><<span class="keyword">class</span> TT>
|
||||
<a name="l00084"></a>00084 <span class="keyword">struct </span>arc {
|
||||
<a name="l00085"></a>00085 <a class="code" href="structCSPvariable.html">CSPvariable<TT></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< CSPvariable<T> > variables;
|
||||
<a name="l00090"></a>00090 std::vector< bool (*)(std::vector< CSPvariable<T> >) > 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< std::vector<T> > __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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> > 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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) = __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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) = __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<T> <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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<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< <span class="keywordtype">bool</span>(*)(std::vector< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) > 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< <a class="code" href="structCSPvariable.html" title="Struct used for describing a variable in the CSP.">CSPvariable<T></a> >) );
|
||||
<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<T> <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>
|
||||
</pre></div></div>
|
||||
<!--- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
|
@ -169,7 +174,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -47,27 +47,28 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<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="l00008"></a>00008 <span class="comment"> * Version: 0.1</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Created: 23/05/2010 23:27:43</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), <blacklight@autistici.org></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="comment">// Yes, I know it looks stupid, but ask C++ standard developers about this.</span>
|
||||
<a name="l00020"></a>00020 <span class="comment">// C++ can't expand template class code until a type is explicitely specified.</span>
|
||||
<a name="l00021"></a>00021 <span class="comment">// This is nearly like not using templates at all, but join me in asking C++</span>
|
||||
<a name="l00022"></a>00022 <span class="comment">// compilers developers to massively allow the export keyword and change the</span>
|
||||
<a name="l00023"></a>00023 <span class="comment">// way templates are managed. Until that moment, you must always include the</span>
|
||||
<a name="l00024"></a>00024 <span class="comment">// .cpp file of the library inside your source code as well, and specify later</span>
|
||||
<a name="l00025"></a>00025 <span class="comment">// the types you're going to use this template class for</span>
|
||||
<a name="l00026"></a>00026
|
||||
<a name="l00027"></a>00027 <span class="preprocessor">#include "csp++.cpp"</span>
|
||||
<a name="l00028"></a>00028
|
||||
<a name="l00014"></a>00014 <span class="comment"> * Licence: GNU GPL v.3</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * Company: lulz</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * =====================================================================================</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> */</span>
|
||||
<a name="l00019"></a>00019
|
||||
<a name="l00020"></a>00020 <span class="comment">// Yes, I know it looks stupid, but ask C++ standard developers about this.</span>
|
||||
<a name="l00021"></a>00021 <span class="comment">// C++ can't expand template class code until a type is explicitely specified.</span>
|
||||
<a name="l00022"></a>00022 <span class="comment">// This is nearly like not using templates at all, but join me in asking C++</span>
|
||||
<a name="l00023"></a>00023 <span class="comment">// compilers developers to massively allow the export keyword and change the</span>
|
||||
<a name="l00024"></a>00024 <span class="comment">// way templates are managed. Until that moment, you must always include the</span>
|
||||
<a name="l00025"></a>00025 <span class="comment">// .cpp file of the library inside your source code as well, and specify later</span>
|
||||
<a name="l00026"></a>00026 <span class="comment">// the types you're going to use this template class for</span>
|
||||
<a name="l00027"></a>00027
|
||||
<a name="l00028"></a>00028 <span class="preprocessor">#include "csp++.cpp"</span>
|
||||
<a name="l00029"></a>00029
|
||||
</pre></div></div>
|
||||
<!--- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
|
@ -83,7 +84,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -61,7 +61,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -65,6 +65,7 @@ Here is a list of all documented class members with links to the class documenta
|
|||
</li>
|
||||
<li>domain
|
||||
: <a class="el" href="structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2">CSPvariable< T ></a>
|
||||
, <a class="el" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07">CSP< T ></a>
|
||||
</li>
|
||||
<li>dropConstraint()
|
||||
: <a class="el" href="classCSP.html#a0231b93bceae257f0e1c35041f8fe63f">CSP< T ></a>
|
||||
|
@ -72,12 +73,6 @@ Here is a list of all documented class members with links to the class documenta
|
|||
<li>fixed
|
||||
: <a class="el" href="structCSPvariable.html#a8e7a1cbd9af27e295508794f871dc599">CSPvariable< T ></a>
|
||||
</li>
|
||||
<li>getDomain()
|
||||
: <a class="el" href="classCSP.html#a2a9a7d8072613f6984795d5495373847">CSP< T ></a>
|
||||
</li>
|
||||
<li>getSize()
|
||||
: <a class="el" href="classCSP.html#a91a0e89bc1882d39b88122bee392c5f3">CSP< T ></a>
|
||||
</li>
|
||||
<li>hasUniqueSolution()
|
||||
: <a class="el" href="classCSP.html#ae96286c6c7dfb6fe077544e0d4af15f4">CSP< T ></a>
|
||||
</li>
|
||||
|
@ -102,6 +97,12 @@ Here is a list of all documented class members with links to the class documenta
|
|||
<li>setValue()
|
||||
: <a class="el" href="classCSP.html#ac25064c5b2d4e1020173b56913251ebd">CSP< T ></a>
|
||||
</li>
|
||||
<li>size()
|
||||
: <a class="el" href="classCSP.html#a125c7171c19b99e631926bbe011f127d">CSP< T ></a>
|
||||
</li>
|
||||
<li>solve()
|
||||
: <a class="el" href="classCSP.html#a7ff61c379081881c21626926bdfd8733">CSP< T ></a>
|
||||
</li>
|
||||
<li>unsetValue()
|
||||
: <a class="el" href="classCSP.html#a4c0cae125a610f519dc22eaec255a0ae">CSP< T ></a>
|
||||
</li>
|
||||
|
@ -128,7 +129,7 @@ Here is a list of all documented class members with links to the class documenta
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -63,15 +63,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<li>CSPexception()
|
||||
: <a class="el" href="classCSPexception.html#a810bcfbb11d2e35d7b95f1e2b11b408c">CSPexception</a>
|
||||
</li>
|
||||
<li>domain()
|
||||
: <a class="el" href="classCSP.html#ae9db774b971c480cbef66168b9b6cf07">CSP< T ></a>
|
||||
</li>
|
||||
<li>dropConstraint()
|
||||
: <a class="el" href="classCSP.html#a0231b93bceae257f0e1c35041f8fe63f">CSP< T ></a>
|
||||
</li>
|
||||
<li>getDomain()
|
||||
: <a class="el" href="classCSP.html#a2a9a7d8072613f6984795d5495373847">CSP< T ></a>
|
||||
</li>
|
||||
<li>getSize()
|
||||
: <a class="el" href="classCSP.html#a91a0e89bc1882d39b88122bee392c5f3">CSP< T ></a>
|
||||
</li>
|
||||
<li>hasUniqueSolution()
|
||||
: <a class="el" href="classCSP.html#ae96286c6c7dfb6fe077544e0d4af15f4">CSP< T ></a>
|
||||
</li>
|
||||
|
@ -93,6 +90,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
<li>setValue()
|
||||
: <a class="el" href="classCSP.html#ac25064c5b2d4e1020173b56913251ebd">CSP< T ></a>
|
||||
</li>
|
||||
<li>size()
|
||||
: <a class="el" href="classCSP.html#a125c7171c19b99e631926bbe011f127d">CSP< T ></a>
|
||||
</li>
|
||||
<li>solve()
|
||||
: <a class="el" href="classCSP.html#a7ff61c379081881c21626926bdfd8733">CSP< T ></a>
|
||||
</li>
|
||||
<li>unsetValue()
|
||||
: <a class="el" href="classCSP.html#a4c0cae125a610f519dc22eaec255a0ae">CSP< T ></a>
|
||||
</li>
|
||||
|
@ -118,7 +121,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -79,7 +79,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -52,7 +52,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:01 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -9,8 +9,11 @@
|
|||
<div class="SRStatus" id="Loading">Loading...</div>
|
||||
<div class="SRResult" id="SR_domain">
|
||||
<div class="SREntry">
|
||||
<a id="Item0" onkeydown="return searchResults.Nav(event,0)" onkeypress="return searchResults.Nav(event,0)" onkeyup="return searchResults.Nav(event,0)" class="SRSymbol" href="../structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2" target="_parent">domain</a>
|
||||
<span class="SRScope">CSPvariable</span>
|
||||
<a id="Item0" onkeydown="return searchResults.Nav(event,0)" onkeypress="return searchResults.Nav(event,0)" onkeyup="return searchResults.Nav(event,0)" class="SRSymbol" href="javascript:searchResults.Toggle('SR_domain')">domain</a>
|
||||
<div class="SRChildren">
|
||||
<a id="Item0_c0" onkeydown="return searchResults.NavChild(event,0,0)" onkeypress="return searchResults.NavChild(event,0,0)" onkeyup="return searchResults.NavChild(event,0,0)" class="SRScope" href="../structCSPvariable.html#a66cf86ebf0fbbf8e571d7b585c9528a2" target="_parent">CSPvariable::domain()</a>
|
||||
<a id="Item0_c1" onkeydown="return searchResults.NavChild(event,0,1)" onkeypress="return searchResults.NavChild(event,0,1)" onkeyup="return searchResults.NavChild(event,0,1)" class="SRScope" href="../classCSP.html#ae9db774b971c480cbef66168b9b6cf07" target="_parent">CSP::domain()</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_dropconstraint">
|
||||
|
|
|
@ -31,6 +31,18 @@
|
|||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_size">
|
||||
<div class="SREntry">
|
||||
<a id="Item3" onkeydown="return searchResults.Nav(event,3)" onkeypress="return searchResults.Nav(event,3)" onkeyup="return searchResults.Nav(event,3)" class="SRSymbol" href="../classCSP.html#a125c7171c19b99e631926bbe011f127d" target="_parent">size</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_solve">
|
||||
<div class="SREntry">
|
||||
<a id="Item4" onkeydown="return searchResults.Nav(event,4)" onkeypress="return searchResults.Nav(event,4)" onkeyup="return searchResults.Nav(event,4)" class="SRSymbol" href="../classCSP.html#a7ff61c379081881c21626926bdfd8733" target="_parent">solve</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRStatus" id="Searching">Searching...</div>
|
||||
<div class="SRStatus" id="NoMatches">No Matches</div>
|
||||
<script type="text/javascript"><!--
|
||||
|
|
|
@ -7,9 +7,15 @@
|
|||
<body class="SRPage">
|
||||
<div id="SRIndex">
|
||||
<div class="SRStatus" id="Loading">Loading...</div>
|
||||
<div class="SRResult" id="SR_domain">
|
||||
<div class="SREntry">
|
||||
<a id="Item0" onkeydown="return searchResults.Nav(event,0)" onkeypress="return searchResults.Nav(event,0)" onkeyup="return searchResults.Nav(event,0)" class="SRSymbol" href="../classCSP.html#ae9db774b971c480cbef66168b9b6cf07" target="_parent">domain</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_dropconstraint">
|
||||
<div class="SREntry">
|
||||
<a id="Item0" onkeydown="return searchResults.Nav(event,0)" onkeypress="return searchResults.Nav(event,0)" onkeyup="return searchResults.Nav(event,0)" class="SRSymbol" href="../classCSP.html#a0231b93bceae257f0e1c35041f8fe63f" target="_parent">dropConstraint</a>
|
||||
<a id="Item1" onkeydown="return searchResults.Nav(event,1)" onkeypress="return searchResults.Nav(event,1)" onkeyup="return searchResults.Nav(event,1)" class="SRSymbol" href="../classCSP.html#a0231b93bceae257f0e1c35041f8fe63f" target="_parent">dropConstraint</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -31,6 +31,18 @@
|
|||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_size">
|
||||
<div class="SREntry">
|
||||
<a id="Item3" onkeydown="return searchResults.Nav(event,3)" onkeypress="return searchResults.Nav(event,3)" onkeyup="return searchResults.Nav(event,3)" class="SRSymbol" href="../classCSP.html#a125c7171c19b99e631926bbe011f127d" target="_parent">size</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRResult" id="SR_solve">
|
||||
<div class="SREntry">
|
||||
<a id="Item4" onkeydown="return searchResults.Nav(event,4)" onkeypress="return searchResults.Nav(event,4)" onkeyup="return searchResults.Nav(event,4)" class="SRSymbol" href="../classCSP.html#a7ff61c379081881c21626926bdfd8733" target="_parent">solve</a>
|
||||
<span class="SRScope">CSP</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="SRStatus" id="Searching">Searching...</div>
|
||||
<div class="SRStatus" id="NoMatches">No Matches</div>
|
||||
<script type="text/javascript"><!--
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
var indexSectionsWithContent =
|
||||
{
|
||||
0: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101101111000000001101110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
0: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101101011000000001101110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100111000000001101110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100011000000001101110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
3: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101001000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
};
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -88,7 +88,7 @@ std::vector< T > </td><td class="memItemRight" valign="bottom"><a cla
|
|||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon May 24 01:58:02 2010 for libCSP++ by
|
||||
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu May 27 11:41:31 2010 for libCSP++ by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
||||
</body>
|
||||
|
|
|
@ -40,14 +40,16 @@ void \hyperlink{classCSP_a0231b93bceae257f0e1c35041f8fe63f}{dropConstraint} (siz
|
|||
\begin{DoxyCompactList}\small\item\em Drops a constraint from the \hyperlink{classCSP}{CSP}. \item\end{DoxyCompactList}\item
|
||||
void \hyperlink{classCSP_a8dc6aec6ca7e40d198e58b0ec14fee66}{appendConstraint} (bool($\ast$c)(std::vector$<$ \hyperlink{structCSPvariable}{CSPvariable}$<$ T $>$ $>$))
|
||||
\begin{DoxyCompactList}\small\item\em Append a constraint to the list of the constraint of the \hyperlink{classCSP}{CSP}. \item\end{DoxyCompactList}\item
|
||||
\hypertarget{classCSP_a466845256e638c5e258fd728b641359f}{
|
||||
void \hyperlink{classCSP_a466845256e638c5e258fd728b641359f}{refreshDomains} (void)}
|
||||
\label{classCSP_a466845256e638c5e258fd728b641359f}
|
||||
|
||||
void \hyperlink{classCSP_a466845256e638c5e258fd728b641359f}{refreshDomains} (void)
|
||||
\begin{DoxyCompactList}\small\item\em Updates the domains of the variables. Any constraint or node fixed value is applied. \item\end{DoxyCompactList}\item
|
||||
std::vector$<$ T $>$ \hyperlink{classCSP_a2a9a7d8072613f6984795d5495373847}{getDomain} (size\_\-t index)
|
||||
\hypertarget{classCSP_a7ff61c379081881c21626926bdfd8733}{
|
||||
void \hyperlink{classCSP_a7ff61c379081881c21626926bdfd8733}{solve} (size\_\-t maxIterations=0)}
|
||||
\label{classCSP_a7ff61c379081881c21626926bdfd8733}
|
||||
|
||||
\begin{DoxyCompactList}\small\item\em Get, if it exists, the solution of the \hyperlink{classCSP}{CSP}, calling refreshDomains until a fixed point is reached. \item\end{DoxyCompactList}\item
|
||||
std::vector$<$ T $>$ \hyperlink{classCSP_ae9db774b971c480cbef66168b9b6cf07}{domain} (size\_\-t index)
|
||||
\begin{DoxyCompactList}\small\item\em Get the domain of the i-\/th variable. \item\end{DoxyCompactList}\item
|
||||
size\_\-t \hyperlink{classCSP_a91a0e89bc1882d39b88122bee392c5f3}{getSize} (void)
|
||||
size\_\-t \hyperlink{classCSP_a125c7171c19b99e631926bbe011f127d}{size} (void)
|
||||
\begin{DoxyCompactList}\small\item\em Get the number of variables in the current \hyperlink{classCSP}{CSP}. \item\end{DoxyCompactList}\item
|
||||
void \hyperlink{classCSP_ac25064c5b2d4e1020173b56913251ebd}{setValue} (size\_\-t index, T value)
|
||||
\begin{DoxyCompactList}\small\item\em Set the value of a variable as a constraint. \item\end{DoxyCompactList}\item
|
||||
|
@ -113,6 +115,21 @@ Append a constraint to the list of the constraint of the \hyperlink{classCSP}{CS
|
|||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em c}]A function pointer returning a boolean value representing the new constraint \end{DoxyParams}
|
||||
\hypertarget{classCSP_ae9db774b971c480cbef66168b9b6cf07}{
|
||||
\index{CSP@{CSP}!domain@{domain}}
|
||||
\index{domain@{domain}!CSP@{CSP}}
|
||||
\subsubsection[{domain}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T $>$ std::vector$<$ T $>$ {\bf CSP}$<$ T $>$::domain (size\_\-t {\em index})\hspace{0.3cm}{\ttfamily \mbox{[}inline\mbox{]}}}}
|
||||
\label{classCSP_ae9db774b971c480cbef66168b9b6cf07}
|
||||
|
||||
|
||||
Get the domain of the i-\/th variable.
|
||||
|
||||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em index}]Variable for which we're going to get the domain \end{DoxyParams}
|
||||
\begin{DoxyReturn}{Returns}
|
||||
The domain of the i-\/th variable as a vector of T
|
||||
\end{DoxyReturn}
|
||||
\hypertarget{classCSP_a0231b93bceae257f0e1c35041f8fe63f}{
|
||||
\index{CSP@{CSP}!dropConstraint@{dropConstraint}}
|
||||
\index{dropConstraint@{dropConstraint}!CSP@{CSP}}
|
||||
|
@ -125,33 +142,6 @@ Drops a constraint from the \hyperlink{classCSP}{CSP}.
|
|||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em index}]Index of the constraint to be dropped \end{DoxyParams}
|
||||
\hypertarget{classCSP_a2a9a7d8072613f6984795d5495373847}{
|
||||
\index{CSP@{CSP}!getDomain@{getDomain}}
|
||||
\index{getDomain@{getDomain}!CSP@{CSP}}
|
||||
\subsubsection[{getDomain}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T $>$ std::vector$<$ T $>$ {\bf CSP}$<$ T $>$::getDomain (size\_\-t {\em index})\hspace{0.3cm}{\ttfamily \mbox{[}inline\mbox{]}}}}
|
||||
\label{classCSP_a2a9a7d8072613f6984795d5495373847}
|
||||
|
||||
|
||||
Get the domain of the i-\/th variable.
|
||||
|
||||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em index}]Variable for which we're going to get the domain \end{DoxyParams}
|
||||
\begin{DoxyReturn}{Returns}
|
||||
The domain of the i-\/th variable as a vector of T
|
||||
\end{DoxyReturn}
|
||||
\hypertarget{classCSP_a91a0e89bc1882d39b88122bee392c5f3}{
|
||||
\index{CSP@{CSP}!getSize@{getSize}}
|
||||
\index{getSize@{getSize}!CSP@{CSP}}
|
||||
\subsubsection[{getSize}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T $>$ size\_\-t {\bf CSP}$<$ T $>$::getSize (void)\hspace{0.3cm}{\ttfamily \mbox{[}inline\mbox{]}}}}
|
||||
\label{classCSP_a91a0e89bc1882d39b88122bee392c5f3}
|
||||
|
||||
|
||||
Get the number of variables in the current \hyperlink{classCSP}{CSP}.
|
||||
|
||||
\begin{DoxyReturn}{Returns}
|
||||
Size of the \hyperlink{classCSP}{CSP}
|
||||
\end{DoxyReturn}
|
||||
\hypertarget{classCSP_ae96286c6c7dfb6fe077544e0d4af15f4}{
|
||||
\index{CSP@{CSP}!hasUniqueSolution@{hasUniqueSolution}}
|
||||
\index{hasUniqueSolution@{hasUniqueSolution}!CSP@{CSP}}
|
||||
|
@ -191,6 +181,18 @@ Check if the i-\/th variable in the \hyperlink{classCSP}{CSP} has a fixed value.
|
|||
\begin{DoxyReturn}{Returns}
|
||||
true if the i-\/th variable has a fixed value, false otherwise
|
||||
\end{DoxyReturn}
|
||||
\hypertarget{classCSP_a466845256e638c5e258fd728b641359f}{
|
||||
\index{CSP@{CSP}!refreshDomains@{refreshDomains}}
|
||||
\index{refreshDomains@{refreshDomains}!CSP@{CSP}}
|
||||
\subsubsection[{refreshDomains}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T $>$ void {\bf CSP}$<$ T $>$::refreshDomains (void)\hspace{0.3cm}{\ttfamily \mbox{[}inline\mbox{]}}}}
|
||||
\label{classCSP_a466845256e638c5e258fd728b641359f}
|
||||
|
||||
|
||||
Updates the domains of the variables. Any constraint or node fixed value is applied.
|
||||
|
||||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em max\_\-iterations}]Maximum number of iterations, after which the function will quit. This can be used to break endless loops in domains assignations. \end{DoxyParams}
|
||||
\hypertarget{classCSP_a457e1df05d4ec16be00118bda22fd882}{
|
||||
\index{CSP@{CSP}!setConstraint@{setConstraint}}
|
||||
\index{setConstraint@{setConstraint}!CSP@{CSP}}
|
||||
|
@ -251,6 +253,18 @@ Set the value of a variable as a constraint.
|
|||
|
||||
\begin{DoxyParams}{Parameters}
|
||||
\item[{\em index}]Index of the parameter to be set \item[{\em value}]Value to be set \end{DoxyParams}
|
||||
\hypertarget{classCSP_a125c7171c19b99e631926bbe011f127d}{
|
||||
\index{CSP@{CSP}!size@{size}}
|
||||
\index{size@{size}!CSP@{CSP}}
|
||||
\subsubsection[{size}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T $>$ size\_\-t {\bf CSP}$<$ T $>$::size (void)\hspace{0.3cm}{\ttfamily \mbox{[}inline\mbox{]}}}}
|
||||
\label{classCSP_a125c7171c19b99e631926bbe011f127d}
|
||||
|
||||
|
||||
Get the number of variables in the current \hyperlink{classCSP}{CSP}.
|
||||
|
||||
\begin{DoxyReturn}{Returns}
|
||||
Size of the \hyperlink{classCSP}{CSP}
|
||||
\end{DoxyReturn}
|
||||
\hypertarget{classCSP_a4c0cae125a610f519dc22eaec255a0ae}{
|
||||
\index{CSP@{CSP}!unsetValue@{unsetValue}}
|
||||
\index{unsetValue@{unsetValue}!CSP@{CSP}}
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
\fancyplain{}{\bfseries\thepage}%
|
||||
}
|
||||
\rfoot[\fancyplain{}{\bfseries\scriptsize%
|
||||
Generated on Mon May 24 01:58:01 2010 for libCSP++ by Doxygen }]{}
|
||||
Generated on Thu May 27 11:41:31 2010 for libCSP++ by Doxygen }]{}
|
||||
\lfoot[]{\fancyplain{}{\bfseries\scriptsize%
|
||||
Generated on Mon May 24 01:58:01 2010 for libCSP++ by Doxygen }}
|
||||
Generated on Thu May 27 11:41:31 2010 for libCSP++ by Doxygen }}
|
||||
\cfoot{}
|
||||
|
||||
%---------- Internal commands used in this style file ----------------
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
\vspace*{1cm}
|
||||
{\large Generated by Doxygen 1.6.3}\\
|
||||
\vspace*{0.5cm}
|
||||
{\small Mon May 24 01:58:01 2010}\\
|
||||
{\small Thu May 27 11:41:31 2010}\\
|
||||
\end{center}
|
||||
\end{titlepage}
|
||||
\clearemptydoublepage
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: main.cpp
|
||||
* Filename: fourcolours.cpp
|
||||
*
|
||||
* Description:
|
||||
* Description: Interactively select a colour for some European countries. At each
|
||||
* selection, the domains of colours for remaining countries are
|
||||
* restricted, under the constraint "two adjacent countries cannot have
|
||||
* the same colour"
|
||||
*
|
||||
* Complile: g++ -IPATH/TO/csp++.h -o fourcolours fourcolours.cpp
|
||||
* Version: 1.0
|
||||
* Created: 17/05/2010 09:22:25
|
||||
* Revision: none
|
||||
|
@ -27,7 +31,7 @@
|
|||
using namespace std;
|
||||
|
||||
typedef enum {
|
||||
I, CH, DK, D, A, F, E, P, B, L, NL
|
||||
I, CH, DK, D, A, F, B, E, P, L, NL,
|
||||
} Country;
|
||||
|
||||
typedef enum {
|
||||
|
@ -38,7 +42,7 @@ typedef enum {
|
|||
#define COLOURS 4
|
||||
|
||||
static const char* countries[COUNTRIES] = {
|
||||
"Italy", "Switz.", "Denmark", "Germany", "Austria", "France", "Spain", "Portugal", "Belgium", "Luxemb.", "Holland"
|
||||
"Italy", "Switz.", "Denmark", "Germany", "Austria", "France", "Belgium", "Spain", "Portugal", "Luxemb.", "Holland",
|
||||
};
|
||||
|
||||
static const char* colours[COLOURS] = {
|
||||
|
@ -88,10 +92,10 @@ printDomain (CSP<Colour> csp, int variable)
|
|||
{
|
||||
cout << "[ ";
|
||||
|
||||
for ( size_t i=0; i < csp.getDomain(variable).size(); i++ ) {
|
||||
cout << colours[csp.getDomain(variable)[i]];
|
||||
for ( size_t i=0; i < csp.domain(variable).size(); i++ ) {
|
||||
cout << colours[csp.domain(variable)[i]];
|
||||
|
||||
if ( i < csp.getDomain(variable).size() - 1 )
|
||||
if ( i < csp.domain(variable).size() - 1 )
|
||||
cout << ", ";
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,7 @@ printDomain (CSP<Colour> csp, int variable)
|
|||
void
|
||||
printDomains (CSP<Colour> csp)
|
||||
{
|
||||
for ( size_t i=0; i < csp.getSize(); i++) {
|
||||
for ( size_t i=0; i < csp.size(); i++) {
|
||||
cout << "Domain for variable '" << countries[i] << "':\t";
|
||||
printDomain(csp, i);
|
||||
cout << endl;
|
||||
|
@ -149,8 +153,8 @@ getIndexByColour ( const char* colour )
|
|||
*/
|
||||
bool
|
||||
valueOK ( CSP<Colour> csp, size_t variable, Colour value ) {
|
||||
for ( size_t i=0; i < csp.getDomain(variable).size(); i++ ) {
|
||||
if (csp.getDomain(variable)[i] == value)
|
||||
for ( size_t i=0; i < csp.domain(variable).size(); i++ ) {
|
||||
if (csp.domain(variable)[i] == value)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -180,17 +184,17 @@ main ( int argc, char *argv[] )
|
|||
bool satisfiable = true;
|
||||
|
||||
// If a variable has an empty domain, something went wrong
|
||||
// if (csp.getDomain(i).size() == 0) {
|
||||
// cout << "No values left for country " << countries[i]
|
||||
// << ", the domain was probably too small (few colours) or the problem is unsatisfiable\n";
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
if (csp.domain(i).size() == 0) {
|
||||
cout << "No values left for country " << countries[i]
|
||||
<< ", the domain was probably too small (few colours) or the problem is unsatisfiable\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// If a variable has a domain containing an only element,
|
||||
// just choose it without annoying the user
|
||||
if (csp.getDomain(i).size() == 1) {
|
||||
cout << "Setting colour " << colours[csp.getDomain(i)[0]] << " for " << countries[i] << endl;
|
||||
csp.setValue( i, csp.getDomain(i)[0] );
|
||||
if (csp.domain(i).size() == 1) {
|
||||
cout << "Setting colour " << colours[csp.domain(i)[0]] << " for " << countries[i] << endl;
|
||||
csp.setValue( i, csp.domain(i)[0] );
|
||||
csp.refreshDomains();
|
||||
continue;
|
||||
}
|
||||
|
|
35
sudoku.cpp
35
sudoku.cpp
|
@ -205,7 +205,7 @@ getSudoku (const char* sudokuFile)
|
|||
csp.appendConstraint(colsConstraint);
|
||||
csp.appendConstraint(cellsConstraint);
|
||||
|
||||
for ( int i=0; i < csp.getSize(); i++ )
|
||||
for ( int i=0; i < csp.size(); i++ )
|
||||
csp.setDomain(i, domain);
|
||||
|
||||
for ( int i=0; i < sudoku.size(); i++ ) {
|
||||
|
@ -245,37 +245,10 @@ main ( int argc, char *argv[] )
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
int steps = 1;
|
||||
vector< vector<int> > oldDomains(csp.getSize());
|
||||
|
||||
do {
|
||||
cout << "Solving ... step " << steps++ << endl;
|
||||
|
||||
for ( int i=0; i < csp.getSize(); i++ ) {
|
||||
oldDomains[i] = csp.getDomain(i);
|
||||
}
|
||||
|
||||
csp.refreshDomains();
|
||||
csp.assignUniqueDomains();
|
||||
|
||||
if (csp.hasUniqueSolution())
|
||||
break;
|
||||
|
||||
changed = false;
|
||||
|
||||
for ( int i=0; i < csp.getSize(); i++ ) {
|
||||
if (csp.getDomain(i).size() != oldDomains[i].size())
|
||||
changed = true;
|
||||
|
||||
for ( int j=0; j < csp.getDomain(i).size() && !changed; j++ ) {
|
||||
if ( csp.getDomain(i)[j] != oldDomains[i][j] )
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} while (changed);
|
||||
|
||||
cout << "Solving..." << endl;
|
||||
csp.solve();
|
||||
cout << endl;
|
||||
|
||||
printSudoku(csp);
|
||||
|
||||
if (csp.isSatisfiable()) {
|
||||
|
|
Loading…
Reference in a new issue