- Main Page
- Classes
- Files

- File List

# OptFrame/Examples/TSP/RandomInitialSolution.hpp

    00001 #ifndef TSP_INITIALSOLUTION_Random_HPP_
    00002 #define TSP_INITIALSOLUTION_Random_HPP_
    00003
    00004 #include "../../../OptFrame/InitialSolution.h"
    00005 #include "../../../OptFrame/Util/TestSolution.hpp"
    00006
    00007 #include "ProblemInstance.hpp"
    00008
    00009 #include "Representation.h"
    00010 #include "Solution.h"
    00011
    00012 #include "Evaluator.hpp"
    00013 #include "../../RandGen.hpp"
    00014 #include <list>
    00015
    00016 #include <algorithm>
    00017 #include <stdlib.h>
    00018
    00019 using namespace std;
    00020
    00021 class RandomInitialSolutionTSP: public InitialSolution<RepTSP>
    00022 {
    00023 private:
    00024         TSPProblemInstance* pI;
    00025         RandGen& rg;
    00026
    00027         // Your private vars
    00028
    00029 public:
    00030
    00031         RandomInitialSolutionTSP(TSPProblemInstance* pI,RandGen& _rg): rg(_rg) // If necessary, add more parameters
    00032         {
    00033                 this->pI = pI;
    00034                 // Put the rest of your code here
    00035         };
    00036
    00037         SolutionTSP& generateSolution()
    00038         {
    00039                 RepTSP* newRep = new vector<int>(pI->n);
    00040
    00041                 vector<int>* r = new vector<int>(pI->n);
    00042                 for(unsigned int i=0;i<r->size();i++)
    00043                         (*r)[i]=i;
    00044
    00045                 rg.shuffle(*r); // shuffle elements of r
    00046
    00047                 for(unsigned int i=0;i<newRep->size();i++)
    00048                         (*newRep)[i] = (*r)[i];
    00049
    00050                 delete r;
    00051
    00052                 return * new TestSolution<RepTSP>(*newRep);
    00053         }
    00054
    00055 };
    00056
    00057 #endif /*TSP_INITIALSOLUTION_Random_HPP_*/

All Classes Functions