Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <inclusion.h>
Public Member Functions | |
InclusionDetector (const Storage &storage) | |
void | Reset () |
Resets the class to an empty state. | |
void | AddPotentialSubset (int index) |
void | AddPotentialSuperset (int index) |
void | AddPotentialSet (int index) |
void | SetWorkLimit (uint64_t work_limit) |
void | DetectInclusions (const std::function< void(int subset, int superset)> &process) |
std::vector< bool > | IsInSuperset () const |
void | StopProcessingCurrentSubset () |
void | StopProcessingCurrentSuperset () |
void | Stop () |
void | IncreaseWorkDone (uint64_t increase) |
int | num_potential_subsets () const |
Stats. | |
int | num_potential_supersets () const |
uint64_t | work_done () const |
An helper class to process many sets of integer in [0, n] and detects all the set included in each others. This is a common operations in presolve, and while it can be slow the algorithm used here is pretty efficient in practice.
The algorithm is based on the SAT preprocessing algorithm to detect clauses that subsumes others. It uses a one-watcher scheme where each subset candidate has only one element watched. To identify all potential subset of a superset, one need to inspect the watch list for all element of the superset candidate.
The number n will be detected automatically but we allocate various vector of size n, so avoid having large integer values in your sets.
All set contents will be accessed via storage_[index]. This can be used with a vector<vector<>> or our CompactVectorVector that we use in a few place. But it can also be anything that support:
Definition at line 54 of file inclusion.h.
|
inlineexplicit |
Definition at line 56 of file inclusion.h.
|
inline |
Definition at line 170 of file inclusion.h.
|
inline |
Adds a candidate set to consider for the next DetectInclusions() call. The argument is an index that will only be used via storage_[index] to get the content of the candidate set.
Definition at line 182 of file inclusion.h.
|
inline |
Definition at line 193 of file inclusion.h.
|
inline |
Finds all subset included in a superset and call "process" on each of the detected inclusion. The std::function argument corresponds to indices passed to the Add*() calls.
The order of detection will be by increasing superset size. For superset with the same size, the order will be deterministic but not specified. And similarly, for a given superset, the order of the included subsets is deterministic but not specified.
No need to do any work in these cases.
Temp data must be ready to use.
Main algo.
Compute the signature and also resize vector if needed. We want a signature that is order invariant and is compatible with inclusion.
Bitset should be cleared.
Find any subset included in current superset.
We make a copy because process() might alter the content of the storage when it returns "stop_with_current_superset_" and we need to clean is_in_superset_ properly.
Quick check with signature.
Long check with bitset.
Remove from the watcher list.
Cleanup.
Add new subset candidate to the watchers.
Tricky: If this was also a superset and has been removed, we don't want to watch it!
Choose to watch the one with smallest list.
Stop also performs some cleanup.
Definition at line 206 of file inclusion.h.
|
inline |
The algorithm here can detect many small set included in a big set while only scanning the superset once. So if we do scan the superset in the process function, we can do a lot more work. This is here to reuse the deterministic limit mechanism.
Definition at line 120 of file inclusion.h.
|
inline |
Function that should only be used from within "process()". Returns the bitset corresponsing to the elements of the current superset passed to the process() function.
Definition at line 102 of file inclusion.h.
|
inline |
Stats.
Definition at line 123 of file inclusion.h.
|
inline |
Definition at line 124 of file inclusion.h.
|
inline |
Resets the class to an empty state.
Definition at line 59 of file inclusion.h.
|
inline |
By default we will detect all inclusions. It is possible to make sure we don't do more than O(work_limit) operations and eventually abort early by setting this. Note that we don't reset it on Reset().
This is needed, because for m candidates of size n, we can have O(m ^ 2) inclusions, each requiring O(n) work to check.
Definition at line 81 of file inclusion.h.
|
inline |
Definition at line 109 of file inclusion.h.
|
inline |
Function that should only be used from within "process()". Stop will abort the current search. The other two will cause the corresponding candidate set to never appear in any future inclusion.
Definition at line 107 of file inclusion.h.
|
inline |
Definition at line 108 of file inclusion.h.
|
inline |
Definition at line 125 of file inclusion.h.