20#ifndef OR_TOOLS_UTIL_PIECEWISE_LINEAR_FUNCTION_H_
21#define OR_TOOLS_UTIL_PIECEWISE_LINEAR_FUNCTION_H_
36 int64_t other_point_x);
39 int64_t
Value(int64_t
x)
const;
41 int64_t
start_x()
const {
return start_x_; }
43 int64_t
end_x()
const {
return end_x_; }
49 int64_t
slope()
const {
return slope_; }
74 int64_t SafeValuePostReference(int64_t
x)
const;
78 int64_t SafeValuePreReference(int64_t
x)
const;
91 int64_t intersection_y_;
116 std::vector<int64_t> points_x, std::vector<int64_t> points_y,
117 std::vector<int64_t> slopes, std::vector<int64_t> other_points_x);
123 std::vector<int64_t> points_x, std::vector<int64_t> points_y,
124 std::vector<int64_t> other_points_x);
132 int64_t initial_level, std::vector<int64_t> points_x,
133 std::vector<int64_t> slopes);
137 int64_t point_x, int64_t point_y, int64_t slope, int64_t other_point_x);
164 int64_t reference, int64_t earliness_slope, int64_t tardiness_slope);
173 int64_t early_slack, int64_t late_slack, int64_t earliness_slope,
174 int64_t tardiness_slope);
186 int64_t
Value(int64_t
x)
const;
194 int64_t
GetMaximum(int64_t range_start, int64_t range_end)
const;
198 int64_t
GetMinimum(int64_t range_start, int64_t range_end)
const;
202 int64_t range_start, int64_t range_end, int64_t
value)
const;
206 int64_t range_start, int64_t range_end, int64_t
value)
const;
210 int64_t range_start, int64_t range_end, int64_t value_min,
211 int64_t value_max)
const;
233 const std::vector<PiecewiseSegment>&
segments()
const {
return segments_; }
246 const std::function<int64_t(int64_t, int64_t)>& operation);
249 bool FindSegmentIndicesFromRange(int64_t range_start, int64_t range_end,
250 int* start_segment,
int* end_segment)
const;
251 void UpdateStatus() {
253 is_convex_ = IsConvexInternal();
254 is_non_decreasing_ = IsNonDecreasingInternal();
255 is_non_increasing_ = IsNonIncreasingInternal();
256 is_modified_ =
false;
259 bool IsConvexInternal()
const;
260 bool IsNonDecreasingInternal()
const;
261 bool IsNonIncreasingInternal()
const;
265 std::vector<PiecewiseSegment> segments_;
268 bool is_non_decreasing_;
269 bool is_non_increasing_;
int64_t GetMaximum() const
Returns the maximum value of all the segments in the function.
std::vector< PiecewiseLinearFunction * > DecomposeToConvexFunctions() const
static PiecewiseLinearFunction * CreateFullDomainFunction(int64_t initial_level, std::vector< int64_t > points_x, std::vector< int64_t > slopes)
static PiecewiseLinearFunction * CreateRightRayFunction(int64_t point_x, int64_t point_y, int64_t slope)
bool IsNonIncreasing() const
Returns true if the piecewise linear function is non-increasing.
std::pair< int64_t, int64_t > GetSmallestRangeLessThanValue(int64_t range_start, int64_t range_end, int64_t value) const
static const int kNotFound
static PiecewiseLinearFunction * CreateFixedChargeFunction(int64_t slope, int64_t value)
std::string DebugString() const
void Add(const PiecewiseLinearFunction &other)
static PiecewiseLinearFunction * CreateStepFunction(std::vector< int64_t > points_x, std::vector< int64_t > points_y, std::vector< int64_t > other_points_x)
int64_t GetMinimum() const
Returns the minimum value of all the segments in the function.
void AddConstantToY(int64_t constant)
const std::vector< PiecewiseSegment > & segments() const
static PiecewiseLinearFunction * CreateOneSegmentFunction(int64_t point_x, int64_t point_y, int64_t slope, int64_t other_point_x)
Builds a function consisting of one segment.
std::pair< int64_t, int64_t > GetSmallestRangeInValueRange(int64_t range_start, int64_t range_end, int64_t value_min, int64_t value_max) const
static PiecewiseLinearFunction * CreateLeftRayFunction(int64_t point_x, int64_t point_y, int64_t slope)
bool IsNonDecreasing() const
Returns true if the piecewise linear function is non-decreasing.
static PiecewiseLinearFunction * CreateEarlyTardyFunction(int64_t reference, int64_t earliness_slope, int64_t tardiness_slope)
void AddConstantToX(int64_t constant)
static PiecewiseLinearFunction * CreatePiecewiseLinearFunction(std::vector< int64_t > points_x, std::vector< int64_t > points_y, std::vector< int64_t > slopes, std::vector< int64_t > other_points_x)
static PiecewiseLinearFunction * CreateEarlyTardyFunctionWithSlack(int64_t early_slack, int64_t late_slack, int64_t earliness_slope, int64_t tardiness_slope)
int64_t Value(int64_t x) const
Returns the value of the piecewise linear function for x.
std::pair< int64_t, int64_t > GetSmallestRangeGreaterThanValue(int64_t range_start, int64_t range_end, int64_t value) const
bool InDomain(int64_t x) const
Returns if x is in the domain of the function.
void Subtract(const PiecewiseLinearFunction &other)
int64_t end_x() const
Returns the end of the segment's domain.
int64_t start_y() const
Returns the value at the start of the segment's domain.
static bool FindComparator(int64_t point, const PiecewiseSegment &segment)
Comparison method useful for finding in which segment a point belongs.
static bool SortComparator(const PiecewiseSegment &segment1, const PiecewiseSegment &segment2)
Comparison method useful for sorting a sequence of segments.
std::string DebugString() const
void ExpandEnd(int64_t end_x)
void AddConstantToY(int64_t constant)
Adds 'constant' to the 'y' the segments.
int64_t intersection_y() const
Returns the intersection of the segment's extension with the y axis.
int64_t slope() const
Returns the segment's slope.
int64_t start_x() const
Returns the start of the segment's domain.
void AddConstantToX(int64_t constant)
Adds 'constant' to the 'x' the segments.
PiecewiseSegment(int64_t point_x, int64_t point_y, int64_t slope, int64_t other_point_x)
int64_t Value(int64_t x) const
Returns the value of the segment at point x.
int64_t end_y() const
Returns the value at the end of the segment's domain.
In SWIG mode, we don't want anything besides these top-level includes.