This example tries to solve the following problem: We have a NxN checker. Every (i,j) case contains k points (in this example k=4). One entry point that is a point located into the case's boundary. Two points are inside the case and the last point is an exit point, also at the boundary (different from entry).
The algorithm uses Branch & Bound technique to: given an initial case and an end case, compute the minimal cost path from init to end.
It also uses visitor pattern to get results.
Implementation needs to be finished in some points.
Main library: "pathfinder.h"
#ifndef PATHFINDER_H_INCLUDED
#define PATHFINDER_H_INCLUDED
#include "visitor.h"
#include
Getting results (visitor pattern): "visitor.h"
#ifndef VISITOR_H_INCLUDED
#define VISITOR_H_INCLUDED
#include "pathfinder.h"
#include
class SolutionDisplay {
public:
SolutionDisplay(Solution * sol);
~SolutionDisplay();
virtual void print();
private:
Solution * _solution;
};
class Visitor {
public:
Visitor();
~Visitor();
virtual void visit(Backtracking * b)
virtual void printSolution();
virtual vector* getSolution();
virtual double getCost();
private:
Solution * _solution;
SolutionDisplay * _solutionDis;
};
void Visitor::printSolution(){
this->_solutionDis = new SolutionDisplay(this->_solution);
this->_solutionDis->print();
}
class PathFinderVisitor: public Visitor {
public:
PathFinderVisitor();
~PathFinderVisitor();
private:
};
void PathFinderVisitor::visit(Backtracking * backtracking) {
if(!backtracking->compute())
this->_solution = backtracking->getSolution();
}
#endif // VISITOR_H_INCLUDED