Skip to content

Commit 1f5a4c5

Browse files
committed
Fixed generator
1 parent af61b11 commit 1f5a4c5

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

.idea/advanced_algorithms.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
add_executable(he_xu he_xu.cpp)
2-
add_executable(knapsack_generator generator.cpp)
1+
add_executable(knapsack hexu_and_dp.cpp)
2+
add_executable(knapsack_generator generator.cpp)

5/generator.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <random>
21
#include <iosfwd>
32
#include <iostream>
3+
#include <random>
44

55
using namespace std;
66

@@ -9,34 +9,43 @@ int main(int argc, char** argv) {
99
cin.tie(nullptr);
1010

1111
if (argc < 2) {
12-
cerr << "Usage: generator n\n";
12+
cerr << "Usage: generator n <capacity> <w_max>\n";
13+
return EXIT_FAILURE;
1314
}
1415

1516
auto n = stoull(argv[1]);
1617

18+
uint64_t capacity = n * numeric_limits<uint8_t>::max() / 4;
19+
if (argc >= 3) {
20+
capacity = stoull(argv[2]);
21+
}
22+
23+
uint16_t max_weight = numeric_limits<uint8_t>::max();
24+
if (argc >= 4) {
25+
max_weight = stoul(argv[3]);
26+
}
27+
1728
random_device rd;
1829
mt19937_64 g(rd());
1930

2031
constexpr uint8_t MAX_VALUE = numeric_limits<uint8_t>::max();
21-
constexpr uint8_t MAX_WEIGHT = numeric_limits<uint8_t>::max();
2232

23-
uniform_int_distribution<uint8_t> value_dist(1, MAX_VALUE);
24-
uniform_int_distribution<uint8_t> weight_dist(1, MAX_WEIGHT);
25-
26-
// Capacity is a forth of the maximum weight
27-
uint64_t capacity = n * MAX_WEIGHT / 4;
33+
uniform_int_distribution<uint16_t> value_dist(1, MAX_VALUE);
34+
uniform_int_distribution<uint16_t> weight_dist(1, max_weight);
2835

2936
cout << n << ' ' << capacity << '\n';
3037

3138
// Values
3239
for (uint64_t i = 0; i < n; ++i) {
33-
cout << static_cast<uint32_t>(value_dist(g)) << ' ';
40+
cout << value_dist(g) << ' ';
3441
}
3542
cout << '\n';
3643

3744
// Weight
3845
for (uint64_t i = 0; i < n; ++i) {
39-
cout << static_cast<uint32_t>(weight_dist(g)) << ' ';
46+
cout << weight_dist(g) << ' ';
4047
}
4148
cout << '\n';
42-
}
49+
50+
return EXIT_SUCCESS;
51+
}

5/he_xu.cpp renamed to 5/hexu_and_dp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <random>
77
#include <ranges>
88
#include <span>
9-
#include <unordered_map>
109
#include <vector>
1110

1211
using namespace std;
@@ -116,6 +115,6 @@ int main() {
116115
auto time_hexu =
117116
chrono::duration_cast<chrono::milliseconds>(chrono::duration(now - start)).count();
118117

119-
cout << result_dp << ',' << time_dp << ',' << updates_dp << ',' << result_dp << ',' << time_hexu
118+
cout << result_dp << ',' << time_dp << ',' << updates_dp << ',' << result_hexu << ',' << time_hexu
120119
<< ',' << updates_hexu << '\n';
121120
}

0 commit comments

Comments
 (0)