PenaltyFunction

abstract class PenaltyFunction(val constraint: PenalizableConstraint?)(source)

A penalty function applied to a constraint's violation; the penalty is added to the problem's objective function.

Following Option B, a penalty is bound to the constraint it serves (see constraint). A problem-level default is an unbound template (constraint = null) that ProblemDefinition resolves into a per-constraint bound instance via boundTo before it is used to compute a value.

Inheritors

Constructors

Link copied to clipboard
constructor(constraint: PenalizableConstraint?)

Properties

Link copied to clipboard

The constraint this penalty serves, or null for an unbound template. Bound instances that are actually used to compute a penalty always have a non-null value.

Link copied to clipboard

True when this penalty accumulates memory across visits, so the evaluator folds each visit's new observations into it. Memoryless penalties leave this false and carry no memory.

Functions

Link copied to clipboard

Returns a copy of this penalty bound to the supplied constraint. Used to resolve a default template into a per-constraint instance.

Link copied to clipboard
open fun foldVisit(newObservations: EstimatedResponse, prior: PenaltyMemory?, iteration: Int): PenaltyMemory?

Folds a visit's new observations for this penalty's constraint into the prior memory, returning the snapshot to carry on the resulting solution. Memoryless penalties keep the default (null).

Link copied to clipboard
abstract fun penalty(solution: Solution): Double

The penalty contribution for this penalty's constraint at the supplied solution. Must be a pure function of the solution (and this penalty's own state) so that the penalized objective is a stable, Solver-free property of an immutable solution. Called only on bound instances.