text
stringlengths
1
4.74k
code
stringlengths
69
637k
Ideal sensor to measure the rotation of a Flange. Measures a normalized angle in a 1D normalized rotational system. Cannot be connected to components from the Modelica.Mechanics.Rotational library.
within VehicleInterfaces.Mechanics.NormalisedRotational; model AngleSensor "Ideal sensor to measure the rotation of a Flange" extends Modelica.Icons.RoundSensor; Interfaces.Flange flange_a "flange to be measured" Modelica.Blocks.Interfaces.RealOutput phi "Absolute angle of flange as output signal" equation phi = flange_a.phi; 0 = flange_a.tau; end AngleSensor;
Collection of normalized rotational mechanics
within VehicleInterfaces.Mechanics; package NormalisedRotational "Collection of normalized rotational mechanics" extends Modelica.Icons.Package; end NormalisedRotational;
Applies a rotation to a Flange. Applies a normalized angle to a 1D normalized rotational system. Cannot be connected to components from the Modelica.Mechanics.Rotational library.
within VehicleInterfaces.Mechanics.NormalisedRotational; model Position "Applies a rotation to a Flange" parameter Boolean exact=true "True/false exact treatment/filtering the input signal"; parameter SI.Frequency f_crit=50 "If exact=false: critical frequency of filter to filter input signal" Interfaces.Flange flange_b "flange to be rotated" Modelica.Blocks.Interfaces.RealInput phi_ref "position to be applied" Types.NormalizedReal phi; protected parameter Real w_crit=2*Modelica.Constants.pi*f_crit "critical frequency in [1/s]"; constant Real af=1.3617 "Coefficient s of Bessel filter"; constant Real bf=0.6180 "Coefficient s*s of Bessel filter"; Real w; Real a; equation phi = flange_b.phi; w = der(phi); a = der(w); if exact then phi = phi_ref; else a = ((phi_ref - phi)*w_crit - af*w)*(w_crit/bf); end if; initial equation if not exact then phi = phi_ref; end if; end Position;
Applies a torque to a Flange. Applies a torque to a 1D normalized rotational system. Cannot be connected to components from the Modelica.Mechanics.Rotational library.
within VehicleInterfaces.Mechanics.NormalisedRotational; model Torque "Applies a torque to a Flange" Interfaces.Flange flange_b "Flange to be turned" Modelica.Blocks.Interfaces.RealInput tau "Torque to be applied" equation tau = -flange_b.tau; end Torque;
Collection of connector definitions
within VehicleInterfaces.Mechanics.NormalisedRotational; package Interfaces "Collection of connector definitions" extends Modelica.Icons.InterfacesPackage; end Interfaces;
Applies a force to a Flange. Applies a force to a 1D normalized translational system. Cannot be connected to components from the Modelica.Mechanics.Translational library.
within VehicleInterfaces.Mechanics.NormalisedTranslational; model Force "Applies a force to a Flange" Interfaces.Flange flange_b "Flange to be forced" Modelica.Blocks.Interfaces.RealInput force "Force to be applied" equation force = -flange_b.f; end Force;
Collection of normalized translational mechanics
within VehicleInterfaces.Mechanics; package NormalisedTranslational "Collection of normalized translational mechanics" extends Modelica.Icons.Package; end NormalisedTranslational;
Applies a position to a Flange. Applies a normalized position to a 1D normalized translational system. Cannot be connected to components from the Modelica.Mechanics.Translational library.
within VehicleInterfaces.Mechanics.NormalisedTranslational; model Position "Applies a position to a Flange" parameter Boolean exact=true "True/false exact treatment/filtering the input signal"; parameter SI.Frequency f_crit=50 "If exact=false: critical frequency of filter to filter input signal" Interfaces.Flange flange_b "flange to be positioned" Modelica.Blocks.Interfaces.RealInput position "position to be applied" Types.NormalizedReal s "Normalized position"; protected parameter Real w_crit=2*Modelica.Constants.pi*f_crit "Critical frequency in [1/s]"; constant Real af=1.3617 "Coefficient s of Bessel filter"; constant Real bf=0.6180 "Coefficient s*s of Bessel filter"; Real v; Real a; equation s = flange_b.s; if exact then s = position; v = 0; a = 0; else v = der(s); a = der(v); a = ((position - s)*w_crit - af*v)*(w_crit/bf); end if; initial equation if not exact then s = position; end if; end Position;
Ideal sensor to measure the position of a Flange. Measures a normalized position in a 1D normalized translational system. Cannot be connected to components from the Modelica.Mechanics.Translational library.
within VehicleInterfaces.Mechanics.NormalisedTranslational; model PositionSensor "Ideal sensor to measure the position of a Flange" extends Modelica.Icons.RectangularSensor; Interfaces.Flange flange_a "Flange to be measured" Modelica.Blocks.Interfaces.RealOutput position "Absolute position of flange as output signal" equation position = flange_a.s; 0 = flange_a.f; end PositionSensor;
Collection of connector definitions
within VehicleInterfaces.Mechanics.NormalisedTranslational; package Interfaces "Collection of connector definitions" extends Modelica.Icons.InterfacesPackage; end Interfaces;
Collection of powertrain mounts subsystem definition
within VehicleInterfaces; package PowertrainMounts "Collection of powertrain mounts subsystem definition" extends Modelica.Icons.VariantsPackage; end PowertrainMounts;
1 system rigid mount. Rigidly mounts one power train system such as the engine or transmission on one supporting system, usually the chassis.
within VehicleInterfaces.PowertrainMounts; model SingleSystemRigidMount "1 system rigid mount" extends Interfaces.SingleSystemMount; extends VehicleInterfaces.Icons.SingleMount; parameter SI.Position r_ChassisToMount1[3]={0,0,0} "Vector from chassis frame to mount_1 frame" Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount1(r= r_ChassisToMount1) equation connect(chassisFrameToMount1.frame_a, chassisFrame) connect(chassisFrameToMount1.frame_b, mount_1) end SingleSystemRigidMount;
3 system rigid mount. Rigidly mounts three power train systems such as the engine, transmission and driveline on one supporting system, usually the chassis.
within VehicleInterfaces.PowertrainMounts; model ThreeSystemRigidMount "3 system rigid mount" extends Interfaces.TripleSystemMount; extends VehicleInterfaces.Icons.MultipleMounts; parameter SI.Position r_ChassisToMount1[3]={0,0,0} "Vector from chassis frame to mount_1 frame" parameter SI.Position r_ChassisToMount2[3]={0,0,0} "Vector from chassis frame to mount_2 frame" parameter SI.Position r_ChassisToMount3[3]={0,0,0} "Vector from chassis frame to mount_3 frame" Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount1(r= r_ChassisToMount1, animation=false) Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount2( animation=false, r=r_ChassisToMount2) Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount3( animation=false, r=r_ChassisToMount3) equation connect(chassisFrameToMount1.frame_a, chassisFrame) connect(chassisFrameToMount1.frame_b, mount_1) connect(chassisFrameToMount2.frame_b, mount_2) connect(chassisFrameToMount3.frame_b, mount_3) connect(chassisFrameToMount2.frame_a, chassisFrame) connect(chassisFrameToMount3.frame_a, chassisFrame) end ThreeSystemRigidMount;
Powertrain Mounts Tutorial.
within VehicleInterfaces.PowertrainMounts; class Tutorial "Powertrain Mounts Tutorial" extends Modelica.Icons.Information; end Tutorial;
2 system rigid mount. Rigidly mounts two power train systems such as the engine and transmission on one supporting system, usually the chassis.
within VehicleInterfaces.PowertrainMounts; model TwoSystemRigidMount "2 system rigid mount" extends Interfaces.DualSystemMount; extends VehicleInterfaces.Icons.TwoMounts; parameter SI.Position r_ChassisToMount1[3]={0,0,0} "Vector from chassis frame to mount_1 frame" parameter SI.Position r_ChassisToMount2[3]={0,0,0} "Vector from chassis frame to mount_2 frame" Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount1( r=r_ChassisToMount1) Modelica.Mechanics.MultiBody.Parts.FixedTranslation chassisFrameToMount2( r=r_ChassisToMount2) equation connect(chassisFrameToMount1.frame_a, chassisFrame) connect(chassisFrameToMount2.frame_b, mount_2) connect(chassisFrameToMount1.frame_b, mount_1) connect(chassisFrameToMount2.frame_a, chassisFrame) end TwoSystemRigidMount;
Basic interface definition for a mounting system. This partial model defines the common interfaces required for a&nbsp;mounting subsystem. See the <a href=\"modelica://VehicleInterfaces.PowertrainMounts\">documentation</a> and <a href=\"modelica://VehicleInterfaces.PowertrainMounts.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.PowertrainMounts.Interfaces; partial model Base "Basic interface definition for a mounting system" Modelica.Mechanics.MultiBody.Interfaces.Frame_a chassisFrame "Chassis frame" end Base;
Two powertrain subsystem mounting interface definition. This partial model defines the interfaces required for two powertrain system mounting subsystem. This class should be extended to form a&nbsp;particular powertrain mounting model. See the <a href=\"modelica://VehicleInterfaces.PowertrainMounts\">documentation</a> and <a href=\"modelica://VehicleInterfaces.PowertrainMounts.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.PowertrainMounts.Interfaces; partial model DualSystemMount "Two powertrain subsystem mounting interface definition" extends Base; Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_1 "Powertrain system 1" Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_2 "Powertrain system 2" end DualSystemMount;
Collection of interface definitions for powertrain mounting system
within VehicleInterfaces.PowertrainMounts; package Interfaces "Collection of interface definitions for powertrain mounting system" extends Modelica.Icons.InterfacesPackage; end Interfaces;
Single powertrain subsystem mounting interface definition. This partial model defines the interfaces required for a&nbsp;single powertrain system mounting subsystem. This class should be extended to form a particular powertrain mounting model. See the <a href=\"modelica://VehicleInterfaces.PowertrainMounts\">documentation</a> and <a href=\"modelica://VehicleInterfaces.PowertrainMounts.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.PowertrainMounts.Interfaces; partial model SingleSystemMount "Single powertrain subsystem mounting interface definition" extends Base; Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_1 "Powertrain system 1" end SingleSystemMount;
Three powertrain subsystem mounting interface definition. This partial model defines the interfaces required for three powertrain system mounting subsystem. This class should be extended to form a&nbsp;particular powertrain mounting model. See the <a href=\"modelica://VehicleInterfaces.PowertrainMounts\">documentation</a> and <a href=\"modelica://VehicleInterfaces.PowertrainMounts.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.PowertrainMounts.Interfaces; partial model TripleSystemMount "Three powertrain subsystem mounting interface definition" extends Base; Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_1 "Powertrain system 1" Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_2 "Powertrain system 2" Modelica.Mechanics.MultiBody.Interfaces.Frame_b mount_3 "Powertrain system 3" end TripleSystemMount;
Circular road (perpendicular to world z-axis). The road is a&nbsp;circle described by "radius" and "width". The road surface parameters are defined as:
within VehicleInterfaces.Roads; model CircleRoad "Circular road (perpendicular to world z-axis)" extends VehicleInterfaces.Roads.Interfaces.Base( redeclare final function position = circlePosition (radius=radius, width=width), redeclare final function trackOffset = constantOffset, redeclare final function normal = circleNormal, redeclare final function headingDirection = circleHeadingDirection (radius=radius), redeclare final function frictionCoefficient = circleFrictionCoefficient (mu_fixed=mu)); parameter Boolean animation=true "= true, if road shall be visualized"; parameter SI.Radius radius "Radius of road"; parameter SI.Length width "Width of road"; parameter Real mu "Friction coefficient of road"; parameter Modelica.Mechanics.MultiBody.Types.Color roadColor={255,0,0} "Color of road"; constant Real pi=Modelica.Constants.pi; protected outer Modelica.Mechanics.MultiBody.World world; VehicleInterfaces.Roads.Internal.VisualizeSimpleRoads roadShape( ns=100, nw=10, s_min=0, s_max=2*pi*radius, w_min=-width/2, w_max=width/2, color=roadColor) if animation and world.enableAnimation; function r_middle "Determine point on road in the middle of the circle (w=0" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real radius=1 "Radius of circle"; output Real r_0[3]={radius*sin(s/radius),-radius*cos(s/radius),0}; algorithm r_0 := {radius*sin(s/radius),-radius*cos(s/radius),0}; end r_middle; function circlePosition "Determine point on road" import Modelica.Math.Vectors.normalize; extends VehicleInterfaces.Roads.Interfaces.positionBase; input SI.Radius radius=1 "Radius of circle"; input SI.Length width=1 "Width of road"; algorithm r_0 := r_middle(s, radius) + w*normalize(r_middle(s, radius)); end circlePosition; function constantOffset "Determine offset from road centre line" extends VehicleInterfaces.Roads.Interfaces.trackOffsetBase; algorithm trackOffset := {0,0,0}; end constantOffset; function circleNormal "Determine unit normal on road, given road surface parameters" extends VehicleInterfaces.Roads.Interfaces.normalBase; algorithm e_n_0 := {0,0,1}; end circleNormal; function circleHeadingDirection "Determine unit heading direction on road" extends VehicleInterfaces.Roads.Interfaces.headingDirectionBase; input SI.Radius radius=1 "Radius of circle"; algorithm e_s_0 := {cos(s/radius),sin(s/radius),0}; end circleHeadingDirection; function circleFrictionCoefficient "Determine friction coefficient at point on road" extends VehicleInterfaces.Roads.Interfaces.frictionCoefficientBase; input Real mu_fixed=1 "Friction coefficient"; algorithm mu := mu_fixed; end circleFrictionCoefficient; end CircleRoad;
Straight road along x-axis (perpendicular to world z-axis). The road is a line along the x-axis of the world system. The road surface parameters are defined as:
within VehicleInterfaces.Roads; model FlatRoad "Straight road along x-axis (perpendicular to world z-axis)" extends VehicleInterfaces.Icons.Road; extends VehicleInterfaces.Roads.Interfaces.Base( redeclare final function position = linePosition, redeclare final function trackOffset = constantOffset (offset=offset), redeclare final function normal = lineNormal, redeclare final function headingDirection = lineHeadingDirection, redeclare final function frictionCoefficient = lineFrictionCoefficient (mu_fixed=mu)); parameter Boolean animation=true "= true, if road shall be visualized"; parameter Real mu=0.5 "Friction coefficient of road"; parameter Modelica.Mechanics.MultiBody.Types.Color roadColor={255,0,0} "Color of road" parameter SI.Length width=8 "Width of road" parameter SI.Position x_min=-100 "Roads is visualized in the range [x_min .. x_max]" parameter SI.Position x_max=100 "Roads is visualized in the range [x_min .. x_max]" parameter SI.Distance offset=0 "Offset from the road centre line"; protected outer Modelica.Mechanics.MultiBody.World world; VehicleInterfaces.Roads.Internal.VisualizeSimpleRoads roadShape( ns=2, nw=2, s_min=x_min, s_max=x_max, w_min=-width/2, w_max=width/2, color=roadColor) if animation and world.enableAnimation; function linePosition "Determine point on road" extends VehicleInterfaces.Roads.Interfaces.positionBase; algorithm r_0 := {s,w,0}; end linePosition; function constantOffset "Determine offset from road centre line" extends VehicleInterfaces.Roads.Interfaces.trackOffsetBase; input SI.Distance offset=0; algorithm trackOffset := {0,offset,0}; end constantOffset; function lineNormal "Determine unit normal on road" extends VehicleInterfaces.Roads.Interfaces.normalBase; algorithm e_n_0 := {0,0,1}; end lineNormal; function lineHeadingDirection "Determine unit heading direction on road" extends VehicleInterfaces.Roads.Interfaces.headingDirectionBase; algorithm e_s_0 := {1,0,0}; end lineHeadingDirection; function lineFrictionCoefficient "Determine friction coefficient at point on road" extends VehicleInterfaces.Roads.Interfaces.frictionCoefficientBase; input Real mu_fixed=1 "Friction coefficient"; algorithm mu := mu_fixed; end lineFrictionCoefficient; end FlatRoad;
Collection of road definitions
within VehicleInterfaces; package Roads "Collection of road definitions" extends Modelica.Icons.VariantsPackage; end Roads;
Roads Tutorial
within VehicleInterfaces.Roads; class Tutorial "Roads Tutorial" extends Modelica.Icons.Information; //rest of definition ... <strong>end</strong> FlatRoad; </pre></blockquote> </li> <li>In redeclaring the functions we have also introduced new parameters <strong>mu</strong> and <strong>offset</strong> that need to be added to the model to define the friction coefficient of the road and the track offset from the road centre line.</li> <li>The <strong>FlatRoad</strong> model included in this package also includes animation of the road surface but this is not essential to the definition of the road and will not be described in this tutorial.</li> <li>The road model is complete and can now be used.</li> </ol> </html>")); end Tutorial;
Check that wheel contact point calculation is properly working with road model. Model to check that the tire contact patch calculation is working correctly with the road models.
within VehicleInterfaces.Roads.Examples; model CheckContactCalculation "Check that wheel contact point calculation is properly working with road model" extends Modelica.Icons.Example; parameter SI.Radius wheelRadius=1 "Radius of wheel"; SI.Angle phi; SI.Radius radius_wheel; Real axis_wheel[3]; SI.Position r_circle[3]={road.radius*sin(phi),-road.radius*cos(phi),0}; VehicleInterfaces.Roads.Examples.Utilities.DummyTyre tyre( wheelRadius=wheelRadius, e_axis=Modelica.Math.Vectors.normalize(axis_wheel), r_wheel={radius_wheel*sin(phi),-radius_wheel*cos(phi),1 + sin(phi)/20}) inner VehicleInterfaces.Roads.CircleRoad road( radius=50, width=8, mu=0.5, roadColor={100,100,100}) inner Modelica.Mechanics.MultiBody.World world( enableAnimation=true, axisLength=20, n={0,0,-1}) protected constant SI.AngularVelocity w = 1; equation // Define movement of center of wheel r_wheel and of wheel axis axis_wheel phi = w*time; radius_wheel = road.radius + (road.radius/20)*sin(20*phi); axis_wheel = {sin(phi),-cos(phi),sin(10*phi)/10}; end CheckContactCalculation;
Check that road functions can be differentiated. Model to check that the road functions can be differentiated correctly
within VehicleInterfaces.Roads.Examples; model CheckFunctionDifferentiation_CircleRoads "Check that road functions can be differentiated" import Modelica.Mechanics.MultiBody.Frames; extends Modelica.Icons.Example; parameter SI.AngularAcceleration k=0.8 "Constant acceleration"; SI.Angle phi; SI.PathLength s; SI.Position r[3]; Real e_s[3]; Real e_n[3]; Real e_y[3]; Real T[3, 3]; SI.Velocity v[3]; SI.Acceleration a[3]; SI.AngularVelocity w[3]; SI.AngularAcceleration z[3]; Frames.Orientation R; inner Modelica.Mechanics.MultiBody.World world( enableAnimation=true, n={0,0,-1}) inner CircleRoad road( radius=1, width=0.2, mu=0.5) equation phi = (k/2)*time*time; s = road.radius*phi; r = road.position(s, 0); e_s = road.headingDirection(s, 0); e_n = road.normal(s, 0); e_y = cross(e_n, e_s); T = transpose([e_s, e_y, e_n]); R = Frames.from_T2(T, der(T)); // Velocity and acceleration v = der(r); a = der(v); // Angular velocity and angular acceleration w = Frames.angularVelocity2(R); z = der(w); end CheckFunctionDifferentiation_CircleRoads;
Check that road functions can be differentiated. Model to check that the road functions can be differentiated correctly.
within VehicleInterfaces.Roads.Examples; model CheckFunctionDifferentiation_FlatRoads "Check that road functions can be differentiated" import Modelica.Mechanics.MultiBody.Frames; extends Modelica.Icons.Example; parameter SI.Acceleration k=0.8 "Constant acceleration"; SI.PathLength s; SI.Position r[3]; Real e_s[3]; Real e_n[3]; Real e_y[3]; Real T[3, 3]; SI.Velocity v[3]; SI.Acceleration a[3]; SI.AngularVelocity w[3]; SI.AngularAcceleration z[3]; Frames.Orientation R; inner Modelica.Mechanics.MultiBody.World world( enableAnimation=true, n={0,0,-1}) inner FlatRoad road equation s = (k/2)*time*time; r = road.position(s, 0); e_s = road.headingDirection(s, 0); e_n = road.normal(s, 0); e_y = cross(e_n, e_s); T = transpose([e_s, e_y, e_n]); R = Frames.from_T2(T, der(T)); // Velocity and acceleration v = der(r); a = der(v); // Angular velocity and angular acceleration w = Frames.angularVelocity2(R); z = der(w); end CheckFunctionDifferentiation_FlatRoads;
Examples that demonstrate the usage of road models
within VehicleInterfaces.Roads; package Examples "Examples that demonstrate the usage of road models" extends Modelica.Icons.ExamplesPackage; end Examples;
Dummy wheel model to test contact point calculation of wheel within model CheckContactCalculation. A&nbsp;dummy wheel model used in test models to check the road definitions. Within this model, no tire force calculation is performed. Only kinematic relationships between wheel input <code>e_axis</code> (unit vector in direction of wheel axis) and <code>r_wheel</code> (wheel center position) and road definition are given.
within VehicleInterfaces.Roads.Examples.Utilities; model DummyTyre "Dummy wheel model to test contact point calculation of wheel within model CheckContactCalculation" import Modelica.Math.Vectors.normalize; parameter SI.Radius wheelRadius=1 "Radius of wheel"; input Real[3] e_axis "Unit vector in direction of wheel axis" input SI.Position[3] r_wheel "Position of center of wheel" output SI.Position[3] r_CP(start={0,-wheelRadius,0}) "Position vector to contact point of wheel with road, resolved in world frame"; output SI.Length penetrationDepth "Penetration depth of wheel with respect to road"; output Real mu "Friction coefficient"; // Auxiliary variables Real s(start=0); Real w(start=0); outer VehicleInterfaces.Roads.Interfaces.Base road; protected Real e_n[3] "Unit vector along road normal"; Real e_s[3] "Unit vector along road heading direction"; Real e_w[3] "Unit vector along road \"lateral\" direction"; Real e_CP[3] "Unit vector from wheel center to contact point, resolved in world frame"; SI.Position d_CP[3]; SI.Radius reducedRadius; equation r_CP = road.position(s, w); e_n = road.normal(s, w); e_s = road.headingDirection(s, w); e_w = cross(e_n, e_s); e_CP = normalize(e_n - (e_n*e_axis)*e_axis); d_CP = r_wheel - r_CP; /* The equation r_CP = r_wheel + (wheelRadius - penetrationDepth)*e_CP; or d_CP = reducedRadius*e_CP; is projected along e_n, e_s, e_w in order to eliminate the unknown penetrationDepth thus reducing the set of 3 non-linear equations to 2 non-linear equations. */ reducedRadius = e_n*d_CP/(e_n*e_CP); penetrationDepth = wheelRadius - reducedRadius; 0 = e_s*d_CP - reducedRadius*(e_s*e_CP); 0 = e_w*d_CP - reducedRadius*(e_w*e_CP); // Friction coefficient at contact point mu = road.frictionCoefficient(s, w); end DummyTyre;
Utility models for road examples
within VehicleInterfaces.Roads.Examples; package Utilities "Utility models for road examples" extends Modelica.Icons.UtilitiesPackage; end Utilities;
Base model for all roads. This function returns the road position vector w.r.t world at the road location (s,w).
within VehicleInterfaces.Roads.Interfaces; partial model Base "Base model for all roads" replaceable function position = Roads.Interfaces.positionBase "Get position vector at a road location" replaceable function trackOffset = Roads.Interfaces.trackOffsetBase "Get track offset at a road location" replaceable function normal = Roads.Interfaces.normalBase "Get road normal at a road location" replaceable function headingDirection = Roads.Interfaces.headingDirectionBase "Get heading direction at a road location" replaceable function frictionCoefficient = Roads.Interfaces.frictionCoefficientBase "Get friction coefficient at a road location" end Base;
Determine friction coefficient on road. Partial base model for friction coefficient at point on road. Extend this model appropriately to define final user model.
within VehicleInterfaces.Roads.Interfaces; partial function frictionCoefficientBase "Determine friction coefficient on road" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real w=0 "Roads surface parameter 2 (usually lateral direction)"; output Real mu=1 "Roads friction coefficient at (s,w)"; end frictionCoefficientBase;
Determine unit heading direction on road. Partial base model for unit heading direction on road. Extend this model appropriately to define final user model.
within VehicleInterfaces.Roads.Interfaces; partial function headingDirectionBase "Determine unit heading direction on road" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real w=0 "Roads surface parameter 2 (usually lateral direction)"; output Real e_s_0[3]={1,0,0} "Unit vector in direction of road heading at (s,w), resolved in world frame"; end headingDirectionBase;
Determine unit normal on road. Partial base model for unit normal on road. Extend this model appropriately to define final user model.
within VehicleInterfaces.Roads.Interfaces; partial function normalBase "Determine unit normal on road" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real w=0 "Roads surface parameter 2 (usually lateral direction)"; output Real e_n_0[3]={0,0,1} "Unit normal of road at (s,w), resolved in world frame"; end normalBase;
Collection of interface definitions for roads
within VehicleInterfaces.Roads; package Interfaces "Collection of interface definitions for roads" extends Modelica.Icons.InterfacesPackage; end Interfaces;
Determine road position. Partial base model for road position. Extend this model appropriately to define final user model.
within VehicleInterfaces.Roads.Interfaces; partial function positionBase "Determine road position" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real w=0 "Roads surface parameter 2 (usually lateral direction)"; output SI.Position r_0[3]=zeros(3) "Position vector from world frame to point on road at (s,w), resolved in world frame"; end positionBase;
Determine track offset from road centre line. Partial base model for track offset from road centre line. Extend this model appropriately to define final user model.
within VehicleInterfaces.Roads.Interfaces; partial function trackOffsetBase "Determine track offset from road centre line" extends Modelica.Icons.Function; input Real s=0 "Roads surface parameter 1 (usually arc length along road)"; input Real w=0 "Roads surface parameter 2 (usually lateral direction)"; output SI.Position trackOffset[3]=zeros(3) "Track offset vector from road centre line to desired trajectory point"; end trackOffsetBase;
Collection of internal material involving roads
within VehicleInterfaces.Roads; package Internal "Collection of internal material involving roads" extends Modelica.Icons.InternalPackage; end Internal;
Simple visualization of a road as parameterized surface. Object used for visualization of road surface. Road position evaluation is performed internally to enable correct visualization of the road surface. The road length and width can be given via parameters (see list below). The road visualization object consists of segments. Their number is dependent on the number of points along <em>s</em> and <em>w</em>.
within VehicleInterfaces.Roads.Internal; model VisualizeSimpleRoads "Simple visualization of a road as parameterized surface" parameter Integer ns(min=2) = 2 "Number of points along surface parameter 1"; parameter Integer nw(min=2) = 2 "Number of points along surface parameter 2"; extends Modelica.Mechanics.MultiBody.Visualizers.Advanced.Surface( final nu=ns, final nv=nw, redeclare final function surfaceCharacteristic = roadSurfaceCharacteristic ( final position=road.position, final s_min=s_min, final s_max=s_max, final w_min=w_min, final w_max=w_max)); parameter SI.Length s_min=0 "Minimum value of s"; parameter SI.Length s_max=1 "Maximum value of s"; parameter SI.Length w_min=-1 "Minimum value of w"; parameter SI.Length w_max=1 "Maximum value of w"; protected outer VehicleInterfaces.Roads.Interfaces.Base road; encapsulated function roadSurfaceCharacteristic import Modelica; import VehicleInterfaces; extends Modelica.Mechanics.MultiBody.Interfaces.partialSurfaceCharacteristic( final multiColoredSurface=false); input VehicleInterfaces.Roads.Interfaces.positionBase position; input Real s_min=0 "Minimum value of s"; input Real s_max=1 "Maximum value of s"; input Real w_min=-1 "Minimum value of w"; input Real w_max=1 "Maximum value of w"; protected Real s; Real w; Real r[3]; parameter Real ds = s_max - s_min "Length of one segment in s-direction"; parameter Real dw = w_max - w_min "Length of one segment in w-direction"; algorithm for j in 1:nv loop w := w_min + (j - 1)*dw/(nv - 1); for i in 1:nu loop s := s_min + (i - 1)*ds/(nu - 1); r := position(s, w); X[i, j] := r[1]; Y[i, j] := r[2]; Z[i, j] := r[3]; end for; end for; end roadSurfaceCharacteristic; end VisualizeSimpleRoads;
Empty transmission. Empty transmission model (just rigid connection between engine and driveline flange). Using this empty model in overall vehicle architecture the functionality of transmission can be eliminated.
within VehicleInterfaces.Transmissions; model NoTransmissions "Empty transmission" extends VehicleInterfaces.Icons.Transmission; extends VehicleInterfaces.Icons.Empty; extends Interfaces.Base; equation connect(engineFlange, drivelineFlange) end NoTransmissions;
Collection of transmission subsystem definitions
within VehicleInterfaces; package Transmissions "Collection of transmission subsystem definitions" extends Modelica.Icons.VariantsPackage; end Transmissions;
Simple power split device based on an ideal epicyclic gear. Simple power-split device based on an ideal epicyclic gear. No losses are included in this model.
within VehicleInterfaces.Transmissions; model PowerSplitDevice "Simple power split device based on an ideal epicyclic gear" extends Interfaces.BaseTwoInputTransmission; parameter Real ratio=100/50 "Number of ring_teeth/sun_teeth (e.g. ratio=100/50)"; Modelica.Mechanics.Rotational.Sensors.SpeedSensor outputSpeed Modelica.Mechanics.Rotational.Components.IdealPlanetary idealPlanetary( ratio=ratio) Modelica.Blocks.Sources.IntegerConstant currentGear(k=1) protected VehicleInterfaces.Interfaces.TransmissionBus transmissionBus VehicleInterfaces.Interfaces.TransmissionControlBus transmissionControlBus outer Modelica.Mechanics.MultiBody.World world; equation connect(outputSpeed.flange, drivelineFlange.flange) connect(controlBus.transmissionBus, transmissionBus) connect(idealPlanetary.ring, drivelineFlange.flange) connect(idealPlanetary.sun, engineFlange.flange) connect(idealPlanetary.carrier, motorFlange.flange) connect(controlBus.transmissionControlBus, transmissionControlBus) connect(currentGear.y, transmissionControlBus.currentGear) connect(outputSpeed.w, transmissionBus.outputSpeed) end PowerSplitDevice;
Simple fixed gear ratio, automatic transmission, no torque converter. A&nbsp;single gear transmission without a&nbsp;launch device that is based on the automatic transmission model interface definition.
within VehicleInterfaces.Transmissions; model SingleGearAutomaticTransmission "Simple fixed gear ratio, automatic transmission, no torque converter" extends VehicleInterfaces.Icons.Transmission; extends Interfaces.BaseAutomaticTransmission(includeMount=world.driveTrainMechanics3D); parameter Real gearRatio=4 "Gear ratio"; Modelica.Mechanics.Rotational.Components.IdealGear gear( ratio=gearRatio, useSupport=true) Modelica.Mechanics.MultiBody.Parts.Mounting1D mounting1D Modelica.Mechanics.Rotational.Sensors.SpeedSensor outputSpeed Modelica.Blocks.Sources.IntegerConstant currentGear(k=1) protected VehicleInterfaces.Interfaces.TransmissionBus transmissionBus VehicleInterfaces.Interfaces.TransmissionControlBus transmissionControlBus outer Modelica.Mechanics.MultiBody.World world; equation connect(mounting1D.flange_b,gear.support) connect(mounting1D.frame_a, transmissionMount) connect(gear.flange_b,outputSpeed.flange) connect(controlBus.transmissionBus, transmissionBus) connect(transmissionControlBus, controlBus.transmissionControlBus) connect(currentGear.y, transmissionControlBus.currentGear) connect(gear.flange_a, engineFlange.flange) connect(gear.flange_b, drivelineFlange.flange) connect(outputSpeed.w, transmissionBus.outputSpeed) end SingleGearAutomaticTransmission;
Simple fixed gear ratio, manual transmission, uses physical connectors. A&nbsp;single gear transmission based on the manual transmission model interface definition. Includes a clutch model and uses physical connections between the driver and transmission system for the clutch position and current gear number (although the gear number is ignored in this model.
within VehicleInterfaces.Transmissions; model SingleGearManualTransmission "Simple fixed gear ratio, manual transmission, uses physical connectors" extends VehicleInterfaces.Icons.Transmission; extends Interfaces.BaseManualTransmission( includeMount=world.driveTrainMechanics3D, includeManualShiftConnector=true, includeClutchPedal=true); parameter Real gearRatio=4 "Gear ratio"; Modelica.Mechanics.Rotational.Components.IdealGear gear( ratio=gearRatio, useSupport=true) Modelica.Mechanics.MultiBody.Parts.Mounting1D mounting1D Modelica.Mechanics.Rotational.Sensors.SpeedSensor outputSpeed VehicleInterfaces.Interfaces.ShiftOutput shiftOutput Modelica.Mechanics.Rotational.Components.Clutch clutch(fn_max=1) Modelica.Mechanics.Translational.Components.Fixed fixed Modelica.Mechanics.Translational.Sensors.ForceSensor forceSensor Modelica.Mechanics.Translational.Components.SpringDamper pedalSpring(c=1, d=1) Modelica.Blocks.Sources.BooleanExpression clutchLocked(y=clutch.locked) protected VehicleInterfaces.Interfaces.TransmissionBus transmissionBus VehicleInterfaces.Interfaces.TransmissionControlBus transmissionControlBus outer Modelica.Mechanics.MultiBody.World world; public Modelica.Blocks.Math.Gain normalise(k=1/clutch.fn_max) equation connect(mounting1D.flange_b,gear.support) connect(mounting1D.frame_a, transmissionMount) connect(gear.flange_b,outputSpeed.flange) connect(shiftConnector, shiftOutput.shiftConnector) connect(clutch.flange_b, gear.flange_a) connect(forceSensor.flange_a,fixed.flange) connect(clutchPedal, pedalSpring.flange_b) connect(pedalSpring.flange_a, forceSensor.flange_b) connect(clutchLocked.y, transmissionBus.clutchLocked) connect(controlBus.transmissionBus, transmissionBus) connect(clutch.flange_a, engineFlange.flange) connect(gear.flange_b, drivelineFlange.flange) connect(transmissionControlBus, controlBus.transmissionControlBus) connect(shiftOutput.gear, transmissionControlBus.currentGear) connect(forceSensor.f, normalise.u) connect(normalise.y, clutch.f_normalized) connect(outputSpeed.w, transmissionBus.outputSpeed) end SingleGearManualTransmission;
Transmissions Tutorial.
within VehicleInterfaces.Transmissions; class Tutorial "Transmissions Tutorial" extends Modelica.Icons.Information; end Tutorial;
Basic interface definition for a transmission. This partial model defines the common interfaces required for a&nbsp;transmission subsystem. See the <a href=\"modelica://VehicleInterfaces.Transmissions\">documentation</a> and <a href=\"modelica://VehicleInterfaces.Transmissions.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.Transmissions.Interfaces; partial model Base "Basic interface definition for a transmission" parameter Boolean usingMultiBodyEngine=false "= true, if connecting to a MultiBody engine" parameter Boolean usingMultiBodyDriveline=false "= true, if connecting to a MultiBody driveline" protected parameter Boolean includeMount=false "Include the transmission mount connection"; parameter Boolean includeDrivelineBearing=false "Include the driveline bearing"; parameter Boolean includeEngineBearing=false "Include the engine bearing"; public Modelica.Mechanics.MultiBody.Interfaces.FlangeWithBearing engineFlange( final includeBearingConnector=includeEngineBearing or usingMultiBodyEngine) "Connection to the engine" Modelica.Mechanics.MultiBody.Interfaces.FlangeWithBearing drivelineFlange( final includeBearingConnector=includeDrivelineBearing or usingMultiBodyDriveline) "Connection to the driveline" Modelica.Mechanics.MultiBody.Interfaces.Frame_a transmissionMount if includeMount "Transmission mount connection (optional)" VehicleInterfaces.Interfaces.ControlBus controlBus "Control signal bus" Mechanics.MultiBody.MultiBodyEnd end_1( final includeBearingConnector=includeEngineBearing or usingMultiBodyEngine) Mechanics.MultiBody.MultiBodyEnd end_2( final includeBearingConnector=includeDrivelineBearing or usingMultiBodyDriveline) equation connect(end_1.flange, engineFlange) connect(end_2.flange, drivelineFlange) end Base;
Interface definition for an automatic transmission. This partial model defines the interfaces required for an automatic transmission model within the VehicleInterfaces package. See the <a href=\"modelica://VehicleInterfaces.Transmissions\">documentation</a> and <a href=\"modelica://VehicleInterfaces.Transmissions.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.Transmissions.Interfaces; partial model BaseAutomaticTransmission "Interface definition for an automatic transmission" extends Base; end BaseAutomaticTransmission;
Interface definition for a manual transmission. This partial model defines the interfaces required for a&nbsp;manual transmission model within the VehicleInterfaces package. See the <a href=\"modelica://VehicleInterfaces.Transmissions\">documentation</a> and <a href=\"modelica://VehicleInterfaces.Transmissions.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.Transmissions.Interfaces; partial model BaseManualTransmission "Interface definition for a manual transmission" extends Base; protected parameter Boolean includeManualShiftConnector=false "Include the manual shift connection"; parameter Boolean includeClutchPedal=false "Include the clutch pedal connection"; public Modelica.Mechanics.Translational.Interfaces.Flange_b clutchPedal if includeClutchPedal "Clutch pedal connection (optional)" VehicleInterfaces.Interfaces.ShiftConnector shiftConnector if includeManualShiftConnector "Manual shift selector connection (optional)" end BaseManualTransmission;
Interface definition for a transmission with two input shafts. This partial model defines the interfaces required for a transmission model that has two input shafts (such as a power-split device) within the VehicleInterfaces package. See the <a href=\"modelica://VehicleInterfaces.Transmissions\">documentation</a> and <a href=\"modelica://VehicleInterfaces.Transmissions.Tutorial\">tutorial</a> for more information.
within VehicleInterfaces.Transmissions.Interfaces; model BaseTwoInputTransmission "Interface definition for a transmission with two input shafts" extends Base; parameter Boolean usingMultiBodyMotor=false "= true, if connecting to a MultiBody motor" protected parameter Boolean includeMotorBearing=false "Include the motor bearing connection"; public Modelica.Mechanics.MultiBody.Interfaces.FlangeWithBearing motorFlange( final includeBearingConnector=includeMotorBearing or usingMultiBodyMotor) "Connection to the electric machine" Mechanics.MultiBody.MultiBodyEnd end_3( final includeBearingConnector=includeMotorBearing or usingMultiBodyMotor) equation connect(end_3.flange, motorFlange) end BaseTwoInputTransmission;
Collection of interface definitions for transmission
within VehicleInterfaces.Transmissions; package Interfaces "Collection of interface definitions for transmission" extends Modelica.Icons.InterfacesPackage; end Interfaces;
Collection of internal material involving transmission
within VehicleInterfaces.Transmissions; package Internal "Collection of internal material involving transmission" extends Modelica.Icons.InternalPackage; end Internal;
activation process of continuous transitions.
within PNlib.Blocks; block activationCon "activation process of continuous transitions" //no events are generated within while-loops; for-loops are applied parameter input Integer nIn "number of input places"; parameter input Integer nOut "number of output places"; input Real tIn[:] "marking of input places"; input Real tOut[:] "marking of output places"; input Integer tIntIn[:] "marking of input places"; input Integer tIntOut[:] "marking of output places"; input PNlib.Types.ArcType arcType[:] "arc type of input places"; input Real arcWeightIn[:] "arc weights of input places"; input Real arcWeightOut[:] "arc weights of output places"; input Integer arcWeightIntIn[:] "arc weights of input places"; input Integer arcWeightIntOut[:] "arc weights of output places"; input Real minTokens[:] "minimum capacities of input places"; input Real maxTokens[:] "maximum capacities of output places"; input Integer minTokensInt[:] "minimum capacities of input places"; input Integer maxTokensInt[:] "maximum capacities of output places"; input Boolean firingCon "firing condition"; input Boolean fed[:] "input places are fed?"; input Boolean emptied[:] "output places are emptied?"; input Boolean disPlaceIn[:] "types of input places"; input Boolean disPlaceOut[:] "types of output places"; input Real testValue[:] "test values of test and inhibitor arcs"; input Integer testValueInt[:] "integer test values of test and inhibitor arcs"; input Boolean normalArc[:] "normal or double arc?"; output Boolean active "activation of transition"; output Boolean weaklyInputActiveVec[nIn] "places that causes weakly input activation"; output Boolean weaklyOutputActiveVec[nOut] "places that causes weakly output activation"; Boolean NoTokens; algorithm NoTokens := false; active := true; weaklyInputActiveVec := fill(false, nIn); weaklyOutputActiveVec := fill(false, nOut); //check input places for i in 1:nIn loop if disPlaceIn[i] then //discrete place if arcType[i] == PNlib.Types.ArcType.NormalArc and (tIntIn[i] - arcWeightIntIn[i] < minTokensInt[i]) then //normal arc active := false; elseif arcType[i] == PNlib.Types.ArcType.RealTestArc and (tIntIn[i] <= testValueInt[i]) then //real test arc active := false; elseif arcType[i] == PNlib.Types.ArcType.TestArc and (tIntIn[i] < testValueInt[i]) then //test arc active := false; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and (tIntIn[i] >= testValueInt[i]) then // real inhibition arc active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and (tIntIn[i] > testValueInt[i]) then //inhibition arc active := false; end if; else //continuous place if arcType[i] == PNlib.Types.ArcType.NormalArc or not normalArc[i] then //normal arc or double arc NoTokens := not (tIn[i] - minTokens[i] >= -Constants.almost_eps); if arcWeightIn[i] <= 0.0 then elseif NoTokens and (not fed[i]) then active := false; elseif NoTokens and fed[i] then //weakly input active?? weaklyInputActiveVec[i] := true; end if; end if; if arcType[i] == PNlib.Types.ArcType.RealTestArc then //real test arc if tIn[i] <= testValue[i] + Constants.almost_eps then active := false; end if; if tIn[i] > testValue[i] + Constants.almost_eps and fed[i] and not normalArc[i] then //weakly input active?? weaklyInputActiveVec[i] := true; end if; elseif arcType[i] == PNlib.Types.ArcType.TestArc then //test arc if tIn[i] < testValue[i] - Constants.almost_eps then active := false; end if; if tIn[i] >= testValue[i] - Constants.almost_eps and fed[i] and not normalArc[i] then //weakly input active?? weaklyInputActiveVec[i] := true; end if; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and (tIn[i] >= testValue[i] - Constants.almost_eps) then //real inhibitor arc active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and (tIn[i] > testValue[i] + Constants.almost_eps) then //inhibitor arc active := false; end if; end if; end for; //output places for i in 1:nOut loop if disPlaceOut[i] then //discrete place if tIntOut[i] + arcWeightIntOut[i] > maxTokensInt[i] then active := false; end if; else //continuous place if tOut[i] >= maxTokens[i] then if emptied[i] then weaklyOutputActiveVec[i] := true; else active := false; end if; end if; end if; end for; active := active and firingCon; // hack for Dymola 2017 // weaklyOutputActiveVec := weaklyOutputActiveVec and fill(firingCon, nOut); for i in 1:nOut loop weaklyOutputActiveVec[i] := weaklyOutputActiveVec[i] and firingCon; end for; // hack for Dymola 2017 //weaklyInputActiveVec := weaklyInputActiveVec and fill(firingCon, nIn); for i in 1:nIn loop weaklyInputActiveVec[i] := weaklyInputActiveVec[i] and firingCon; end for; end activationCon;
Activation of a discrete transition.
within PNlib.Blocks; block activationDis "Activation of a discrete transition" parameter input Integer nIn "number of input places"; parameter input Integer nOut "number of output places"; input Real tIn[:] "tokens of input places"; input Real tOut[:] "tokens of output places"; input Integer tIntIn[:] "tokens of input places"; input Integer tIntOut[:] "tokens of output places"; input PNlib.Types.ArcType arcType[:] "arc type of input places"; input Real arcWeightIn[:] "arc weights of input places"; input Integer arcWeightIntIn[:] "arc weights of input places"; input Real arcWeightOut[:] "arc weights of output places"; input Integer arcWeightIntOut[:] "arc weights of output places"; input Real minTokens[:] "minimum capacities of input places"; input Integer minTokensInt[:] "minimum capacities of input places"; input Real maxTokens[:] "maximum capacities of output places"; input Integer maxTokensInt[:] "maximum capacities of output places"; input Boolean firingCon "firing condition of transition"; input Boolean disPlaceIn[:] "types of input places"; input Boolean disPlaceOut[:] "types of output places"; input Boolean normalArc[:] "normal or double arc?"; input Real testValue[:] "test values of test and inhibitor arcs"; input Integer testValueInt[:] "integer test values of test and inhibitor arcs"; output Boolean active "activation of transition"; algorithm active := true; //check input places for i in 1:nIn loop if disPlaceIn[i] then //discrete if (arcType[i] == PNlib.Types.ArcType.NormalArc or not normalArc[i]) and not (tIntIn[i] - arcWeightIntIn[i] >= minTokensInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealTestArc and not (tIntIn[i] > testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.TestArc and not (tIntIn[i] >= testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and not (tIntIn[i] < testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and not (tIntIn[i] <= testValueInt[i]) then active := false; end if; else //continuous if (arcType[i] == PNlib.Types.ArcType.NormalArc or not normalArc[i]) and not (tIn[i] - arcWeightIn[i] - minTokens[i] >= -Constants.almost_eps) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealTestArc and not (tIn[i] > testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.TestArc and not (tIn[i] >= testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and not (tIn[i] < testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and not (tIn[i] <= testValue[i]) then active := false; end if; end if; end for; //check output places for i in 1:nOut loop if disPlaceOut[i] then //discrete if not (tIntOut[i] + arcWeightIntOut[i] <= maxTokensInt[i]) then active := false; end if; else //continuous if not (tOut[i] + arcWeightOut[i] - maxTokens[i] <= Constants.almost_eps) then active := false; end if; end if; end for; active := active and firingCon; end activationDis;
Input Activation of a discrete transition.
within PNlib.Blocks; block activationDisIn "Input Activation of a discrete transition" parameter input Integer nIn "number of input places"; input Real tIn[:] "tokens of input places"; input Integer tIntIn[:] "tokens of input places"; input PNlib.Types.ArcType arcType[:] "arc type of input places"; input Real arcWeightIn[:] "arc weights of input places"; input Integer arcWeightIntIn[:] "arc weights of input places"; input Real minTokens[:] "minimum capacities of input places"; input Integer minTokensInt[:] "minimum capacities of input places"; input Boolean firingCon "firing condition of transition"; input Boolean disPlaceIn[:] "types of input places"; input Boolean normalArc[:] "normal or double arc?"; input Real testValue[:] "test values of test and inhibitor arcs"; input Integer testValueInt[:] "integer test values of test and inhibitor arcs"; output Boolean active "activation of transition"; algorithm active := true; //check input places for i in 1:nIn loop if disPlaceIn[i] then //discrete if (arcType[i] == PNlib.Types.ArcType.NormalArc or not normalArc[i]) and not (tIntIn[i] - arcWeightIntIn[i] >= minTokensInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealTestArc and not (tIntIn[i] > testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.TestArc and not (tIntIn[i] >= testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and not (tIntIn[i] < testValueInt[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and not (tIntIn[i] <= testValueInt[i]) then active := false; end if; else //continuous if (arcType[i] == PNlib.Types.ArcType.NormalArc or not normalArc[i]) and not (tIn[i] - arcWeightIn[i] - minTokens[i] >= -Constants.almost_eps) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealTestArc and not (tIn[i] > testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.TestArc and not (tIn[i] >= testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.RealInhibitorArc and not (tIn[i] < testValue[i]) then active := false; elseif arcType[i] == PNlib.Types.ArcType.InhibitorArc and not (tIn[i] <= testValue[i]) then active := false; end if; end if; end for; active := active and firingCon; end activationDisIn;
Output activation of a discrete transition.
within PNlib.Blocks; block activationDisOut "Output activation of a discrete transition" parameter input Integer nOut "number of output places"; input Real tOut[:] "tokens of output places"; input Integer tIntOut[:] "tokens of output places"; input Real arcWeightOut[:] "arc weights of output places"; input Integer arcWeightIntOut[:] "arc weights of output places"; input Real maxTokens[:] "maximum capacities of output places"; input Integer maxTokensInt[:] "maximum capacities of output places"; input Boolean firingCon "firing condition of transition"; input Boolean disPlaceOut[:] "types of output places"; output Boolean active "activation of transition"; algorithm active := true; //check output places for i in 1:nOut loop if disPlaceOut[i] then //discrete if not (tIntOut[i] + arcWeightIntOut[i] <= maxTokensInt[i]) then active := false; end if; else //continuous if not (tOut[i] + arcWeightOut[i] - maxTokens[i] <= Constants.almost_eps) then active := false; end if; end if; end for; active := active and firingCon; end activationDisOut;
Does any entry of a Boolean vector change its value?.
within PNlib.Blocks; block anyChange "Does any entry of a Boolean vector change its value?" input Boolean vec[:](each start = false, each fixed = true); output Boolean anychange; algorithm anychange := false; for i in 1:size(vec, 1) loop anychange := anychange or change(vec[i]); end for; end anyChange;
Is any entry of a Boolean vector true?.
within PNlib.Blocks; block anyTrue "Is any entry of a Boolean vector true?" input Boolean vec[:]; output Boolean anytrue; output Integer numtrue; algorithm anytrue := false; numtrue := 0; for i in 1:size(vec, 1) loop anytrue := anytrue or vec[i]; if vec[i] then numtrue := numtrue + 1; end if; end for; end anyTrue;
enabling process of input transitions (continuous places).
within PNlib.Blocks; block enablingInCon "enabling process of input transitions (continuous places)" parameter input Integer nIn "number of input transitions"; input Real arcWeight[nIn] "arc weights of input transitions"; input Real t "current marking"; input Real maxMarks "maximum capacity"; input Boolean TAein[nIn] "active input transitions which are already enabled by their input places"; input PNlib.Types.EnablingType enablingType "resolution of actual conflicts"; input Integer enablingPrio[:] "enabling priorities of output transitions"; input Real enablingProb[nIn] "enabling probabilites of input transitions"; input Boolean disTransition[nIn] "discrete transition?"; input Boolean delayPassed "Does any delayPassed of a output transition"; input Boolean active[nIn] "Are the input transitions active?"; parameter input Integer localSeed "Local seed to initialize random number generator"; parameter input Integer globalSeed "Global seed to initialize random number generator"; output Boolean TEin_[nIn] "enabled input transitions"; protected discrete Integer state128[4] "state of random number generator"; Boolean TEin[nIn] "enabled input transitions"; Boolean disTAin[nIn](each start = false, each fixed = true) "discret active input transitions"; Integer remTAin[nIn](each start = 0, each fixed = true) "remaining active input transitions"; discrete Real cumEnablingProb[nIn](each start = 0, each fixed = true) "cumulated, scaled enabling probabilities"; discrete Real arcWeightSum "arc weight sum"; Integer nremTAin "number of remaining active input transitions"; Integer nTAin "number ofactive input transitions"; Integer k "iteration index"; Integer posTE "possible enabled transition"; discrete Real randNum "uniform distributed random number"; discrete Real sumEnablingProbTAin "sum of the enabling probabilities of the active input transitions"; Boolean endWhile; Integer Index "priority Index"; initial algorithm // Generate initial state from localSeed and globalSeed state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, globalSeed); (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128); algorithm TEin := fill(false, nIn); when delayPassed then if nIn > 0 then // hack for Dymola 2017 //disTAin := TAein and disTransition; disTAin := Functions.OddsAndEnds.boolAnd(TAein, disTransition); arcWeightSum := Functions.OddsAndEnds.conditionalSum(arcWeight, disTAin); //arc weight sum of all active input transitions which are already enabled by their input places if t + arcWeightSum - maxMarks <= Constants.almost_eps or Functions.OddsAndEnds.isEqual(arcWeightSum, 0.0) then //Place has no actual conflict; all active input transitions are enabled TEin := TAein; else //Place has an actual conflict // hack for Dymola 2017 // TEin := TAein and not disTransition; TEin := Functions.OddsAndEnds.boolAnd(TAein, not disTransition); if enablingType == PNlib.Types.EnablingType.Priority then //deterministic enabling according to priorities arcWeightSum := 0; for i in 1:nIn loop Index := Modelica.Math.Vectors.find(i, enablingPrio); if Index > 0 and disTAin[Index] and ((t + arcWeightSum + arcWeight[Index] - maxMarks <= Constants.almost_eps) or Functions.OddsAndEnds.isEqual(arcWeight[Index], 0.0)) then TEin[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; else //probabilistic enabling according to enabling probabilities arcWeightSum := 0; remTAin := zeros(nIn); nremTAin := 0; for i in 1:nIn loop if disTAin[i] then nremTAin := nremTAin + 1; //number of active input transitions remTAin[nremTAin] := i; //active input transitions end if; end for; nTAin := nremTAin; //number of active input transitions sumEnablingProbTAin := sum(enablingProb[remTAin[1:nremTAin]]); //enabling probability sum of all active input transitions cumEnablingProb := zeros(nIn); //cumulative, scaled enabling probabilities cumEnablingProb[1] := enablingProb[remTAin[1]]/sumEnablingProbTAin; for j in 2:nremTAin loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAin[j]]/sumEnablingProbTAin; end for; for i in 1:nTAin loop (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128)) "uniform distributed random number"; endWhile := false; k := 1; while k <= nremTAin and not endWhile loop if randNum <= cumEnablingProb[k] then posTE := remTAin[k]; endWhile := true; else k := k + 1; end if; end while; if t + arcWeightSum + arcWeight[posTE] - maxMarks <= Constants.almost_eps or Functions.OddsAndEnds.isEqual(arcWeight[i], 0.0) then arcWeightSum := arcWeightSum + arcWeight[posTE]; TEin[posTE] := true; end if; nremTAin := nremTAin - 1; if nremTAin > 0 then remTAin := Functions.OddsAndEnds.deleteElementInt(remTAin, k); cumEnablingProb := zeros(nIn); sumEnablingProbTAin := sum(enablingProb[remTAin[1:nremTAin]]); if sumEnablingProbTAin > 0 then cumEnablingProb[1] := enablingProb[remTAin[1]]/sumEnablingProbTAin; for j in 2:nremTAin loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAin[j]]/sumEnablingProbTAin; end for; else cumEnablingProb[1:nremTAin] := fill(1/nremTAin, nremTAin); end if; end if; end for; end if; end if; else disTAin := fill(false, nIn); remTAin := fill(0, nIn); cumEnablingProb := fill(0.0, nIn); arcWeightSum := 0.0; nremTAin := 0; nTAin := 0; k := 0; posTE := 0; randNum := 0.0; state128 := pre(state128); sumEnablingProbTAin := 0.0; endWhile := false; Index := 0; end if; end when; // hack for Dymola 2017 // TEin_ := TEin and active; for i in 1:nIn loop TEin_[i] := TEin[i] and active[i]; end for; end enablingInCon;
enabling process of discrete input transitions.
within PNlib.Blocks; block enablingInDis "enabling process of discrete input transitions" parameter input Integer nIn "number of input transitions"; input Integer arcWeight[:] "arc weights of input transitions"; input Integer t "current token number"; input Integer maxTokens "maximum capacity"; input Boolean TAein[:] "active previous transitions which are already enabled by their input places"; input PNlib.Types.EnablingType enablingType "resolution of actual conflicts"; input Integer enablingPrio[:] "enabling priorities of input transitions"; input Real enablingProb[:] "enabling probabilites of input transitions"; input Real enablingBene[:] "enabling benefit of input transitions"; input PNlib.Types.BenefitType benefitType "algorithm for benefit"; input Boolean disTransition[:] "type of input transitions"; input Boolean delayPassed "Does any delayPassed of a output transition"; input Boolean active[:] "Are the input transitions active?"; parameter input Integer localSeed "Local seed to initialize random number generator"; parameter input Integer globalSeed "Global seed to initialize random number generator"; output Boolean TEin_[nIn] "enabled input transitions"; protected discrete Integer state128[4] "state of random number generator"; Boolean TEin[nIn] "enabled input transitions"; Integer remTAin[nIn](each start = 0, each fixed = true) "remaining active input transitions"; discrete Real cumEnablingProb[nIn](each start = 0, each fixed = true) "cumulated, scaled enabling probabilities"; Integer arcWeightSum "arc weight sum"; Integer nremTAin "number of remaining active input transitions"; Integer nTAin "number ofactive input transitions"; Integer k "iteration index"; Integer posTE "possible enabled transition"; discrete Real randNum "uniform distributed random number"; discrete Real sumEnablingProbTAin "sum of the enabling probabilities of the active input transitions"; Boolean endWhile; Integer Index "priority Index"; discrete Real benefitMax "theoretical benefit"; Boolean valid "valid solution"; discrete Real benefitLimit "best valid benefit"; initial algorithm // Generate initial state from localSeed and globalSeed state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, globalSeed); (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128); algorithm TEin := fill(false, nIn); arcWeightSum := 0; when delayPassed then if nIn > 0 then arcWeightSum := Functions.OddsAndEnds.conditionalSumInt(arcWeight, TAein); //arc weight sum of all active input transitions which are already enabled by their input places if t + arcWeightSum <= maxTokens then //Place has no actual conflict; all active input transitions are enabled TEin := TAein; else //Place has an actual conflict if enablingType == PNlib.Types.EnablingType.Priority then //deterministic enabling according to priorities arcWeightSum := 0; for i in 1:nIn loop Index := Modelica.Math.Vectors.find(i, enablingPrio); if Index > 0 and TAein[Index] and disTransition[Index] and t + (arcWeightSum + arcWeight[Index]) <= maxTokens then ///new 07.03.2011 TEin[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; for i in 1:nIn loop //continuous transitions afterwards (discrete transitions have priority over continuous transitions) Index := Modelica.Math.Vectors.find(i, enablingPrio); if TAein[Index] and not disTransition[Index] and t + (arcWeightSum + arcWeight[Index]) <= maxTokens then TEin[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; elseif enablingType == PNlib.Types.EnablingType.Probability then //probabilistic enabling according to enabling probabilities arcWeightSum := 0; remTAin := zeros(nIn); nremTAin := 0; for i in 1:nIn loop if TAein[i] and disTransition[i] then nremTAin := nremTAin + 1; //number of active input transitions remTAin[nremTAin] := i; //active input transitions end if; end for; nTAin := nremTAin; //number of active input transitions sumEnablingProbTAin := sum(enablingProb[remTAin[1:nremTAin]]); //enabling probability sum of all active input transitions cumEnablingProb := zeros(nIn); //cumulative, scaled enabling probabilities cumEnablingProb[1] := enablingProb[remTAin[1]]/sumEnablingProbTAin; for j in 2:nremTAin loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAin[j]]/sumEnablingProbTAin; end for; for i in 1:nTAin loop (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128)) "uniform distributed random number"; endWhile := false; k := 1; while k <= nremTAin and not endWhile loop if randNum <= cumEnablingProb[k] then posTE := remTAin[k]; endWhile := true; else k := k + 1; end if; end while; if t + arcWeightSum + arcWeight[posTE] <= maxTokens then arcWeightSum := arcWeightSum + arcWeight[posTE]; TEin[posTE] := true; end if; nremTAin := nremTAin - 1; if nremTAin > 0 then remTAin := Functions.OddsAndEnds.deleteElementInt(remTAin, k); cumEnablingProb := zeros(nIn); sumEnablingProbTAin := sum(enablingProb[remTAin[1:nremTAin]]); if sumEnablingProbTAin > 0 then cumEnablingProb[1] := enablingProb[remTAin[1]]/sumEnablingProbTAin; for j in 2:nremTAin loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAin[j]]/sumEnablingProbTAin; end for; else cumEnablingProb[1:nremTAin] := fill(1/nremTAin, nremTAin); end if; end if; end for; else if benefitType == PNlib.Types.BenefitType.Greedy then TEin := PNlib.Functions.Enabling.benefitGreedyDisIn(nIn, arcWeight, t, maxTokens, TAein, enablingBene, disTransition); elseif benefitType == PNlib.Types.BenefitType.BenefitQuotient then TEin := PNlib.Functions.Enabling.benefitQuotientDisIn(nIn, arcWeight, t, maxTokens, TAein, enablingBene, disTransition); else //TEin:=fill(false, nIn); arcWeightSum := 0; benefitMax := sum(enablingBene); benefitLimit := 0; (TEin, arcWeightSum, benefitMax, valid, benefitLimit) := PNlib.Functions.Enabling.benefitBaBDisIn(1, nIn, enablingBene, arcWeight, enablingBene./arcWeight, t, benefitMax, maxTokens, TEin, 0, benefitLimit, TAein, disTransition); end if; end if; end if; else remTAin := fill(0, nIn); cumEnablingProb := fill(0.0, nIn); arcWeightSum := 0; nremTAin := 0; nTAin := 0; k := 0; posTE := 0; randNum := 0; state128 := pre(state128); sumEnablingProbTAin := 0; endWhile := false; Index := 0; benefitMax := 0; valid := false; benefitLimit := 0; end if; end when; // hack for Dymola 2017 // TEin_ := TEin and active; for i in 1:nIn loop TEin_[i] := TEin[i] and active[i]; end for; end enablingInDis;
enabling process of output transitions (continuous places).
within PNlib.Blocks; block enablingOutCon "enabling process of output transitions (continuous places)" parameter input Integer nOut "number of output transitions"; input Real arcWeight[:] "arc weights of output transitions"; input Real t "current marks"; input Real minMarks "minimum capacity"; input Boolean TAout[:] "active output transitions with passed delay"; input PNlib.Types.EnablingType enablingType "resolution of actual conflicts"; input Integer enablingPrio[:] "enabling priorities of output transitions"; input Real enablingProb[:] "enabling probabilites of output transitions"; input Boolean disTransition[:] "discrete transition?"; input Boolean delayPassed "Does any delayPassed of a output transition"; parameter input Integer localSeed "Local seed to initialize random number generator"; parameter input Integer globalSeed "Global seed to initialize random number generator"; output Boolean TEout_[nOut] "enabled output transitions"; protected discrete Integer state128[4] "state of random number generator"; Boolean TEout[nOut] "enabled output transitions"; Boolean disTAout[nOut](each start = false, each fixed = true) "discret active output transitions"; Integer remTAout[nOut](each start = 0, each fixed = true) "remaining active output transitions"; discrete Real cumEnablingProb[nOut](each start = 0, each fixed = true) "cumulated, scaled enabling probabilities"; discrete Real arcWeightSum "arc weight sum"; Integer nremTAout "number of remaining active output transitions"; Integer nTAout "number of active output transitions"; Integer k "iteration index"; Integer posTE "possible enabled transition"; discrete Real randNum "uniform distributed random number"; discrete Real sumEnablingProbTAout "sum of the enabling probabilities of the active output transitions"; Boolean endWhile; Integer Index; initial algorithm // Generate initial state from localSeed and globalSeed state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, globalSeed); (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128); algorithm TEout := fill(false, nOut); when delayPassed then if nOut > 0 then // hack for Dymola 2017 // disTAout := TAout and disTransition; disTAout := Functions.OddsAndEnds.boolAnd(TAout, disTransition); arcWeightSum := Functions.OddsAndEnds.conditionalSum(arcWeight, disTAout); //arc weight sum of all active output transitions if t - arcWeightSum - minMarks >= -Constants.almost_eps or Functions.OddsAndEnds.isEqual(arcWeightSum, 0.0) then //Place has no actual conflict; all active output transitions are enabled TEout := TAout; else //Place has an actual conflict; // hack for Dymola 2017 // TEout := TAout and not disTransition; TEout := Functions.OddsAndEnds.boolAnd(TAout, not disTransition); if enablingType == PNlib.Types.EnablingType.Priority then //deterministic enabling according to priorities arcWeightSum := 0; for i in 1:nOut loop //discrete transitions are proven at first Index := Modelica.Math.Vectors.find(i, enablingPrio); if Index > 0 and disTAout[Index] and ((t - arcWeightSum - arcWeight[Index] - minMarks >= -Constants.almost_eps) or Functions.OddsAndEnds.isEqual(arcWeight[Index], 0.0)) then TEout[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; else //probabilistic enabling according to enabling probabilities arcWeightSum := 0; remTAout := zeros(nOut); nremTAout := 0; for i in 1:nOut loop if disTAout[i] then nremTAout := nremTAout + 1; //number of active output transitions remTAout[nremTAout] := i; //active output transitions end if; end for; nTAout := nremTAout; //number of active output transitions sumEnablingProbTAout := sum(enablingProb[remTAout[1:nremTAout]]); //enabling probability sum of all active output transitions cumEnablingProb := zeros(nOut); //cumulative, scaled enabling probabilities cumEnablingProb[1] := enablingProb[remTAout[1]]/sumEnablingProbTAout; for j in 2:nremTAout loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAout[j]]/sumEnablingProbTAout; end for; for i in 1:nTAout loop (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128)) "uniform distributed random number"; endWhile := false; k := 1; while k <= nremTAout and not endWhile loop if randNum <= cumEnablingProb[k] then posTE := remTAout[k]; endWhile := true; else k := k + 1; end if; end while; if (t - (arcWeightSum + arcWeight[posTE]) - minMarks >= -Constants.almost_eps) or Functions.OddsAndEnds.isEqual(arcWeight[i], 0.0) then arcWeightSum := arcWeightSum + arcWeight[posTE]; TEout[posTE] := true; end if; nremTAout := nremTAout - 1; if nremTAout > 0 then remTAout := Functions.OddsAndEnds.deleteElementInt(remTAout, k); cumEnablingProb := zeros(nOut); sumEnablingProbTAout := sum(enablingProb[remTAout[1:nremTAout]]); if sumEnablingProbTAout > 0 then cumEnablingProb[1] := enablingProb[remTAout[1]]/sumEnablingProbTAout; for j in 2:nremTAout loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAout[j]]/sumEnablingProbTAout; end for; else cumEnablingProb[1:nremTAout] := fill(1/nremTAout, nremTAout); end if; end if; end for; end if; end if; else disTAout := fill(false, nOut); remTAout := fill(0, nOut); cumEnablingProb := fill(0.0, nOut); arcWeightSum := 0.0; nremTAout := 0; nTAout := 0; k := 0; posTE := 0; randNum := 0.0; state128 := pre(state128); sumEnablingProbTAout := 0.0; endWhile := false; Index := 0; end if; end when; // hack for Dymola 2017 // TEout_ := TEout and TAout; for i in 1:nOut loop TEout_[i] := TEout[i] and TAout[i]; end for; end enablingOutCon;
enabling process of output transitions.
within PNlib.Blocks; block enablingOutDis "enabling process of output transitions" parameter input Integer nOut "number of output transitions"; input Integer arcWeight[:] "arc weights of output transitions"; input Integer t "current token number"; input Integer minTokens "minimum capacity"; input Boolean TAout[:] "active output transitions with passed delay"; input PNlib.Types.EnablingType enablingType "resolution of actual conflicts"; input Integer enablingPrio[:] "enabling priorities of output transitions"; input Real enablingProb[:] "enabling probabilites of output transitions"; input Real enablingBene[:] "enabling benefit of output transitions"; input PNlib.Types.BenefitType benefitType "algorithm for benefit"; input Boolean disTransition[:] "discrete output transition"; input Boolean delayPassed "Does any delayPassed of a output transition"; input Boolean activeCon "change of activation of output transitions"; parameter input Integer localSeed "Local seed to initialize random number generator"; parameter input Integer globalSeed "Global seed to initialize random number generator"; output Boolean TEout_[nOut] "enabled output transitions"; protected discrete Integer state128[4] "state of random number generator"; Boolean TEout[nOut] "enabled output transitions"; Integer remTAout[nOut](each start = 0, each fixed = true) "remaining active output transitions"; discrete Real cumEnablingProb[nOut](each start = 0, each fixed = true) "cumulated, scaled enabling probabilities"; Integer arcWeightSum "arc weight sum"; Integer nremTAout "number of remaining active output transitions"; Integer nTAout "number of active output transitions"; Integer k "iteration index"; Integer posTE "possible enabled transition"; discrete Real randNum "uniform distributed random number"; discrete Real sumEnablingProbTAout "sum of the enabling probabilities of the active output transitions"; Boolean endWhile; Integer Index "priority Index"; discrete Real benefitMax "theoretical benefit"; Boolean valid "valid solution"; discrete Real benefitLimit "best valid benefit"; initial algorithm // Generate initial state from localSeed and globalSeed state128 := Modelica.Math.Random.Generators.Xorshift128plus.initialState(localSeed, globalSeed); (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(state128); algorithm TEout := fill(false, nOut); arcWeightSum := 0; for i in 1:nOut loop //continuous transitions afterwards (discrete transitions have priority over continuous transitions) if TAout[i] and not disTransition[i] and t - (arcWeightSum + arcWeight[i]) >= minTokens then TEout[i] := true; arcWeightSum := arcWeightSum + arcWeight[i]; end if; end for; when delayPassed or activeCon then if nOut > 0 then arcWeightSum := Functions.OddsAndEnds.conditionalSumInt(arcWeight, TAout); //arc weight sum of all active output transitions if t - arcWeightSum >= minTokens then //Place has no actual conflict; all active output transitions are enabled TEout := TAout; else //Place has an actual conflict; if enablingType == PNlib.Types.EnablingType.Priority then //deterministic enabling according to priorities arcWeightSum := 0; for i in 1:nOut loop //discrete transitions are proven at first Index := Modelica.Math.Vectors.find(i, enablingPrio); if Index > 0 and TAout[Index] and disTransition[Index] and t - (arcWeightSum + arcWeight[Index]) >= minTokens then TEout[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; for i in 1:nOut loop //continuous transitions afterwards (discrete transitions have priority over continuous transitions) Index := Modelica.Math.Vectors.find(i, enablingPrio); if TAout[Index] and not disTransition[Index] and t - (arcWeightSum + arcWeight[Index]) >= minTokens then TEout[Index] := true; arcWeightSum := arcWeightSum + arcWeight[Index]; end if; end for; elseif enablingType == PNlib.Types.EnablingType.Probability then //probabilistic enabling according to enabling probabilities remTAout := zeros(nOut); nremTAout := 0; arcWeightSum := 0; for i in 1:nOut loop if TAout[i] and disTransition[i] then nremTAout := nremTAout + 1; //number of active output transitions remTAout[nremTAout] := i; //active output transitions end if; end for; nTAout := nremTAout; //number of active output transitions if nTAout > 0 then sumEnablingProbTAout := sum(enablingProb[remTAout[1:nremTAout]]); //enabling probability sum of all active output transitions cumEnablingProb := zeros(nOut); //cumulative, scaled enabling probabilities cumEnablingProb[1] := enablingProb[remTAout[1]]/sumEnablingProbTAout; for j in 2:nremTAout loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAout[j]]/sumEnablingProbTAout; end for; for i in 1:nTAout loop (randNum, state128) := Modelica.Math.Random.Generators.Xorshift128plus.random(pre(state128)) "uniform distributed random number"; endWhile := false; k := 1; while k <= nremTAout and not endWhile loop if randNum <= cumEnablingProb[k] then posTE := remTAout[k]; endWhile := true; else k := k + 1; end if; end while; if t - (arcWeightSum + arcWeight[posTE]) >= minTokens then arcWeightSum := arcWeightSum + arcWeight[posTE]; TEout[posTE] := true; end if; nremTAout := nremTAout - 1; if nremTAout > 0 then remTAout := Functions.OddsAndEnds.deleteElementInt(remTAout, k); cumEnablingProb := zeros(nOut); sumEnablingProbTAout := sum(enablingProb[remTAout[1:nremTAout]]); if sumEnablingProbTAout > 0 then cumEnablingProb[1] := enablingProb[remTAout[1]]/sumEnablingProbTAout; for j in 2:nremTAout loop cumEnablingProb[j] := cumEnablingProb[j - 1] + enablingProb[remTAout[j]]/sumEnablingProbTAout; end for; else cumEnablingProb[1:nremTAout] := fill(1/nremTAout, nremTAout); end if; end if; end for; end if; for i in 1:nOut loop if TAout[i] and not disTransition[i] and t - (arcWeightSum + arcWeight[i]) >= minTokens then TEout[i] := true; arcWeightSum := arcWeightSum + arcWeight[i]; end if; end for; else if benefitType == PNlib.Types.BenefitType.Greedy then TEout := PNlib.Functions.Enabling.benefitGreedyDisOut(nOut, arcWeight, t, minTokens, TAout, enablingBene, disTransition); elseif benefitType == PNlib.Types.BenefitType.BenefitQuotient then TEout := PNlib.Functions.Enabling.benefitQuotientDisOut(nOut, arcWeight, t, minTokens, TAout, enablingBene, disTransition); else arcWeightSum := 0; benefitMax := sum(enablingBene); benefitLimit := 0; (TEout, arcWeightSum, benefitMax, valid, benefitLimit) := PNlib.Functions.Enabling.benefitBaBDisOut(1, nOut, enablingBene, arcWeight, enablingBene./arcWeight, t, benefitMax, minTokens, TEout, 0, benefitLimit, TAout, disTransition); end if; end if; end if; else remTAout := fill(0, nOut); cumEnablingProb := fill(0.0, nOut); arcWeightSum := 0; nremTAout := 0; nTAout := 0; k := 0; posTE := 0; randNum := 0; state128 := pre(state128); sumEnablingProbTAout := 0.0; endWhile := false; Index := 0; benefitMax := 0; valid := false; benefitLimit := 0; end if; end when; // hack for Dymola 2017 // TEout_ := TEout and TAout; for i in 1:nOut loop TEout_[i] := TEout[i] and TAout[i]; end for; end enablingOutDis;
calculates the firing sum of continuous places.
within PNlib.Blocks; block firingSumCon "calculates the firing sum of continuous places" input Boolean fire[:] "firability of transitions"; input Real arcWeight[:] "arc weights"; input Real instSpeed[:] "istantaneous speed of transitions"; input Boolean disTransition[:] "types of transitions"; output Real conFiringSum "continuous firing sum"; output Real disFiringSum "discrete firing sum"; protected Real vec1[size(fire, 1)]; Real vec2[size(fire, 1)]; //algorithm //changed 21.03.11 due to negative values equation for i in 1:size(fire, 1) loop if fire[i] and not disTransition[i] then vec1[i] = arcWeight[i]*instSpeed[i]; else vec1[i] = 0; end if; if fire[i] and disTransition[i] then vec2[i] = arcWeight[i]; else vec2[i] = 0; end if; end for; conFiringSum = sum(vec1); disFiringSum = sum(vec2); end firingSumCon;
calculates the firing sum of discrete places.
within PNlib.Blocks; block firingSumDis "calculates the firing sum of discrete places" input Boolean fire[:] "firability of transitions"; input Integer arcWeight[:] "arc weights"; output Integer firingSum "firing sum"; algorithm firingSum := 0; for i in 1:size(fire, 1) loop if fire[i] then firingSum := firingSum + arcWeight[i]; end if; end for; end firingSumDis;
contains blocks with specific procedures that are used in the Petri net component models
within PNlib; package Blocks "contains blocks with specific procedures that are used in the Petri net component models" end Blocks;
Calculates the token flow for a continuous place..
within PNlib.Blocks; block tokenFlowCon "Calculates the token flow for a continuous place." parameter input Integer nIn "number of input transitions"; parameter input Integer nOut "number of output transitions"; input Real conFiringSumIn; input Real conFiringSumOut; input Boolean fireIn[nIn]; input Boolean fireOut[nOut]; input Real arcWeightIn[nIn]; input Real arcWeightOut[nOut]; input Real instSpeedIn[nIn]; input Real instSpeedOut[nOut]; output Real inflowSum; output Real inflow[nIn]; output Real outflowSum; output Real outflow[nOut]; equation der(inflowSum) = conFiringSumIn; // der(inflow) = arcWeightIn .* instSpeedIn; for i in 1:nIn loop der(inflow[i]) = if pre(fireIn[i]) then arcWeightIn[i]*instSpeedIn[i] else 0.0; end for; der(outflowSum) = conFiringSumOut; // der(outflow) = arcWeightOut .* instSpeedOut; for i in 1:nOut loop der(outflow[i]) = if pre(fireOut[i]) then arcWeightOut[i]*instSpeedOut[i] else 0.0; end for; end tokenFlowCon;
Calculates the token flow for a discrete place..
within PNlib.Blocks; block tokenFlowDis "Calculates the token flow for a discrete place." parameter input Integer nIn "number of input transitions"; parameter input Integer nOut "number of output transitions"; input Boolean fireIn[nIn]; input Boolean fireOut[nOut]; input Integer arcWeightIn[nIn]; input Integer arcWeightOut[nOut]; output Integer inflowSum; output Integer inflow[nIn]; output Integer outflowSum; output Integer outflow[nOut]; equation for i in 1:nIn loop inflow[i] = pre(inflow[i]) + (if pre(fireIn[i]) then arcWeightIn[i] else 0); end for; inflowSum = sum(inflow); for i in 1:nOut loop outflow[i] = pre(outflow[i]) + (if pre(fireOut[i]) then arcWeightOut[i] else 0); end for; outflowSum = sum(outflow); end tokenFlowDis;
Inhibitor Arc.
within PNlib.Components; model IA "Inhibitor Arc" //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****// parameter Real testValue = 1 "marking that has to be deceeded to enable firing" parameter Boolean realInhibitorArc = true "real Inhibitor arc <, Inhibitor arc <=" parameter Boolean normalArc = true "double arc: inhibitor 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 realInhibitorArc then PNlib.Types.ArcType.RealInhibitorArc else PNlib.Types.ArcType.InhibitorArc, 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 >= 0, "Test values must be greater or equal than zero."); //****ERROR MESSENGES END****// end IA;
Contains component models to compose models of petri nets.
within PNlib; package Components "Contains component models to compose models of petri nets." extends Modelica.Icons.Package; end Components;
Continuous Place.
within PNlib.Components; model PC "Continuous Place" Real t "marking"; parameter Integer nIn(min = 0) = 0 "number of input transitions" parameter Integer nOut(min = 0) = 0 "number of output transitions" //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****// parameter Real startMarks = 0 "start marks" parameter Real minMarks = 0 "minimum capacity" parameter Real maxMarks = PNlib.Constants.inf "maximum capacity" Boolean reStart = false "restart condition" parameter Real reStartMarks = 0 "number of marks at restart" parameter Integer N = settings.N "N+1=amount of levels" parameter PNlib.Types.EnablingType enablingType = PNlib.Types.EnablingType.Priority "resolution type of actual conflict (type-1-conflict)" parameter Integer enablingPrioIn[nIn] = 1:nIn "enabling priorities of input transitions" parameter Integer enablingPrioOut[nOut] = 1:nOut "enabling priorities of output transitions" parameter Real enablingProbIn[nIn] = fill(1/nIn, nIn) "enabling probabilities of input transitions" parameter Real enablingProbOut[nOut] = fill(1/nOut, nOut) "enabling probabilities of output transitions" //****MODIFIABLE PARAMETERS AND VARIABLES END****// Real levelCon "conversion of tokens to level concentration according to M and N of the settings box"; Boolean showPlaceName = settings.showPlaceName "only for place animation and display (Do not change!)"; Boolean showCapacity = settings.showCapacity "only for place animation and display (Do not change!)"; Boolean animateMarking = settings.animateMarking "only for place animation and display (Do not change!)"; Real color[3] "only for place animation and display (Do not change!)"; parameter Boolean showTokenFlow = settings.showTokenFlow Blocks.tokenFlowCon tokenFlow(nIn = nIn, nOut = nOut, conFiringSumIn = firingSumIn.conFiringSum, conFiringSumOut = firingSumOut.conFiringSum, fireIn = fireIn, fireOut = fireOut, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut, instSpeedIn = instSpeedIn, instSpeedOut = instSpeedOut) if showTokenFlow; parameter Integer localSeedIn = PNlib.Functions.Random.counter() "Local seed to initialize random number generator for input conflicts" parameter Integer localSeedOut = PNlib.Functions.Random.counter() "Local seed to initialize random number generator for output conflicts" Interfaces.PlaceIn inTransition[nIn](each t = t_, each tint = 1, each maxTokens = maxMarks, each maxTokensint = 1, enable = enableIn.TEin_, each emptied = emptying.anytrue, decreasingFactor = decFactorIn, each disPlace = false, each speedSum = firingSumOut.conFiringSum, fire = fireIn, disTransition = disTransitionIn, active = activeIn, arcWeight = arcWeightIn, instSpeed = instSpeedIn, maxSpeed = maxSpeedIn, prelimSpeed = prelimSpeedIn, enabledByInPlaces = enabledByInPlaces) if nIn > 0 "connector for input transitions" Interfaces.PlaceOut outTransition[nOut](each t = t_, each tint = 1, each minTokens = minMarks, each minTokensint = 1, enable = enableOut.TEout_, each fed = feeding.anytrue, decreasingFactor = decFactorOut, each disPlace = false, each arcType = PNlib.Types.ArcType.NormalArc, each speedSum = firingSumIn.conFiringSum, each tokenInOut = pre(disMarksInOut), fire = fireOut, disTransition = disTransitionOut, active = activeOut, arcWeight = arcWeightOut, instSpeed = instSpeedOut, maxSpeed = maxSpeedOut, prelimSpeed = prelimSpeedOut, each testValue = -1, each testValueint = -1, each normalArc = false) if nOut > 0 "connector for output transitions" Modelica.Blocks.Interfaces.RealOutput pc_t = t "connector for Simulink connection" protected outer PNlib.Components.Settings settings "global settings for animation and display"; Real disMarkChange "discrete mark change"; Real conMarkChange "continuous mark change"; Real arcWeightIn[nIn] "weights of input arcs"; Real arcWeightOut[nOut] "weights of output arcs"; Real instSpeedIn[nIn] "instantaneous speed of input transitions"; Real instSpeedOut[nOut] "instantaneous speed of output transitions"; Real maxSpeedIn[nIn] "maximum speed of input transitions"; Real maxSpeedOut[nOut] "maximum speed of output transitions"; Real prelimSpeedIn[nIn] "preliminary speed of input transitions"; Real prelimSpeedOut[nOut] "preliminary speed of output transitions"; Real tokenscale "only for place animation and display"; Real t_(start = startMarks, fixed = true) "marking"; Boolean disMarksInOut(start = false, fixed = true) "discrete marks change"; Boolean preFireIn[nIn] "pre-value of fireIn"; Boolean preFireOut[nOut] "pre-value of fireOut"; Boolean fireIn[nIn](each start = false, each fixed = true) "Does any input transition fire?"; Boolean fireOut[nOut](each start = false, each fixed = true) "Does any output transition fire?"; Boolean disTransitionIn[nIn] "Are the input transitions discrete?"; Boolean disTransitionOut[nOut] "Are the output transitions discrete?"; Boolean activeIn[nIn] "Are the input transitions active?"; Boolean activeOut[nOut] "Are the output transitions active?"; Boolean enabledByInPlaces[nIn] "Are the input transitions enabled by all their input places?"; //****BLOCKS BEGIN****// since no events are generated within functions!!! //enabling discrete transitions Blocks.enablingInCon enableIn(active = activeIn, delayPassed = delayPassedIn.anytrue, nIn = nIn, arcWeight = arcWeightIn, t = t_, maxMarks = maxMarks, TAein = enabledByInPlaces and activeIn, enablingType = enablingType, enablingPrio = enablingPrioIn, enablingProb = enablingProbIn, disTransition = disTransitionIn, localSeed = localSeedIn, globalSeed = settings.globalSeed); Blocks.enablingOutCon enableOut(delayPassed = delayPassedOut.anytrue, nOut = nOut, arcWeight = arcWeightOut, t = t_, minMarks = minMarks, TAout = activeOut, enablingType = enablingType, enablingPrio = enablingPrioOut, enablingProb = enablingProbOut, disTransition = disTransitionOut, localSeed = localSeedOut, globalSeed = settings.globalSeed); //Does any delay passed of a connected transition? Blocks.anyTrue delayPassedOut(vec = activeOut and disTransitionOut); Blocks.anyTrue delayPassedIn(vec = activeIn and disTransitionIn); //Does any discrete transition fire? Blocks.anyTrue disMarksOut(vec = fireOut and disTransitionOut); Blocks.anyTrue disMarksIn(vec = fireIn and disTransitionIn); //Is the place fed by input transitions? Blocks.anyTrue feeding(vec = preFireIn and not disTransitionIn); //Is the place emptied by output transitions?" Blocks.anyTrue emptying(vec = preFireOut and not disTransitionOut); //firing sum calculation Blocks.firingSumCon firingSumIn(fire = preFireIn, arcWeight = arcWeightIn, instSpeed = instSpeedIn, disTransition = disTransitionIn); Blocks.firingSumCon firingSumOut(fire = preFireOut, arcWeight = arcWeightOut, instSpeed = instSpeedOut, disTransition = disTransitionOut); //****BLOCKS END****// Real decFactorIn[nIn] "decreasing factors for input transitions"; Real decFactorOut[nOut] "decreasing factors for output transitions"; equation //decreasing factor calculation (decFactorIn, decFactorOut) = Functions.decreasingFactor(nIn = nIn, nOut = nOut, t = t_, minMarks = minMarks, maxMarks = maxMarks, speedIn = firingSumIn.conFiringSum, speedOut = firingSumOut.conFiringSum, maxSpeedIn = maxSpeedIn, maxSpeedOut = maxSpeedOut, prelimSpeedIn = prelimSpeedIn, prelimSpeedOut = prelimSpeedOut, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut, firingIn = fireIn and not disTransitionIn, firingOut = fireOut and not disTransitionOut); //calculation of continuous mark change conMarkChange = firingSumIn.conFiringSum - firingSumOut.conFiringSum; der(t_) = conMarkChange; //calculation of discrete mark change disMarkChange = firingSumIn.disFiringSum - firingSumOut.disFiringSum; disMarksInOut = pre(disMarksOut.anytrue) or pre(disMarksIn.anytrue); when {disMarksInOut, reStart} then reinit(t_, if reStart then reStartMarks else t_ + pre(disMarkChange)); end when; //Conversion of tokens to level concentrations levelCon = t*settings.M/N; for i in 1:nOut loop preFireOut[i] = if disTransitionOut[i] then fireOut[i] else pre(fireOut[i]); end for; for i in 1:nIn loop preFireIn[i] = if disTransitionIn[i] then fireIn[i] else pre(fireIn[i]); end for; t = noEvent(if t_ < minMarks then minMarks elseif t_ > maxMarks then maxMarks else t_); //****MAIN END****// //****ANIMATION BEGIN****// //scaling of tokens for animation tokenscale = t*settings.scale; color = if settings.animatePlace then if tokenscale < 100 then {255, 255 - 2.55*tokenscale, 255 - 2.55*tokenscale} else {255, 0, 0} else {255, 255, 255}; //****ANIMATION END****// //****ERROR MESSENGES BEGIN****// assert(Functions.OddsAndEnds.prioCheck(enablingPrioIn, nIn) or nIn == 0 or enablingType == PNlib.Types.EnablingType.Probability, "The priorities of the input priorities may be given only once and must be selected from 1 to nIn"); assert(Functions.OddsAndEnds.prioCheck(enablingPrioOut, nOut) or nOut == 0 or enablingType == PNlib.Types.EnablingType.Probability, "The priorities of the output priorities may be given only once and must be selected from 1 to nOut"); assert(Functions.OddsAndEnds.isEqual(sum(enablingProbIn), 1.0, 1e-6) or nIn == 0 or enablingType == PNlib.Types.EnablingType.Priority, "The sum of input enabling probabilities has to be equal to 1"); assert(Functions.OddsAndEnds.isEqual(sum(enablingProbOut), 1.0, 1e-6) or nOut == 0 or enablingType == PNlib.Types.EnablingType.Priority, "The sum of output enabling probabilities has to be equal to 1"); assert(startMarks >= minMarks and startMarks <= maxMarks, "minMarks<=startMarks<=maxMarks"); //****ERROR MESSENGES END****// end PC;
Discrete Place.
within PNlib.Components; model PD "Discrete Place" discrete Integer t(start = startTokens, fixed = true) "marking"; parameter Integer nIn(min = 0) = 0 "number of input transitions" parameter Integer nOut(min = 0) = 0 "number of output transitions" //****MODIFIABLE PARAMETERS AND VARIABLES BEGIN****// parameter Integer startTokens = 0 "start tokens" parameter Integer minTokens = 0 "minimum capacity" parameter Integer maxTokens = PNlib.Constants.Integer_inf "maximum capacity" Boolean reStart(start = false, fixed = true) = false "restart condition" parameter Integer reStartTokens = startTokens "number of tokens at restart" parameter PNlib.Types.EnablingType enablingType = PNlib.Types.EnablingType.Priority "resolution type of actual conflict (type-1-conflict)" parameter Integer enablingPrioIn[nIn] = 1:nIn "enabling priorities of input transitions" parameter Integer enablingPrioOut[nOut] = 1:nOut "enabling priorities of output transitions" parameter Real enablingProbIn[nIn] = fill(1/nIn, nIn) "enabling probabilities of input transitions" parameter Real enablingProbOut[nOut] = fill(1/nOut, nOut) "enabling probabilities of output transitions" parameter Real enablingBeneIn[nIn] = 1:nIn "enabling benefit of input transitions" parameter Real enablingBeneOut[nOut] = 1:nOut "enabling benefit of output transitions" parameter PNlib.Types.BenefitType benefitType = PNlib.Types.BenefitType.Greedy "enabling strategy for benefit" parameter Integer N = settings.N "N+1=amount of levels" //****MODIFIABLE PARAMETERS AND VARIABLES END****// Real levelCon "conversion of tokens to level concentration according to M and N of the settings box"; Boolean showCapacity = settings.showCapacity "only for place animation and display (Do not change!)"; Boolean animateMarking = settings.animateMarking "only for place animation and display (Do not change!)"; Real color[3] "only for place animation and display (Do not change!)"; parameter Boolean showTokenFlow = settings.showTokenFlow Blocks.tokenFlowDis tokenFlow(nIn = nIn, nOut = nOut, fireIn = fireIn, fireOut = fireOut, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut) if showTokenFlow; parameter Integer localSeedIn = PNlib.Functions.Random.counter() "Local seed to initialize random number generator for input conflicts" parameter Integer localSeedOut = PNlib.Functions.Random.counter() "Local seed to initialize random number generator for output conflicts" PNlib.Interfaces.PlaceIn inTransition[nIn](each t = pret, each tint = pret, each maxTokens = maxTokens, each maxTokensint = maxTokens, enable = enableIn.TEin_, each emptied = false, each decreasingFactor = 1, each disPlace = true, each speedSum = 0, fire = fireIn, disTransition = disTransitionIn, arcWeightint = arcWeightIn, active = activeIn, enabledByInPlaces = enabledByInPlaces) if nIn > 0 "connector for input transitions" PNlib.Interfaces.PlaceOut outTransition[nOut](each t = pret, each tint = pret, each minTokens = minTokens, each minTokensint = minTokens, enable = enableOut.TEout_, each fed = false, each decreasingFactor = 1, each disPlace = true, each arcType = PNlib.Types.ArcType.NormalArc, each speedSum = 0, each tokenInOut = pre(tokeninout), fire = fireOut, disTransition = disTransitionOut, arcWeightint = arcWeightOut, active = activeOut, each testValue = -1, each testValueint = -1, each normalArc = false) if nOut > 0 "connector for output transitions" Modelica.Blocks.Interfaces.IntegerOutput pd_t = t "connector for Simulink connection" protected outer PNlib.Components.Settings settings "global settings for animation and display"; Real tokenscale "only for place animation and display"; discrete Integer pret "pre marking"; Integer arcWeightIn[nIn] "Integer weights of input arcs"; Integer arcWeightOut[nOut] "Integer weights of output arcs"; Boolean tokeninout(start = false, fixed = true) "change of tokens?"; Boolean fireIn[nIn] "Do input transtions fire?"; Boolean fireOut[nOut] "Do output transitions fire?"; Boolean disTransitionIn[nIn] "Are the input transitions discrete?"; Boolean disTransitionOut[nOut] "Are the output transtions discrete?"; Boolean activeIn[nIn] "Are delays passed of input transitions?"; Boolean activeOut[nOut](each start = false, each fixed = true) "Are delay passed of output transitions?"; Boolean enabledByInPlaces[nIn] "Are input transitions are enabled by all their input places?"; //****BLOCKS BEGIN****// since no events are generated within functions!!! //change of activation of output transitions Blocks.anyChange activeConOut(vec = pre(activeOut) and not disTransitionOut); //Does any delay passed of a connected transition? Blocks.anyTrue delayPassedOut(vec = activeOut and disTransitionOut); Blocks.anyTrue delayPassedIn(vec = activeIn and disTransitionIn); //firing sum calculation Blocks.firingSumDis firingSumIn(fire = fireIn and disTransitionIn, arcWeight = arcWeightIn); Blocks.firingSumDis firingSumOut(fire = fireOut and disTransitionOut, arcWeight = arcWeightOut); //Enabling process Blocks.enablingOutDis enableOut(delayPassed = delayPassedOut.anytrue, activeCon = activeConOut.anychange, nOut = nOut, arcWeight = arcWeightOut, t = pret, minTokens = minTokens, TAout = activeOut, enablingType = enablingType, enablingPrio = enablingPrioOut, enablingProb = enablingProbOut, enablingBene = enablingBeneOut, benefitType = benefitType, disTransition = disTransitionOut, localSeed = localSeedOut, globalSeed = settings.globalSeed); Blocks.enablingInDis enableIn(delayPassed = delayPassedIn.anytrue, active = activeIn, nIn = nIn, arcWeight = arcWeightIn, t = pret, maxTokens = maxTokens, TAein = enabledByInPlaces and activeIn, enablingType = enablingType, enablingPrio = enablingPrioIn, enablingProb = enablingProbIn, enablingBene = enablingBeneIn, benefitType = benefitType, disTransition = disTransitionIn, localSeed = localSeedIn, globalSeed = settings.globalSeed); //****BLOCKS END****// equation //****MAIN BEGIN****// //recalculation of tokens pret = pre(t); tokeninout = pre(firingSumIn.firingSum) > 0 or pre(firingSumOut.firingSum) > 0; when pre(reStart) then t = reStartTokens; elsewhen {pre(firingSumIn.firingSum) > 0, pre(firingSumOut.firingSum) > 0} then t = pret + pre(firingSumIn.firingSum) - pre(firingSumOut.firingSum); end when; //Conversion of tokens to level concentrations levelCon = t*settings.M/N; //****MAIN END****// //****ANIMATION BEGIN****// tokenscale = t*settings.scale; color = if settings.animatePlace then if tokenscale < 100 then {255, 255 - 2.55*tokenscale, 255 - 2.55*tokenscale} else {255, 0, 0} else {255, 255, 255}; //****ANIMATION END****// //****ERROR MESSENGES BEGIN****// assert(Functions.OddsAndEnds.prioCheck(enablingPrioIn, nIn) or nIn == 0 or enablingType == PNlib.Types.EnablingType.Probability, "The priorities of the input priorities may be given only once and must be selected from 1 to nIn"); assert(Functions.OddsAndEnds.prioCheck(enablingPrioOut, nOut) or nOut == 0 or enablingType == PNlib.Types.EnablingType.Probability, "The priorities of the output priorities may be given only once and must be selected from 1 to nOut"); assert(Functions.OddsAndEnds.isEqual(sum(enablingProbIn), 1.0, 1e-6) or nIn == 0 or enablingType == PNlib.Types.EnablingType.Priority, "The sum of input enabling probabilities has to be equal to 1"); assert(Functions.OddsAndEnds.isEqual(sum(enablingProbOut), 1.0, 1e-6) or nOut == 0 or enablingType == PNlib.Types.EnablingType.Priority, "The sum of output enabling probabilities has to be equal to 1"); assert(startTokens >= minTokens and startTokens <= maxTokens, "minTokens<=startTokens<=maxTokens"); //****ERROR MESSENGES END****// end PD;
Global Settings for Animation and Display.
within PNlib.Components; model Settings "Global Settings for Animation and Display" parameter Boolean showPlaceName = true "show names of places" parameter Boolean showTransitionName = true "show names of transitions" parameter Boolean showTime = true "show Time variables of discrete transitions" parameter Boolean showCapacity = false "show capacities of places" parameter Boolean animateMarking = true "animation of markings" parameter Boolean animatePlace = true "animation of places" parameter Real scale = 1 "scale factor for place animation 0-100" parameter Boolean animateTransition = true "animation of transitions" parameter Real timeFire = 0.3 "time of transition animation" parameter Boolean animatePutFireTime = true "animation of putative fire time of stochastic transitions" parameter Boolean animateHazardFunc = true "animation of hazard functions of stochastic transitions" parameter Boolean animateSpeed = true "animation speed of continuous transitions" parameter Boolean animateWeightTIarc = true "show weights of test and inhibitor arcs" parameter Boolean animateTIarc = true "animation of test and inhibition arcs" parameter Integer N = 10 "N+1=amount of levels" parameter Real M = 1 "maximum concentration" parameter Boolean showTokenFlow = false parameter Integer globalSeed = 30020 "global seed to initialize random number generator" end Settings;
immediate Transition.
within PNlib.Components; model T "immediate 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 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(start = false, fixed = true) "Is the transition active?"; Boolean fire "Does the transition fire?"; PNlib.Interfaces.TransitionIn inPlaces[nIn](each active = active, 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 = active, 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 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=real test arc, 3=test arc, 4=real inhibitor arc, 5=inhibitor 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 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 active = activation.active and not pre(active); //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 T;
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;
contains constants which are used in the Petri net component models
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;