Commit 4f513a7c authored by Maxime's avatar Maxime
Browse files

update old project

parent 8168a098
......@@ -19,17 +19,21 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="bierwirthManager.cpp" />
<ClCompile Include="gestion_graphe.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="bierwirth.cpp" />
<ClCompile Include="solution.cpp" />
<ClCompile Include="utils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bierwirth.h" />
<ClInclude Include="gestion_graphes.h" />
<ClInclude Include="bierwirthManager.h" />
<ClInclude Include="bierwirth_t.h" />
<ClInclude Include="conf.h" />
<ClInclude Include="gestion_graphe.h" />
<ClInclude Include="graph_t.h" />
<ClInclude Include="pr.h" />
<ClInclude Include="solution.h" />
<ClInclude Include="solution_t.h" />
<ClInclude Include="utils.h" />
</ItemGroup>
<ItemGroup>
......
......@@ -18,9 +18,6 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bierwirth.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -30,21 +27,36 @@
<ClCompile Include="solution.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bierwirthManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="bierwirth.h">
<ClInclude Include="utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utils.h">
<ClInclude Include="solution.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="gestion_graphes.h">
<ClInclude Include="pr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="solution.h">
<ClInclude Include="bierwirth_t.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pr.h">
<ClInclude Include="bierwirthManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="conf.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="gestion_graphe.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="graph_t.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="solution_t.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
......
#ifndef BIERWIRTH_H
#define BIERWIRTH_H
#define MAX_VECTOR_SIZE 200
#include <vector>
#include "pr.h"
typedef std::vector<int> bierwirth;
class bierwirth_t {
public:
static bierwirth generateVector(int n, int m);
static void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int n, int m);
static int prToIndex(bierwirth& vector, pr_t i, int n, int m);
static bool isVectorValid(bierwirth& v, int nbPiece);
static bool areVectorsEquals(bierwirth& v1, bierwirth& v2);
};
#endif
\ No newline at end of file
#include "bierwirth.h"
#include <vector>
#include "bierwirthManager.h"
#include "utils.h"
#include <iostream>
using namespace std;
bierwirth bierwirth_t::generateVector(int n, int m) {
bierwirth_t bierwirthManager::generateVector(int n, int m) {
vector<int> vect(n, m);
vector<int> vectPiece;
long size = n * m;
bierwirth v(size);
bierwirth_t v(size);
int maxIteration = n * m;
int indexRandom;
......@@ -35,7 +34,7 @@ bierwirth bierwirth_t::generateVector(int n, int m) {
return v;
}
void bierwirth_t::permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int n, int m) {
void bierwirthManager::permutation(bierwirth_t& vectorIn, bierwirth_t& vectorOut, pr_t i, pr_t j, int n, int m) {
int iIndex = prToIndex(vectorIn, i, n, m);
int jIndex = prToIndex(vectorIn, j, n, m);
if (iIndex != -1 && jIndex != -1) {
......@@ -55,7 +54,7 @@ void bierwirth_t::permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i,
int bierwirth_t::prToIndex(bierwirth& vector, pr_t i, int n, int m) {
int bierwirthManager::prToIndex(bierwirth_t& vector, pr_t i, int n, int m) {
int index = n * m - 1;
int cpt = m ;
while (index >= 0) {
......@@ -70,7 +69,7 @@ int bierwirth_t::prToIndex(bierwirth& vector, pr_t i, int n, int m) {
bool bierwirth_t::isVectorValid(bierwirth& v, int nbPiece) {
bool bierwirthManager::isVectorValid(bierwirth_t& v, int nbPiece) {
vector<int> count(nbPiece);
std::fill(count.begin(), count.end(), 0);
for (int i = 0; i < v.size(); i++)
......@@ -95,7 +94,7 @@ bool bierwirth_t::isVectorValid(bierwirth& v, int nbPiece) {
}
bool bierwirth_t::areVectorsEquals(bierwirth& v1, bierwirth& v2) {
bool bierwirthManager::areVectorsEquals(bierwirth_t& v1, bierwirth_t& v2) {
if (v1.size() != v2.size())
return false;
for (int i = 0; i < v1.size(); i++)
......
#pragma once
#include "pr.h"
#include <vector>
#include "bierwirth_t.h"
class bierwirthManager {
public:
static bierwirth_t generateVector(int n, int m);
static void permutation(bierwirth_t& vectorIn, bierwirth_t& vectorOut, pr_t i, pr_t j, int n, int m);
static int prToIndex(bierwirth_t& vector, pr_t i, int n, int m);
static bool isVectorValid(bierwirth_t& v, int nbPiece);
static bool areVectorsEquals(bierwirth_t& v1, bierwirth_t& v2);
};
#pragma once
#include <vector>
typedef std::vector<int> bierwirth_t;
\ No newline at end of file
#pragma once
//Solution
#define SOLUTION_MAX_SIZE 100
#define SOLUTION_MAX_TAB 100
#define HASH_SIZE 90000
#define MAX_NEIGHBOURS 5
#define MAX_COUNT 10
#define MAX_COUNT_HASH 100
#define MAX_IT 1000
//Vector
#define MAX_VECTOR_SIZE 200
//Graph
#define GRAPH_MAX_SIZE 30
#include "gestion_graphes.h"
#include "gestion_graphe.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
t_graphe gestionGraph::lecture_fichier(string nom_fichier)
graph_t gestionGraph::lecture_fichier(string nom_fichier)
{
ifstream monflux(nom_fichier.c_str());
int nb_pieces;
int nb_machines;
int machine;
int temps;
t_graphe graph;
graph_t graph;
monflux >> graph.supposedBestSolution;
monflux >> nb_pieces;
......@@ -35,7 +35,7 @@ t_graphe gestionGraph::lecture_fichier(string nom_fichier)
return graph;
}
void gestionGraph::affiche_taches(t_graphe graphe)
void gestionGraph::affiche_taches(graph_t graphe)
{
cout << "graphe : " << endl;
cout << "---------------------"<< endl;
......
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include "graph_t.h"
class gestionGraph {
public:
static graph_t lecture_fichier(std::string nom_fichier);
static void affiche_taches(graph_t graphe);
};
#ifndef GESTION_GRAPHE_H
#define GESTION_GRAPHE_H
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int nbmax = 30;
typedef struct t_graph
{
int nb_pieces;
int nb_machines;
int supposedBestSolution;
int mach[nbmax][nbmax];
int d[nbmax][nbmax];
} t_graphe;
class gestionGraph {
public:
static t_graphe lecture_fichier(string nom_fichier);
static void affiche_taches(t_graphe graphe);
};
#endif
\ No newline at end of file
#pragma once
#include "conf.h"
typedef struct
{
int nb_pieces;
int nb_machines;
int supposedBestSolution;
int mach[GRAPH_MAX_SIZE][GRAPH_MAX_SIZE];
int d[GRAPH_MAX_SIZE][GRAPH_MAX_SIZE];
} graph_t;
\ No newline at end of file
#include "bierwirth.h"
#include "gestion_graphes.h"
#include "bierwirth_t.h"
#include "gestion_graphe.h"
#include "solution.h"
#include "utils.h"
#include <chrono>
#include <iostream>
#include <vector>
#include "bierwirthManager.h"
using namespace std;
using namespace std::chrono;
......@@ -12,11 +14,11 @@ using namespace std::chrono;
int main() {
srand(21058465);
t_graphe graph;
graph = gestionGraph::lecture_fichier("ft06.txt");
graph_t graph;
graph = gestionGraph::lecture_fichier("la06.txt");
solution_t sol;
bierwirth v = bierwirth_t::generateVector(graph.nb_pieces, graph.nb_machines);
bierwirth_t v = bierwirthManager::generateVector(graph.nb_pieces, graph.nb_machines);
sol.cost = INT16_MAX;
auto before = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
......
#ifndef PR_H
#define PR_H
#pragma once
typedef struct {
......@@ -8,5 +6,3 @@ typedef struct {
int rang;
}pr_t;
#endif
\ No newline at end of file
#include "solution.h"
#include "gestion_graphes.h"
#include "utils.h"
#include "pr.h"
#include "bierwirthManager.h"
#include <iostream>
solution_t solution::rechercheLocale(bierwirth& v, t_graph& graph, int maxIteration) {
using namespace std;
solution_t solution::rechercheLocale(bierwirth_t& v, graph_t& graph, int maxIteration) {
solution_t solutionEvaluated = evaluer(v, graph);
solution_t solutionOpti;
pr_t j = solutionEvaluated.lastFather;
pr_t jFather = solutionEvaluated.father[j.piece][j.rang];
bierwirth vInput = v;
bierwirth vOpti = v;
bierwirth_t vInput = v;
bierwirth_t vOpti = v;
int iteration = 0;
while (iteration < maxIteration && (jFather.piece != -1 && jFather.rang != -1)) {
if (graph.mach[j.piece][j.rang] == graph.mach[jFather.piece][jFather.rang]) {
bierwirth_t::permutation(vInput, vOpti, j, jFather, graph.nb_pieces, graph.nb_machines);
bierwirthManager::permutation(vInput, vOpti, j, jFather, graph.nb_pieces, graph.nb_machines);
solutionOpti = evaluer(vOpti, graph);
if (solutionOpti.cost < solutionEvaluated.cost) {
vInput = vOpti;
......@@ -35,7 +38,7 @@ solution_t solution::rechercheLocale(bierwirth& v, t_graph& graph, int maxIterat
return solutionEvaluated;
}
solution_t solution::evaluer(bierwirth v, t_graphe graphe) {
solution_t solution::evaluer(bierwirth_t& v, graph_t& graphe) {
solution_t sol;
int machine;
int n = graphe.nb_pieces;
......@@ -136,7 +139,7 @@ void solution::affiche_solution(solution_t sol)
}
void solution::vecteur_valide(bierwirth v, int nb_machines, int nb_pieces)
void solution::vecteur_valide(bierwirth_t& v, int nb_machines, int nb_pieces)
{
int tab[SOLUTION_MAX_SIZE];
......@@ -156,22 +159,19 @@ void solution::vecteur_valide(bierwirth v, int nb_machines, int nb_pieces)
}
}
solution_t solution::genNeighbour(bierwirth v, int size, int n, int m)
solution_t solution::genNeighbour(bierwirth_t& v, int size, int n, int m)
{
solution_t new_solution;
new_solution.v = bierwirth_t::generateVector(n, m);
//cout << "oui4" << endl;
new_solution.v = bierwirthManager::generateVector(n, m);
int rand1 = rand() % size;
int rand2 = rand() % size;
//cout << v[0] << endl;
for (int i = 0; i < size; ++i)
{
(new_solution.v)[i] = v[i];
//cout << "oui4" << endl;
}
new_solution.v[rand1] = v[rand2];
......@@ -204,11 +204,11 @@ int solution::sameH(solution_t sol, int* hash, int size)
return val;
}
void solution::grasp(solution_t* sol, t_graph graphe)
void solution::grasp(solution_t* sol, graph_t& graphe)
{
solution_t new_solution;
solution_t best_neighbour;
bierwirth v;
bierwirth_t v;
int nb_neighbours = 0;
int nb_it = 0;
int count;
......@@ -234,7 +234,7 @@ void solution::grasp(solution_t* sol, t_graph graphe)
do
{
v = bierwirth_t::generateVector(graphe.nb_pieces, graphe.nb_machines);
v = bierwirthManager::generateVector(graphe.nb_pieces, graphe.nb_machines);
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
needToStopCount++;
......@@ -248,7 +248,7 @@ void solution::grasp(solution_t* sol, t_graph graphe)
new_solution = genNeighbour(new_solution.v, size, graphe.nb_pieces, graphe.nb_machines);
v = new_solution.v;
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
if (sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent
......@@ -266,7 +266,7 @@ void solution::grasp(solution_t* sol, t_graph graphe)
}
}
if (best_neighbour.cost<sol->cost)
if (best_neighbour.cost < sol->cost)
{
*sol = best_neighbour;
}
......@@ -276,3 +276,6 @@ void solution::grasp(solution_t* sol, t_graph graphe)
}
}
#ifndef SOLUTION_H
#define SOLUTION_H
#include "bierwirth.h"
#include "gestion_graphes.h"
#include "pr.h"
#define SOLUTION_MAX_SIZE 100
#define SOLUTION_MAX_TAB 100
#define HASH_SIZE 90000
#define MAX_NEIGHBOURS 5
#define MAX_COUNT 10
#define MAX_COUNT_HASH 100
#define MAX_IT 1000
typedef struct {
bierwirth v;
int ST[SOLUTION_MAX_SIZE];
pr_t father[SOLUTION_MAX_SIZE][SOLUTION_MAX_SIZE];
int cost;
pr_t lastFather;
int sol_size;
}solution_t;
#pragma once
#include "bierwirth_t.h"
#include "gestion_graphe.h"
#include "solution_t.h"
......@@ -35,16 +12,13 @@ class solution
{
public:
static solution_t rechercheLocale(bierwirth& v, t_graph& graph, int maxIteration);
static solution_t evaluer(bierwirth v, t_graphe graphe);
static solution_t rechercheLocale(bierwirth_t& v, graph_t& graph, int maxIteration);
static solution_t evaluer(bierwirth_t& v, graph_t& graphe);
static void affiche_solution(solution_t sol);
static void grasp(solution_t* sol, t_graph graphe);
static void vecteur_valide(bierwirth v, int nb_machines, int nb_pieces);
static solution_t genNeighbour(bierwirth v, int size, int n, int m);
static void grasp(solution_t* sol, graph_t& graphe);
static void vecteur_valide(bierwirth_t& v, int nb_machines, int nb_pieces);
static solution_t genNeighbour(bierwirth_t& v, int size, int n, int m);
static int sameH(solution_t sol, int* hash, int size);
};
#endif
\ No newline at end of file
#pragma once
#include "bierwirth_t.h"
#include "conf.h"
#include "pr.h"
typedef struct {
bierwirth_t v;
int ST[SOLUTION_MAX_SIZE];
pr_t father[SOLUTION_MAX_SIZE][SOLUTION_MAX_SIZE];
int cost;
pr_t lastFather;
int sol_size;
}solution_t;
#ifndef UTILS_H
#define UTILS_H
#pragma once
#include <vector>
......@@ -15,6 +13,3 @@ public:
static void print2(std::vector<int> v1, std::vector<int> v2);
};
#endif
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment