Test Arc.

within PNlib.Components;

model TA "Test Arc"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  parameter Real testValue = 1 "marking that has to be exceeded to enable firing"
  parameter Boolean realTestArc = true "real Test arc >, Test arc >="
  parameter Boolean normalArc = true "Double arc: test and normal arc?"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean animateWeightTIarc = settings.animateWeightTIarc "only for transition animation and display (Do not change!)";
  Integer testColor[3] "only for transition animation and display (Do not change!)";
  Interfaces.TransitionIn inPlace(active = outTransition.active, fire = outTransition.fire, arcWeight = if normalArc then 0 else outTransition.arcWeight, arcWeightint = if normalArc then 0 else outTransition.arcWeightint, disTransition = outTransition.disTransition, instSpeed = if normalArc then 0 else outTransition.instSpeed, prelimSpeed = if normalArc then 0 else outTransition.prelimSpeed, maxSpeed = if normalArc then 0 else outTransition.maxSpeed) "connector for place"
  Interfaces.PlaceOut outTransition(t = inPlace.t, tint = inPlace.tint, minTokens = inPlace.minTokens, minTokensint = inPlace.minTokensint, enable = inPlace.enable, fed = inPlace.fed, decreasingFactor = inPlace.decreasingFactor, disPlace = inPlace.disPlace, tokenInOut = inPlace.tokenInOut, arcType = if realTestArc then PNlib.Types.ArcType.RealTestArc else PNlib.Types.ArcType.TestArc, testValue = testValue, testValueint = testValueInt, normalArc = normalArc, speedSum = inPlace.speedSum) "connector for transition"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Integer testValueInt "integer test value (for generating events!)";
equation
  if outTransition.disPlace then
    testValueInt = integer(testValue);
  else
    testValueInt = 1;
  end if;
  //****ANIMATION BEGIN****//
  if inPlace.t > testValue and settings.animateTIarc then
    testColor = {0, 255, 0};
  elseif settings.animateTIarc then
    testColor = {255, 0, 0};
  else
    testColor = {255, 255, 255};
  end if;
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  assert((outTransition.disPlace and testValue - testValueInt <= 0.0) or not outTransition.disPlace, "Test arcs connected to discrete places must have integer test values.");
  assert(testValue >= inPlace.minTokens, "Test values must be greater or equal than minimum values.");
  //****ERROR MESSENGES END****//
end TA;


Continuous Transition.

within PNlib.Components;

model TC "Continuous Transition"
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  Real maximumSpeed = 1 "maximum speed"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean fire "Does the transition fire?";
  Real instantaneousSpeed "instantaneous speed";
  Real actualSpeed = if fire then instantaneousSpeed else 0.0;
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean animateSpeed = settings.animateSpeed "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  Interfaces.TransitionIn[nIn] inPlaces(each active = activation.active, each fire = fire, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each disTransition = false, each instSpeed = instantaneousSpeed, each prelimSpeed = prelimSpeed, each maxSpeed = maximumSpeed, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, fed = fed, disPlace = disPlaceIn, enable = enableIn, speedSum = speedSumIn, decreasingFactor = decreasingFactorIn, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  Interfaces.TransitionOut[nOut] outPlaces(each active = activation.active, each fire = fire, each enabledByInPlaces = true, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each disTransition = false, each instSpeed = instantaneousSpeed, each prelimSpeed = prelimSpeed, each maxSpeed = maximumSpeed, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, emptied = emptied, disPlace = disPlaceOut, speedSum = speedSumOut, decreasingFactor = decreasingFactorOut) if nOut > 0 "connector for output places"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Real prelimSpeed "preliminary speed";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real speedSumIn[nIn] "Input speeds of continuous input places";
  Real speedSumOut[nOut] "Output speeds of continuous output places";
  Real decreasingFactorIn[nIn] "decreasing factors of input places";
  Real decreasingFactorOut[nOut] "decreasing factors of output places";
  Real testValue[nIn] "test values of test or inhibitor arcs";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer tIntIn[nIn] "integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "integer tokens of output places (for generating events!)";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean fed[nIn] "Are the input places fed by their input transitions?";
  Boolean emptied[nOut] "Are the output places emptied by their output transitions?";
  Boolean disPlaceIn[nIn] "Are the input places discrete?";
  Boolean disPlaceOut[nOut] "Are the output places discrete?";
  Boolean enableIn[nIn] "Is the transition enabled by all its discrete input transitions?";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationCon activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut, arcWeightIntIn = arcWeightIntIn, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, fed = fed, emptied = emptied, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //firing process
  Boolean fire_ = Functions.OddsAndEnds.allTrue(/* hack for Dymola 2017 */Functions.OddsAndEnds.boolOr(enableIn, not disPlaceIn));
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //preliminary speed calculation
  prelimSpeed = Functions.preliminarySpeed(nIn = nIn, nOut = nOut, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut, speedSumIn = speedSumIn, speedSumOut = speedSumOut, maximumSpeed = maximumSpeed, weaklyInputActiveVec = activation.weaklyInputActiveVec, weaklyOutputActiveVec = activation.weaklyOutputActiveVec);
  //firing process
  fire = fire_ and activation.active and not maximumSpeed <= 0;
  //instantaneous speed calculation
  instantaneousSpeed = min(min(min(decreasingFactorIn), min(decreasingFactorOut))*maximumSpeed, prelimSpeed);
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  color = if (fire and settings.animateTransition) then {255, 255, 0} else {255, 255, 255};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//  hier noch Message gleiches Kantengewicht und auch Kante dis Place!!
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  //****ERROR MESSENGES END****//
end TC;


Discrete Transition with delay .

within PNlib.Components;

model TD "Discrete Transition with delay "
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  Real delay = 1 "delay of timed transition"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean active "Is the transition active?";
  Boolean fire "Does the transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = delayPassed, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fire, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = delayPassed, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fire, each enabledByInPlaces = enabledByInPlaces, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean showDelay = settings.showTime "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Real firingTime "next putative firing time";
  Real fireTime "for transition animation";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real delay_ = if delay < 1e-6 then 1e-6 else delay "due to event problems if delay==0";
  Integer tIntIn[nIn] "integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean delayPassed(start = false, fixed = true) "Is the delay passed?";
  Boolean ani "for transition animation";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDis activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //reset active when delay passed
  active = activation.active and not pre(delayPassed);
  //save next putative firing time
  when active then
    firingTime = time + delay_;
  end when;
  //delay passed?
  delayPassed = active and time >= firingTime;
  //firing process
  fire = if nOut == 0 then enabledByInPlaces else enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fire then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  //****ERROR MESSENGES END****//
end TD;


Stochastic Transition with delay.

within PNlib.Components;

model TDS "Stochastic Transition with delay"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  parameter PNlib.Types.DistributionType distributionType = PNlib.Types.DistributionType.Exponential "distribution type of delay"
  parameter Real h = 1 "probability density"
  parameter Real a = 0 "Lower Limit"
  parameter Real b = 1 "Upper Limit"
  parameter Real c = 0.5 "Most likely value"
  parameter Real mu = 0.5 "Expected value"
  parameter Real sigma = 1/6 "Standard deviation"
  parameter Real E[:] = {1, 2, 3, 4, 5, 6} "Events of Discrete Distribution"
  parameter Real P[:] = {1/6, 1/6, 1/6, 1/6, 1/6, 1/6} "Probability of Discrete Distribution"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  discrete Real putFireTime "putative firing time";
  discrete Real putDelay "putative Dealy";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean animatePutFireTime = settings.animatePutFireTime "only for transition animation and display (Do not change!)";
  Boolean animateHazardFunc = settings.animateHazardFunc "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  parameter Integer localSeed = PNlib.Functions.Random.counter() "Local seed to initialize random number generator"
  Boolean active "Is the transition active?";
  Boolean fire "Does the transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = delayPassed, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fire, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, tokenInOut = tokenInOut, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = delayPassed, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fire, each enabledByInPlaces = enabledByInPlaces, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  discrete Integer state128[4] "state of random number generator";
  Real r128 "random number";
  outer PNlib.Components.Settings settings "global settings for animation and display";
  discrete Real fireTime "for transition animation";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer tIntIn[nIn] "Integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "Integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean delayPassed(start = false, fixed = true) "Is the delay passed?";
  Boolean ani "for transition animation";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean tokenInOut[nIn] "Have the tokens of input places changed?";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDis activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //Has at least one input place changed its tokens?
  Blocks.anyTrue tokenChange(vec = tokenInOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //reset active when delay passed
  active = activation.active and not pre(delayPassed);
  //delay passed?
  delayPassed = active and time >= putFireTime;
  //firing process
  fire = if nOut == 0 then enabledByInPlaces else enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fire then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  assert(h > 0 or distributionType <> PNlib.Types.DistributionType.Exponential, "The probability density must be greater than zero");
  assert((a < b and a <= c and c <= b) or distributionType <> PNlib.Types.DistributionType.Triangular, "The Lower Limit must be less than or equal to the Most likely value and the Most likely value must be less than or equal to the Upper Limit but he Lower Limit must be less than the Upper Limit");
  assert(a < b or distributionType <> PNlib.Types.DistributionType.Uniform, "The Lower Limit must be less than the Upper Limit");
  assert(Functions.OddsAndEnds.isEqual(sum(P), 1.0, 1e-6) or distributionType <> PNlib.Types.DistributionType.Discrete, "The Probability sum Probability of Discrete Distribution has to be equal to 1");
  assert(size(E, 1) == size(P, 1) or distributionType <> PNlib.Types.DistributionType.Discrete, "Discrete probability distribution must have the same number of events and probabilities");
  //****ERROR MESSENGES END****//
algorithm
  //****MAIN BEGIN****//
  //generate random putative fire time according to Next-Reaction method of Gibson and Bruck
  when pre(fire) then //17.06.11 Reihenfolge getauscht!
    (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128));
    if distributionType == PNlib.Types.DistributionType.Exponential then
      putDelay := PNlib.Functions.Random.randomexp(h, r128);
    elseif distributionType == PNlib.Types.DistributionType.Triangular then
      putDelay := PNlib.Functions.Random.randomtriangular(a, b, c, r128);
    elseif distributionType == PNlib.Types.DistributionType.Uniform then
      putDelay := Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
    elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
      putDelay := Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
    else
      putDelay := max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
    end if;
  end when;
  when active then
    putFireTime := time + putDelay;
  end when;
  //****MAIN END****//
initial equation
  //to initialize the random generator otherwise the first random number is always the same in every simulation run
  if distributionType == PNlib.Types.DistributionType.Exponential then
    putDelay = PNlib.Functions.Random.randomexp(h, r128);
  elseif distributionType == PNlib.Types.DistributionType.Triangular then
    putDelay = PNlib.Functions.Random.randomtriangular(a, b, c, r128);
  elseif distributionType == PNlib.Types.DistributionType.Uniform then
    putDelay = Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
  elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
    putDelay = Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
  else
    putDelay = max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
  end if;
  putFireTime = time + putDelay;
initial algorithm
  // Generate initial state from localSeed and globalSeed
  state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, settings.globalSeed);
  (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128);
end TDS;


Discrete Transition with event.

within PNlib.Components;

model TE "Discrete Transition with event"
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  Real event[:] = {1, 2, 3} "Event time of timed transition"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean active "Is the transition active?";
  Boolean fire "Does the transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = eventPassed, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fire, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = eventPassed, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fire, each enabledByInPlaces = enabledByInPlaces, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean showevent = settings.showTime "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Real firingTime "next putative firing time";
  Real fireTime "for transition animation";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real event_[:] = Functions.OddsAndEnds.addElement(event) "solves last-time problem";
  Integer tIntIn[nIn] "integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean eventPassed(start = false, fixed = true) "Is the event passed?";
  Boolean ani "for transition animation";
  Integer eventIndex(start = 1, fixed = true);
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDis activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //****BLOCKS END****//
algorithm
  when time >= event_[eventIndex] then
    eventIndex := eventIndex + 1;
  end when;
equation
  //****MAIN BEGIN****//
  //reset active when event passed
  active = activation.active and not pre(eventPassed);
  //save next putative firing time
  when active then
    firingTime = event_[eventIndex];
  end when;
  //event passed?
  eventPassed = active and time >= firingTime;
  //firing process
  fire = if nOut == 0 then enabledByInPlaces else enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fire then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  assert(Functions.OddsAndEnds.eventCheck(event), "The event time must be greater than zero and must be specified in a larger order");
  //****ERROR MESSENGES END****//
end TE;


Stochastic Transition with event.

within PNlib.Components;

model TES "Stochastic Transition with event"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  parameter PNlib.Types.DistributionType distributionType = PNlib.Types.DistributionType.Exponential "distribution type of event"
  parameter Real h = 1 "probability density"
  parameter Real a = 0 "Lower Limit"
  parameter Real b = 1 "Upper Limit"
  parameter Real c = 0.5 "Most likely value"
  parameter Real mu = 0.5 "Expected value"
  parameter Real sigma = 1/6 "Standard deviation"
  parameter Real E[:] = {1, 2, 3, 4, 5, 6} "Events of Discrete Distribution"
  parameter Real P[:] = {1/6, 1/6, 1/6, 1/6, 1/6, 1/6} "Probability of Discrete Distribution"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  discrete Real putFireTime "putative firing time";
  discrete Real putEvent "putative Event";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean animatePutFireTime = settings.animatePutFireTime "only for transition animation and display (Do not change!)";
  Boolean animateHazardFunc = settings.animateHazardFunc "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  parameter Integer localSeed = PNlib.Functions.Random.counter() "Local seed to initialize random number generator"
  Boolean TimeOver;
  Boolean active "Is the transition active?";
  Boolean fire "Does the transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = eventPassed, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fire, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, tokenInOut = tokenInOut, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = eventPassed, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fire, each enabledByInPlaces = enabledByInPlaces, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  discrete Integer state128[4] "state of random number generator";
  Real r128 "random number";
  outer PNlib.Components.Settings settings "global settings for animation and display";
  discrete Real fireTime "for transition animation";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer tIntIn[nIn] "Integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "Integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean eventPassed(start = false, fixed = true) "Is the event passed?";
  Boolean ani "for transition animation";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean tokenInOut[nIn] "Have the tokens of input places changed?";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDis activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //Has at least one input place changed its tokens?
  Blocks.anyTrue tokenChange(vec = tokenInOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //reset active when event passed
  active = activation.active and not pre(eventPassed);
  //event passed?
  eventPassed = active and time >= putFireTime;
  //firing process
  fire = if nOut == 0 then enabledByInPlaces else enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fire then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  assert(h > 0 or distributionType <> PNlib.Types.DistributionType.Exponential, "The probability density must be greater than zero");
  assert((a < b and a <= c and c <= b) or distributionType <> PNlib.Types.DistributionType.Triangular, "The Lower Limit must be less than or equal to the Most likely value and the Most likely value must be less than or equal to the Upper Limit but he Lower Limit must be less than the Upper Limit");
  assert(a < b or distributionType <> PNlib.Types.DistributionType.Uniform, "The Lower Limit must be less than the Upper Limit");
  assert(Functions.OddsAndEnds.isEqual(sum(P), 1.0, 1e-6) or distributionType <> PNlib.Types.DistributionType.Discrete, "The Probability sum Probability of Discrete Distribution has to be equal to 1");
  assert(size(E, 1) == size(P, 1) or distributionType <> PNlib.Types.DistributionType.Discrete, "Discrete probability distribution must have the same number of events and probabilities");
  //****ERROR MESSENGES END****//
algorithm
  //****MAIN BEGIN****//
  TimeOver := time >= putFireTime;
  //generate random putative fire time according to Next-Reaction method of Gibson and Bruck
  when pre(TimeOver) then //17.06.11 Reihenfolge getauscht!
    (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128));
    if distributionType == PNlib.Types.DistributionType.Exponential then
      putEvent := PNlib.Functions.Random.randomexp(h, r128);
    elseif distributionType == PNlib.Types.DistributionType.Triangular then
      putEvent := PNlib.Functions.Random.randomtriangular(a, b, c, r128);
    elseif distributionType == PNlib.Types.DistributionType.Uniform then
      putEvent := Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
    elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
      putEvent := Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
    else
      putEvent := max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
    end if;
    putFireTime := time + putEvent;
  end when;
  //****MAIN END****//
initial equation
  //to initialize the random generator otherwise the first random number is always the same in every simulation run
  if distributionType == PNlib.Types.DistributionType.Exponential then
    putEvent = PNlib.Functions.Random.randomexp(h, r128);
  elseif distributionType == PNlib.Types.DistributionType.Triangular then
    putEvent = PNlib.Functions.Random.randomtriangular(a, b, c, r128);
  elseif distributionType == PNlib.Types.DistributionType.Uniform then
    putEvent = Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
  elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
    putEvent = Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
  else
    putEvent = max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
  end if;
  putFireTime = time + putEvent;
initial algorithm
  // Generate initial state from localSeed and globalSeed
  state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, settings.globalSeed);
  (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128);
end TES;


Discrete Transition with fire duration.

within PNlib.Components;

model TFD "Discrete Transition with fire duration"
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  Real duration = 1 "duration of timed transition"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean activeIn "Is the transition Input active?";
  Boolean activeOut "Is the transition Output active?";
  Boolean fireIn "Does the transition Input fire?";
  Boolean fireOut "Does the transition Output fire?";
  Boolean fire(start = false, fixed = true) "Is the Transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = durationPassedIn, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fireIn, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = durationPassedOut, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fireOut, each enabledByInPlaces = true, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean showDuration = settings.showTime "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Real firingTimeIn "next putative firing time";
  Real firingTimeOut "next putative firing time";
  Real fireTime "for transition animation";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real duration_ = if duration < 1e-6 then 1e-6 else duration "due to event problems if duration==0";
  Integer tIntIn[nIn] "integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=real test arc,  3=test arc, 4=real inhibitor arc, 5=inhibitor arc, 6=read arc";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean durationPassedIn(start = false, fixed = true) "Is the duration passed?";
  Boolean durationPassedOut(start = false, fixed = true) "Is the duration passed?";
  Boolean ani "for transition animation";
  Boolean prefire(start = false, fixed = true) "Was the Transition fire?";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDisIn activationIn(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, tIn = tIn, tIntIn = tIntIn, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, minTokens = minTokens, minTokensInt = minTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn);
  Blocks.activationDisOut activationOut(nOut = nOut, tOut = tOut, tIntOut = tIntOut, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, maxTokens = maxTokens, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //reset active when duration passed
  activeIn = activationIn.active and not pre(durationPassedIn) and not prefire;
  activeOut = activationOut.active and not pre(durationPassedOut) and prefire;
  //save next putative firing time
  when activeIn then
    firingTimeIn = time + 1e-6;
  end when;
  when activeOut then
    firingTimeOut = if time >= firingTimeIn + duration_ - 1e-6 then time + 1e-6 else firingTimeIn + duration_ - 1e-6;
  end when;
  //is the Transition fire?
  prefire = pre(fire);
  when {fireIn, fireOut} then
    if durationPassedOut then
      fire = false;
    else
      fire = true;
    end if;
  end when;
  //duration passed?
  durationPassedIn = activeIn and time >= firingTimeIn;
  durationPassedOut = activeOut and time >= firingTimeOut;
  //firing process
  fireIn = enabledByInPlaces;
  fireOut = enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fireIn then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  //****ERROR MESSENGES END****//
end TFD;


Stochastic Transition with fire duration.

within PNlib.Components;

model TFDS "Stochastic Transition with fire duration"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  parameter PNlib.Types.DistributionType distributionType = PNlib.Types.DistributionType.Exponential "distribution type of duration"
  parameter Real h = 1 "probability density"
  parameter Real a = 0 "Lower Limit"
  parameter Real b = 1 "Upper Limit"
  parameter Real c = 0.5 "Most likely value"
  parameter Real mu = 0.5 "Expected value"
  parameter Real sigma = 1/6 "Standard deviation"
  parameter Real E[:] = {1, 2, 3, 4, 5, 6} "Events of Discrete Distribution"
  parameter Real P[:] = {1/6, 1/6, 1/6, 1/6, 1/6, 1/6} "Probability of Discrete Distribution"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  discrete Real putDuration "putative firing time";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean animateputDuration = settings.animatePutFireTime "only for transition animation and display (Do not change!)";
  Boolean animateHazardFunc = settings.animateHazardFunc "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  parameter Integer localSeed = PNlib.Functions.Random.counter() "Local seed to initialize random number generator"
  Boolean activeIn "Is the transition Input active?";
  Boolean activeOut "Is the transition Output active?";
  Boolean fireIn "Does the transition Input fire?";
  Boolean fireOut "Does the transition Output fire?";
  Boolean fire(start = false, fixed = true) "Is the Transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = durationPassedIn, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fireIn, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, tokenInOut = tokenInOut, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = durationPassedOut, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fireOut, each enabledByInPlaces = true, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  discrete Integer state128[4] "state of random number generator";
  Real r128 "random number";
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Real firingTimeIn "next putative firing time";
  Real firingTimeOut "next putative firing time";
  discrete Real fireTime "for transition animation";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer tIntIn[nIn] "Integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "Integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=test arc, 3=inhibitor arc, 4=read arc";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean durationPassedIn(start = false, fixed = true) "Is the duration passed?";
  Boolean durationPassedOut(start = false, fixed = true) "Is the duration passed?";
  Boolean ani "for transition animation";
  Boolean prefire(start = false, fixed = true) "Was the Transition fire?";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean tokenInOut[nIn] "Have the tokens of input places changed?";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDisIn activationIn(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, tIn = tIn, tIntIn = tIntIn, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, minTokens = minTokens, minTokensInt = minTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn);
  Blocks.activationDisOut activationOut(nOut = nOut, tOut = tOut, tIntOut = tIntOut, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, maxTokens = maxTokens, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //Has at least one input place changed its tokens?
  Blocks.anyTrue tokenChange(vec = tokenInOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  //reset active when duration passed
  activeIn = activationIn.active and not pre(durationPassedIn) and not prefire;
  activeOut = activationOut.active and not pre(durationPassedOut) and prefire;
  //save next putative firing time
  when activeIn then
    firingTimeIn = time + 1e-6;
  end when;
  when activeOut then
    firingTimeOut = if time >= firingTimeIn + putDuration - 1e-6 then time + 1e-6 else firingTimeIn + putDuration - 1e-6;
  end when;
  //is the Transition fire?
  prefire = pre(fire);
  when {fireIn, fireOut} then
    if durationPassedOut then
      fire = false;
    else
      fire = true;
    end if;
  end when;
  //duration passed?
  durationPassedIn = activeIn and time >= firingTimeIn;
  durationPassedOut = activeOut and time >= firingTimeOut;
  //firing process
  fireIn = enabledByInPlaces;
  fireOut = enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fireIn then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  assert(h > 0 or distributionType <> PNlib.Types.DistributionType.Exponential, "The probability density must be greater than zero");
  assert((a < b and a <= c and c <= b) or distributionType <> PNlib.Types.DistributionType.Triangular, "The Lower Limit must be less than or equal to the Most likely value and the Most likely value must be less than or equal to the Upper Limit but he Lower Limit must be less than the Upper Limit");
  assert(a < b or distributionType <> PNlib.Types.DistributionType.Uniform, "The Lower Limit must be less than the Upper Limit");
  assert(Functions.OddsAndEnds.isEqual(sum(P), 1.0, 1e-6) or distributionType <> PNlib.Types.DistributionType.Discrete, "The Probability sum Probability of Discrete Distribution has to be equal to 1");
  assert(size(E, 1) == size(P, 1) or distributionType <> PNlib.Types.DistributionType.Discrete, "Discrete probability distribution must have the same number of events and probabilities");
  //****ERROR MESSENGES END****//
algorithm
  //****MAIN BEGIN****//
  //generate random putative fire time according to Next-Reaction method of Gibson and Bruck
  when pre(fireOut) then //17.06.11 Reihenfolge getauscht!
    (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128));
    if distributionType == PNlib.Types.DistributionType.Exponential then
      putDuration := PNlib.Functions.Random.randomexp(h, r128);
    elseif distributionType == PNlib.Types.DistributionType.Triangular then
      putDuration := PNlib.Functions.Random.randomtriangular(a, b, c, r128);
    elseif distributionType == PNlib.Types.DistributionType.Uniform then
      putDuration := Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
    elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
      putDuration := Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
    else
      putDuration := max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
    end if;
  end when;
  //****MAIN END****//
initial equation
  //to initialize the random generator otherwise the first random number is always the same in every simulation run
  if distributionType == PNlib.Types.DistributionType.Exponential then
    putDuration = PNlib.Functions.Random.randomexp(h, r128);
  elseif distributionType == PNlib.Types.DistributionType.Triangular then
    putDuration = PNlib.Functions.Random.randomtriangular(a, b, c, r128);
  elseif distributionType == PNlib.Types.DistributionType.Uniform then
    putDuration = Modelica.Math.Distributions.Uniform.quantile(max(r128, 10^(-10)), a, b);
  elseif distributionType == PNlib.Types.DistributionType.TruncatedNormal then
    putDuration = Modelica.Math.Distributions.TruncatedNormal.quantile(max(r128, 10^(-10)), a, b, mu, sigma);
  else
    putDuration = max(PNlib.Functions.Random.randomdis(E, P, r128), 1e-6);
  end if;
initial algorithm
  // Generate initial state from localSeed and globalSeed
  state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, settings.globalSeed);
  (r128, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128);
end TFDS;


Discrete Transition.

within PNlib.Components;

model TT "Discrete Transition"
  parameter Integer nIn(min = 0) = 0 "number of input places"
  parameter Integer nOut(min = 0) = 0 "number of output places"
  //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****//
  parameter Real tactIntervall = 1 "tact intervall of timed transition"
  parameter Real tactStart = 1 "tact start of timed transition"
  Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places"
  Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places"
  Boolean firingCon = true "additional firing condition"
  //****MODIFIABLE PARAMETERS AND VARIABLES END****//
  Boolean active "Is the transition active?";
  Boolean fire "Does the transition fire?";
  PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = tactPassed, arcWeight = arcWeightIn, arcWeightint = arcWeightIntIn, each fire = fire, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tIn, tint = tIntIn, arcType = arcType, minTokens = minTokens, minTokensint = minTokensInt, disPlace = disPlaceIn, enable = enableIn, testValue = testValue, testValueint = testValueInt, normalArc = normalArc) if nIn > 0 "connector for input places"
  PNlib.Interfaces.TransitionOut outPlaces[nOut](each active = tactPassed, arcWeight = arcWeightOut, arcWeightint = arcWeightIntOut, each fire = fire, each enabledByInPlaces = enabledByInPlaces, each disTransition = true, each instSpeed = 0, each prelimSpeed = 0, each maxSpeed = 0, t = tOut, tint = tIntOut, maxTokens = maxTokens, maxTokensint = maxTokensInt, disPlace = disPlaceOut, enable = enableOut) if nOut > 0 "connector for output places"
protected
  outer PNlib.Components.Settings settings "global settings for animation and display";
  Boolean showTransitionName = settings.showTransitionName "only for transition animation and display (Do not change!)";
  Boolean showTakt = settings.showTime "only for transition animation and display (Do not change!)";
  Real color[3] "only for transition animation and display (Do not change!)";
  Real tIn[nIn] "tokens of input places";
  Real tOut[nOut] "tokens of output places";
  Real testValue[nIn] "test values of input arcs";
  Real firingTime "next putative firing time";
  Real fireTime "for transition animation";
  Real minTokens[nIn] "minimum tokens of input places";
  Real maxTokens[nOut] "maximum tokens of output places";
  Integer tIntIn[nIn] "integer tokens of input places (for generating events!)";
  Integer tIntOut[nOut] "integer tokens of output places (for generating events!)";
  PNlib.Types.ArcType arcType[nIn] "type of input arcs 1=normal, 2=test arc, 3=inhibitor arc, 4=read arc";
  Integer arcWeightIntIn[nIn] "Integer arc weights of discrete input places (for generating events!)";
  Integer arcWeightIntOut[nOut] "Integer arc weights of discrete output places (for generating events!)";
  Integer minTokensInt[nIn] "Integer minimum tokens of input places (for generating events!)";
  Integer maxTokensInt[nOut] "Integer maximum tokens of output places (for generating events!)";
  Integer testValueInt[nIn] "Integer test values of input arcs (for generating events!)";
  Boolean normalArc[nIn] "1=no, 2=yes, i.e. double arc: test and normal arc or inhibitor and normal arc";
  Boolean disPlaceIn[nIn] "Are the input places discrete or continuous? true=discrete";
  Boolean disPlaceOut[nOut] "Are the output places discrete or continuous? true=discrete";
  Boolean enableIn[nIn] "Is the transition enabled by input places?";
  Boolean enableOut[nOut] "Is the transition enabled by output places?";
  Boolean tactPassed(start = false, fixed = true) "Is the tact passed?";
  Boolean ani "for transition animation";
  //****BLOCKS BEGIN****// since no events are generated within functions!!!
  //activation process
  Blocks.activationDis activation(testValue = testValue, testValueInt = testValueInt, normalArc = normalArc, nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, tIntIn = tIntIn, tIntOut = tIntOut, arcType = arcType, arcWeightIn = arcWeightIn, arcWeightIntIn = arcWeightIntIn, arcWeightOut = arcWeightOut, arcWeightIntOut = arcWeightIntOut, minTokens = minTokens, maxTokens = maxTokens, minTokensInt = minTokensInt, maxTokensInt = maxTokensInt, firingCon = firingCon, disPlaceIn = disPlaceIn, disPlaceOut = disPlaceOut);
  //Is the transition enabled by all input places?
  Boolean enabledByInPlaces = Functions.OddsAndEnds.allTrue(enableIn);
  //Is the transition enabled by all output places?
  Boolean enabledByOutPlaces = Functions.OddsAndEnds.allTrue(enableOut);
  //****BLOCKS END****//
equation
  //****MAIN BEGIN****//
  active = activation.active;
  //save next putative firing time
  //due to event problems if tactStart==0
  when active and sample(max(tactStart, 10^(-8)), max(tactIntervall, 10^(-6))) then
    firingTime = time;
  end when;
  //tact passed?
  tactPassed = active and abs(time - firingTime) <= 10^(-9);
  //firing process
  fire = if nOut == 0 then enabledByInPlaces else enabledByOutPlaces;
  //****MAIN END****//
  //****ANIMATION BEGIN****//
  when fire then
    fireTime = time;
    ani = true;
  end when;
  color = if (fireTime + settings.timeFire >= time and settings.animateTransition and ani) then {255, 255, 0} else {0, 0, 0};
  //****ANIMATION END****//
  //****ERROR MESSENGES BEGIN****//
  for i in 1:nIn loop
    if disPlaceIn[i] then
      arcWeightIntIn[i] = integer(arcWeightIn[i]);
    else
      arcWeightIntIn[i] = 1;
    end if;
    assert((disPlaceIn[i] and arcWeightIn[i] - arcWeightIntIn[i] <= 0.0) or not disPlaceIn[i], "Input arcs connected to discrete places must have integer weights.");
    assert(arcWeightIn[i] >= 0, "Input arc weights must be positive.");
  end for;
  for i in 1:nOut loop
    if disPlaceOut[i] then
      arcWeightIntOut[i] = integer(arcWeightOut[i]);
    else
      arcWeightIntOut[i] = 1;
    end if;
    assert((disPlaceOut[i] and arcWeightOut[i] - arcWeightIntOut[i] <= 0.0) or not disPlaceOut[i], "Output arcs connected to discrete places must have integer weights.");
    assert(arcWeightOut[i] >= 0, "Output arc weights must be positive.");
  end for;
  //****ERROR MESSENGES END****//
end TT;


within PNlib;

package Constants "contains constants which are used in the Petri net component models"
  constant Real inf = 3.40282e+038 "Biggest Real number such that inf and -inf are representable on the machine";
  constant Integer Integer_inf = 1073741823 "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine";
  constant Real eps = 1.e-15 "Biggest number such that 1.0 + eps = 1.0";
  constant Real almost_eps = 1.e-9;
end Constants;


newton.

within PNlib.Examples.ConTest;

model Conflict
  extends Modelica.Icons.Example;
  PNlib.Components.TC T1(nOut = 1)
  PNlib.Components.TC T2(maximumSpeed = 2, nIn = 1, nOut = 1)
  PNlib.Components.TC T3(nIn = 1, nOut = 1)
  PNlib.Components.PC P1(nIn = 1, nOut = 2)
  PNlib.Components.PC P2(nIn = 1)
  PNlib.Components.PC P3(nIn = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T2.inPlaces[1])
  connect(T2.outPlaces[1], P2.inTransition[1])
  connect(T3.inPlaces[1], P1.outTransition[2])
  connect(P3.inTransition[1], T3.outPlaces[1])
end Conflict;


within PNlib.Examples.ConTest;

model ConflictLoop
  extends Modelica.Icons.Example;
  PNlib.Components.TC T1(nOut = 1, nIn = 2, arcWeightOut = {3}, arcWeightIn = {2, 1})
  PNlib.Components.TC T2(nIn = 1, nOut = 1, maximumSpeed = 4)
  PNlib.Components.TC T3(nIn = 1, nOut = 1, maximumSpeed = 2)
  PNlib.Components.PC P1(nIn = 1, nOut = 2)
  PNlib.Components.PC P2(nIn = 1, nOut = 1, startMarks = 2)
  PNlib.Components.PC P3(nIn = 1, nOut = 1, startMarks = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T2.inPlaces[1])
  connect(T2.outPlaces[1], P2.inTransition[1])
  connect(T3.inPlaces[1], P1.outTransition[2])
  connect(P3.inTransition[1], T3.outPlaces[1])
  connect(P2.outTransition[1], T1.inPlaces[1])
  connect(P3.outTransition[1], T1.inPlaces[2])
end ConflictLoop;


within PNlib.Examples.ConTest;

model LoopAndArcweight
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PC P1(nOut = 1, nIn = 1, startMarks = 1)
  PNlib.Components.TC T1(nIn = 1, nOut = 2, arcWeightIn = {3}, arcWeightOut = {2, 2})
  PNlib.Components.PC P2(nIn = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(P1.inTransition[1], T1.outPlaces[1])
  connect(P2.inTransition[1], T1.outPlaces[2])
end LoopAndArcweight;


within PNlib.Examples.ConTest;

model PCtoTC
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PC P1(nOut = 1, startMarks = 1)
  PNlib.Components.TC T1(nIn = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
end PCtoTC;


within PNlib.Examples.ConTest;

model PCtoTCfunction
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PC P1(nOut = 1, startMarks = 1)
  PNlib.Components.TC T1(arcWeightIn = {P1.t}, nIn = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
end PCtoTCfunction;


within PNlib.Examples.ConTest;

model SinglePC
  extends Modelica.Icons.Example;
  PNlib.Components.PC P1
  inner PNlib.Components.Settings settings
end SinglePC;


within PNlib.Examples.ConTest;

model SingleTC
  extends Modelica.Icons.Example;
  PNlib.Components.TC T1
  inner PNlib.Components.Settings settings
end SingleTC;


within PNlib.Examples.ConTest;

model Speed
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.TC T1(nOut = 1, maximumSpeed = 2)
  PNlib.Components.PC P1(nIn = 2, nOut = 1)
  PNlib.Components.TC T2(nOut = 1, arcWeightOut = {2})
  PNlib.Components.TC T3(nIn = 1, nOut = 1, arcWeightIn = {4}, arcWeightOut = {4})
  PNlib.Components.PC P2(nIn = 1)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(T2.outPlaces[1], P1.inTransition[2])
  connect(T3.inPlaces[1], P1.outTransition[1])
  connect(T3.outPlaces[1], P2.inTransition[1])
end Speed;


within PNlib.Examples.ConTest;

model TCtoPC
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.TC T1(nOut = 1)
  PNlib.Components.PC P1(nIn = 1)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
end TCtoPC;


within PNlib.Examples.ConTest;

model TCtoPCfunction
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.TC T1(arcWeightOut = {P1.t}, nOut = 1)
  PNlib.Components.PC P1(nIn = 1, startMarks = 1)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
end TCtoPCfunction;


within PNlib.Examples.ConTest;

model ZeroArcWeight
  extends Modelica.Icons.Example;
  PNlib.Components.PC P1(nOut = 1)
  PNlib.Components.PC P2(nOut = 1, startMarks = 10)
  PNlib.Components.TC T1(nIn = 2, nOut = 1, arcWeightIn = {0, 1})
  PNlib.Components.PC P3(nIn = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(P2.outTransition[1], T1.inPlaces[2])
  connect(T1.outPlaces[1], P3.inTransition[1])
end ZeroArcWeight;


within PNlib.Examples.ConTest;

model ZeroPlace
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.TC T1(nOut = 1)
  PNlib.Components.PC P1(nIn = 1, nOut = 1)
  PNlib.Components.TC T2(nIn = 1, nOut = 1)
  PNlib.Components.PC P2(nIn = 1)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T2.inPlaces[1])
  connect(T2.outPlaces[1], P2.inTransition[1])
end ZeroPlace;


within PNlib.Examples.DisTest;

model ConflictBeneBaB
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1)
  PNlib.Components.TD T1(arcWeightIn = {4}, nIn = 1, nOut = 1)
  PNlib.Components.TD T2(arcWeightIn = {3}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  inner PNlib.Components.Settings settings
  PNlib.Components.TD T3(arcWeightIn = {1}, nIn = 1, nOut = 1)
  PNlib.Components.TD T4(arcWeightIn = {1}, nIn = 1, nOut = 1)
  PNlib.Components.TD T5(arcWeightIn = {1}, nIn = 1, nOut = 1)
  PNlib.Components.PD P4(nIn = 1)
  PNlib.Components.PD P5(maxTokens = 1, nIn = 1, nOut = 1, startTokens = 1)
  PNlib.Components.PD P7(benefitType = PNlib.Types.BenefitType.BranchAndBound, enablingBeneOut = {6, 5, 3, 4, 2, 0}, enablingType = PNlib.Types.EnablingType.Benefit, nIn = 1, nOut = 6, startTokens = 4)
  PNlib.Components.TD T7(arcWeightOut = {4}, delay = 2, nIn = 1, nOut = 1)
  PNlib.Components.TD T6(arcWeightIn = {1}, nIn = 1, nOut = 1)
  PNlib.Components.PD P6(nIn = 1)
equation
  connect(T6.inPlaces[1], P7.outTransition[6])
  connect(T6.outPlaces[1], P6.inTransition[1])
  connect(T4.outPlaces[1], P5.inTransition[1])
  connect(T5.outPlaces[1], P4.inTransition[1])
  connect(T3.outPlaces[1], P3.inTransition[1])
  connect(T2.outPlaces[1], P2.inTransition[1])
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(P7.outTransition[5], T4.inPlaces[1])
  connect(P7.outTransition[4], T5.inPlaces[1])
  connect(P7.outTransition[3], T3.inPlaces[1])
  connect(P7.outTransition[2], T2.inPlaces[1])
  connect(P7.outTransition[1], T1.inPlaces[1])
  connect(T7.outPlaces[1], P7.inTransition[1])
  connect(T7.inPlaces[1], P5.outTransition[1])
end ConflictBeneBaB;


within PNlib.Examples.DisTest;

model ConflictBeneGreedy
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(enablingType = PNlib.Types.EnablingType.Benefit, nIn = 1, nOut = 2, startTokens = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end ConflictBeneGreedy;


within PNlib.Examples.DisTest;

model ConflictBeneQuotient
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(benefitType = PNlib.Types.BenefitType.BenefitQuotient, enablingBeneOut = {10, 7}, enablingType = PNlib.Types.EnablingType.Benefit, nIn = 1, nOut = 2, startTokens = 9)
  PNlib.Components.TD T1(arcWeightIn = {5}, nIn = 1, nOut = 1)
  PNlib.Components.TD T2(arcWeightIn = {3}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(arcWeightOut = {4}, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end ConflictBeneQuotient;


within PNlib.Examples.DisTest;

model ConflictPrio
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1, nOut = 2, startTokens = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end ConflictPrio;


within PNlib.Examples.DisTest;

model ConflictProb
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1, startTokens = 2, nOut = 2, enablingType = PNlib.Types.EnablingType.Probability, enablingProbOut = {0.5, 0.5}, localSeedIn = 1, localSeedOut = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1, localSeedIn = 3, localSeedOut = 4)
  PNlib.Components.PD P3(nIn = 1, localSeedIn = 5, localSeedOut = 6)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end ConflictProb;


within PNlib.Examples.DisTest;

model DisLoopAndArcweight
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nOut = 1, nIn = 1, startTokens = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1, arcWeightIn = {2}, arcWeightOut = {3})
  inner PNlib.Components.Settings settings
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P1.inTransition[1])
end DisLoopAndArcweight;


within PNlib.Examples.DisTest;

model EightConflictProb
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(startTokens = 1, enablingType = PNlib.Types.EnablingType.Probability, nOut = 8, localSeedIn = 1, localSeedOut = 2)
  PNlib.Components.TD T1(nIn = 1)
  PNlib.Components.TD T2(nIn = 1)
  PNlib.Components.TD T3(nIn = 1)
  PNlib.Components.TD T4(nIn = 1)
  PNlib.Components.TD T5(nIn = 1)
  PNlib.Components.TD T6(nIn = 1)
  PNlib.Components.TD T7(nIn = 1)
  PNlib.Components.TD T8(nIn = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T3.inPlaces[1], P1.outTransition[3])
  connect(T4.inPlaces[1], P1.outTransition[4])
  connect(T5.inPlaces[1], P1.outTransition[5])
  connect(T6.inPlaces[1], P1.outTransition[6])
  connect(T7.inPlaces[1], P1.outTransition[7])
  connect(T8.inPlaces[1], P1.outTransition[8])
end EightConflictProb;


within PNlib.Examples.DisTest;

model FiveTimes
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 3)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1, nOut = 1, startTokens = 3)
  PNlib.Components.PD P4(nIn = 1)
  PNlib.Components.PD P5(nIn = 1, nOut = 1, startTokens = 3)
  PNlib.Components.PD P6(nIn = 1)
  PNlib.Components.PD P7(nIn = 1, nOut = 1, startTokens = 3)
  PNlib.Components.PD P8(nIn = 1)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TE T2(event = {1, 3, 4, 5, 6, 9}, nIn = 1, nOut = 1)
  PNlib.Components.TFD T3(nIn = 1, nOut = 1)
  PNlib.Components.TT T4(nIn = 1, nOut = 1, tactStart = 2)
  PNlib.Components.TE T6(arcWeightOut = {3, 3, 3, 3, 3}, event = {5.5}, nOut = 5)
  PNlib.Components.PC P9(nIn = 1, nOut = 1, startMarks = 3)
  PNlib.Components.PC P10(nIn = 1)
  PNlib.Components.TC T5(nIn = 1, nOut = 1)
equation
  connect(T6.outPlaces[5], P9.inTransition[1])
  connect(P9.outTransition[1], T5.inPlaces[1])
  connect(T5.outPlaces[1], P10.inTransition[1])
  connect(T4.outPlaces[1], P8.inTransition[1])
  connect(P7.outTransition[1], T4.inPlaces[1])
  connect(T6.outPlaces[4], P7.inTransition[1])
  connect(T6.outPlaces[3], P5.inTransition[1])
  connect(T6.outPlaces[2], P3.inTransition[1])
  connect(T6.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P6.inTransition[1])
  connect(P5.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P4.inTransition[1])
  connect(P3.outTransition[1], T2.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
end FiveTimes;


within PNlib.Examples.DisTest;

model InputConflictBeneBaB
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(benefitType = PNlib.Types.BenefitType.BranchAndBound, enablingBeneIn = {6, 5}, enablingType = PNlib.Types.EnablingType.Benefit, maxTokens = 5, nIn = 2, nOut = 1)
  PNlib.Components.TD T1(arcWeightIn = {3}, nIn = 1)
  PNlib.Components.TD T2(arcWeightOut = {3}, nIn = 1, nOut = 1)
  PNlib.Components.TD T3(arcWeightOut = {2}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(startTokens = 5, nOut = 1)
  PNlib.Components.PD P3(startTokens = 5, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T1.inPlaces[1], P1.outTransition[1])
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P3.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[2])
end InputConflictBeneBaB;


within PNlib.Examples.DisTest;

model InputConflictBeneGreedy
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(enablingBeneIn = {1, 2}, enablingType = PNlib.Types.EnablingType.Benefit, maxTokens = 2, nIn = 2, nOut = 1)
  PNlib.Components.TD T1(nIn = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.TD T3(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(startTokens = 5, nOut = 1)
  PNlib.Components.PD P3(startTokens = 5, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P3.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[2])
  connect(T1.inPlaces[1], P1.outTransition[1])
end InputConflictBeneGreedy;


within PNlib.Examples.DisTest;

model InputConflictBeneQuotient
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(benefitType = PNlib.Types.BenefitType.BenefitQuotient, enablingBeneIn = {6, 5}, enablingType = PNlib.Types.EnablingType.Benefit, maxTokens = 5, nIn = 2, nOut = 1)
  PNlib.Components.TD T1(arcWeightIn = {3}, nIn = 1)
  PNlib.Components.TD T2(arcWeightOut = {3}, nIn = 1, nOut = 1)
  PNlib.Components.TD T3(arcWeightOut = {2}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(startTokens = 5, nOut = 1)
  PNlib.Components.PD P3(startTokens = 5, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P3.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[2])
  connect(T1.inPlaces[1], P1.outTransition[1])
end InputConflictBeneQuotient;


within PNlib.Examples.DisTest;

model InputConflictPrio
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(maxTokens = 2, nIn = 2, nOut = 1)
  PNlib.Components.TD T1(nIn = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.TD T3(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(startTokens = 5, nOut = 1)
  PNlib.Components.PD P3(startTokens = 5, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P3.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[2])
  connect(T1.inPlaces[1], P1.outTransition[1])
end InputConflictPrio;


within PNlib.Examples.DisTest;

model InputConflictProb
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(maxTokens = 2, nIn = 2, nOut = 1, enablingType = PNlib.Types.EnablingType.Probability, localSeedIn = 1, localSeedOut = 2)
  PNlib.Components.TD T1(nIn = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.TD T3(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(startTokens = 5, nOut = 1, localSeedIn = 3, localSeedOut = 4)
  PNlib.Components.PD P3(startTokens = 5, nOut = 1, localSeedIn = 5, localSeedOut = 6)
  inner PNlib.Components.Settings settings
equation
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P3.outTransition[1], T3.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[2])
  connect(T1.inPlaces[1], P1.outTransition[1])
end InputConflictProb;


within PNlib.Examples.DisTest;

model NoInputConflict
  extends Modelica.Icons.Example;
  PNlib.Components.TD T1(nOut = 1)
  PNlib.Components.TD T2(delay = 2, nOut = 1)
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(enablingPrioIn = {2, 1}, maxTokens = 1, nIn = 2)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
  connect(T2.outPlaces[1], P1.inTransition[2])
end NoInputConflict;


within PNlib.Examples.DisTest;

model OutputConflictBeneBaB
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(benefitType = PNlib.Types.BenefitType.BranchAndBound, enablingBeneOut = {8, 7}, enablingType = PNlib.Types.EnablingType.Benefit, minTokens = 8, nIn = 1, nOut = 2, startTokens = 15)
  PNlib.Components.TD T1(arcWeightIn = {4}, nIn = 1, nOut = 1)
  PNlib.Components.TD T2(arcWeightIn = {3}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(arcWeightOut = {2}, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end OutputConflictBeneBaB;


within PNlib.Examples.DisTest;

model OutputConflictBeneGreedy
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(enablingBeneOut = {2, 1}, enablingType = PNlib.Types.EnablingType.Benefit, minTokens = 2, nIn = 1, nOut = 2, startTokens = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end OutputConflictBeneGreedy;


within PNlib.Examples.DisTest;

model OutputConflictBeneQuotient
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(benefitType = PNlib.Types.BenefitType.BenefitQuotient, enablingBeneOut = {8, 7}, enablingType = PNlib.Types.EnablingType.Benefit, minTokens = 8, nIn = 1, nOut = 2, startTokens = 8)
  PNlib.Components.TD T1(arcWeightIn = {4}, nIn = 1, nOut = 1)
  PNlib.Components.TD T2(arcWeightIn = {3}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(arcWeightOut = {2}, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end OutputConflictBeneQuotient;


within PNlib.Examples.DisTest;

model OutputConflictPrio
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1, startTokens = 2, nOut = 2, minTokens = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end OutputConflictPrio;


within PNlib.Examples.DisTest;

model OutputConflictProb
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1, startTokens = 2, nOut = 2, enablingProbOut = {0.5, 0.5}, minTokens = 2, enablingType = PNlib.Types.EnablingType.Probability, localSeedIn = 1, localSeedOut = 2)
  PNlib.Components.TD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1, localSeedIn = 3, localSeedOut = 4)
  PNlib.Components.PD P3(nIn = 1, localSeedIn = 5, localSeedOut = 6)
  PNlib.Components.TD T3(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(T3.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
end OutputConflictProb;


within PNlib.Examples.DisTest;

model PDtoTD
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nOut = 1, startTokens = 10)
  PNlib.Components.TD T1(nIn = 1)
equation
  connect(T1.inPlaces[1], P1.outTransition[1])
end PDtoTD;


within PNlib.Examples.DisTest;

model PDtoTDfunction
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nOut = 1, startTokens = 10)
  PNlib.Components.TD T1(arcWeightIn = {P1.t}, nIn = 1)
equation
  connect(T1.inPlaces[1], P1.outTransition[1])
end PDtoTDfunction;


within PNlib.Examples.DisTest;

model PDtoTT
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nOut = 1, startTokens = 10)
  PNlib.Components.TT T1(nIn = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
end PDtoTT;


within PNlib.Examples.DisTest;

model PrioTest
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(enablingPrioOut = {4, 3, 2, 1}, nIn = 1, nOut = 4, startTokens = 1)
  PNlib.Components.TD T1(nOut = 1)
  PNlib.Components.TD T2(nIn = 1, nOut = 1)
  PNlib.Components.TD T3(nIn = 1, nOut = 1)
  PNlib.Components.TD T4(nIn = 1, nOut = 1)
  PNlib.Components.TD T5(nIn = 1, nOut = 1)
  PNlib.Components.PD P2(maxTokens = 1, nIn = 1)
  PNlib.Components.PD P3(maxTokens = 1, nIn = 1)
  PNlib.Components.PD P4(maxTokens = 1, nIn = 1)
  PNlib.Components.PD P5(maxTokens = 1, nIn = 1)
equation
  connect(T5.outPlaces[1], P5.inTransition[1])
  connect(T4.outPlaces[1], P4.inTransition[1])
  connect(T3.outPlaces[1], P3.inTransition[1])
  connect(T2.outPlaces[1], P2.inTransition[1])
  connect(P1.outTransition[4], T5.inPlaces[1])
  connect(P1.outTransition[1], T2.inPlaces[1])
  connect(P1.outTransition[3], T4.inPlaces[1])
  connect(P1.outTransition[2], T3.inPlaces[1])
  connect(T1.outPlaces[1], P1.inTransition[1])
end PrioTest;


within PNlib.Examples.DisTest;

model SinglePD
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1
  inner PNlib.Components.Settings settings
end SinglePD;


within PNlib.Examples.DisTest;

model SingleTD
  extends Modelica.Icons.Example;
  PNlib.Components.TD T1
  inner PNlib.Components.Settings settings
end SingleTD;


within PNlib.Examples.DisTest;

model SixConflictProb
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(startTokens = 1, enablingType = PNlib.Types.EnablingType.Probability, nOut = 6, localSeedIn = 1, localSeedOut = 2)
  PNlib.Components.TD T1(nIn = 1)
  PNlib.Components.TD T2(nIn = 1)
  PNlib.Components.TD T3(nIn = 1)
  PNlib.Components.TD T4(nIn = 1)
  PNlib.Components.TD T5(nIn = 1)
  PNlib.Components.TD T6(nIn = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T3.inPlaces[1], P1.outTransition[3])
  connect(T4.inPlaces[1], P1.outTransition[4])
  connect(T5.inPlaces[1], P1.outTransition[5])
  connect(T6.inPlaces[1], P1.outTransition[6])
end SixConflictProb;


within PNlib.Examples.DisTest;

model TDtoPD
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nOut = 0, nIn = 1)
  PNlib.Components.TD T1(nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P1.inTransition[1], T1.outPlaces[1])
end TDtoPD;


within PNlib.Examples.DisTest;

model TDtoPDfunction
  extends Modelica.Icons.Example;
  PNlib.Components.PD P1(nIn = 1, nOut = 0, startTokens = 1)
  PNlib.Components.TD T1(arcWeightOut = {P1.t}, nOut = 1)
  inner PNlib.Components.Settings settings
equation
  connect(P1.inTransition[1], T1.outPlaces[1])
end TDtoPDfunction;


within PNlib.Examples.DisTest;

model TEnoInput
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, startTokens = 0)
  PNlib.Components.TE T2(event = {0.5, 2.5, 2.8}, nOut = 1)
equation
  connect(T2.outPlaces[1], P1.inTransition[1])
end TEnoInput;


within PNlib.Examples.DisTest;

model TEtest
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 0)
  PNlib.Components.TE T1(nIn = 1, nOut = 1)
  PNlib.Components.TE T2(event = {0.5, 2.5, 2.8}, nIn = 1, nOut = 1)
  PNlib.Components.PD P2(nIn = 1, nOut = 1, startTokens = 1)
equation
  connect(P2.inTransition[1], T1.outPlaces[1])
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(T1.inPlaces[1], P1.outTransition[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
end TEtest;


within PNlib.Examples.DisTest;

model TFDinputConflict
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 0)
  PNlib.Components.PD P2(enablingPrioIn = {2, 1}, maxTokens = 1, nIn = 2, nOut = 1, startTokens = 0)
  PNlib.Components.TFD T1(nIn = 1, nOut = 1)
  PNlib.Components.TE T2(event = {1, 2.5, 3.8}, nOut = 1)
  PNlib.Components.TE T3(event = {1.8, 2.3, 3.9}, nIn = 1)
  PNlib.Components.TE T4(event = {1.5, 3.5}, nOut = 1)
equation
  connect(T4.outPlaces[1], P2.inTransition[2])
  connect(P2.outTransition[1], T3.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
end TFDinputConflict;


within PNlib.Examples.DisTest;

model TFDoutCap
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 0)
  PNlib.Components.PD P2(maxTokens = 1, nIn = 1, nOut = 1, startTokens = 1)
  PNlib.Components.TFD T1(nIn = 1, nOut = 1)
  PNlib.Components.TE T2(event = {1, 2.5, 3.8}, nOut = 1)
  PNlib.Components.TE T3(event = {1.5, 4}, nIn = 1)
equation
  connect(T2.outPlaces[1], P1.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(P2.outTransition[1], T3.inPlaces[1])
end TFDoutCap;


within PNlib.Examples.DisTest;

model TFDoutputConflict
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(enablingType = PNlib.Types.EnablingType.Probability, localSeedIn = 1, localSeedOut = 2, nIn = 1, nOut = 2, startTokens = 0)
  PNlib.Components.PD P2(localSeedIn = 3, localSeedOut = 4, nIn = 1)
  PNlib.Components.TFD T1(nIn = 1, nOut = 1)
  PNlib.Components.TD T3(nOut = 1)
  PNlib.Components.TFD T2(nIn = 1, nOut = 1)
  PNlib.Components.PD P3(localSeedIn = 5, localSeedOut = 6, nIn = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(T2.inPlaces[1], P1.outTransition[2])
  connect(T2.outPlaces[1], P3.inTransition[1])
  connect(T3.outPlaces[1], P1.inTransition[1])
end TFDoutputConflict;


within PNlib.Examples.DisTest;

model TFDtest
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 0, nOut = 1, startTokens = 5)
  PNlib.Components.PD P2(nIn = 1)
  PNlib.Components.TFD T1(nIn = 1, nOut = 1)
equation
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
end TFDtest;


within PNlib.Examples.DisTest;

model TTcircle
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 1)
  PNlib.Components.TT T1(nIn = 1, nOut = 1, tactIntervall = 1, tactStart = 0)
  PNlib.Components.PD P2(nIn = 1, nOut = 1)
  PNlib.Components.TT T2(nIn = 1, nOut = 1, tactIntervall = 2, tactStart = 1.5)
equation
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(P2.outTransition[1], T2.inPlaces[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
end TTcircle;


within PNlib.Examples.DisTest;

model Ttest
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1, nOut = 1, startTokens = 0)
  PNlib.Components.TE T2(event = {1, 2, 3, 4}, nOut = 1)
  PNlib.Components.PD P2(nIn = 1, nOut = 2)
  PNlib.Components.T T1(arcWeightIn = {2}, arcWeightOut = {3}, nIn = 1, nOut = 1)
  PNlib.Components.T T3(arcWeightIn = {2}, arcWeightOut = {2}, nIn = 1, nOut = 1)
  PNlib.Components.PD P3(nIn = 1)
  PNlib.Components.T T4(arcWeightIn = {2}, arcWeightOut = {2}, nIn = 1, nOut = 1)
  PNlib.Components.PD P4(nIn = 1)
equation
  connect(T4.inPlaces[1], P2.outTransition[2])
  connect(T4.outPlaces[1], P4.inTransition[1])
  connect(T3.outPlaces[1], P3.inTransition[1])
  connect(T3.inPlaces[1], P2.outTransition[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(P1.outTransition[1], T1.inPlaces[1])
  connect(T2.outPlaces[1], P1.inTransition[1])
end Ttest;


within PNlib.Examples.DisTest;

model TTtoPD
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PD P1(nIn = 1)
  PNlib.Components.TT T1(nOut = 1)
equation
  connect(T1.outPlaces[1], P1.inTransition[1])
end TTtoPD;


within PNlib.Examples.ExtTest;

model ArcswithPCtoTC
  extends Modelica.Icons.Example;
  inner PNlib.Components.Settings settings
  PNlib.Components.PC P1(nOut = 1, startMarks = 1)
  PNlib.Components.PC P2(nIn = 1)
  PNlib.Components.PC P3(nOut = 1, startMarks = 1)
  PNlib.Components.PC P4(nIn = 1)
  PNlib.Components.PC P5(nOut = 1, startMarks = 1)
  PNlib.Components.PC P6(nIn = 1)
  PNlib.Components.PC P7(nOut = 1, startMarks = 1)
  PNlib.Components.PC P8(nIn = 1)
  PNlib.Components.TC T1(nIn = 1, nOut = 1)
  PNlib.Components.TC T2(nIn = 1, nOut = 1)
  PNlib.Components.TC T3(nIn = 1, nOut = 1)
  PNlib.Components.TC T4(nIn = 1, nOut = 1)
  PNlib.Components.TA TA1
  PNlib.Components.TA TA2(realTestArc = false)
  PNlib.Components.IA IA1
  PNlib.Components.IA IA2(realInhibitorArc = false)
equation
  connect(T4.outPlaces[1], P8.inTransition[1])
  connect(T3.outPlaces[1], P6.inTransition[1])
  connect(T2.outPlaces[1], P4.inTransition[1])
  connect(T1.outPlaces[1], P2.inTransition[1])
  connect(IA2.outTransition, T4.inPlaces[1])
  connect(P7.outTransition[1], IA2.inPlace)
  connect(IA1.outTransition, T3.inPlaces[1])
  connect(P5.outTransition[1], IA1.inPlace)
  connect(TA2.outTransition, T2.inPlaces[1])
  connect(P3.outTransition[1], TA2.inPlace)
  connect(TA1.outTransition, T1.inPlaces[1])
  connect(P1.outTransition[1], TA1.inPlace)
end ArcswithPCtoTC;