Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <lp_utils.h>
Public Member Functions | |
SumWithOneMissing () | |
void | Add (Fractional x) |
void | RemoveOneInfinity () |
Fractional | Sum () const |
Fractional | SumWithout (Fractional x) const |
Fractional | SumWithoutLb (Fractional c) const |
Fractional | SumWithoutUb (Fractional c) const |
Given N Fractional elements, this class maintains their sum and can provide, for each element X, the sum of all elements except X. The subtelty is that it works well with infinities: for example, if there is exactly one infinite element X, then SumWithout(X) will be finite.
Two flavors of this class are provided: SumWithPositiveInfiniteAndOneMissing supports calling Add() with normal numbers and positive infinities (and will DCHECK() that), and SumWithNegativeInfiniteAndOneMissing does the same with negative infinities.
The numerical accuracy suffers however. If X is 1e100 and SumWithout(X) should be 1e-100, then the value actually returned by SumWithout(X) is likely to be wrong.
Definition at line 328 of file lp_utils.h.
|
inline |
Definition at line 330 of file lp_utils.h.
|
inline |
If we overflow, then there is not much we can do. This is needed because KahanSum seems to give nan if we try to add stuff to an infinite sum.
Definition at line 332 of file lp_utils.h.
|
inline |
Definition at line 349 of file lp_utils.h.
|
inline |
Definition at line 354 of file lp_utils.h.
|
inline |
Definition at line 359 of file lp_utils.h.
|
inline |
When the term we substract has a big magnitude, the SumWithout() can be quite imprecise. On can use these version to have more defensive bounds.
Definition at line 371 of file lp_utils.h.
|
inline |
Definition at line 376 of file lp_utils.h.