Skip to content

Commit ac8726c

Browse files
committed
Fixed generator
1 parent af61b11 commit ac8726c

4 files changed

Lines changed: 25 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: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <random>
1+
#include <string>
22
#include <iosfwd>
33
#include <iostream>
4+
#include <random>
45

56
using namespace std;
67

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

1112
if (argc < 2) {
12-
cerr << "Usage: generator n\n";
13+
cerr << "Usage: generator n <capacity> <w_max>\n";
14+
return EXIT_FAILURE;
1315
}
1416

1517
auto n = stoull(argv[1]);
1618

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

2032
constexpr uint8_t MAX_VALUE = numeric_limits<uint8_t>::max();
21-
constexpr uint8_t MAX_WEIGHT = numeric_limits<uint8_t>::max();
2233

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;
34+
uniform_int_distribution<uint16_t> value_dist(1, MAX_VALUE);
35+
uniform_int_distribution<uint16_t> weight_dist(1, max_weight);
2836

2937
cout << n << ' ' << capacity << '\n';
3038

3139
// Values
3240
for (uint64_t i = 0; i < n; ++i) {
33-
cout << static_cast<uint32_t>(value_dist(g)) << ' ';
41+
cout << value_dist(g) << ' ';
3442
}
3543
cout << '\n';
3644

3745
// Weight
3846
for (uint64_t i = 0; i < n; ++i) {
39-
cout << static_cast<uint32_t>(weight_dist(g)) << ' ';
47+
cout << weight_dist(g) << ' ';
4048
}
4149
cout << '\n';
42-
}
50+
51+
return EXIT_SUCCESS;
52+
}

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)