GreedyFlowSolver
extends AbstractPathSolver
in package
implements
ExecutionSolverInterface
Executes movement flows directly with greedy semantics.
Shares its edge resolution, policy application and quantity limiting with the planning solvers through AbstractPathSolver. That is not merely to avoid repetition: a plan is only worth anything if it predicts what execution will do, so the two must resolve edges, apply policies and cap quantities by the same code, not by two copies that can drift apart.
Tags
Table of Contents
Interfaces
- ExecutionSolverInterface
- Executes one flow against one quantity state.
Properties
- $trace : bool
Methods
- __construct() : mixed
- execute() : MovementResult
- Execute one resolved flow against one quantity state.
- applyMove() : MovementEvent
- Apply one movement to the working state and record it as an event.
- edgeKeys() : array<int, string>
- edgeTrace() : array<string|int, mixed>
- One candidate edge's outcome.
- paramsFromContext() : array<string, string>
- Extract the string-valued execute parameters from an application context.
- stepTrace() : array<string|int, mixed>
- One flow step's decision record.
Properties
$trace read-only
private
bool
$trace
= false
Methods
__construct()
public
__construct([bool $trace = false ]) : mixed
Parameters
- $trace : bool = false
-
collect a per-step decision record on the result; see MovementResult::trace(). Off by default, because it costs memory per step and most executions never look at one
execute()
Execute one resolved flow against one quantity state.
public
execute(QuantityState $state, SlotSpace $space, Flow $flow, int|float $quantity[, mixed $subject = null ][, array<string|int, mixed> $appContext = [] ][, array<string, scalar|null> $params = [] ]) : MovementResult
Parameters
- $state : QuantityState
- $space : SlotSpace
- $flow : Flow
- $quantity : int|float
- $subject : mixed = null
- $appContext : array<string|int, mixed> = []
- $params : array<string, scalar|null> = []
Attributes
- #[Override]
Return values
MovementResultapplyMove()
Apply one movement to the working state and record it as an event.
private
applyMove(QuantityState $state, MovementEdge $edge, int|float $quantity) : MovementEvent
Distinct from AbstractPathSolver::applyMovement(), which returns a fresh state for path exploration: execution advances one working state and reports what happened.
Parameters
- $state : QuantityState
- $edge : MovementEdge
- $quantity : int|float
Return values
MovementEventedgeKeys()
private
static edgeKeys(array<int, MovementEdge> $edges) : array<int, string>
Parameters
- $edges : array<int, MovementEdge>
Return values
array<int, string>edgeTrace()
One candidate edge's outcome.
private
static edgeTrace(MovementEdge $edge, int|float $available, int|float $movable, int|float $moved[, int|float|null $allocated = null ]) : array<string|int, mixed>
The three quantities are what make a trace diagnostic rather than decorative: available is
what the source held, movable what survived the step's quantity constraints, and moved
what the outstanding request actually took. Each drop to zero has a different cause.
Parameters
- $edge : MovementEdge
- $available : int|float
- $movable : int|float
- $moved : int|float
- $allocated : int|float|null = null
Tags
Return values
array<string|int, mixed>paramsFromContext()
Extract the string-valued execute parameters from an application context.
private
paramsFromContext(array<string|int, mixed> $context) : array<string, string>
Parameters
- $context : array<string|int, mixed>
Return values
array<string, string>stepTrace()
One flow step's decision record.
private
static stepTrace(int $index, FlowStep $step, array<int, string> $candidates, array<int, string> $afterFilters, array<int, string> $afterOrdering, array<int, TTraceEdge> $edgeTrace, int|float $remainingBefore, int|float $remainingAfter, bool $allocated) : array<string|int, mixed>
Parameters
- $index : int
- $step : FlowStep
- $candidates : array<int, string>
- $afterFilters : array<int, string>
- $afterOrdering : array<int, string>
- $edgeTrace : array<int, TTraceEdge>
- $remainingBefore : int|float
- $remainingAfter : int|float
- $allocated : bool