libpetri 0.5.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,10 @@ declare class MarkingStateBuilder {
35
35
  tokens(place: Place<any>, count: number): this;
36
36
  /** Adds tokens to a place. */
37
37
  addTokens(place: Place<any>, count: number): this;
38
+ /** Removes tokens from a place. Throws if insufficient. */
39
+ removeTokens(place: Place<any>, count: number): this;
40
+ /** Copies all token counts from another marking state. */
41
+ copyFrom(other: MarkingState): this;
38
42
  build(): MarkingState;
39
43
  }
40
44
 
@@ -142,14 +146,14 @@ declare class IncidenceMatrix {
142
146
  /**
143
147
  * How to treat environment places during analysis.
144
148
  */
145
- type EnvironmentAnalysisMode = {
149
+ type EnvironmentAnalysisMode$1 = {
146
150
  readonly type: 'unbounded';
147
151
  } | {
148
152
  readonly type: 'bounded';
149
153
  readonly maxTokens: number;
150
154
  };
151
- declare function unbounded(): EnvironmentAnalysisMode;
152
- declare function bounded(maxTokens: number): EnvironmentAnalysisMode;
155
+ declare function unbounded(): EnvironmentAnalysisMode$1;
156
+ declare function bounded$1(maxTokens: number): EnvironmentAnalysisMode$1;
153
157
  /**
154
158
  * Flattens a PetriNet into a FlatNet suitable for SMT encoding.
155
159
  *
@@ -160,7 +164,7 @@ declare function bounded(maxTokens: number): EnvironmentAnalysisMode;
160
164
  * 4. Recording inhibitor, read, and reset arcs
161
165
  * 5. Setting environment bounds for bounded analysis mode
162
166
  */
163
- declare function flatten(net: PetriNet, environmentPlaces?: Set<EnvironmentPlace<any>>, environmentMode?: EnvironmentAnalysisMode): FlatNet;
167
+ declare function flatten(net: PetriNet, environmentPlaces?: Set<EnvironmentPlace<any>>, environmentMode?: EnvironmentAnalysisMode$1): FlatNet;
164
168
 
165
169
  /**
166
170
  * A P-invariant (place invariant) of a Petri net.
@@ -397,7 +401,7 @@ declare class SmtVerifier {
397
401
  initialMarking(configurator: (builder: MarkingStateBuilder) => void): this;
398
402
  property(property: SmtProperty): this;
399
403
  environmentPlaces(...places: EnvironmentPlace<any>[]): this;
400
- environmentMode(mode: EnvironmentAnalysisMode): this;
404
+ environmentMode(mode: EnvironmentAnalysisMode$1): this;
401
405
  /**
402
406
  * Declares expected sink (terminal) places for deadlock-freedom analysis.
403
407
  * Markings where any sink place has a token are not considered deadlocks.
@@ -508,4 +512,194 @@ interface DecodedTrace {
508
512
  */
509
513
  declare function decode(ctx: any, answer: Expr | null, flatNet: FlatNet): DecodedTrace;
510
514
 
511
- export { type DeadlockFree, type DecodedTrace, type EncodingResult, type EnvironmentAnalysisMode, type FlatNet, type FlatTransition, IncidenceMatrix, MarkingState, MarkingStateBuilder, type MutualExclusion, type PInvariant, type PlaceBound, type Proven, type QueryProven, type QueryResult, type QueryUnknown, type QueryViolated, type SmtProperty, type SmtStatistics, type SmtVerificationResult, SmtVerifier, type SpacerContext, type StructuralCheckResult, type Unknown, type Unreachable, type Verdict, type Violated, bounded, computePInvariants, createSpacerRunner, deadlockFree, decode, encode, findMaximalTrapIn, findMinimalSiphons, flatNetIndexOf, flatNetPlaceCount, flatNetTransitionCount, flatTransition, flatten, isCoveredByInvariants, isProven, isViolated, mutualExclusion, pInvariant, pInvariantToString, placeBound, propertyDescription, structuralCheck, unbounded, unreachable };
515
+ /**
516
+ * Difference Bound Matrix (DBM) for Time Petri Net state class analysis.
517
+ *
518
+ * Implements the Berthomieu-Diaz (1991) algorithm for computing firing domains
519
+ * and their successors. Matrix bounds[i][j] = upper bound on (xi - xj).
520
+ * Index 0 is the reference clock; index i+1 is the clock for transition i.
521
+ */
522
+ declare class DBM {
523
+ private readonly bounds;
524
+ private readonly dim;
525
+ readonly clockNames: readonly string[];
526
+ private readonly _empty;
527
+ private constructor();
528
+ /** Creates an initial firing domain for enabled transitions. */
529
+ static create(clockNames: readonly string[], lowerBounds: number[], upperBounds: number[]): DBM;
530
+ /** Creates an empty (unsatisfiable) zone. */
531
+ static empty(clockNames: readonly string[]): DBM;
532
+ isEmpty(): boolean;
533
+ clockCount(): number;
534
+ private get;
535
+ /** Gets the lower bound (earliest firing time) for clock i. */
536
+ getLowerBound(clockIndex: number): number;
537
+ /** Gets the upper bound (latest firing time / deadline) for clock i. */
538
+ getUpperBound(clockIndex: number): number;
539
+ /** Checks if transition can fire (lower bound <= 0 after time passage). */
540
+ canFire(clockIndex: number): boolean;
541
+ /**
542
+ * Computes the successor firing domain after firing transition t_f.
543
+ * Implements the 5-step Berthomieu-Diaz successor formula.
544
+ */
545
+ fireTransition(firedClock: number, newClockNames: readonly string[], newLowerBounds: number[], newUpperBounds: number[], persistentClocks: number[]): DBM;
546
+ /** Lets time pass: set all lower bounds to 0. */
547
+ letTimePass(): DBM;
548
+ private canonicalize;
549
+ equals(other: DBM): boolean;
550
+ toString(): string;
551
+ }
552
+
553
+ /**
554
+ * A State Class in Time Petri Net analysis.
555
+ *
556
+ * A state class is a pair (M, D) where M is a marking and D is a firing domain (DBM).
557
+ * State classes provide a finite abstraction of the infinite state space of Time Petri Nets.
558
+ */
559
+ declare class StateClass {
560
+ readonly marking: MarkingState;
561
+ readonly firingDomain: DBM;
562
+ readonly enabledTransitions: readonly Transition[];
563
+ constructor(marking: MarkingState, firingDomain: DBM, enabledTransitions: readonly Transition[]);
564
+ isEmpty(): boolean;
565
+ canFire(transition: Transition): boolean;
566
+ transitionIndex(transition: Transition): number;
567
+ equals(other: StateClass): boolean;
568
+ toString(): string;
569
+ }
570
+
571
+ /**
572
+ * Strongly Connected Component analysis using Tarjan's algorithm.
573
+ * Generic over node type T. Uses a key function for Map-based lookups.
574
+ */
575
+ /** Computes all SCCs in a graph. O(V + E) via Tarjan's algorithm. */
576
+ declare function computeSCCs<T>(nodes: Iterable<T>, successors: (node: T) => Iterable<T>): Set<T>[];
577
+ /** Finds terminal (bottom) SCCs — SCCs with no outgoing edges to other SCCs. */
578
+ declare function findTerminalSCCs<T>(nodes: Iterable<T>, successors: (node: T) => Iterable<T>): Set<T>[];
579
+
580
+ /**
581
+ * Analysis mode for environment places in state class graph construction.
582
+ */
583
+ type EnvironmentAnalysisMode = {
584
+ readonly type: 'always-available';
585
+ } | {
586
+ readonly type: 'bounded';
587
+ readonly maxTokens: number;
588
+ } | {
589
+ readonly type: 'ignore';
590
+ };
591
+ /** Assumes environment places always have sufficient tokens. */
592
+ declare function alwaysAvailable(): EnvironmentAnalysisMode;
593
+ /** Analyzes with a bounded number of tokens in environment places. */
594
+ declare function bounded(maxTokens: number): EnvironmentAnalysisMode;
595
+ /** Treats environment places as regular places (default). */
596
+ declare function ignore(): EnvironmentAnalysisMode;
597
+
598
+ /** Edge that tracks which XOR branch was taken. */
599
+ interface BranchEdge {
600
+ readonly branchIndex: number;
601
+ readonly target: StateClass;
602
+ }
603
+ /**
604
+ * State Class Graph for Time Petri Net analysis.
605
+ *
606
+ * Implements the Berthomieu-Diaz (1991) algorithm for computing the state class
607
+ * graph of a bounded Time Petri Net.
608
+ */
609
+ declare class StateClassGraph {
610
+ readonly net: PetriNet;
611
+ readonly initialClass: StateClass;
612
+ private readonly _stateClasses;
613
+ private readonly _transitions;
614
+ private readonly _successors;
615
+ private readonly _predecessors;
616
+ private readonly _complete;
617
+ private constructor();
618
+ /** Builds the state class graph for a Time Petri Net. */
619
+ static build(net: PetriNet, initialMarking: MarkingState, maxClasses: number, environmentPlaces?: Set<EnvironmentPlace<any>>, environmentMode?: EnvironmentAnalysisMode): StateClassGraph;
620
+ stateClasses(): readonly StateClass[];
621
+ size(): number;
622
+ isComplete(): boolean;
623
+ successors(sc: StateClass): Set<StateClass>;
624
+ predecessors(sc: StateClass): Set<StateClass>;
625
+ /** Returns all outgoing transitions with their branch edges. */
626
+ outgoingBranchEdges(sc: StateClass): Map<Transition, BranchEdge[]>;
627
+ /** Returns the branch edges for a specific transition from a state class. */
628
+ branchEdges(sc: StateClass, transition: Transition): BranchEdge[];
629
+ /** Returns all transitions that are enabled from a state class. */
630
+ enabledTransitions(sc: StateClass): Set<Transition>;
631
+ /** Finds all state classes with a given marking. */
632
+ classesWithMarking(marking: MarkingState): StateClass[];
633
+ /** Checks if a marking is reachable. */
634
+ isReachable(marking: MarkingState): boolean;
635
+ /** Gets all reachable markings. */
636
+ reachableMarkings(): Set<string>;
637
+ /** Counts edges in the graph (each branch edge counts separately). */
638
+ edgeCount(): number;
639
+ toString(): string;
640
+ }
641
+
642
+ /** Result of liveness analysis. */
643
+ interface LivenessResult {
644
+ readonly stateClassGraph: StateClassGraph;
645
+ readonly allSCCs: Set<StateClass>[];
646
+ readonly terminalSCCs: Set<StateClass>[];
647
+ readonly goalClasses: Set<StateClass>;
648
+ readonly canReachGoal: Set<StateClass>;
649
+ readonly isGoalLive: boolean;
650
+ readonly isL4Live: boolean;
651
+ readonly isComplete: boolean;
652
+ readonly report: string;
653
+ }
654
+ /** Information about XOR branch coverage for a single transition. */
655
+ interface XorBranchInfo {
656
+ readonly totalBranches: number;
657
+ readonly takenBranches: Set<number>;
658
+ readonly untakenBranches: Set<number>;
659
+ readonly branchOutputs: ReadonlyArray<ReadonlySet<Place<any>>>;
660
+ }
661
+ /** Result of XOR branch analysis. */
662
+ interface XorBranchAnalysis {
663
+ readonly transitionBranches: Map<Transition, XorBranchInfo>;
664
+ unreachableBranches(): Map<Transition, Set<number>>;
665
+ isXorComplete(): boolean;
666
+ report(): string;
667
+ }
668
+ /**
669
+ * Formal analyzer for Time Petri Nets using the State Class Graph method.
670
+ * Implements Berthomieu-Diaz (1991) analysis.
671
+ */
672
+ declare class TimePetriNetAnalyzer {
673
+ private readonly net;
674
+ private readonly initialMarking;
675
+ private readonly goalPlaces;
676
+ private readonly maxClasses;
677
+ private readonly environmentPlaces;
678
+ private readonly environmentMode;
679
+ /** @internal Called by builder — use `TimePetriNetAnalyzer.forNet()` instead. */
680
+ static create(net: PetriNet, initialMarking: MarkingState, goalPlaces: Set<Place<any>>, maxClasses: number, environmentPlaces: Set<EnvironmentPlace<any>>, environmentMode: EnvironmentAnalysisMode): TimePetriNetAnalyzer;
681
+ private constructor();
682
+ static forNet(net: PetriNet): TimePetriNetAnalyzerBuilder;
683
+ /** Performs formal liveness analysis. */
684
+ analyze(): LivenessResult;
685
+ /** Analyzes XOR branch coverage for a built state class graph. */
686
+ static analyzeXorBranches(scg: StateClassGraph): XorBranchAnalysis;
687
+ }
688
+ /** Builder for TimePetriNetAnalyzer. */
689
+ declare class TimePetriNetAnalyzerBuilder {
690
+ private readonly net;
691
+ private _initialMarking;
692
+ private readonly _goalPlaces;
693
+ private _maxClasses;
694
+ private readonly _environmentPlaces;
695
+ private _environmentMode;
696
+ constructor(net: PetriNet);
697
+ initialMarking(marking: MarkingState): this;
698
+ goalPlaces(...places: Place<any>[]): this;
699
+ maxClasses(max: number): this;
700
+ environmentPlaces(...places: EnvironmentPlace<any>[]): this;
701
+ environmentMode(mode: EnvironmentAnalysisMode): this;
702
+ build(): TimePetriNetAnalyzer;
703
+ }
704
+
705
+ export { type EnvironmentAnalysisMode as AnalysisEnvironmentMode, type BranchEdge, DBM, type DeadlockFree, type DecodedTrace, type EncodingResult, type EnvironmentAnalysisMode$1 as EnvironmentAnalysisMode, type FlatNet, type FlatTransition, IncidenceMatrix, type LivenessResult, MarkingState, MarkingStateBuilder, type MutualExclusion, type PInvariant, type PlaceBound, type Proven, type QueryProven, type QueryResult, type QueryUnknown, type QueryViolated, type SmtProperty, type SmtStatistics, type SmtVerificationResult, SmtVerifier, type SpacerContext, StateClass, StateClassGraph, type StructuralCheckResult, TimePetriNetAnalyzer, TimePetriNetAnalyzerBuilder, type Unknown, type Unreachable, type Verdict, type Violated, type XorBranchAnalysis, type XorBranchInfo, alwaysAvailable as analysisAlwaysAvailable, bounded as analysisBounded, ignore as analysisIgnore, bounded$1 as bounded, computePInvariants, computeSCCs, createSpacerRunner, deadlockFree, decode, encode, findMaximalTrapIn, findMinimalSiphons, findTerminalSCCs, flatNetIndexOf, flatNetPlaceCount, flatNetTransitionCount, flatTransition, flatten, isCoveredByInvariants, isProven, isViolated, mutualExclusion, pInvariant, pInvariantToString, placeBound, propertyDescription, structuralCheck, unbounded, unreachable };