Commit f76671e3 authored by Maxime's avatar Maxime
Browse files

refactor code

parent b2aa4205
......@@ -116,6 +116,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
......
......@@ -6,7 +6,7 @@
using namespace std;
bierwirth generateVector(int n, int m) {
bierwirth bierwirth_t::generateVector(int n, int m) {
vector<int> vect(n, m);
vector<int> vectPiece;
long size = n * m;
......@@ -35,7 +35,7 @@ bierwirth generateVector(int n, int m) {
return v;
}
void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int n, int m) {
void bierwirth_t::permutation(bierwirth& vectorIn, bierwirth& 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 +55,7 @@ void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int
int prToIndex(bierwirth& vector, pr_t i, int n, int m) {
int bierwirth_t::prToIndex(bierwirth& vector, pr_t i, int n, int m) {
int index = n * m - 1;
int cpt = m ;
while (index >= 0) {
......@@ -70,7 +70,7 @@ int prToIndex(bierwirth& vector, pr_t i, int n, int m) {
bool isVectorValid(bierwirth& v, int nbPiece) {
bool bierwirth_t::isVectorValid(bierwirth& v, int nbPiece) {
vector<int> count(nbPiece);
std::fill(count.begin(), count.end(), 0);
for (int i = 0; i < v.size(); i++)
......@@ -95,7 +95,7 @@ bool isVectorValid(bierwirth& v, int nbPiece) {
}
bool areVectorsEquals(bierwirth& v1, bierwirth& v2) {
bool bierwirth_t::areVectorsEquals(bierwirth& v1, bierwirth& v2) {
if (v1.size() != v2.size())
return false;
for (int i = 0; i < v1.size(); i++)
......
#pragma once
#ifndef BIERWIRTH_H
#define BIERWIRTH_H
#define MAX_VECTOR_SIZE 200
......@@ -7,9 +8,13 @@
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);
};
bierwirth generateVector(int n, int m);
void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int n, int m);
int prToIndex(bierwirth& vector, pr_t i, int n, int m);
bool isVectorValid(bierwirth& v, int nbPiece);
bool areVectorsEquals(bierwirth& v1, bierwirth& v2);
\ No newline at end of file
#endif
\ No newline at end of file
......@@ -5,7 +5,7 @@
using namespace std;
t_graphe lecture_fichier(string nom_fichier)
t_graphe gestionGraph::lecture_fichier(string nom_fichier)
{
ifstream monflux(nom_fichier.c_str());
int nb_pieces;
......@@ -35,7 +35,7 @@ t_graphe lecture_fichier(string nom_fichier)
return graph;
}
void affiche_taches(t_graphe graphe)
void gestionGraph::affiche_taches(t_graphe graphe)
{
cout << "graphe : " << endl;
cout << "---------------------"<< endl;
......
#pragma once
#ifndef GESTION_GRAPHE_H
#define GESTION_GRAPHE_H
#include <iostream>
#include <string>
#include <fstream>
......@@ -8,14 +11,21 @@ const int nbmax = 30;
typedef struct t_graph
{
int nb_pieces;
int nb_machines;
int supposedBestSolution;
int nb_pieces;
int nb_machines;
int supposedBestSolution;
int mach[nbmax][nbmax];
int d[nbmax][nbmax];
int mach[nbmax][nbmax];
int d[nbmax][nbmax];
} t_graphe;
t_graphe lecture_fichier(string nom_fichier);
void affiche_taches(t_graphe 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
......@@ -13,16 +13,16 @@ int main() {
srand(21058465);
t_graphe graph;
graph = lecture_fichier("la01.txt");
graph = gestionGraph::lecture_fichier("la01.txt");
solution_t sol;
bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines);
bierwirth v = bierwirth_t::generateVector(graph.nb_pieces, graph.nb_machines);
sol.cost = INT16_MAX;
auto before = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
grasp(&sol, graph, 666);
solution::grasp(&sol, graph);
auto after = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
affiche_solution(sol);
solution::affiche_solution(sol);
cout << "meilleur cout final : " << sol.cost << endl;
cout << after.count() - before.count() << " ms" << endl;
......
#pragma once
#ifndef PR_H
#define PR_H
typedef struct {
int piece;
int rang;
}pr_t;
#endif
\ No newline at end of file
......@@ -13,7 +13,7 @@ solution_t solution::rechercheLocale(bierwirth& v, t_graph& graph, int maxIterat
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]) {
permutation(vInput, vOpti, j, jFather, graph.nb_pieces, graph.nb_machines);
bierwirth_t::permutation(vInput, vOpti, j, jFather, graph.nb_pieces, graph.nb_machines);
solutionOpti = evaluer(vOpti, graph);
if (solutionOpti.cost < solutionEvaluated.cost) {
vInput = vOpti;
......@@ -159,7 +159,7 @@ 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 new_solution;
new_solution.v = generateVector(n, m);
new_solution.v = bierwirth_t::generateVector(n, m);
//cout << "oui4" << endl;
int rand1 = rand() % size;
......@@ -230,7 +230,7 @@ void solution::grasp(solution_t* sol, t_graph graphe)
do
{
v = generateVector(graphe.nb_pieces, graphe.nb_machines);
v = bierwirth_t::generateVector(graphe.nb_pieces, graphe.nb_machines);
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
} while (sameH(new_solution, hash, HASH_SIZE));
......
#pragma once
#ifndef SOLUTION_H
#define SOLUTION_H
#include "bierwirth.h"
#include "gestion_graphes.h"
#include "pr.h"
......@@ -35,8 +40,10 @@ public:
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 int sameH(solution_t sol, int* hash, int size)
static int sameH(solution_t sol, int* hash, int size);
};
#endif
\ No newline at end of file
#pragma once
#ifndef UTILS_H
#define UTILS_H
#include <vector>
......@@ -14,3 +16,5 @@ public:
};
#endif
\ No newline at end of file
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\vc142.pdb
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\vc142.idb
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\utils.obj
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\bierwirth.obj
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\main.obj
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\solution.obj
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\gestion_graphe.obj
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\x64\debug\jobshop.exe
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.ilk
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\x64\debug\jobshop.pdb
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\solution.obj.enc
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\cl.command.1.tlog
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\cl.read.1.tlog
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\cl.write.1.tlog
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\link.command.1.tlog
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\link.read.1.tlog
c:\users\poula\documents\travail\zz2\s3\aide décision\tp\tp2\oad-tp2\code\jobshop\x64\debug\jobshop.tlog\link.write.1.tlog
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\poula\Documents\Travail\ZZ2\S3\Aide Décision\TP\TP2\oad-tp2\Code\x64\Debug\JobShop.dll</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>
\ 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