14 #ifndef OR_TOOLS_SAT_DIFFN_UTIL_H_
15 #define OR_TOOLS_SAT_DIFFN_UTIL_H_
25 #include "absl/container/flat_hash_set.h"
26 #include "absl/random/bit_gen_ref.h"
27 #include "absl/strings/str_format.h"
28 #include "absl/types/span.h"
44 x_min =
std::min(x_min, other.x_min);
45 y_min =
std::min(y_min, other.y_min);
46 x_max =
std::max(x_max, other.x_max);
47 y_max =
std::max(y_max, other.y_max);
50 IntegerValue
Area()
const {
return (x_max - x_min) * (y_max - y_min); }
52 bool IsDisjoint(
const Rectangle& other)
const;
55 return absl::StrFormat(
"rectangle(x(%i..%i), y(%i..%i))", x_min.value(),
56 x_max.value(), y_min.value(), y_max.value());
66 const std::vector<Rectangle>& rectangles,
67 absl::Span<int> active_rectangles);
72 const std::vector<IntegerValue>& energies,
73 absl::Span<const int> boxes,
74 Rectangle* conflict =
nullptr);
83 SchedulingConstraintHelper* x,
84 SchedulingConstraintHelper* y);
95 const std::vector<Rectangle>& rectangles,
96 const std::vector<IntegerValue>& rectangle_energies,
97 IntegerValue* x_threshold, IntegerValue* y_threshold,
98 Rectangle* conflict =
nullptr);
104 const std::vector<Rectangle>& cached_rectangles, absl::Span<int> boxes,
105 IntegerValue threshold_x, IntegerValue threshold_y, absl::BitGenRef random);
112 const std::vector<Rectangle>& cached_rectangles,
113 const std::vector<IntegerValue>& energies, absl::Span<int> boxes);
129 return std::tie(
a.start,
a.end,
a.index) <
130 std::tie(
b.start,
b.end,
b.index);
135 return a.start <
b.start;
149 std::vector<IndexedInterval>* intervals,
150 std::vector<std::vector<int>>* result);
157 std::vector<IndexedInterval>* intervals,
158 std::vector<std::vector<int>>* components);
165 std::vector<IndexedInterval>* intervals);
181 return start == other.start &&
height == other.height;
184 IntegerValue
start = IntegerValue(0);
191 void AddRectangle(IntegerValue x_min, IntegerValue x_max, IntegerValue y_min,
197 IntegerValue y_height);
218 enum EventType { START_RECTANGLE, END_RECTANGLE, CHANGE_MANDATORY_PROFILE };
228 const bool operator<(
const Event& other)
const {
return time < other.time; }
232 struct QueueElement {
234 const bool operator<(
const QueueElement& o)
const {
235 return value < o.value;
242 static Event StartRectangleEvent(
int index, IntegerValue x_min,
243 IntegerValue y_min, IntegerValue y_max) {
244 return {x_min, y_min, y_max, START_RECTANGLE,
index};
247 static Event EndRectangleEvent(
int index, IntegerValue x_max) {
251 static Event ChangeMandatoryProfileEvent(IntegerValue x, IntegerValue
delta) {
253 CHANGE_MANDATORY_PROFILE, -1};
256 std::vector<Event> events_;
257 int num_rectangles_added_ = 0;
void AddMandatoryConsumption(IntegerValue x_min, IntegerValue x_max, IntegerValue y_height)
void AddRectangle(IntegerValue x_min, IntegerValue x_max, IntegerValue y_min, IntegerValue y_max)
void BuildResidualCapacityProfile(std::vector< Rectangle > *result)
IntegerValue GetBoundingArea()
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
std::vector< int > GetIntervalArticulationPoints(std::vector< IndexedInterval > *intervals)
void GetOverlappingIntervalComponents(std::vector< IndexedInterval > *intervals, std::vector< std::vector< int >> *components)
std::vector< absl::Span< int > > GetOverlappingRectangleComponents(const std::vector< Rectangle > &rectangles, absl::Span< int > active_rectangles)
absl::Span< int > FilterBoxesAndRandomize(const std::vector< Rectangle > &cached_rectangles, absl::Span< int > boxes, IntegerValue threshold_x, IntegerValue threshold_y, absl::BitGenRef random)
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue.value())
void ConstructOverlappingSets(bool already_sorted, std::vector< IndexedInterval > *intervals, std::vector< std::vector< int >> *result)
bool AnalyzeIntervals(bool transpose, absl::Span< const int > local_boxes, const std::vector< Rectangle > &rectangles, const std::vector< IntegerValue > &rectangle_energies, IntegerValue *x_threshold, IntegerValue *y_threshold, Rectangle *conflict)
bool ReportEnergyConflict(Rectangle bounding_box, absl::Span< const int > boxes, SchedulingConstraintHelper *x, SchedulingConstraintHelper *y)
bool BoxesAreInEnergyConflict(const std::vector< Rectangle > &rectangles, const std::vector< IntegerValue > &energies, absl::Span< const int > boxes, Rectangle *conflict)
absl::Span< int > FilterBoxesThatAreTooLarge(const std::vector< Rectangle > &cached_rectangles, const std::vector< IntegerValue > &energies, absl::Span< int > boxes)
Collection of objects used to extend the Constraint Solver library.
bool operator<(const Rectangle &other) const
bool operator==(const Rectangle &other) const
Rectangle(IntegerValue start, IntegerValue height)
bool operator()(const IndexedInterval &a, const IndexedInterval &b) const
bool operator()(const IndexedInterval &a, const IndexedInterval &b) const
bool operator==(const IndexedInterval &rhs) const
IntegerValue Area() const
std::string DebugString() const
void TakeUnionWith(const Rectangle &other)