Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::PiecewiseLinearFunction Class Reference

#include <piecewise_linear_function.h>

Public Member Functions

bool InDomain (int64_t x) const
 Returns if x is in the domain of the function.
 
bool IsConvex () const
 
bool IsNonDecreasing () const
 Returns true if the piecewise linear function is non-decreasing.
 
bool IsNonIncreasing () const
 Returns true if the piecewise linear function is non-increasing.
 
int64_t Value (int64_t x) const
 Returns the value of the piecewise linear function for x.
 
int64_t GetMaximum () const
 Returns the maximum value of all the segments in the function.
 
int64_t GetMinimum () const
 Returns the minimum value of all the segments in the function.
 
int64_t GetMaximum (int64_t range_start, int64_t range_end) const
 
int64_t GetMinimum (int64_t range_start, int64_t range_end) const
 
std::pair< int64_t, int64_t > GetSmallestRangeGreaterThanValue (int64_t range_start, int64_t range_end, int64_t value) const
 
std::pair< int64_t, int64_t > GetSmallestRangeLessThanValue (int64_t range_start, int64_t range_end, int64_t value) const
 
std::pair< int64_t, int64_t > GetSmallestRangeInValueRange (int64_t range_start, int64_t range_end, int64_t value_min, int64_t value_max) const
 
void AddConstantToX (int64_t constant)
 
void AddConstantToY (int64_t constant)
 
void Add (const PiecewiseLinearFunction &other)
 
void Subtract (const PiecewiseLinearFunction &other)
 
std::vector< PiecewiseLinearFunction * > DecomposeToConvexFunctions () const
 
const std::vector< PiecewiseSegment > & segments () const
 
std::string DebugString () const
 

Static Public Member Functions

static PiecewiseLinearFunctionCreatePiecewiseLinearFunction (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 PiecewiseLinearFunctionCreateStepFunction (std::vector< int64_t > points_x, std::vector< int64_t > points_y, std::vector< int64_t > other_points_x)
 
static PiecewiseLinearFunctionCreateFullDomainFunction (int64_t initial_level, std::vector< int64_t > points_x, std::vector< int64_t > slopes)
 
static PiecewiseLinearFunctionCreateOneSegmentFunction (int64_t point_x, int64_t point_y, int64_t slope, int64_t other_point_x)
 Builds a function consisting of one segment.
 
static PiecewiseLinearFunctionCreateRightRayFunction (int64_t point_x, int64_t point_y, int64_t slope)
 
static PiecewiseLinearFunctionCreateLeftRayFunction (int64_t point_x, int64_t point_y, int64_t slope)
 
static PiecewiseLinearFunctionCreateFixedChargeFunction (int64_t slope, int64_t value)
 
static PiecewiseLinearFunctionCreateEarlyTardyFunction (int64_t reference, int64_t earliness_slope, int64_t tardiness_slope)
 
static PiecewiseLinearFunctionCreateEarlyTardyFunctionWithSlack (int64_t early_slack, int64_t late_slack, int64_t earliness_slope, int64_t tardiness_slope)
 

Static Public Attributes

static const int kNotFound = -1
 

Detailed Description

In mathematics, a piecewise linear function is a function composed of straight-line, non overlapping sections.

Definition at line 96 of file piecewise_linear_function.h.

Member Function Documentation

◆ Add()

void operations_research::PiecewiseLinearFunction::Add ( const PiecewiseLinearFunction & other)

Adds the function to the existing one. The domain of the resulting function is the intersection of the two domains. The overflows and the underflows are sticky.

Definition at line 637 of file piecewise_linear_function.cc.

◆ AddConstantToX()

void operations_research::PiecewiseLinearFunction::AddConstantToX ( int64_t constant)

Adds 'constant' to the 'x' of all segments. If the argument is positive, the translation is to the right and when it's negative, to the left. The overflows and the underflows are sticky.

Definition at line 623 of file piecewise_linear_function.cc.

◆ AddConstantToY()

void operations_research::PiecewiseLinearFunction::AddConstantToY ( int64_t constant)

Adds 'constant' to the 'y' of all segments. If the argument is positive, the translation is up and when it's negative, down. The overflows and the underflows are sticky.

Definition at line 630 of file piecewise_linear_function.cc.

◆ CreateEarlyTardyFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateEarlyTardyFunction ( int64_t reference,
int64_t earliness_slope,
int64_t tardiness_slope )
static

Builds an earliness-tardiness two-segment piecewise linear cost function. The reference specifies the point where the cost is zero. Before the reference, the cost increases with the earliness slope and after the reference, it increases with the tardiness slope. The absolute values of the slopes are given.

Definition at line 385 of file piecewise_linear_function.cc.

◆ CreateEarlyTardyFunctionWithSlack()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateEarlyTardyFunctionWithSlack ( int64_t early_slack,
int64_t late_slack,
int64_t earliness_slope,
int64_t tardiness_slope )
static

Builds an earliness-tardiness three-segment piecewise linear cost function with a slack period around the due date. The early slack is the point before which the cost increases with the ealiness slope specified. The late slack is the point after which the cost increases with the late slope specified. Between the early and the late slack point, the cost is zero. The absolute values of the slopes are given.

Definition at line 396 of file piecewise_linear_function.cc.

◆ CreateFixedChargeFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateFixedChargeFunction ( int64_t slope,
int64_t value )
static

Builds a two-segment fixed charge piecewise linear cost function. For values less than zero, the cost is zero. For values greater than zero, cost follows the line specified by the slope and the value given as arguments. The slope and value are positive.

Definition at line 375 of file piecewise_linear_function.cc.

◆ CreateFullDomainFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateFullDomainFunction ( int64_t initial_level,
std::vector< int64_t > points_x,
std::vector< int64_t > slopes )
static

Builds a multiple-segment piecewise linear function with domain from from kint64min to kint64max with n points and n+1 slopes. Each slope stops at the point with the corresponding index apart from the last one which stops at kint64max. The first slope stops at the first point at the level specified.

Definition at line 328 of file piecewise_linear_function.cc.

◆ CreateLeftRayFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateLeftRayFunction ( int64_t point_x,
int64_t point_y,
int64_t slope )
static

Builds a function consisting of one ray starting at the specified x and y coordinates with the specified slope.

Definition at line 368 of file piecewise_linear_function.cc.

◆ CreateOneSegmentFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateOneSegmentFunction ( int64_t point_x,
int64_t point_y,
int64_t slope,
int64_t other_point_x )
static

Builds a function consisting of one segment.

Visual studio 2013: We cannot inline the vector in the PiecewiseLinearFunction ctor.

Definition at line 352 of file piecewise_linear_function.cc.

◆ CreatePiecewiseLinearFunction()

PiecewiseLinearFunction * operations_research::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

This API provides a factory for creating different families of Piecewise Linear Functions based on specific properties of each family. The PiecewiseLinearFunction is composed by a set of PiecwiseSegments and upon creation is not modifiable but with the provided function operations. The object returned by any of these builders in the factory is owned by the client code. Builds the most generic form of multiple-segment piecewise linear function supporting domain holes. For a fixed index i the elements in points_x[i] points_y[i], slopes[i], other_points_x[i] represent a segment. The point (points_x[i], points_y[i]) represents one of the endpoints of the segment and the other_points_x[i] represents the x coordinate of the other endpoint which may precede, follow or coincide with points_x[i]. The segments represented by these vectors should not be overlapping. Common endpoints are allowed.

Definition at line 295 of file piecewise_linear_function.cc.

◆ CreateRightRayFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateRightRayFunction ( int64_t point_x,
int64_t point_y,
int64_t slope )
static

Builds a function consisting of one ray starting at the specified x and y coordinates with the specified slope.

Definition at line 361 of file piecewise_linear_function.cc.

◆ CreateStepFunction()

PiecewiseLinearFunction * operations_research::PiecewiseLinearFunction::CreateStepFunction ( std::vector< int64_t > points_x,
std::vector< int64_t > points_y,
std::vector< int64_t > other_points_x )
static

Builds a multiple-segment step function with continuous or non continuous domain. The arguments have the same semantics with the generic builder of the piecewise linear function. In the step function all the slopes are 0.

Definition at line 312 of file piecewise_linear_function.cc.

◆ DebugString()

std::string operations_research::PiecewiseLinearFunction::DebugString ( ) const

Definition at line 679 of file piecewise_linear_function.cc.

◆ DecomposeToConvexFunctions()

std::vector< PiecewiseLinearFunction * > operations_research::PiecewiseLinearFunction::DecomposeToConvexFunctions ( ) const

Decomposes the piecewise linear function in a set of convex piecewise linear functions. The objects in the vector are owned by the client code.

The segment belongs to the convex sub-function formulated up to now.

Definition at line 646 of file piecewise_linear_function.cc.

◆ GetMaximum() [1/2]

int64_t operations_research::PiecewiseLinearFunction::GetMaximum ( ) const

Returns the maximum value of all the segments in the function.

Definition at line 513 of file piecewise_linear_function.cc.

◆ GetMaximum() [2/2]

int64_t operations_research::PiecewiseLinearFunction::GetMaximum ( int64_t range_start,
int64_t range_end ) const

Returns the maximum endpoint value of the segments in the specified range. If the range is disjoint from the segments in the function, it returns kint64max.

Definition at line 445 of file piecewise_linear_function.cc.

◆ GetMinimum() [1/2]

int64_t operations_research::PiecewiseLinearFunction::GetMinimum ( ) const

Returns the minimum value of all the segments in the function.

Definition at line 517 of file piecewise_linear_function.cc.

◆ GetMinimum() [2/2]

int64_t operations_research::PiecewiseLinearFunction::GetMinimum ( int64_t range_start,
int64_t range_end ) const

Returns the minimum endpoint value of the segments in the specified range. If the range is disjoint from the segments in the function, it returns kint64max.

Definition at line 479 of file piecewise_linear_function.cc.

◆ GetSmallestRangeGreaterThanValue()

std::pair< int64_t, int64_t > operations_research::PiecewiseLinearFunction::GetSmallestRangeGreaterThanValue ( int64_t range_start,
int64_t range_end,
int64_t value ) const

Returns the smallest range within a given range containing all values greater than a given value.

Definition at line 522 of file piecewise_linear_function.cc.

◆ GetSmallestRangeInValueRange()

std::pair< int64_t, int64_t > operations_research::PiecewiseLinearFunction::GetSmallestRangeInValueRange ( int64_t range_start,
int64_t range_end,
int64_t value_min,
int64_t value_max ) const

Returns the smallest range within a given range containing all values greater than value_min and less than value_max.

Definition at line 597 of file piecewise_linear_function.cc.

◆ GetSmallestRangeLessThanValue()

std::pair< int64_t, int64_t > operations_research::PiecewiseLinearFunction::GetSmallestRangeLessThanValue ( int64_t range_start,
int64_t range_end,
int64_t value ) const

Returns the smallest range within a given range containing all values less than a given value.

Definition at line 529 of file piecewise_linear_function.cc.

◆ InDomain()

bool operations_research::PiecewiseLinearFunction::InDomain ( int64_t x) const

Returns if x is in the domain of the function.

Definition at line 409 of file piecewise_linear_function.cc.

◆ IsConvex()

bool operations_research::PiecewiseLinearFunction::IsConvex ( ) const

Determines whether the piecewise linear function is convex or non-convex and returns true when the function is convex.

Definition at line 420 of file piecewise_linear_function.cc.

◆ IsNonDecreasing()

bool operations_research::PiecewiseLinearFunction::IsNonDecreasing ( ) const

Returns true if the piecewise linear function is non-decreasing.

Definition at line 425 of file piecewise_linear_function.cc.

◆ IsNonIncreasing()

bool operations_research::PiecewiseLinearFunction::IsNonIncreasing ( ) const

Returns true if the piecewise linear function is non-increasing.

Definition at line 430 of file piecewise_linear_function.cc.

◆ segments()

const std::vector< PiecewiseSegment > & operations_research::PiecewiseLinearFunction::segments ( ) const
inline

Definition at line 233 of file piecewise_linear_function.h.

◆ Subtract()

void operations_research::PiecewiseLinearFunction::Subtract ( const PiecewiseLinearFunction & other)

Subtracts the function to the existing one. The domain of the resulting function is the intersection of the two domains. The overflows and the underflows are sticky.

Definition at line 641 of file piecewise_linear_function.cc.

◆ Value()

int64_t operations_research::PiecewiseLinearFunction::Value ( int64_t x) const

Returns the value of the piecewise linear function for x.

Todo
(user): Allow the user to specify the undefined value and use kint64max as the default.

Definition at line 435 of file piecewise_linear_function.cc.

Member Data Documentation

◆ kNotFound

const int operations_research::PiecewiseLinearFunction::kNotFound = -1
static

Definition at line 98 of file piecewise_linear_function.h.


The documentation for this class was generated from the following files: