Classes | Public Types | Public Member Functions | List of all members
operations_research::DynamicPartition Class Reference

Partition class that supports incremental splitting, with backtracking. More...

#include <dynamic_partition.h>

Classes

struct  IterablePart
 

Public Types

enum  DebugStringSorting { SORT_LEXICOGRAPHICALLY, SORT_BY_PART }
 Dump the partition to a std::string. More...
 

Public Member Functions

 DynamicPartition (int num_elements)
 Creates a DynamicPartition on n elements, numbered 0..n-1. More...
 
 DynamicPartition (const std::vector< int > &initial_part_of_element)
 Ditto, but specify the initial part of each elements. More...
 
int NumElements () const
 Accessors. More...
 
const int NumParts () const
 
IterablePart ElementsInPart (int i) const
 *** Implementation of inline methods of the above classes. *** More...
 
int PartOf (int element) const
 
int SizeOfPart (int part) const
 
int ParentOfPart (int part) const
 
IterablePart ElementsInSamePartAs (int i) const
 A handy shortcut to ElementsInPart(PartOf(e)). More...
 
uint64 FprintOfPart (int part) const
 Returns a fingerprint of the given part. More...
 
void Refine (const std::vector< int > &distinguished_subset)
 Refines the partition such that elements that are in distinguished_subset never share the same part as elements that aren't in that subset. More...
 
void UndoRefineUntilNumPartsEqual (int original_num_parts)
 Undo one or several Refine() operations, until the number of parts becomes equal to "original_num_parts". More...
 
std::string DebugString (DebugStringSorting sorting) const
 
const std::vector< int > & ElementsInHierarchicalOrder () const
 ADVANCED USAGE: All elements (0..n-1) of the partition, sorted in a way that's compatible with the hierarchical partitioning: More...
 

Detailed Description

Partition class that supports incremental splitting, with backtracking.

See http://en.wikipedia.org/wiki/Partition_refinement . More precisely, the supported edit operations are:

Definition at line 49 of file dynamic_partition.h.

Member Enumeration Documentation

◆ DebugStringSorting

Dump the partition to a std::string.

There might be different conventions for sorting the parts and the elements inside them.

Enumerator
SORT_LEXICOGRAPHICALLY 

Elements are sorted within parts, and parts are then sorted lexicographically.

SORT_BY_PART 

Elements are sorted within parts, and parts are kept in order.

Definition at line 117 of file dynamic_partition.h.

Constructor & Destructor Documentation

◆ DynamicPartition() [1/2]

operations_research::DynamicPartition::DynamicPartition ( int  num_elements)
explicit

Creates a DynamicPartition on n elements, numbered 0..n-1.

Start with the trivial partition (only one subset containing all elements).

◆ DynamicPartition() [2/2]

operations_research::DynamicPartition::DynamicPartition ( const std::vector< int > &  initial_part_of_element)
explicit

Ditto, but specify the initial part of each elements.

Part indices must form a dense integer set starting at 0; eg. [2, 1, 0, 1, 1, 3, 0] is valid.

Member Function Documentation

◆ DebugString()

std::string operations_research::DynamicPartition::DebugString ( DebugStringSorting  sorting) const

◆ ElementsInHierarchicalOrder()

const std::vector<int>& operations_research::DynamicPartition::ElementsInHierarchicalOrder ( ) const
inline

ADVANCED USAGE: All elements (0..n-1) of the partition, sorted in a way that's compatible with the hierarchical partitioning:

  • All the elements of any given part are contiguous.
  • Elements of a part P are always after elements of part Parent(P).
  • The order remains identical (and the above property holds) after any UndoRefine*() operation.
    Note
    the order does get changed by Refine() operations. This is a reference, so it'll only remain valid and constant until the class is destroyed or until Refine() get called.

Definition at line 136 of file dynamic_partition.h.

◆ ElementsInPart()

DynamicPartition::IterablePart operations_research::DynamicPartition::ElementsInPart ( int  i) const
inline

*** Implementation of inline methods of the above classes. ***

Definition at line 276 of file dynamic_partition.h.

◆ ElementsInSamePartAs()

DynamicPartition::IterablePart operations_research::DynamicPartition::ElementsInSamePartAs ( int  i) const
inline

A handy shortcut to ElementsInPart(PartOf(e)).

The returned IterablePart will never be empty, since it contains at least i.

Definition at line 303 of file dynamic_partition.h.

◆ FprintOfPart()

uint64 operations_research::DynamicPartition::FprintOfPart ( int  part) const
inline

Returns a fingerprint of the given part.

While collisions are possible, their probability is quite low. Two parts that have the same size and the same fingerprint are most likely identical. Also, two parts that have the exact same set of elements will always have the same fingerprint.

Definition at line 308 of file dynamic_partition.h.

◆ NumElements()

int operations_research::DynamicPartition::NumElements ( ) const
inline

Accessors.

Definition at line 60 of file dynamic_partition.h.

◆ NumParts()

const int operations_research::DynamicPartition::NumParts ( ) const
inline

Definition at line 61 of file dynamic_partition.h.

◆ ParentOfPart()

int operations_research::DynamicPartition::ParentOfPart ( int  part) const
inline

Definition at line 297 of file dynamic_partition.h.

◆ PartOf()

int operations_research::DynamicPartition::PartOf ( int  element) const
inline

Definition at line 284 of file dynamic_partition.h.

◆ Refine()

void operations_research::DynamicPartition::Refine ( const std::vector< int > &  distinguished_subset)

Refines the partition such that elements that are in distinguished_subset never share the same part as elements that aren't in that subset.

This might be a no-op: in that case, NumParts() won't change, but the order of elements inside each part may change.

ORDERING OF PARTS: For each i such that Part #i has a non-trivial intersection with "distinguished_subset" (neither empty, nor the full Part); Part #i is stripped out of all elements that are in "distinguished_subset", and those elements are sent to a newly created part, whose parent_part = i. The parts newly created by a single Refine() operations are sorted by parent_part. Example: a Refine() on a partition with 6 parts causes parts #1, #3 and #4 to be split: the partition will now contain 3 new parts: part #6 (with parent_part = 1), part #7 (with parent_part = 3) and part #8 (with parent_part = 4).

Todo:
(user): the graph symmetry finder could probably benefit a lot from keeping track of one additional bit of information for each part that remains unchanged by a Refine() operation: was that part entirely in the distinguished subset or entirely out?

◆ SizeOfPart()

int operations_research::DynamicPartition::SizeOfPart ( int  part) const
inline

Definition at line 290 of file dynamic_partition.h.

◆ UndoRefineUntilNumPartsEqual()

void operations_research::DynamicPartition::UndoRefineUntilNumPartsEqual ( int  original_num_parts)

Undo one or several Refine() operations, until the number of parts becomes equal to "original_num_parts".

Prerequisite: NumParts() >= original_num_parts.


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