ConstraintDirective struct
#include <gtopt/constraint_directive.hpp>
Typed metadata payload for a UserConstraint directive.
Only the fields that kind admits are expected to be populated; the rest must stay std::nullopt. valid_for_kind() is the canonical invariant used by the JSON loader (to reject bad inputs at parse time) and by the LP-build dispatch (defensive check).
The struct is intentionally tiny — three optionals + an enum — so it can live by-value on UserConstraint without growing the per-element memory footprint meaningfully.
Public functions
- auto effective_penalty(OptReal scalar_penalty) const -> OptReal noexcept
- auto implies_daily_sum() const -> bool noexcept
- auto valid_for_kind() const -> bool noexcept
Public variables
Friends
- auto operator==(const ConstraintDirective&, const ConstraintDirective&) -> bool defaulted
Function documentation
OptReal gtopt:: ConstraintDirective:: effective_penalty(OptReal scalar_penalty) const noexcept
Effective soft-penalty cost for the LP-build layer. Directive override wins; falls back to the constraint-level scalar so legacy JSON that sets penalty directly keeps working unchanged.
bool gtopt:: ConstraintDirective:: implies_daily_sum() const noexcept
True when the directive implies a per-day aggregator. Caller uses this to override UserConstraint::daily_sum = true at LP-build time without mutating the underlying UserConstraint.
DailyBudget always; MaxStartsWindow only when the window happens to be 24h (the daily-aggregator-aliased case). Wider windows fall through to Step P2's generic window(N h, expr) primitive.
bool gtopt:: ConstraintDirective:: valid_for_kind() const noexcept
True when the populated fields are consistent with kind.
Enforced at JSON-load time (json_user_constraint.hpp) and as a defensive precondition inside UserConstraintLP.
Variable documentation
OptReal gtopt:: ConstraintDirective:: penalty
Soft-penalty override [$ / unit-of-violation]. When set, wins over UserConstraint::penalty at LP-build time so directive policy is the single source of truth for the soft tier. Populated for RegRange / ReserveProvSum (and any directive that wants a kind-specific cost). Forbidden for HydroFloor / MaxStartsWindow.
OptInt gtopt:: ConstraintDirective:: window_hours
Rolling window length in HOURS. Required and > 0 for MaxStartsWindow; forbidden elsewhere. 24 is the canonical daily window; 168 the canonical weekly window.