gtopt::detail namespace

Classes

struct ColKeyInfo
Compact reverse map from ColIndex to state variable identity.
struct GaussRule
Gauss–Legendre nodes / weights on [−1, 1] (Newton on P_m).
template<typename IndexHolder, typename = void>
struct holder_index_value
template<typename IndexHolder>
struct holder_index_value<IndexHolder, std::void_t<typename std::remove_cvref_t<typename std::remove_cvref_t<IndexHolder>::mapped_type>::mapped_type>>
struct IntCacheData
struct label_size
template<typename T, typename Tuple>
struct lp_type_index_impl
template<typename T, typename... Ts>
struct lp_type_index_impl<T, std::tuple<Ts...>>
class string_holder

Typedefs

using ColKeyMap = std::unordered_map<ColIndex, ColKeyInfo>
template<typename IndexHolder>
using holder_index_value_t = typename holder_index_value<IndexHolder>::type

Functions

auto ascii_iequals(std::string_view a, std::string_view b) -> bool noexcept
ASCII case-insensitive equality (no locale, constexpr-friendly).
void balance_additive(std::vector<std::vector<IntegrationTerm>>& rows, std::span<const double> row_target, std::span<const double> col_target)
void balance_scaling(std::vector<std::vector<IntegrationTerm>>& rows, std::span<const double> row_target, std::span<const double> col_target)
auto build_col_key_map(const SimulationLP& sim, SceneIndex si, PhaseIndex pi) -> ColKeyMap
auto build_int_cache() -> IntCacheData noexcept
auto cached_int_view(std::int64_t n) -> std::optional<std::string_view> noexcept
auto cfg_expected_names(std::span<const EnumEntry<int>> entries) -> std::string
Comma-joined non-alias names of entries for warning messages.
auto cfg_strip_inline_comment(std::string_view value) -> std::string_view noexcept
auto cfg_value_is_number(std::string_view value) -> bool noexcept
auto check_convexity(ConvexKind kind, ConstraintType ctype, double coef) -> bool noexcept
auto create_block_array(std::span<const Block> block_array, const Stage& stage) -> auto
auto create_scenario_array(std::span<const Scenario> scenario_array, const Scene& scene, SceneIndex scene_index) -> auto
auto create_stage_array(const Phase& phase, PhaseIndex phase_index, double annual_discount_rate, std::span<const Stage> stage_array, std::span<const Block> all_blocks) -> auto
auto eval_if_atom(const IfCondAtom& atom, uid_t value) -> bool noexcept
auto finest_time_window_in_terms(const std::vector<ConstraintTerm>& terms, std::optional<TimeWindow> best = std::nullopt) -> std::optional<TimeWindow> noexcept
auto gauss_legendre(std::size_t m) -> GaussRule
auto hash_combine(size_t seed, size_t h) -> size_t noexcept
auto is_ascii_digit(char c) -> bool noexcept
auto is_ascii_lower(char c) -> bool noexcept
auto is_ascii_upper(char c) -> bool noexcept
void lagrange_integrals(std::span<const double> xs, double a, double b, std::span<double> out)
template<typename ElementLP>
auto lp_error_context(const ElementLP& element) -> LpBuildErrorInfo
auto prefix_matches(std::string_view prefix, std::string_view class_short, std::string_view constraint) -> bool noexcept
auto round_with_threshold(double v, double threshold, double lb, double ub) -> double noexcept
auto rounded_start_with_rules(const MipStartContext& ctx, std::string_view generator_name) -> std::vector<double>
auto snake_case_size(std::string_view sv) -> std::size_t noexcept
auto snake_needs_underscore_before(std::string_view sv, std::size_t i) -> bool noexcept
auto to_lower_char(char c) -> char noexcept
template<string_like T>
auto to_string_view(T&& sv) -> std::string_view noexcept
template<typename Tuple, size_t... Is>
auto tuple_hash_impl(const Tuple& t, std::index_sequence<Is...>) -> size_t noexcept
template<typename T, typename... Ts>
auto type_index_in() -> std::size_t noexcept
template<typename SourceArrayType>
auto widen_to_double_array(const arrow::Array& chunk) -> std::shared_ptr<arrow::DoubleArray>
template<typename SourceArrayType>
auto widen_to_int32_array(const arrow::Array& chunk) -> std::shared_ptr<arrow::Int32Array>
Cast an Arrow array chunk to Int32Array, handling int8/int16/int64 conversion.
void write_cut_coefficients(std::ostream& ofs, const StoredCut& cut, const LinearInterface&, const ColKeyMap& col_keys)
void write_cut_coefficients_unscaled(std::ostream& ofs, const StoredCut& cut, double)

Variables

double builtin_max_process_swap_mb
double builtin_swap_growth_mb
auto cfg_bool_entries
Generic boolean spellings accepted for any key without an enum table.
std::atomic<double> g_default_max_process_swap_mb
std::atomic<double> g_default_swap_growth_mb
std::size_t int_buf_size
IntCacheData int_cache
std::size_t int_cache_buf_len
std::size_t int_cache_size
template<typename T, typename = void>
bool is_nested_block_map_v
template<typename T>
bool is_nested_block_map_v< T, std::void_t< typename std::remove_cvref_t< T >::mapped_type, decltype(std::declval< std::remove_cvref_t< T > >().begin())> >

Typedef documentation

using gtopt::detail::ColKeyMap = std::unordered_map<ColIndex, ColKeyInfo>

template<typename IndexHolder>
using gtopt::detail::holder_index_value_t = typename holder_index_value<IndexHolder>::type

Function documentation

bool gtopt::detail::ascii_iequals(std::string_view a, std::string_view b) noexcept

ASCII case-insensitive equality (no locale, constexpr-friendly).

Folds [A-Z] to [a-z] on the fly and compares byte-for-byte. Non-ASCII bytes are compared literally, which is fine because every entry in the project's enum tables is lowercase ASCII.

void gtopt::detail::balance_additive(std::vector<std::vector<IntegrationTerm>>& rows, std::span<const double> row_target, std::span<const double> col_target)

Balanced minimum-norm additive correction (signed rules): the smallest change δ on the sparsity pattern (min ‖δ‖₂) giving row sums = interval lengths and column sums = block weights. The minimiser is δ_kj = α_k + β_j, with (α, β) solving the (singular, consistent) normal equations by conjugate gradients.

void gtopt::detail::balance_scaling(std::vector<std::vector<IntegrationTerm>>& rows, std::span<const double> row_target, std::span<const double> col_target)

Balanced nonnegative correction (_pos rules): alternating row / column scaling (RAS / Sinkhorn) of the clipped weights towards the row targets (interval lengths) and the column targets (block weights). Keeps every weight ≥ 0 and the sparsity pattern; the last sweep is a column scaling, so column sums are exact.

ColKeyMap gtopt::detail::build_col_key_map(const SimulationLP& sim, SceneIndex si, PhaseIndex pi)

Build a ColIndex → (class_name, col_name, uid) reverse map from the state variables registered for a given (scene, phase).

IntCacheData gtopt::detail::build_int_cache() noexcept

std::optional<std::string_view> gtopt::detail::cached_int_view(std::int64_t n) noexcept

std::string gtopt::detail::cfg_expected_names(std::span<const EnumEntry<int>> entries)

Comma-joined non-alias names of entries for warning messages.

std::string_view gtopt::detail::cfg_strip_inline_comment(std::string_view value) noexcept

Strip an inline trailing comment (value # note / ; note / // note) plus surrounding whitespace. Only a WHITESPACE-preceded marker starts a comment, so values themselves can never be split (all solver parameter values are single tokens).

bool gtopt::detail::cfg_value_is_number(std::string_view value) noexcept

True when value is fully consumed as a (possibly signed / fractional / exponent) number — such values pass through untranslated.

bool gtopt::detail::check_convexity(ConvexKind kind, ConstraintType ctype, double coef) noexcept

Pure convexity check for a single nonlinear wrapper term.

Returns true iff coef · f(x) can be safely lowered under the given ctype without flipping the feasible set (i.e. the resulting LP is a valid outer approximation, not an inner one). See ConvexKind for the per-shape rules.

Pure / noexcept / constexpr so it is trivially unit-testable without instantiating a LinearProblem.

auto gtopt::detail::create_block_array(std::span<const Block> block_array, const Stage& stage)

auto gtopt::detail::create_scenario_array(std::span<const Scenario> scenario_array, const Scene& scene, SceneIndex scene_index)

auto gtopt::detail::create_stage_array(const Phase& phase, PhaseIndex phase_index, double annual_discount_rate, std::span<const Stage> stage_array, std::span<const Block> all_blocks)

bool gtopt::detail::eval_if_atom(const IfCondAtom& atom, uid_t value) noexcept

Pure evaluator for a single IfCondAtom against a coordinate value.

The caller is responsible for extracting the integer value of the coord that atom.coord names (scenario/stage/block uid) and passing it here. This split keeps the evaluator free of any LP context, making it trivial to unit-test and constexpr/noexcept.

std::optional<TimeWindow> gtopt::detail::finest_time_window_in_terms(const std::vector<ConstraintTerm>& terms, std::optional<TimeWindow> best = std::nullopt) noexcept

GaussRule gtopt::detail::gauss_legendre(std::size_t m)

size_t gtopt::detail::hash_combine(size_t seed, size_t h) noexcept

bool gtopt::detail::is_ascii_digit(char c) noexcept

bool gtopt::detail::is_ascii_lower(char c) noexcept

bool gtopt::detail::is_ascii_upper(char c) noexcept

void gtopt::detail::lagrange_integrals(std::span<const double> xs, double a, double b, std::span<double> out)

∫_a^b of the Lagrange basis polynomials on xs (exact: Gauss rule with ⌈|xs|/2⌉ + 1 points). Writes one weight per node.

template<typename ElementLP>
LpBuildErrorInfo gtopt::detail::lp_error_context(const ElementLP& element)

bool gtopt::detail::prefix_matches(std::string_view prefix, std::string_view class_short, std::string_view constraint) noexcept

Compile-time check: returns true iff prefix matches the runtime row label produced by LabelMaker::make_row_label, which emits <lowercase(class_name)>_<constraint_name>_…. Used in the static_asserts below to pin every sddp_*_row_prefix to its (class_short, constraint_name) pair so a rename of either constant fails the build instead of silently de-syncing the prefixes from the emitted cut-row labels.

double gtopt::detail::round_with_threshold(double v, double threshold, double lb, double ub) noexcept

Round v to the nearest integer biased by threshold (a relaxed binary at v rounds up iff v >= threshold), then clamp to [lb, ub]. The generic, domain-agnostic rounding step (stage 1) — any solver does this.

Round a relaxed value to its nearest feasible integer, biased by threshold: a relaxed binary at v rounds up iff v >= threshold (floor(v + 1 - threshold)), then clamp to [lb, ub].

std::vector<double> gtopt::detail::rounded_start_with_rules(const MipStartContext& ctx, std::string_view generator_name)

Stage 1 + 2 of the MIP-start pipeline: round the relaxation's integer columns (round_with_threshold) and apply the default domain commitment- repair pipeline (make_default_domain_rules, built per-call from ctx.opts.domain_rules) to the result. Continuous columns are kept at their relaxation value. Returns the dense raw candidate start (empty iff the relaxation has no primal). Used by the default round+rules generator.

std::size_t gtopt::detail::snake_case_size(std::string_view sv) noexcept

bool gtopt::detail::snake_needs_underscore_before(std::string_view sv, std::size_t i) noexcept

char gtopt::detail::to_lower_char(char c) noexcept

template<string_like T>
std::string_view gtopt::detail::to_string_view(T&& sv) noexcept

template<typename Tuple, size_t... Is>
size_t gtopt::detail::tuple_hash_impl(const Tuple& t, std::index_sequence<Is...>) noexcept

template<typename T, typename... Ts>
std::size_t gtopt::detail::type_index_in() noexcept

Returns the 0-based position of T in the pack Ts..., or sizeof...(Ts) if not found. Implemented as a consteval function (C++20) with a local bool array to avoid recursive template instantiation depth.

template<typename SourceArrayType>
std::shared_ptr<arrow::DoubleArray> gtopt::detail::widen_to_double_array(const arrow::Array& chunk)

template<typename SourceArrayType>
std::shared_ptr<arrow::Int32Array> gtopt::detail::widen_to_int32_array(const arrow::Array& chunk)

Cast an Arrow array chunk to Int32Array, handling int8/int16/int64 conversion.

Parameters
chunk The Arrow array chunk to cast
Returns A shared pointer to an Int32Array, or nullptr if the type is incompatible

void gtopt::detail::write_cut_coefficients(std::ostream& ofs, const StoredCut& cut, const LinearInterface&, const ColKeyMap& col_keys)

Write a single cut's coefficients to an output stream.

Format: class:var:uid=coeff (structured key, portable without LP names). Every column referenced in a cut must be a registered state variable — including alpha, which is registered by SDDPMethod::initialize_alpha_variables.

StoredCut already holds physical-space values: post-migration cuts are built by build_benders_cut_physical, which emits physical coefficients and a physical RHS; the SparseRow is captured in SDDPCutManager::store_cut before add_row applies per-row equilibration, so cut.coefficients is what we need to serialise verbatim. No * scale_obj / col_scale conversion is applied here — the file value IS the physical value.

void gtopt::detail::write_cut_coefficients_unscaled(std::ostream& ofs, const StoredCut& cut, double)

Write cut coefficients without variable scaling (fallback when phase UID is not found). Values are physical.

Variable documentation

double gtopt::detail::builtin_max_process_swap_mb

double gtopt::detail::builtin_swap_growth_mb

auto gtopt::detail::cfg_bool_entries

Generic boolean spellings accepted for any key without an enum table.

std::atomic<double> gtopt::detail::g_default_max_process_swap_mb

std::atomic<double> gtopt::detail::g_default_swap_growth_mb

std::size_t gtopt::detail::int_buf_size

IntCacheData gtopt::detail::int_cache

std::size_t gtopt::detail::int_cache_buf_len

std::size_t gtopt::detail::int_cache_size

template<typename T, typename = void>
bool gtopt::detail::is_nested_block_map_v

True when T is a per-block inner map (the mapped_type of an STB-style holder's outer map): it exposes mapped_type and is not itself the scalar index value. Used by OutputContext::first_index_of to decide whether the outer map's value is a nested block map (STB) or the index value directly (ST / T / GSTB).