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

#include <constraint_violation.h>

Inheritance diagram for operations_research::sat::CompiledReservoirConstraint:
operations_research::sat::CompiledConstraint

Public Member Functions

 CompiledReservoirConstraint (LinearExpressionProto capacity, std::vector< std::optional< int > > is_active, std::vector< LinearExpressionProto > times, std::vector< LinearExpressionProto > demands)
 
int64_t ComputeViolation (absl::Span< const int64_t > solution) final
 
void PerformMove (int, int64_t, absl::Span< const int64_t > solution_with_new_value) final
 Updates the violation with the new value.
 
int64_t ViolationDelta (int var, int64_t, absl::Span< const int64_t > solution_with_new_value) final
 Returns the delta if var changes from old_value to solution[var].
 
std::vector< int > UsedVariables (const CpModelProto &model_proto) const final
 
- Public Member Functions inherited from operations_research::sat::CompiledConstraint
 CompiledConstraint ()=default
 
virtual ~CompiledConstraint ()=default
 
void InitializeViolation (absl::Span< const int64_t > solution)
 Recomputes the violation of the constraint from scratch.
 
int64_t violation () const
 The cached violation of this constraint.
 

Additional Inherited Members

- Protected Member Functions inherited from operations_research::sat::CompiledConstraint
- Protected Attributes inherited from operations_research::sat::CompiledConstraint
int64_t violation_
 

Detailed Description

This can be used to encode reservoir or a cumulative constraints for LS. We have a set of event time, and we use for overal violation the sum of overload over time.

This version support an incremental computation when just a few events changes, which is roughly O(n) instead of O(n log n) which makes it significantly faster than recomputing and sorting the profile on each ViolationDelta().

Definition at line 591 of file constraint_violation.h.

Constructor & Destructor Documentation

◆ CompiledReservoirConstraint()

operations_research::sat::CompiledReservoirConstraint::CompiledReservoirConstraint ( LinearExpressionProto capacity,
std::vector< std::optional< int > > is_active,
std::vector< LinearExpressionProto > times,
std::vector< LinearExpressionProto > demands )
inline

Definition at line 593 of file constraint_violation.h.

Member Function Documentation

◆ ComputeViolation()

int64_t operations_research::sat::CompiledReservoirConstraint::ComputeViolation ( absl::Span< const int64_t > solution)
inlinefinalvirtual
Note
since we have our own ViolationDelta() implementation this is only used for initialization and our PerformMove(). It is why we set violations_ here.

Implements operations_research::sat::CompiledConstraint.

Definition at line 610 of file constraint_violation.h.

◆ PerformMove()

void operations_research::sat::CompiledReservoirConstraint::PerformMove ( int var,
int64_t old_value,
absl::Span< const int64_t > solution_with_new_value )
inlinefinalvirtual

Updates the violation with the new value.

Todo
(user): we could probably be more incremental here, but it is a bit tricky to get right and not too important since the time is dominated by evaluating moves, not taking them.

Reimplemented from operations_research::sat::CompiledConstraint.

Definition at line 615 of file constraint_violation.h.

◆ UsedVariables()

std::vector< int > operations_research::sat::CompiledReservoirConstraint::UsedVariables ( const CpModelProto & model_proto) const
finalvirtual

Returns the sorted vector of variables used by this constraint. This is used to known when a violation might change, and is only called once during initialization, so speed is not to much of a concern here.

The global proto is needed to resolve interval variables reference.

Implements operations_research::sat::CompiledConstraint.

Definition at line 2240 of file constraint_violation.cc.

◆ ViolationDelta()

int64_t operations_research::sat::CompiledReservoirConstraint::ViolationDelta ( int var,
int64_t old_value,
absl::Span< const int64_t > solution_with_new_value )
inlinefinalvirtual

Returns the delta if var changes from old_value to solution[var].

Reimplemented from operations_research::sat::CompiledConstraint.

Definition at line 623 of file constraint_violation.h.


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