Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MH-Builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orkad-public
MH-Builder
Commits
c3c578aa
Commit
c3c578aa
authored
Jun 28, 2021
by
Cyprien Borée
Browse files
Options
Downloads
Patches
Plain Diff
replace HC with PLS
parent
649bc99c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/tspTest.cpp
+20
-30
20 additions, 30 deletions
bin/tspTest.cpp
with
20 additions
and
30 deletions
bin/tspTest.cpp
+
20
−
30
View file @
c3c578aa
...
@@ -16,8 +16,7 @@ int main(int argc, char* argv[]){
...
@@ -16,8 +16,7 @@ int main(int argc, char* argv[]){
unsigned
INITIAL_SOLUTIONS
=
1000000
;
unsigned
INITIAL_SOLUTIONS
=
1000000
;
unsigned
ARCHIVE_BOUND
=
100
;
unsigned
ARCHIVE_BOUND
=
100
;
unsigned
MAX_ITER
=
100
;
long
long
int
TIME_LIMIT
=
20000
;
//ms
long
long
int
TIME_LIMIT
=
20
;
//ms per solution
std
::
cout
<<
"Reading instance files..."
<<
std
::
endl
;
std
::
cout
<<
"Reading instance files..."
<<
std
::
endl
;
tsp
::
TSP
tsp_instance1
(
"../../instances/tsp/tsp_test/cgC50_10_01.txt"
);
tsp
::
TSP
tsp_instance1
(
"../../instances/tsp/tsp_test/cgC50_10_01.txt"
);
...
@@ -41,38 +40,29 @@ int main(int argc, char* argv[]){
...
@@ -41,38 +40,29 @@ int main(int argc, char* argv[]){
std
::
cout
<<
"Initial archive contains "
<<
bounded_archive
.
size
()
<<
" solutions : "
<<
std
::
endl
;
std
::
cout
<<
"Initial archive contains "
<<
bounded_archive
.
size
()
<<
" solutions : "
<<
std
::
endl
;
std
::
cout
<<
bounded_archive
<<
std
::
endl
;
std
::
cout
<<
bounded_archive
<<
std
::
endl
;
opt
::
TimeCriterion
<
SOL
>
time_criterion
(
TIME_LIMIT
);
opt
::
TimeCriterion
<
BOUNDED_ARCHIVE
>
time_criterion
(
TIME_LIMIT
);
for
(
unsigned
i
=
0
;
i
<
MAX_ITER
;
++
i
){
core
::
HammingDiversityCriterion
<
SOL
>
global_diversity
;
// Pick a random solution within the archive.
SOL
tmp_sol
;
if
(
bounded_archive
.
size
()){
unsigned
random_sol_idx
=
core
::
RNGHelper
::
get
()
->
random
(
bounded_archive
.
size
());
tmp_sol
=
bounded_archive
[
random_sol_idx
];
}
else
{
tmp_sol
=
bounded_archive
[
0
];
}
// Explore solution's neighborhood.
std
::
cout
<<
"initial global diversity: "
<<
global_diversity
.
recompute_all
(
bounded_archive
)
<<
std
::
endl
;
representation
::
TwoOptNeighbor
<
SOL
>
optNeighbor
;
opt
::
OrderNeighborhood
<
SOL
>
orderNeighborhood
(
optNeighbor
);
opt
::
SelectAll
<
BOUNDED_ARCHIVE
>
*
select
=
new
opt
::
SelectAll
<
BOUNDED_ARCHIVE
>
();
opt
::
FirstImprNeighborhoodExplorer
<
SOL
>
firstImprNeighborhoodExplorer
(
orderNeighborhood
,
eval
);
opt
::
HillClimbing
<
SOL
>
hillClimbing
(
firstImprNeighborhoodExplorer
,
eval
);
representation
::
TwoOptNeighbor
<
SOL
>
twoOptNeighbor
;
optNeighbor
.
init
(
tmp_sol
);
opt
::
RndWithoutRemplNeighborhood
<
SOL
>
rndWithoutRemplNeighborhood
(
twoOptNeighbor
);
hillClimbing
.
init
(
tmp_sol
);
auto
initial_fitness
=
tmp_sol
.
fitness
();
opt
::
Neighborhood
<
SOL
>
*
neighborhood
=
&
rndWithoutRemplNeighborhood
;
hillClimbing
(
tmp_sol
,
time_criterion
);
auto
new_fitness
=
tmp_sol
.
fitness
();
opt
::
Explorer
<
BOUNDED_ARCHIVE
>
*
explorer
=
new
opt
::
NDomExplorer
<
BOUNDED_ARCHIVE
>
(
*
neighborhood
,
eval
);
if
(
new_fitness
>
initial_fitness
){
opt
::
ParetoLocalSearch
<
BOUNDED_ARCHIVE
>
*
paretoLocalSearch
=
new
opt
::
ParetoLocalSearch
<
BOUNDED_ARCHIVE
>
(
*
select
,
*
explorer
);
std
::
cout
<<
"fitness improved!"
<<
std
::
endl
;
}
bounded_archive
(
tmp_sol
);
}
time_criterion
.
init
();
paretoLocalSearch
->
operator
()(
bounded_archive
,
time_criterion
);
std
::
cout
<<
"Final archive contains "
<<
bounded_archive
.
size
()
<<
" solutions : "
<<
std
::
endl
;
std
::
cout
<<
"Final archive contains "
<<
bounded_archive
.
size
()
<<
" solutions : "
<<
std
::
endl
;
std
::
cout
<<
bounded_archive
<<
std
::
endl
;
std
::
cout
<<
bounded_archive
<<
std
::
endl
;
std
::
cout
<<
"final global diversity: "
<<
global_diversity
.
recompute_all
(
bounded_archive
)
<<
std
::
endl
;
std
::
cout
<<
"Program ended!"
<<
std
::
endl
;
std
::
cout
<<
"Program ended!"
<<
std
::
endl
;
return
0
;
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment