See Knuth D.E. (1981). The Art of Computer Programming, Seminumerical Algorithms, vol. 2, 2nd ed., Addison-Wesley, U.S.A. as a reference to random number generation.
Name | Default | Description |
---|---|---|
mean | 10 | Exponential mean |
seed | 1973272912 |
model TDelayExp "Transition with one input and one output connection" parameter Real mean=10 "Exponential mean"; parameter Integer seed=1973272912; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; Integer Xi(start=seed); Integer Xiplus; Integer m=2147483647; //(2^31) - 1 Integer a=7^5; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; //Multiplicative Linear Congruential Method Xiplus := mod(a*Xi, m); delay := -mean*ln(Xiplus/m); Xi := Xiplus; //The built in function only runs for a certain number of samples and then //breaks down //delay := -mean*ln(RandomUniform(time)); end when; end TDelayExp;
Name | Default | Description |
---|---|---|
mean | 10 | Mean of normal distribution |
standardDev | 1 | Standard deviation of normal distribution |
seed1 | 1973272912 | |
seed2 | 28864 |
model TDelayNormal "Transition with one input and one output connection" parameter Real mean=10 "Mean of normal distribution"; parameter Real standardDev=1 "Standard deviation of normal distribution"; parameter Integer seed1=1973272912; parameter Integer seed2=28864; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; Integer X1(start=seed1); Integer X1plus; Integer X2(start=seed2); Integer X2plus; Real YnormalStandard; Real Ynormal; Integer m=2147483647; //(2^31) - 1 Integer a=7^5; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; //Multiplicative Linear Congruential Method X1plus := mod(a*X1, m); X2plus := mod(a*X2, m); //Box-Mueller transformation method for normal distribution YnormalStandard := sqrt(-2*ln(X1plus/m))*cos(2*Modelica.Constants.pi*( X2plus/m)); Ynormal := mean + standardDev*YnormalStandard; delay := Ynormal; X1 := X1plus; X2 := X2plus; end when; end TDelayNormal;
Name | Default | Description |
---|---|---|
mean | 10 | Exponential mean |
model TDelayExpBIRNG "Transition with one input and one output connection" parameter Real mean=10 "Exponential mean"; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; //The built in function only runs for a certain number (quite large) // of samples and then miraculously creates extremly large values! delay := -mean*ln(RandomUniform(time)); end when; end TDelayExpBIRNG;
Name | Default | Description |
---|---|---|
center | 5.0 | Normal around center |
standardDev | 1.0 | Standard deviation of the normal distribution |
model TDelayNormalBIRNG "Transition with one input and one output connection" parameter Real center=5.0 "Normal around center"; parameter Real standardDev=1.0 "Standard deviation of the normal distribution"; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //set activation time when activated then last_activation_time = time; delay = center + standardDev*(RandomNormal(time)); end when; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; end TDelayNormalBIRNG;
Name | Default | Description |
---|---|---|
delay | 5 |
model TDelay "Transition with one input and one output connection" parameter Real delay=5; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //set activation time when activated then last_activation_time = time; end when; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; end TDelay;
Name | Default | Description |
---|---|---|
num_tokens_start | 0 | Initial number of tokens |
N | 1 | Capacity limit for tokens |
model P10Capacity "Place with one input and one output transition" parameter Integer num_tokens_start=0 "Initial number of tokens"; parameter Integer N=1 "Capacity limit for tokens"; Integer num_tokens(start=num_tokens_start) "number of tokens present on the place"; Boolean full; Integer new_num_tokens(start=num_tokens_start); Boolean tokenin; public PetriNets.Interfaces.SetPortIn inTransition; equation // Set new token number for next iteration num_tokens = pre(new_num_tokens); tokenin = inTransition.set and not full; when tokenin then new_num_tokens = num_tokens + 1; end when; full = num_tokens == N; // Report state to input and output transitions inTransition.state = full and not pre(tokenin); end P10Capacity;
Name | Default | Description |
---|---|---|
num_tokens_start | 0 | Initial number of tokens |
N | 1 | Capacity limit for tokens |
model P01Capacity "Place with one input and one output transition" parameter Integer num_tokens_start=0 "Initial number of tokens"; parameter Integer N=1 "Capacity limit for tokens"; Integer num_tokens(start=num_tokens_start) "number of tokens present on the place"; Boolean empty; Integer new_num_tokens(start=num_tokens_start); Boolean tokenout; Interfaces.FirePortOut outTransition; equation // Set new token number for next iteration num_tokens = pre(new_num_tokens); tokenout = outTransition.fire and not empty; when tokenout then new_num_tokens = num_tokens - 1; end when; empty = num_tokens == 0; // Report state to input and output transitions outTransition.state = not empty and not pre(tokenout); end P01Capacity;
Name | Default | Description |
---|---|---|
num_tokens_start | 0 | Initial number of tokens |
N | 1 | Capacity limit for tokens |
model P11Capacity "Place with one input and one output transition" parameter Integer num_tokens_start=0 "Initial number of tokens"; parameter Integer N=1 "Capacity limit for tokens"; Integer num_tokens(start=num_tokens_start) "number of tokens present on the place"; Boolean full; Boolean empty; Integer new_num_tokens(start=num_tokens_start); Boolean tokenin; Boolean tokenout; Boolean tokeninout; Real Qtotal; Real Qavg; public PetriNets.Interfaces.SetPortIn inTransition; PetriNets.Interfaces.FirePortOut outTransition; Modelica.Blocks.Interfaces.OutPort outTokens; Modelica.Blocks.Interfaces.BooleanOutPort Bchange; equation // Set new token number for next iteration num_tokens = pre(new_num_tokens); tokenin = inTransition.set and not full and not outTransition.fire; tokenout = outTransition.fire and not empty and not inTransition.set; tokeninout = inTransition.set and outTransition.fire; when {tokenin,tokenout,tokeninout} then new_num_tokens = if edge(tokenin) then num_tokens + 1 else if edge(tokenout ) then num_tokens - 1 else num_tokens; end when; full = num_tokens == N; empty = num_tokens == 0; // Report state to input and output transitions inTransition.state = full and not pre(tokenin) and not pre(tokeninout); outTransition.state = not empty and not pre(tokenout) and not pre(tokeninout) ; outTokens.signal[1] = num_tokens; Bchange.signal[1] = not (num_tokens == new_num_tokens); der(Qtotal) = num_tokens; Qavg = Qtotal/(time + 1e-3); end P11Capacity;
model TNoCondition "Transition with one input and one output connection" Boolean fire; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation fire = inTransition.state and not outTransition.state; inTransition.fire = fire; outTransition.set = fire; end TNoCondition;
Name | Default | Description |
---|---|---|
initialState | false | Initial value of state |
model Place11B "Place with one input and one output transition" parameter Boolean initialState=false "Initial value of state"; Boolean state(final start=initialState) "State of place"; protected Boolean newState(final start=initialState); public PetriNets.Interfaces.SetPortIn inTransition; PetriNets.Interfaces.FirePortOut outTransition; Modelica.Blocks.Interfaces.BooleanOutPort BState; equation // Set new state for next iteration state = pre(newState); newState = inTransition.set or state and not outTransition.fire; // Report state to input and output transitions inTransition.state = state; outTransition.state = state; BState.signal[1] = state; end Place11B;
model SynchronizeNoCondition "Transition with two input and one output connections" Boolean fire; PetriNets.Interfaces.FirePortIn inTransition1; PetriNets.Interfaces.FirePortIn inTransition2; PetriNets.Interfaces.SetPortOut outTransition; equation fire = inTransition1.state and inTransition2.state and not outTransition.state; inTransition1.fire = fire; inTransition2.fire = fire; outTransition.set = fire; end SynchronizeNoCondition;
model ParallelNoCondition "Transition with one input and two output connections" Boolean fire; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition1; PetriNets.Interfaces.SetPortOut outTransition2; equation fire = inTransition.state and not (outTransition1.state or outTransition2.state); inTransition.fire = fire; outTransition1.set = fire; outTransition2.set = fire; end ParallelNoCondition;
Name | Default | Description |
---|---|---|
alpha | 1 | Weibull shape parameter alpha |
beta | 2 | Weibull shape parameter beta |
seed | 1973272912 |
model TDelayWeibull "Transition with one input and one output connection" parameter Real alpha=1 "Weibull shape parameter alpha"; parameter Real beta=2 "Weibull shape parameter beta"; parameter Integer seed=1973272912; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; Integer Xi(start=seed); Integer Xiplus; Integer m=2147483647; //(2^31) - 1 Integer a=7^5; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; //Multiplicative Linear Congruential Method Xiplus := mod(a*Xi, m); delay := (-(1/alpha)*ln(1 - Xiplus/m))^(1/beta); Xi := Xiplus; //The built in function only runs for a certain number of samples and then //breaks down //delay := -mean*ln(RandomUniform(time)); end when; end TDelayWeibull;
Name | Default | Description |
---|---|---|
min | 0 | Uniform between min..max |
max | 1 | Uniform between min..max |
model TDelayUniformBIRNG "Transition with one input and one output connection" parameter Real min=0 "Uniform between min..max"; parameter Real max=1 "Uniform between min..max"; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //set activation time when activated then last_activation_time = time; delay = min + (max - min)*(RandomUniform(time)); end when; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; end TDelayUniformBIRNG;
Name | Default | Description |
---|---|---|
alpha | 1 | Weibull shape parameter alpha |
beta | 2 | Weibull shape parameter beta |
model TDelayWeibullBIRNG "Transition with one input and one output connection" parameter Real alpha=1 "Weibull shape parameter alpha"; parameter Real beta=2 "Weibull shape parameter beta"; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; delay := (-(1/alpha)*ln(1 - RandomUniform(time)))^(1/beta); end when; end TDelayWeibullBIRNG;
Name | Default | Description |
---|---|---|
min | 0 | Uniform between min..max |
max | 1 | Uniform between min..max |
seed | 1973272912 |
model TDelayUniform "Transition with one input and one output connection" parameter Real min=0 "Uniform between min..max"; parameter Real max=1 "Uniform between min..max"; parameter Integer seed=1973272912; Boolean activated; Boolean delay_passed; Boolean fire; Real last_activation_time; Real delay; Integer Xi(start=seed); Integer Xiplus; Integer m=2147483647; //(2^31) - 1 Integer a=7^5; PetriNets.Interfaces.FirePortIn inTransition; PetriNets.Interfaces.SetPortOut outTransition; equation //activation of transition activated = inTransition.state; //activated and delay passed delay_passed = activated and ((time - delay) > last_activation_time); //fire command fire = activated and delay_passed and not outTransition.state; //propagate firing to in and output places inTransition.fire = fire; outTransition.set = fire; //set activation time algorithm when activated then last_activation_time := time; Xiplus := mod(a*Xi, m); delay := min + (max - min)*(Xiplus/m); Xi := Xiplus; end when; end TDelayUniform;