Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Maxime POULAIN
OAD - TP2
Commits
b7e914b6
Commit
b7e914b6
authored
Oct 29, 2021
by
Maxime POULAIN
Browse files
working rech local
parent
4ea462b1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Code/JobShop/bierwirth.cpp
View file @
b7e914b6
...
...
@@ -39,26 +39,37 @@ void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int
int
iIndex
=
prToIndex
(
vectorIn
,
i
,
n
,
m
);
int
jIndex
=
prToIndex
(
vectorIn
,
j
,
n
,
m
);
if
(
iIndex
!=
-
1
&&
jIndex
!=
-
1
)
{
for
(
int
i
=
0
;
i
<
n
*
m
;
i
++
)
{
vectorOut
[
i
]
=
vectorIn
[
i
];
}
vectorOut
[
jIndex
]
=
vectorIn
[
iIndex
];
vectorOut
[
iIndex
]
=
vectorIn
[
jIndex
];
}
else
{
cout
<<
"ERROR PERMUT"
<<
endl
;
cout
<<
"piece : "
<<
i
.
piece
<<
" rang : "
<<
i
.
rang
<<
endl
;
cout
<<
"piece : "
<<
j
.
piece
<<
" rang : "
<<
j
.
rang
<<
endl
;
}
}
int
prToIndex
(
bierwirth
&
vector
,
pr_t
i
,
int
n
,
int
m
)
{
int
index
=
n
*
m
-
1
;
int
cpt
=
0
;
int
cpt
=
m
;
while
(
index
>=
0
)
{
if
(
vector
[
index
]
==
i
.
piece
)
cpt
++
;
if
(
cpt
==
m
-
i
.
rang
)
cpt
--
;
if
(
cpt
==
i
.
rang
)
return
index
;
index
--
;
}
return
index
;
}
bool
isVectorValid
(
bierwirth
&
v
,
int
nbPiece
)
{
vector
<
int
>
count
(
nbPiece
);
std
::
fill
(
count
.
begin
(),
count
.
end
(),
0
);
...
...
Code/JobShop/main.cpp
View file @
b7e914b6
...
...
@@ -8,31 +8,26 @@
using
namespace
std
;
int
main
()
{
srand
(
2410557
);
srand
(
21058497
);
t_graphe
graph
;
graph
=
lecture_fichier
(
"la01.txt"
);
affiche_taches
(
graph
);
//bierwirth v{0, 0, 0, 1, 1, 1, 2, 2, 2};
bierwirth
v
=
generateVector
(
graph
.
nb_pieces
,
graph
.
nb_machines
);
solution_t
sol
=
evaluer
(
v
,
graph
);
affiche_solution
(
sol
);
auto
solRech
=
solution
::
rechercheLocale
(
v
,
graph
,
1000
);
cout
<<
endl
<<
endl
<<
endl
;
affiche_solution
(
sol
);
/*
bierwirth v{ 0, 0, 0, 1, 1, 1, 2, 2, 2 };
bierwirth v2 = v;
permutation(v, v2, { 0,0 }, { 1,0 }, 3, 3);
utils::print(v);
utils::print(v2);
*/
int
best
=
INT16_MAX
;
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
bierwirth
v
=
generateVector
(
graph
.
nb_pieces
,
graph
.
nb_machines
);
solution_t
sol
=
evaluer
(
v
,
graph
);
auto
solRech
=
solution
::
rechercheLocale
(
v
,
graph
,
1000
);
if
(
solRech
.
cost
<
best
)
{
best
=
solRech
.
cost
;
}
}
cout
<<
best
<<
endl
;
return
0
;
...
...
Code/JobShop/solution.cpp
View file @
b7e914b6
...
...
@@ -10,24 +10,12 @@ solution_t solution::rechercheLocale(bierwirth& v, t_graph& graph, int maxIterat
pr_t
jFather
=
solutionEvaluated
.
father
[
j
.
piece
][
j
.
rang
];
bierwirth
vInput
=
v
;
bierwirth
vOpti
=
v
;
int
iteration
=
0
;
while
((
jFather
.
piece
!=
-
1
&&
jFather
.
rang
!=
-
1
)
&&
iteration
<
maxIteration
)
{
cout
<<
iteration
<<
endl
;
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
);
if
(
!
isVectorValid
(
vOpti
,
graph
.
nb_pieces
))
{
cout
<<
"Vector vOpti invalid"
<<
endl
;
utils
::
print
(
vInput
);
utils
::
print
(
vOpti
);
break
;
}
solutionOpti
=
evaluer
(
vOpti
,
graph
);
cout
<<
"Cost found : "
<<
solutionOpti
.
cost
<<
endl
;
if
(
solutionOpti
.
cost
<
solutionEvaluated
.
cost
)
{
cout
<<
"NEW BEST : "
<<
solutionOpti
.
cost
<<
endl
;
vInput
=
vOpti
;
solutionEvaluated
=
solutionOpti
;
j
=
solutionEvaluated
.
lastFather
;
...
...
Code/JobShop/utils.cpp
View file @
b7e914b6
...
...
@@ -17,3 +17,14 @@ void utils::print(std::vector<int> v)
}
cout
<<
endl
<<
endl
;
}
void
utils
::
print2
(
std
::
vector
<
int
>
v1
,
std
::
vector
<
int
>
v2
)
{
for
(
size_t
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
cout
<<
i
<<
" : "
<<
v1
[
i
]
<<
" "
<<
v2
[
i
]
<<
endl
;
}
cout
<<
endl
<<
endl
;
}
Code/JobShop/utils.h
View file @
b7e914b6
...
...
@@ -10,7 +10,7 @@ static class utils
public:
static
int
random
(
int
a
,
int
b
);
static
void
print
(
std
::
vector
<
int
>
v
);
static
void
print2
(
std
::
vector
<
int
>
v1
,
std
::
vector
<
int
>
v2
);
};
Code/JobShop/x64/Debug/solution.obj
View file @
b7e914b6
No preview for this file type
Code/View/x64/Debug/View.vcxproj.AssemblyReference.cache
View file @
b7e914b6
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment