import { d as SDCPN } from "./sdcpn-CayOVwJM.js";
import { d as SimulationFrameReader, i as InitialMarking } from "./internal-frame-DSPOSuKI.js";

//#region src/simulation/engine/types.d.ts
/**
 * Runtime parameter values used during simulation execution.
 * Maps parameter names to their resolved numeric or boolean values.
 */
type ParameterValues = Record<string, number | boolean>;
//#endregion
//#region src/simulation/engine/compute-next-frame.d.ts
/**
 * Reason why the simulation completed.
 */
type SimulationCompletionReason = "maxTime" | "deadlock";
//#endregion
//#region src/simulation/monte-carlo/metrics/types.d.ts
type MonteCarloMetricRunStatus = "ready" | "running" | "complete" | "error";
type MonteCarloActiveRunPlaceCountsVisitor = (runIndex: number,
/**
 * Dense place-count view indexed by `placeIds`.
 *
 * Metric implementations must treat this as read-only.
 */

placeCounts: Uint32Array) => void;
type MonteCarloRunFrameMetricView = {
  runIndex: number;
  status: MonteCarloMetricRunStatus;
  frame: SimulationFrameReader;
};
type MonteCarloRunFrameMetricVisitor = (run: MonteCarloRunFrameMetricView) => void;
type MonteCarloFrameMetricContext = {
  frameNumber: number;
  time: number;
  runCount: number;
  activeRunCount: number;
  completedRunCount: number;
  erroredRunCount: number;
  placeIds: readonly string[];
  placeNames: readonly string[];
  forEachActiveRunPlaceCounts: (visitor: MonteCarloActiveRunPlaceCountsVisitor) => void;
  /**
   * Visits every run's current frame as a reader.
   *
   * User-defined metrics can use this to compute arbitrary scalar samples from
   * place token values, transition state, and frame metadata. The reader is only
   * valid during the `observeFrame` call.
   */
  forEachRunFrame: (visitor: MonteCarloRunFrameMetricVisitor) => void;
};
type MonteCarloFrameMetric = {
  observeFrame: (context: MonteCarloFrameMetricContext) => void;
};
type MonteCarloUserDefinedMetricAggregation = "mean" | "sum" | "min" | "max" | "last";
type MonteCarloUserDefinedMetricTimeAggregation = MonteCarloUserDefinedMetricAggregation | "none";
type MonteCarloUserDefinedMetricSampleRuns = "active" | "completed" | "all";
type MonteCarloMetricDistributionBinning = "exact" | {
  width: number;
};
type MonteCarloMetricRunOutput = {
  type: "scalar";
  aggregateRuns?: MonteCarloUserDefinedMetricAggregation;
} | {
  type: "distribution";
  binning?: MonteCarloMetricDistributionBinning;
};
type MonteCarloUserDefinedMetricMeasureInput = {
  runIndex: number;
  status: MonteCarloMetricRunStatus;
  frame: SimulationFrameReader;
};
type MonteCarloUserDefinedMetricConfig = {
  id: string;
  label?: string;
  /**
   * Computes one numeric sample for one run at the current frame.
   *
   * Return `null`, `undefined`, or `NaN` to skip that run for this frame.
   */
  measure: (input: MonteCarloUserDefinedMetricMeasureInput) => number | null | undefined;
  sampleRuns?: MonteCarloUserDefinedMetricSampleRuns;
  /**
   * Controls how sampled run values are represented for each frame.
   *
   * Defaults to scalar output using `aggregateRuns`. Distribution output keeps
   * the run axis unaggregated and bins the sampled run values.
   */
  runOutput?: MonteCarloMetricRunOutput;
  /**
   * Aggregates the per-run samples into the frame value.
   *
   * Defaults to `mean`, which gives the average value over all sampled runs for
   * the current frame.
   */
  aggregateRuns?: MonteCarloUserDefinedMetricAggregation;
  /**
   * Optionally aggregates values over time.
   *
   * Defaults to `none`. For scalar output, this aggregates the scalar frame
   * values and exposes the result as `value`. For distribution output, this
   * aggregates each sampled run over time before binning the resulting per-run
   * values.
   */
  aggregateTime?: MonteCarloUserDefinedMetricTimeAggregation;
};
type MonteCarloMetricSpecBase = {
  id: string;
  label: string;
  sampleRuns?: MonteCarloUserDefinedMetricSampleRuns;
  runOutput?: MonteCarloMetricRunOutput;
  aggregateRuns?: MonteCarloUserDefinedMetricAggregation;
  aggregateTime?: MonteCarloUserDefinedMetricTimeAggregation;
};
type MonteCarloPlaceTokenCountMeanMetricSpec = MonteCarloMetricSpecBase & {
  kind: "placeTokenCountMean";
  placeId: string;
};
type MonteCarloTransitionFiringCountMetricSpec = MonteCarloMetricSpecBase & {
  kind: "transitionFiringCount";
  transitionId: string;
  mode?: "firedInThisFrame" | "cumulative";
};
type MonteCarloExpressionMetricSpec = MonteCarloMetricSpecBase & {
  kind: "expression";
  /**
   * Function body invoked with the same `state` object as persisted timeline
   * metrics. It must `return` a finite number.
   */
  code: string;
};
type MonteCarloMetricSpec = MonteCarloExpressionMetricSpec | MonteCarloPlaceTokenCountMeanMetricSpec | MonteCarloTransitionFiringCountMetricSpec;
type MonteCarloUserDefinedMetricFrameBase = {
  metricId: string;
  label: string;
  frameNumber: number;
  time: number;
  runSampleCount: number;
};
type MonteCarloUserDefinedMetricDistributionBin = readonly [value: number, frequency: number];
type MonteCarloUserDefinedScalarMetricFrame = MonteCarloUserDefinedMetricFrameBase & {
  outputType: "scalar";
  /**
   * The primary scalar to display for this frame.
   *
   * This is the per-frame aggregate unless `aggregateTime` is configured, in
   * which case it is the aggregate over time.
   */
  value: number | null;
  frameValue: number | null;
  timeValue: number | null;
  timeSampleCount: number;
};
type MonteCarloUserDefinedDistributionMetricFrame = MonteCarloUserDefinedMetricFrameBase & {
  outputType: "distribution";
  bins: readonly MonteCarloUserDefinedMetricDistributionBin[];
  value: null;
  frameValue: null;
  timeValue: null;
  timeSampleCount: number;
};
/**
 * Runtime-only user-defined metrics can either keep one scalar aggregate per
 * frame or a distribution across sampled runs. When `aggregateTime` is set on a
 * distribution metric, each run is aggregated over time before values are
 * binned.
 */
type MonteCarloUserDefinedMetricFrame = MonteCarloUserDefinedScalarMetricFrame | MonteCarloUserDefinedDistributionMetricFrame;
type MonteCarloUserDefinedMetric = MonteCarloFrameMetric & {
  readonly id: string;
  readonly label: string;
  readonly frames: readonly MonteCarloUserDefinedMetricFrame[];
  getLatestFrame: () => MonteCarloUserDefinedMetricFrame | null;
  clear: () => void;
};
//#endregion
//#region src/simulation/monte-carlo/types.d.ts
type MonteCarloRunStatus = "ready" | "running" | "complete" | "error";
type MonteCarloRunConfig = {
  seed?: number;
  parameterValues?: Record<string, string>;
  initialMarking?: InitialMarking;
};
type MonteCarloSimulatorConfig = {
  sdcpn: SDCPN;
  runCount: number;
  initialMarking: InitialMarking;
  parameterValues?: Record<string, string>;
  seed?: number;
  dt: number;
  maxTime: number;
  runs?: readonly MonteCarloRunConfig[];
  initialTokenValueCapacity?: number;
  metrics?: readonly MonteCarloFrameMetric[];
};
type MonteCarloRunSummary = {
  index: number;
  status: MonteCarloRunStatus;
  seed: number;
  frameNumber: number;
  currentTime: number;
  rngState: number;
  parameterValues: ParameterValues;
  completionReason: SimulationCompletionReason | null;
  error: string | null;
  tokenValueCount: number;
  tokenValueCapacity: number;
  reallocations: number;
};
type MonteCarloRunSnapshot = MonteCarloRunSummary & {
  placeTokenCounts: Record<string, number>;
};
type MonteCarloAdvanceResult = {
  advancedRuns: number;
  completedRuns: number;
  erroredRuns: number;
  activeRuns: number;
  allFinished: boolean;
};
type MonteCarloRunUntilCompleteOptions = {
  maxBatches?: number;
};
/**
 * Public controller for a memory-bounded Monte Carlo simulation.
 *
 * Implementations should keep binary frame buffers internal and expose only
 * serializable summaries or snapshots to callers.
 */
interface MonteCarloSimulator {
  readonly runCount: number;
  /**
   * Advance every active run by at most one simulation frame.
   */
  advanceAll(): MonteCarloAdvanceResult;
  /**
   * Keep advancing runs until every run is complete/errored or a batch cap is
   * reached.
   */
  runUntilComplete(options?: MonteCarloRunUntilCompleteOptions): MonteCarloAdvanceResult;
  /**
   * Read progress and capacity metadata for one run.
   */
  getRunSummary(index: number): MonteCarloRunSummary;
  /**
   * Read one run summary plus current place token counts.
   */
  getRunSnapshot(index: number): MonteCarloRunSnapshot;
  /**
   * Read progress and capacity metadata for every run.
   */
  getSummaries(): MonteCarloRunSummary[];
}
//#endregion
//#region src/simulation/monte-carlo/metrics/accumulators.d.ts
type MonteCarloMetricMonoid<State> = {
  empty: () => State;
  merge: (left: State, right: State) => State;
};
type MonteCarloMetricValueAccumulator<Input, State, Output> = MonteCarloMetricMonoid<State> & {
  add: (state: State, input: Input) => State;
  read: (state: State) => Output;
};
type MonteCarloMetricNumericAccumulatorState = {
  count: number;
  sum: number;
  min: number | null;
  max: number | null;
  last: number | null;
};
type MonteCarloMetricHistogramAccumulatorState = ReadonlyMap<number, number>;
declare function createMonteCarloMetricNumericAccumulator(method: MonteCarloUserDefinedMetricAggregation): MonteCarloMetricValueAccumulator<number, MonteCarloMetricNumericAccumulatorState, number | null>;
declare function createMonteCarloMetricHistogramAccumulator(binning?: MonteCarloMetricDistributionBinning): MonteCarloMetricValueAccumulator<number, MonteCarloMetricHistogramAccumulatorState, MonteCarloUserDefinedMetricDistributionBin[]>;
declare function addAllMonteCarloMetricValues<Input, State, Output>(accumulator: MonteCarloMetricValueAccumulator<Input, State, Output>, inputs: readonly Input[]): State;
//#endregion
//#region src/simulation/monte-carlo/metrics/specs.d.ts
declare function createMonteCarloUserDefinedMetricConfigsFromSpecs(specs: readonly MonteCarloMetricSpec[], sdcpn: SDCPN): MonteCarloUserDefinedMetricConfig[];
//#endregion
//#region src/simulation/monte-carlo/metrics/user-defined.d.ts
declare function createMonteCarloUserDefinedMetric(config: MonteCarloUserDefinedMetricConfig): MonteCarloUserDefinedMetric;
//#endregion
//#region src/simulation/monte-carlo/worker/messages.d.ts
type MonteCarloInitMessage = {
  type: "init";
  sdcpn: SDCPN;
  initialMarking: InitialMarking;
  parameterValues: Record<string, string>;
  seed: number;
  dt: number;
  maxTime: number;
  runCount: number;
  batchSize?: number;
  metricSpecs?: readonly MonteCarloMetricSpec[];
};
type MonteCarloStartMessage = {
  type: "start";
};
type MonteCarloCancelMessage = {
  type: "cancel";
};
type MonteCarloToWorkerMessage = MonteCarloInitMessage | MonteCarloStartMessage | MonteCarloCancelMessage;
type MonteCarloProgressMessage = {
  type: "progress";
  progress: MonteCarloWorkerProgress;
};
type MonteCarloMetricFramesMessage = {
  type: "metricFrames";
  frames: MonteCarloUserDefinedMetricFrame[];
};
type MonteCarloReadyMessage = {
  type: "ready";
};
type MonteCarloCompleteMessage = {
  type: "complete";
  progress: MonteCarloWorkerProgress;
};
type MonteCarloCancelledMessage = {
  type: "cancelled";
  progress: MonteCarloWorkerProgress | null;
};
type MonteCarloErrorMessage = {
  type: "error";
  message: string;
  itemId: string | null;
};
type MonteCarloWorkerProgress = MonteCarloAdvanceResult & {
  frameNumber: number;
  time: number;
  runCount: number;
};
type MonteCarloToMainMessage = MonteCarloReadyMessage | MonteCarloProgressMessage | MonteCarloMetricFramesMessage | MonteCarloCompleteMessage | MonteCarloCancelledMessage | MonteCarloErrorMessage;
//#endregion
export { MonteCarloActiveRunPlaceCountsVisitor as A, MonteCarloRunFrameMetricView as B, MonteCarloRunConfig as C, MonteCarloRunUntilCompleteOptions as D, MonteCarloRunSummary as E, MonteCarloMetricRunOutput as F, MonteCarloUserDefinedMetricAggregation as G, MonteCarloTransitionFiringCountMetricSpec as H, MonteCarloMetricRunStatus as I, MonteCarloUserDefinedMetricFrame as J, MonteCarloUserDefinedMetricConfig as K, MonteCarloMetricSpec as L, MonteCarloFrameMetric as M, MonteCarloFrameMetricContext as N, MonteCarloSimulator as O, MonteCarloMetricDistributionBinning as P, MonteCarloUserDefinedScalarMetricFrame as Q, MonteCarloMetricSpecBase as R, MonteCarloAdvanceResult as S, MonteCarloRunStatus as T, MonteCarloUserDefinedDistributionMetricFrame as U, MonteCarloRunFrameMetricVisitor as V, MonteCarloUserDefinedMetric as W, MonteCarloUserDefinedMetricSampleRuns as X, MonteCarloUserDefinedMetricMeasureInput as Y, MonteCarloUserDefinedMetricTimeAggregation as Z, MonteCarloMetricNumericAccumulatorState as _, MonteCarloInitMessage as a, createMonteCarloMetricHistogramAccumulator as b, MonteCarloReadyMessage as c, MonteCarloToWorkerMessage as d, MonteCarloWorkerProgress as f, MonteCarloMetricMonoid as g, MonteCarloMetricHistogramAccumulatorState as h, MonteCarloErrorMessage as i, MonteCarloExpressionMetricSpec as j, MonteCarloSimulatorConfig as k, MonteCarloStartMessage as l, createMonteCarloUserDefinedMetricConfigsFromSpecs as m, MonteCarloCancelledMessage as n, MonteCarloMetricFramesMessage as o, createMonteCarloUserDefinedMetric as p, MonteCarloUserDefinedMetricDistributionBin as q, MonteCarloCompleteMessage as r, MonteCarloProgressMessage as s, MonteCarloCancelMessage as t, MonteCarloToMainMessage as u, MonteCarloMetricValueAccumulator as v, MonteCarloRunSnapshot as w, createMonteCarloMetricNumericAccumulator as x, addAllMonteCarloMetricValues as y, MonteCarloPlaceTokenCountMeanMetricSpec as z };
//# sourceMappingURL=messages-CXQE4ofj.d.ts.map