Package jline.lang.state
Class State
java.lang.Object
jline.lang.state.State
- All Implemented Interfaces:
Serializable
Class modeling the state of Stateful nodes
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult class for event handling methodsstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Map<StatefulNode, Matrix> final Map<StatefulNode, Matrix> final Map<StatefulNode, Matrix> -
Constructor Summary
ConstructorsConstructorDescriptionState(Map<StatefulNode, Matrix> initialState, Map<StatefulNode, Matrix> priorInitialState, Map<StatefulNode, Matrix> initialStateSpace) -
Method Summary
Modifier and TypeMethodDescriptionstatic Ret.EventResultafterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation) static Ret.EventResultafterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache) static Ret.EventResultafterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache, AfterEventContext ctx) static Ret.EventResultafterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache, AfterEventContext ctx, boolean noPromote) noPromote: when true, a DEP at an FCFS-family station does not promote a waiting job into the vacated server.static Ret.EventResultafterEventHashed(NetworkStruct sn, int ind, double inhash, EventType event, int Jobclass) afterEventHashedOrAdd(NetworkStruct sn, int ind, int inhash, EventType event, int jobclass) Combination of afterEventHashed with automatic state space extension Migrated from MATLAB afterEventHashedOrAdd.mstatic AfterEventContextPrecomputes the loop-invariant setup of afterEvent so that hot callers (e.g., the Solver_ssa Gillespie loop) avoid re-deriving it on every event evaluation.static booleanarrivalIsLost(NetworkStruct sn, int ist, int jobClass) True when an arrival of classjobClassthat finds no room at stationistis LOST, and false when it must BLOCK the upstream instead.static voidstatic Map<StatefulNode, Map<String, Integer>> buildSpaceHashMap(Map<StatefulNode, Matrix> space) static MatrixfromMarginal(Network model, int ind, int[] n) Generates the state space of a node from the per-class marginal job counts.static MatrixfromMarginalAndRunning(Network model, int ind, int[] n, int[] s) Generates the state space of a node from the per-class marginal job counts and the per-class number of running jobs.static MatrixfromMarginalAndStarted(Network model, int ind, int[] n, int[] s) Generates the state space of a node from the per-class marginal job counts and the per-class number of jobs that have just started service.static Ret.getHashOrAddResultgetHashOrAdd(NetworkStruct sn, int ind, Matrix inspace) Get hash ID for a state space, or add the state to the space if not found Migrated from MATLAB getHashOrAdd.mprotected static State.EventHandleResulthandleEnableEvent(NetworkStruct sn, int ind, GlobalSync glevent, List<Matrix> glspace, List<Matrix> outglspace, Matrix inspace, Matrix spaceBuf, Matrix spaceSrv, Matrix spaceVar, Matrix fK, Matrix fKs, int mode, TransitionNodeParam transParam, int R) Handles ENABLE events for transitions in Stochastic Petri Net (SPN) event processing.protected static State.EventHandleResulthandleFireEvent(NetworkStruct sn, int ind, GlobalSync glevent, List<Matrix> glspace, List<Matrix> outglspace, Matrix inspace, Matrix spaceBuf, Matrix spaceSrv, Matrix spaceVar, Matrix fK, Matrix fKs, int mode, TransitionNodeParam transParam, int R, boolean isSimulation) Handles FIRE events for transitions in Stochastic Petri Net (SPN) event processing.static booleanisPhysicalCapacity(NetworkStruct sn, int ist, int jobClass) True when the capacity bound at stationistforjobClassis a PHYSICAL finite capacity (setCapacity/setClassCapacity), as opposed to a state-space CUTOFF imposed on an open class only to bound enumeration.static booleanstatic booleanisValid(NetworkStruct sn, Matrix n, Matrix s) reachableSpaceGenerator(NetworkStruct sn, SolverOptions options) Generates state space restricted to states reachable from initial state Migrated from MATLAB reachableSpaceGenerator.mstatic voidRounds a fractional marginal queue-length matrix (station x class) to integers with the largest remainder method, so that every closed chain keeps exactly its own population.static MatrixspaceCachePublic(int n, Matrix m, int retrievalSystemCapacity) Make spaceCache method public Generates cache state spacestatic MatrixspaceClosedMulti(int M, Matrix N) static MatrixspaceClosedMultiCS(int M, Matrix N, Matrix chains) static MatrixspaceClosedMultiCSBounded(int M, Matrix N, Matrix chains, Matrix capMatrix, Set<String> visitedSums) static MatrixspaceClosedSinglePublic(int M, int N) Make spaceClosedSingle method public Generates state space for single-class closed networksspaceGenerator(NetworkStruct sn, Matrix cutoff, SolverOptions options) Generates the state space for a queueing network using a matrix cutoff.spaceGeneratorNodes(NetworkStruct sn, Matrix cutoff, SolverOptions options) static MatrixspaceLocalVarsPublic(NetworkStruct sn, int ind) Make spaceLocalVars method public Generates local variable state spaces
-
Field Details
-
initialState
-
priorInitialState
-
initialStateSpace
-
-
Constructor Details
-
State
public State(Map<StatefulNode, Matrix> initialState, Map<StatefulNode, Matrix> priorInitialState, Map<StatefulNode, Matrix> initialStateSpace)
-
-
Method Details
-
arrivalIsLost
True when an arrival of classjobClassthat finds no room at stationistis LOST, and false when it must BLOCK the upstream instead. This is the single predicate that decides the refusal semantics; every refusal path must branch on it. Mirrors the MATLAB State.arrivalIsLost. The rule is the CLASS TYPE, not the drop rule:- OPEN class: LOST. The external arrival stream is memoryless, so a job that finds the station full simply never enters. The caller must then leave the state UNCHANGED (a self-loop): the arrival event still fires, so the offered rate reaches the arrival-rate statistic and the loss shows up as ArvR - Tput. A self-loop cancels on the generator diagonal and therefore cannot perturb the stationary distribution, so QLen/Util/Tput are unaffected.
- CLOSED class: BLOCKED. A closed network's N jobs have nowhere to go; population conservation is a defining invariant, so a closed job can never be dropped. The caller must return an EMPTY outspace, which disables the upstream departure until room frees (and is what the true-BAS become-blocked edge tests for).
- Parameters:
sn- the network structist- the station indexjobClass- the class index- Returns:
- true when the refused arrival is lost, false when it blocks
-
isPhysicalCapacity
True when the capacity bound at stationistforjobClassis a PHYSICAL finite capacity (setCapacity/setClassCapacity), as opposed to a state-space CUTOFF imposed on an open class only to bound enumeration. The distinction matters because a solver may fold the open-class cutoff into the producer's capacity/classcap arguments (SSA overwrites sn.cap/sn.classcap with min(cutoff, physical)), so at the cutoff boundary they are finite even when there is no physical cap. Treating a cutoff boundary as physical would turn a state-space truncation into a self-loop loss. The reliable in-producer signal is the DROP RULE: refreshCapacity sets a finite-capacity rule (Drop, or a blocking/retrial rule) exactly when the station has a physical finite capacity for the class; an open class bounded only by the cutoff keeps the WaitingQueue default. (A user who explicitly sets WaitingQueue on a physical cap is the one ambiguous case; it is already ill-defined and is treated here as a cutoff, i.e. truncated.)- Parameters:
sn- the network structist- the station indexjobClass- the class index- Returns:
- true when a physical finite capacity binds this station-class
-
fromMarginal
Generates the state space of a node from the per-class marginal job counts.- Parameters:
model- the network modelind- the node index (0-based)n- per-class number of resident jobs- Returns:
- the state-space matrix (one row per valid state)
-
fromMarginalAndRunning
Generates the state space of a node from the per-class marginal job counts and the per-class number of running jobs.- Parameters:
model- the network modelind- the node index (0-based)n- per-class number of resident jobss- per-class number of running jobs- Returns:
- the state-space matrix (one row per valid state)
-
fromMarginalAndStarted
Generates the state space of a node from the per-class marginal job counts and the per-class number of jobs that have just started service.- Parameters:
model- the network modelind- the node index (0-based)n- per-class number of resident jobss- per-class number of started jobs- Returns:
- the state-space matrix (one row per valid state)
-
afterEvent
public static Ret.EventResult afterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation) -
afterEvent
public static Ret.EventResult afterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache) -
afterEventInit
Precomputes the loop-invariant setup of afterEvent so that hot callers (e.g., the Solver_ssa Gillespie loop) avoid re-deriving it on every event evaluation. Build it from the SAME sn instance later passed to afterEvent, after any caller-side rewrite of its fields (the Solver_ssa preamble rewrites nservers/cap/classcap in place). -
afterEvent
public static Ret.EventResult afterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache, AfterEventContext ctx) -
afterEvent
public static Ret.EventResult afterEvent(NetworkStruct sn, int ind, Matrix inspace, EventType event, int jobClass, boolean isSimulation, EventCache eventCache, AfterEventContext ctx, boolean noPromote) noPromote: when true, a DEP at an FCFS-family station does not promote a waiting job into the vacated server. Set only for the departure half of an immediate-feedback self-loop (sn.immfeed) so the fed-back job holds the server rather than re-queueing behind the waiting jobs. It is part of the cache key so immediate-feedback and ordinary departures never collide. -
afterEventHashed
public static Ret.EventResult afterEventHashed(NetworkStruct sn, int ind, double inhash, EventType event, int Jobclass) -
afterEventHashedOrAdd
public static Ret.afterEventHashedOrAddResult afterEventHashedOrAdd(NetworkStruct sn, int ind, int inhash, EventType event, int jobclass) Combination of afterEventHashed with automatic state space extension Migrated from MATLAB afterEventHashedOrAdd.m- Parameters:
sn- Network structureind- Node indexinhash- Input hash IDevent- Event typejobclass- Job class- Returns:
- Ret.afterEventHashedOrAddResult containing output hash, rate, probability and updated network
-
handleEnableEvent
protected static State.EventHandleResult handleEnableEvent(NetworkStruct sn, int ind, GlobalSync glevent, List<Matrix> glspace, List<Matrix> outglspace, Matrix inspace, Matrix spaceBuf, Matrix spaceSrv, Matrix spaceVar, Matrix fK, Matrix fKs, int mode, TransitionNodeParam transParam, int R) Handles ENABLE events for transitions in Stochastic Petri Net (SPN) event processing. This method processes the enabling phase of a transition firing, which checks if the transition can be enabled based on available tokens in input places and generates all possible state combinations when the transition becomes enabled. It implements the SPN semantics for transition enabling with support for multiple job classes and server allocation.- Parameters:
sn- Network structure containing the complete SPN model definitionind- Node index of the transition being processedglevent- Global synchronization event containing active and passive eventsglspace- Current global state space (list of states for each stateful node)outglspace- Output global state space to be updatedinspace- Input state space matrix for the transition nodespaceBuf- Buffer state space matrix (job queue states)spaceSrv- Server state space matrix (server allocation states)spaceVar- Variable state space matrix (phase variables)fK- Firing phases matrix for the transitionfKs- Cumulative firing phases matrixmode- Current firing mode of the transitiontransParam- Transition node parameters containing enabling/firing rulesR- Number of job classes in the networkoutspace- Output state space matrix to be populatedoutrate- Output rates matrix to be populatedoutprob- Output probabilities matrix to be populated- Throws:
IllegalArgumentException- if enabling conditions cannot be satisfied- See Also:
-
handleFireEvent
protected static State.EventHandleResult handleFireEvent(NetworkStruct sn, int ind, GlobalSync glevent, List<Matrix> glspace, List<Matrix> outglspace, Matrix inspace, Matrix spaceBuf, Matrix spaceSrv, Matrix spaceVar, Matrix fK, Matrix fKs, int mode, TransitionNodeParam transParam, int R, boolean isSimulation) Handles FIRE events for transitions in Stochastic Petri Net (SPN) event processing. This method processes the firing phase of a transition after it has been enabled, implementing the complete SPN firing semantics including: - Calculating the enabling degree (maximum number of concurrent firings) - Processing PRE events (token consumption from input places) - Processing POST events (token production to output places) - Managing server state transitions and phase changes - Generating all possible outcome states with their associated rates and probabilities The method supports multiple job classes, multi-server environments, and complex firing patterns through multinomial probability distributions for server allocation.- Parameters:
sn- Network structure containing the complete SPN model definitionind- Node index of the transition being firedglevent- Global synchronization event containing active and passive eventsglspace- Current global state space (list of states for each stateful node)outglspace- Output global state space to be updatedinspace- Input state space matrix for the transition nodespaceBuf- Buffer state space matrix (job queue states)spaceSrv- Server state space matrix (server allocation states)spaceVar- Variable state space matrix (phase variables)fK- Firing phases matrix for the transitionfKs- Cumulative firing phases matrixmode- Current firing mode of the transitiontransParam- Transition node parameters containing enabling/firing rulesR- Number of job classes in the networkoutspace- Output state space matrix to be populated with resulting statesoutrate- Output rates matrix to be populated with transition ratesoutprob- Output probabilities matrix to be populated with firing probabilities- Throws:
IllegalStateException- if the transition cannot be fired from the current stateArithmeticException- if probability calculations result in invalid values- See Also:
-
buildSpaceHashMap
public static Map<StatefulNode,Map<String, buildSpaceHashMapInteger>> (Map<StatefulNode, Matrix> space) -
buildSpaceHash
-
getHashOrAdd
Get hash ID for a state space, or add the state to the space if not found Migrated from MATLAB getHashOrAdd.m- Parameters:
sn- Network structureind- Node indexinspace- Input state space- Returns:
- Ret.getHashOrAddResult containing hash IDs and updated network structure
-
isValid
-
roundMarginalPreservingChains
Rounds a fractional marginal queue-length matrix (station x class) to integers with the largest remainder method, so that every closed chain keeps exactly its own population. Plain element-wise rounding does not: it can move a job between classes of the same chain or lose one altogether, which yields a state outside the state space (or inside a different chain population, hence a different steady state). Open chains are rounded element-wise. Modifiesnin place.- Parameters:
n- marginal queue lengths, stations by classessn- structure supplying the chain membership and populations
-
isValid
-
reachableSpaceGenerator
public static Ret.reachableSpaceGeneratorResult reachableSpaceGenerator(NetworkStruct sn, SolverOptions options) Generates state space restricted to states reachable from initial state Migrated from MATLAB reachableSpaceGenerator.m- Parameters:
sn- Network structureoptions- Solver options- Returns:
- Ret.reachableSpaceGeneratorResult containing reachable state spaces
-
spaceCachePublic
Make spaceCache method public Generates cache state space- Parameters:
n- Cache sizem- Number of itemsretrievalSystemCapacity- number of items that can be in the retrieval system simultaneously- Returns:
- Cache state space matrix
-
spaceClosedMulti
-
spaceClosedMultiCS
-
spaceClosedMultiCSBounded
-
spaceClosedSinglePublic
Make spaceClosedSingle method public Generates state space for single-class closed networks- Parameters:
M- Number of stationsN- Number of jobs- Returns:
- State space matrix
-
spaceGenerator
public static State.StateSpaceGeneratorResult spaceGenerator(NetworkStruct sn, Matrix cutoff, SolverOptions options) Generates the state space for a queueing network using a matrix cutoff. Each element of the cutoff matrix specifies the maximum population for the corresponding station-class combination.- Parameters:
sn- Network structurecutoff- Matrix of cutoff values with dimensions nstations × nclassesoptions- Solver options- Returns:
- State space generation result
- Throws:
IllegalArgumentException- if cutoff matrix dimensions don't match network structure
-
spaceGeneratorNodes
public static State.spaceGeneratorNodesResult spaceGeneratorNodes(NetworkStruct sn, Matrix cutoff, SolverOptions options) -
spaceLocalVarsPublic
Make spaceLocalVars method public Generates local variable state spaces- Parameters:
sn- Network structureind- Node index- Returns:
- Local variable state space
-