This sheet will guide you through the example of a local search
algorithm for the Queens problem using the framework EasyLocal. In your
assignments it is possible to avoid using EasyLocal and develop
everything by your own, if you feel overwhelmed by EasyLocal. In this
case it is still recommendable to follow the design of EasyLocal and use
as a starting point the code in Queens/
that we commented in
class.
Queens.tgz
. This is a
worked out example.Queens/
, compile the project and run it with:
nqueens --main::instance queens8.txt
Try
nqueens --help
to see a list of command line parameters (more on this below).
The following is a TODO list to start developing your local search program for a new program following the Queens example.
input.hh
):
input.hh
)::
basics.hh
):
template <class Input, class State, typename CFtype>
CostStructure<CFtype> SearchEngine<Input, State, CFtype>::Go(State& s) throw (ParameterNotSet, IncorrectParameterValue)
{
InitializeRun(s);
while (!MaxEvaluationsExpired() && !StopCriterion() && !LowerBoundReached() && !this->TimeoutExpired())
{
PrepareIteration();
try
{
SelectMove();
if (AcceptableMoveFound())
{
PrepareMove();
MakeMove();
CompleteMove();
UpdateBestState();
}
}
catch (EmptyNeighborhood)
{
break;
}
CompleteIteration();
}
return TerminateRun(s);
}
Figure 1:
Parameter<unsigned long int> max_evaluations; void RegisterParameters() { max_evaluations("max_evaluations", "Maximum total number of cost function evaluations allowed", this->parameters); } |
Print( std::ostream& os = std::cout); |
Hence you can print from main.cc with:
qsd.Print(); |
Each parameter can be printed with:
par.Write(); |
To read parameters from a file, from main.cc:
SAT_solver.ReadParameters(std::istream& is = std::cin, std::ostream& os = std::cout); |
this function will read the parameters from a file stream that you previously open and print what has been read in the stdout.
This function is also implemented in Parametrized and you can read its definition in the EasyLocal framework under utils/parameter.hh
In the file one can write parameters as:
prob 0.5 |
then the parameter "prob" is read and set.
Starting from the example handed out, implement the following: