Skip to content

Commit ad46069

Browse files
committed
fix std::shuffle and SingleObjSearchBuilder
1 parent 334b890 commit ad46069

File tree

18 files changed

+49
-36
lines changed

18 files changed

+49
-36
lines changed

Examples/FCore-Examples/src/TSP-fcore.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ std::vector<int> frandom() {
9191
vector<int> v(pTSP.n, -1); // get information from context
9292
for (unsigned i = 0; i < v.size(); i++) v[i] = i;
9393
// leave 0 on first position and shuffle the rest
94-
std::random_shuffle(v.begin() + 1, v.end());
94+
std::shuffle(v.begin() + 1, v.end());
9595
return v;
9696
}
9797

Examples/FCore-Examples/src/TSP-fxcore.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ using TSPRandom =
8585
[](double timelimit) -> std::optional<std::vector<int>> {
8686
vector<int> v(pTSP.n, -1); // get information from context
8787
for (unsigned i = 0; i < v.size(); i++) v[i] = i;
88-
std::random_shuffle(v.begin(), v.end());
88+
std::shuffle(v.begin(), v.end());
8989
return make_optional(v);
9090
}>;
9191

Examples/FCore-VRP/mainVRP.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ VRP_RepADS frandom(sref<ProblemContext> pVRP) {
127127
vector<int> v(pVRP->n, -1); // get information from context
128128
for (int i = 0; i < v.size(); i++) v[i] = i + 1; // excludes depot 0
129129
// shuffle (TODO: use randgen)
130-
std::random_shuffle(v.begin(), v.end());
130+
std::shuffle(v.begin(), v.end());
131131
//
132132
// begin random construction
133133
// clients are added one by one, unless capacity is exceeded, and a new route

Examples/SVRPDSP/src/ConstructiveRandom.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class ConstructiveRandom
4141
for (unsigned int i = 0; i < pSVRPDSP.n; i++)
4242
p_cust[i] = i + 1 + pSVRPDSP.n;
4343

44-
std::random_shuffle(d_cust.begin(), d_cust.end());
45-
std::random_shuffle(p_cust.begin(), p_cust.end());
44+
std::shuffle(d_cust.begin(), d_cust.end());
45+
std::shuffle(p_cust.begin(), p_cust.end());
4646

4747
RepSVRPDSP repAux;
4848

@@ -57,7 +57,7 @@ class ConstructiveRandom
5757
RepSVRPDSP rep;
5858
rep.push_back(0); // start depot
5959

60-
std::random_shuffle(repAux.begin(), repAux.end());
60+
std::shuffle(repAux.begin(), repAux.end());
6161

6262
for (unsigned i = 0; i < repAux.size(); i++) rep.push_back(repAux[i]);
6363

demo/02_QuickstartKP_SA/MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ git_override(
1010
module_name = "optframe",
1111
remote = "https://github.com/optframe/optframe.git",
1212
branch='master'
13-
# commit = "87ce7ebcfb495b9535729d4a31ea1a50b6a6b95a"
13+
# commit = "334b8901584aa0d33621c0acd1497589c59d2ed7"
1414
)

demo/03_QuickstartTSP_VNS_BRKGA/MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ git_override(
1010
module_name = "optframe",
1111
remote = "https://github.com/optframe/optframe.git",
1212
branch='master'
13-
# commit = "87ce7ebcfb495b9535729d4a31ea1a50b6a6b95a"
13+
# commit = "334b8901584aa0d33621c0acd1497589c59d2ed7"
1414
)

demo/03_QuickstartTSP_VNS_BRKGA/TSP-fcore-part4.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
std::vector<int> frandom(sref<ProblemContext> pTSP) {
22
vector<int> v(pTSP->n, -1); // get information from context
33
for (int i = 0; i < (int)v.size(); i++) v[i] = i;
4-
std::random_shuffle(v.begin(), v.end());
4+
5+
std::random_device rd;
6+
std::mt19937 g{rd()};
7+
8+
std::shuffle(v.begin(), v.end(), g);
59
return v;
610
}
711

demo/03_QuickstartTSP_VNS_BRKGA/TSP-fcore.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ Evaluation<int> fevaluate(sref<ProblemContext> pTSP,
7272
std::vector<int> frandom(sref<ProblemContext> pTSP) {
7373
vector<int> v(pTSP->n, -1); // get information from context
7474
for (int i = 0; i < (int)v.size(); i++) v[i] = i;
75-
std::random_shuffle(v.begin(), v.end());
75+
76+
std::random_device rd;
77+
std::mt19937 g{rd()};
78+
79+
std::shuffle(v.begin(), v.end(), g);
7680
return v;
7781
}
7882

demo/03_QuickstartTSP_VNS_BRKGA/mainTSP-fcore-brkga.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class MyRandomKeysInitEPop
5858
}
5959
};
6060

61+
6162
pair<Evaluation<int>, vector<int>> fDecodeEval(
6263
sref<Evaluator<typename ESolutionTSP::first_type,
6364
typename ESolutionTSP::second_type, ESolutionTSP>>

demo/03_QuickstartTSP_VNS_BRKGA/mainTSP-fcore-ils.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,25 @@ int main() {
7878

7979
VariableNeighborhoodDescent<ESolutionTSP> VND(demo.eval, ns_list);
8080
// VND.setVerbose();//
81-
ILSLPerturbationLPlus2<ESolutionTSP> pert(demo.eval, demo.nsSwap, rg2);
82-
83-
IteratedLocalSearchLevels<ESolutionTSP> ils(demo.eval, nnptr::copy(initRand),
84-
nnptr::copy(VND),
85-
nnptr::copy(pert), 10, 5);
86-
// ils.setVerbose();
87-
88-
std::cout << "will start ILS for 10 seconds" << std::endl;
89-
90-
optframe::Timer t;
91-
ils.setVerbose();
92-
auto status = ils.search(
93-
StopCriteria<ESolutionTSP::second_type>{10.0}); // 3.0 seconds max
94-
ESolutionTSP best = *status.best;
95-
std::cout << "spent time: " << t.now() << "s" << std::endl;
96-
// best solution value
97-
best.second.print();
98-
std::cout << "solution: " << best.first << std::endl;
99-
100-
std::cout << "FINISHED" << std::endl;
101-
return 0;
81+
ILSLPerturbationLPlus2<ESolutionTSP> pert(demo.eval, demo.nsSwap, rg2);
82+
83+
IteratedLocalSearchLevels<ESolutionTSP> ils(demo.eval, nnptr::copy(initRand),
84+
nnptr::copy(VND), nnptr::copy(pert),
85+
10, 5);
86+
// ils.setVerbose();
87+
88+
std::cout << "will start ILS for 10 seconds" << std::endl;
89+
90+
optframe::Timer t;
91+
ils.setVerbose();
92+
auto status = ils.search(
93+
StopCriteria<ESolutionTSP::second_type>{10.0}); // 3.0 seconds max
94+
ESolutionTSP best = *status.best;
95+
std::cout << "spent time: " << t.now() << "s" << std::endl;
96+
// best solution value
97+
best.second.print();
98+
std::cout << "solution: " << best.first << std::endl;
99+
100+
std::cout << "FINISHED" << std::endl;
101+
return 0;
102102
}

demo/05_Advanced_TSP_checkmodule/TSP-fcore-applyupdate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Evaluation<int> fevaluate(sref<ProblemContext> pTSP,
7272
std::vector<int> frandom(sref<ProblemContext> pTSP) {
7373
vector<int> v(pTSP->n, -1); // get information from context
7474
for (int i = 0; i < (int)v.size(); i++) v[i] = i;
75-
std::random_shuffle(v.begin(), v.end());
75+
std::shuffle(v.begin(), v.end());
7676
return v;
7777
}
7878

demo/05_Advanced_TSP_checkmodule/TSP-fcore.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Evaluation<int> fevaluate(sref<ProblemContext> pTSP,
7272
std::vector<int> frandom(sref<ProblemContext> pTSP) {
7373
vector<int> v(pTSP->n, -1); // get information from context
7474
for (int i = 0; i < (int)v.size(); i++) v[i] = i;
75-
std::random_shuffle(v.begin(), v.end());
75+
std::shuffle(v.begin(), v.end());
7676
return v;
7777
}
7878

demo/06_Advanced_OptFCoreLib/mainlib.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ std::any frandom() {
158158
vector<int> v(pTSP.n, -1); // get information from context
159159
for (unsigned i = 0; i < v.size(); i++) v[i] = i;
160160
// leave 0 on first position and shuffle the rest
161-
std::random_shuffle(v.begin() + 1, v.end());
161+
std::shuffle(v.begin() + 1, v.end());
162162
return v;
163163
}
164164

include/OptFCore/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ using TSPRandom = FConstructive <
117117
vector<int> v(pTSP.n, -1); // get information from pTSP problem
118118
for (unsigned i = 0; i < v.size(); i++)
119119
v[i] = i;
120-
std::random_shuffle(v.begin(), v.end());
120+
std::shuffle(v.begin(), v.end());
121121
return make_optional(v);
122122
}
123123
> ;

include/OptFrame/Heuristics/EA/RK/BRKGA.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <OptFrame/Heuristics/EA/RK/RKGA.hpp>
1414
#include <OptFrame/InitialPopulation.hpp>
1515
#include <OptFrame/Search/GlobalSearch.hpp>
16+
#include <OptFrame/Search/GlobalSearchBuilder.hpp>
1617
#include <OptFrame/Search/SingleObjSearch.hpp>
18+
#include <OptFrame/Search/SingleObjSearchBuilder.hpp>
1719

1820
#include "OptFrame/Concepts/MyConcepts.hpp"
1921

include/OptFrame/Heuristics/ILS/IteratedLocalSearch.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <OptFrame/Core/Evaluator.hpp>
1616
#include <OptFrame/Search/ITrajectory.hpp>
1717
#include <OptFrame/Search/SingleObjSearch.hpp>
18+
#include <OptFrame/Search/SingleObjSearchBuilder.hpp>
1819
#include <OptFrame/Timer.hpp>
1920

2021
#include "./ILS.h"

include/OptFrame/Heuristics/ILS/IteratedLocalSearchLevels.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111
//
1212
#include <OptFrame/LocalSearch.hpp>
13+
#include <OptFrame/Search/SingleObjSearchBuilder.hpp>
1314

1415
#include "./ILS.h"
1516
#include "./ILSLPerturbation.hpp"

tests/test-install-OptFCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ constexpr int TSP_N = 3;
2424
using TSPRandom = FConstructive<std::vector<int>, [](double timelimit) -> auto {
2525
vector<int> v(TSP_N, -1); // get information from context
2626
for (unsigned i = 0; i < v.size(); i++) v[i] = i;
27-
std::random_shuffle(v.begin(), v.end());
27+
std::shuffle(v.begin(), v.end());
2828
return make_optional(v);
2929
}>;
3030

0 commit comments

Comments
 (0)