14#ifndef OR_TOOLS_SAT_DIFFN_UTIL_H_
15#define OR_TOOLS_SAT_DIFFN_UTIL_H_
24#include "absl/container/flat_hash_set.h"
25#include "absl/random/bit_gen_ref.h"
26#include "absl/strings/str_format.h"
27#include "absl/types/span.h"
54 return absl::StrFormat(
"rectangle(x(%i..%i), y(%i..%i))",
x_min.value(),
65 const std::vector<Rectangle>& rectangles,
66 absl::Span<int> active_rectangles);
71 const std::vector<IntegerValue>& energies,
72 absl::Span<const int> boxes,
73 Rectangle* conflict =
nullptr);
82 SchedulingConstraintHelper* x,
83 SchedulingConstraintHelper* y);
94 const std::vector<Rectangle>& rectangles,
95 const std::vector<IntegerValue>& rectangle_energies,
96 IntegerValue* x_threshold, IntegerValue* y_threshold,
97 Rectangle* conflict =
nullptr);
103 const std::vector<Rectangle>& cached_rectangles, absl::Span<int> boxes,
104 IntegerValue threshold_x, IntegerValue threshold_y, absl::BitGenRef random);
111 const std::vector<Rectangle>& cached_rectangles,
112 const std::vector<IntegerValue>& energies, absl::Span<int> boxes);
128 return std::tie(
a.start,
a.end,
a.index) <
129 std::tie(
b.start,
b.end,
b.index);
134 return a.start <
b.start;
148 std::vector<IndexedInterval>* intervals,
149 std::vector<std::vector<int>>* result);
156 std::vector<IndexedInterval>* intervals,
157 std::vector<std::vector<int>>* components);
164 std::vector<IndexedInterval>* intervals);
183 IntegerValue
start = IntegerValue(0);
190 void AddRectangle(IntegerValue x_min, IntegerValue x_max, IntegerValue y_min,
196 IntegerValue y_height);
217 enum EventType { START_RECTANGLE, END_RECTANGLE, CHANGE_MANDATORY_PROFILE };
227 const bool operator<(
const Event& other)
const {
return time < other.time; }
231 struct QueueElement {
233 const bool operator<(
const QueueElement& o)
const {
234 return value < o.value;
241 static Event StartRectangleEvent(
int index, IntegerValue x_min,
242 IntegerValue y_min, IntegerValue y_max) {
243 return {x_min, y_min, y_max, START_RECTANGLE,
index};
246 static Event EndRectangleEvent(
int index, IntegerValue x_max) {
250 static Event ChangeMandatoryProfileEvent(IntegerValue x, IntegerValue
delta) {
252 CHANGE_MANDATORY_PROFILE, -1};
255 std::vector<Event> events_;
256 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)
void GetOverlappingIntervalComponents(std::vector< IndexedInterval > *intervals, std::vector< std::vector< int > > *components)
std::vector< int > GetIntervalArticulationPoints(std::vector< IndexedInterval > *intervals)
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())
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)
void ConstructOverlappingSets(bool already_sorted, std::vector< IndexedInterval > *intervals, std::vector< std::vector< int > > *result)
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)
bool IsDisjoint(const Rectangle &other) const