Skip to content
Snippets Groups Projects
Commit c8de579d authored by Caron Olivier's avatar Caron Olivier
Browse files

remove temporary executable file

parent 6f9c5ca0
No related branches found
No related tags found
No related merge requests found
Pipeline #4511 failed
......@@ -6,6 +6,3 @@
# To create bundles of sources:
# set(<NAME> source1 [source2 ...])
# Then use ${NAME}
add_executable(testA testA.cpp)
\ No newline at end of file
......@@ -31,7 +31,7 @@ namespace representation::permutation::problems::fsp {
/**
* Class representing a No-Wait FlowShop Problem) instance
*/
class NoWaitFSP : public FSP {
class NoWaitFSP : public representation::permutation::problems::fsp::FSP {
public:
explicit NoWaitFSP(const std::string &instanceFile) : FSP(instanceFile) {
this->initDelay();
......
//
// Created by carono on 03/06/24.
//
#include "util/RNGHelper.h"
#include "opt/criterion/TimeCriterion.h"
#include "opt/checkpoint/ArchiveCheckpoint.h"
#include "core/Archive.h"
#include "core/fitness/FitnessMin.h"
#include "representation/permutation/problems/tsp/TSP.h"
#include "representation/permutation/problems/tsp/TSPEval.h"
#include "representation/permutation/problems/tsp/TSPEvalBiObjective.h"
#include "opt/factory/singleSolution/NeighborFactory.h"
#include "opt/singleSolution/neighborhood/neighbor/IndexNeighbor.h"
#include "opt/manySolutions/geneticAlgorithm/crossover/OXCrossover.h"
#include "opt/manySolutions/geneticAlgorithm/mutation/Mutation.h"
#include "opt/manySolutions/geneticAlgorithm/NSGA2_Solution.h"
#include "opt/manySolutions/geneticAlgorithm/NSGA2_Algorithm.h"
#include "opt/manySolutions/geneticAlgorithm/NSGA2_Eval.h"
#include "core/archive/AllAcceptedArchive.h"
using namespace representation::permutation::problems::tsp ;
typedef core::fitness::FitnessMin<double> FIT;
typedef TSPSol<FIT> SOL;
typedef TSPEvalBiObjective<SOL> EVAL;
typedef opt::manySolutions::geneticAlgorithm::NSGA2_Solution<SOL> NSGA2_SOL ;
typedef core::archive::AllAcceptedArchive<NSGA2_SOL> POP ;
typedef opt::manySolutions::geneticAlgorithm::crossover::OXCrossover<POP> CROSSOVER ;
typedef opt::manySolutions::geneticAlgorithm::mutation::Mutation<POP> MUTATION ;
typedef opt::criterion::TimeCriterion<POP> STOP ;
typedef opt::manySolutions::geneticAlgorithm::NSGA2_Algorithm<POP> GA ;
int main() {
util::RNGHelper::get()->reseed(120);
std::vector<std::vector<double>> distanceMatrix = {
{0, 10, 15, 20},
{10, 0, 35, 25},
{15, 35, 0, 30},
{20, 25, 30, 0}
};
std::vector<std::vector<double>> timeMatrix = {{
{0, 1, 3, 4},
{1, 0, 5, 2},
{3, 5, 0, 6},
{4, 2, 6, 0}
}};
TSP tsp1(distanceMatrix);
TSP tsp2(timeMatrix);
TSPEval<SOL> tsp1eval(tsp1);
TSPEval<SOL> tsp2eval(tsp2);
EVAL eval(tsp1eval, tsp2eval);
NSGA2_Eval<SOL> nsga2_eval(eval) ;
POP population;
population.clear();
unsigned long long int values[4][4] = {
{0, 1, 2, 3},
{0, 2, 1, 3},
{0, 3, 1, 2},
{0, 2, 3, 1}
};
for (int i = 0; i < 4; i++) {
SOL sol;
for (int j = 0; j < 4; j++) {
sol.push_back(values[i][j]);
}
NSGA2_SOL decorator(sol) ; population(decorator);
}
for (auto &s: population) {
nsga2_eval(s); s.fitness().validate();
}
// components for NSGA2 algorithm
STOP stopGen(1000) ; // using TimeCriterion with 1 seconds
CROSSOVER crossover(0.8, nsga2_eval) ;
// neighbor operator for mutation step
opt::factory::singleSolution::NeighborFactory<NSGA2_SOL, opt::singleSolution::neighborhood::neighbor::IndexNeighbor<NSGA2_SOL>> neighborFactory;
opt::singleSolution::neighborhood::neighbor::IndexNeighbor<NSGA2_SOL> *neighbor = neighborFactory.create("2opt");
MUTATION mutation(0.15, nsga2_eval,*neighbor);
opt::checkpoint::ArchiveCheckpoint<POP> archiveCheckpoint;
GA ga(
&crossover,
&mutation,
nsga2_eval,
&stopGen) ;
ga.setCheckpoint(archiveCheckpoint);
ga(population) ; // run the genetic algorithm
std::cout << "final population :" << std::endl << population << std::endl ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment