31 int num_rectangles, absl::BitGenRef random) {
32 static constexpr int kSizeMax = 1'000'000;
33 std::vector<Rectangle> rectangles;
34 rectangles.reserve(num_rectangles);
36 {.x_min = 0, .x_max = kSizeMax, .y_min = 0, .y_max = kSizeMax});
37 for (
int i = 0;
i < num_rectangles; ++
i) {
38 std::swap(rectangles.back(),
39 rectangles[absl::Uniform(random, 0ull, rectangles.size() - 1)]);
40 const Rectangle& rec = rectangles.back();
41 if (absl::Bernoulli(random, 0.5)) {
42 const IntegerValue cut = IntegerValue(
43 absl::Uniform(random, rec.x_min.value(), rec.x_max.value()));
44 const Rectangle new_range = {.x_min = rec.x_min,
48 const Rectangle new_range2 = {.x_min = cut,
52 rectangles.pop_back();
53 rectangles.push_back(new_range);
54 rectangles.push_back(new_range2);
56 const IntegerValue cut = IntegerValue(
57 absl::Uniform(random, rec.y_min.value(), rec.y_max.value()));
58 const Rectangle new_range = {.x_min = rec.x_min,
62 const Rectangle new_range2 = {.x_min = rec.x_min,
66 rectangles.pop_back();
67 rectangles.push_back(new_range);
68 rectangles.push_back(new_range2);
75 absl::Span<const Rectangle> rectangles,
double slack_factor,
76 absl::BitGenRef random) {
77 IntegerValue size_max_x = 0;
78 IntegerValue size_max_y = 0;
79 for (
const Rectangle& rec : rectangles) {
80 size_max_x = std::max(size_max_x, rec.SizeX());
81 size_max_y = std::max(size_max_y, rec.SizeY());
83 std::vector<RectangleInRange> ranges;
84 ranges.reserve(rectangles.size());
85 const int max_slack_x = slack_factor * size_max_x.value();
86 const int max_slack_y = slack_factor * size_max_y.value();
87 for (
const Rectangle& rec : rectangles) {
90 range.y_size = rec.y_max - rec.y_min;
91 range.bounding_area = {
93 rec.x_min - IntegerValue(absl::Uniform(random, 0, max_slack_x)),
95 rec.x_max + IntegerValue(absl::Uniform(random, 0, max_slack_x)),
97 rec.y_min - IntegerValue(absl::Uniform(random, 0, max_slack_y)),
99 rec.y_max + IntegerValue(absl::Uniform(random, 0, max_slack_y))};
100 ranges.push_back(
range);
107 const std::vector<Rectangle>& rectangles,
double slack_factor,
108 absl::BitGenRef random) {
109 const std::vector<RectangleInRange> range_items =
111 std::vector<ItemForPairwiseRestriction> items;
112 items.reserve(rectangles.size());
113 for (
int i = 0;
i < range_items.size(); ++
i) {
115 items.push_back({.index =
i,
131 absl::BitGenRef random) {
132 const std::vector<Rectangle> rectangles =
134 std::vector<ItemForPairwiseRestriction> items =
140 std::vector<PairwiseRestriction> results;
143 CHECK(restriction.type !=
146 for (
int index : {restriction.first_index, restriction.second_index}) {
147 const auto& rec = rectangles[
index];
149 .x = {.start_min = rec.x_min,
150 .start_max = rec.x_min,
151 .end_min = rec.x_max,
152 .end_max = rec.x_max},
153 .y = {.start_min = rec.y_min,
154 .start_max = rec.y_min,
155 .end_min = rec.y_max,
156 .end_max = rec.y_max}};
159 done = results.empty();