Skip to main content

@getriebe/petri

Inspect and fire Petri nets with explicit token bindings.

Source revision 49560371f6cd34d30383df5619df46969c594ae4.

export interface Arc {
readonly place: PlaceId;
readonly weight?: number;
}
export type FiringResult = {
readonly status: "fired";
readonly marking: Marking;
readonly consumed: readonly PlaceTokens[];
readonly produced: readonly PlaceTokens[];
} | {
readonly status: "rejected";
readonly reason: "unknown-transition" | "disabled" | "invalid-binding" | "capacity";
};
declare class Marking {
constructor(owner: PetriNet, snapshot: MarkingSnapshot);
get size(): number;
get nextTokenId(): TokenId;
tokens(place: PlaceId): readonly TokenId[];
count(place: PlaceId): number;
snapshot(): MarkingSnapshot;
}
export interface MarkingSnapshot {
readonly nextTokenId: TokenId;
readonly places: readonly PlaceTokens[];
}
export declare const maxLiveTokens = 100000;
export interface NetDefinition {
readonly places: readonly PlaceId[];
readonly transitions: readonly TransitionDefinition[];
}
export declare class PetriNet {
constructor(definition: NetDefinition);
initialMarking(counts?: readonly PlaceCount[]): Marking;
restoreMarking(snapshot: unknown): Marking;
isEnabled(marking: Marking, id: TransitionId): boolean;
enabledTransitions(marking: Marking): readonly TransitionId[];
fire(marking: Marking, id: TransitionId, binding?: readonly PlaceTokens[]): FiringResult;
clearPlaces(marking: Marking, places: ReadonlySet<PlaceId>): Marking;
}
export interface PlaceCount {
readonly place: PlaceId;
readonly count: number;
}
export type PlaceId = string;
export interface PlaceTokens {
readonly place: PlaceId;
readonly tokens: readonly TokenId[];
}
export type TokenId = number;
export interface TransitionDefinition {
readonly id: TransitionId;
readonly inputs: readonly Arc[];
readonly outputs: readonly Arc[];
}
export type TransitionId = string;