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

#include <diff.h>

Public Member Functions

 Diff ()=default
void Advance (const std::array< int64_t, kNumElements > &checkpoints)
int64_t checkpoint (const ElementType e) const
const absl::flat_hash_set< int64_t > & deleted_elements (const ElementType e) const
void DeleteElement (const ElementType e, int64_t id)
template<typename AttrType>
const AttrKeyHashSet< AttrKeyFor< AttrType > > & modified_keys (const AttrType a) const
template<typename AttrType>
void SetModified (const AttrType a, const AttrKeyFor< AttrType > attr_key)
 Marks that the attribute a has been modified for attr_key.
template<typename AttrType>
void EraseKeysForAttr (const AttrType a, absl::Span< const AttrKeyFor< AttrType > > keys)

Detailed Description

Stores the modifications to the model since the previous checkpoint (or since creation of the Diff if Advance() has never been called).

Only the following modifications are tracked explicitly:

  • elements before the checkpoint
  • attributes with all elements in the key before the checkpoint as all changes involving an element after the checkpoint are implied to be in the difference.
Note
users of ElementalImpl can only access a const Diff.

When a element is deleted from the model, the creator of the Diff is responsible both for:

  1. Calling Diff::DeleteElement() on the element,
  2. For each Attr with a key element on the element type, calling Diff::EraseKeysForAttr() We cannot do this all at once for the user, as we do not have access to the relevant related keys in steps 3/4 above.

Definition at line 49 of file diff.h.

Constructor & Destructor Documentation

◆ Diff()

operations_research::math_opt::Diff::Diff ( )
default

Member Function Documentation

◆ Advance()

void operations_research::math_opt::Diff::Advance ( const std::array< int64_t, kNumElements > & checkpoints)

Discards all tracked modifications, and in the future, track only modifications where all elements are at most checkpoint.

Generally, checkpoints should be component-wise non-decreasing with each invocation of Advance(), but this is not checked here.

Definition at line 23 of file diff.cc.

◆ checkpoint()

int64_t operations_research::math_opt::Diff::checkpoint ( const ElementType e) const
inline

Elements The current checkpoint for the element type e.

This equals the next element id for the element type e when Advance() was last called (or at creation time if advance was never called).

Definition at line 70 of file diff.h.

◆ deleted_elements()

const absl::flat_hash_set< int64_t > & operations_research::math_opt::Diff::deleted_elements ( const ElementType e) const
inline

The elements of element type e that have been deleted since the last call to Advance() with id less than the checkpoint.

Definition at line 76 of file diff.h.

◆ DeleteElement()

void operations_research::math_opt::Diff::DeleteElement ( const ElementType e,
int64_t id )
inline

Tracks the element id of element type e as deleted if it is less than the checkpoint.

Warning
this does not update any related attributes.

Definition at line 85 of file diff.h.

◆ EraseKeysForAttr()

template<typename AttrType>
void operations_research::math_opt::Diff::EraseKeysForAttr ( const AttrType a,
absl::Span< const AttrKeyFor< AttrType > > keys )
inline

Discard any tracked modifications for attribute a on keys.

Typically invoke when the element with id keys[i] is deleted from the model, and where keys are the keys k for all elements e where the e has a non-default value for a.

Definition at line 117 of file diff.h.

◆ modified_keys()

template<typename AttrType>
const AttrKeyHashSet< AttrKeyFor< AttrType > > & operations_research::math_opt::Diff::modified_keys ( const AttrType a) const
inline

Attributes Returns the keys with all elements below the checkpoint where the Attr2 a was modified since the last call to Advance().

Definition at line 98 of file diff.h.

◆ SetModified()

template<typename AttrType>
void operations_research::math_opt::Diff::SetModified ( const AttrType a,
const AttrKeyFor< AttrType > attr_key )
inline

Marks that the attribute a has been modified for attr_key.

Definition at line 105 of file diff.h.


The documentation for this class was generated from the following files:
  • ortools/math_opt/elemental/diff.h
  • ortools/math_opt/elemental/diff.cc