Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Modelica PetriNets Examples

Modelica PetriNets Examples

Hello,
To study ModelicaAdditions.PetriNets, I copied and used a segment of code in PetriNets.mo, the code is:

Code:


  package Examples
    extends Modelica.Icons.Library;
    encapsulated model Parallel "Example to demonstrate parallel activities described by a petri net  "
      import Modelica.Icons;
      import ModelicaAdditions.PetriNets;
      extends Icons.Example;
      output Boolean S1state;
      output Boolean P1state;
      output Boolean P2state;
      output Boolean P3state;
      output Boolean P4state;
      output Boolean P5state;
      output Boolean P6state;
      PetriNets.Place01 S1(initialState = true) annotation(extent = [ -60,80; -40,100], rotation =  -90);
      PetriNets.Place11 P1 annotation(extent = [ -60, -10; -40,10], rotation =  -90);
      PetriNets.Parallel Par1(condLabel = "time>1") annotation(extent = [ -60,50; -40,70], rotation =  -90);
      PetriNets.Place12 P2 annotation(extent = [20,50;40,70], rotation =  -90);
      PetriNets.Transition T1(condLabel = "time>2") annotation(extent = [ -20,20;0,40], rotation =  -90);
      PetriNets.Transition T2(condLabel = "time>3") annotation(extent = [60,20;80,40], rotation =  -90);
      PetriNets.Place11 P3 annotation(extent = [ -20, -10;0,10], rotation =  -90);
      PetriNets.Transition T3(condLabel = "time>4") annotation(extent = [ -20, -36;0, -16], rotation =  -90);
      PetriNets.Place11 P4 annotation(extent = [60, -10;80,10], rotation =  -90);
      PetriNets.Transition T4(condLabel = "time>5") annotation(extent = [60, -36;80, -16], rotation =  -90);
      PetriNets.Place21 P5 annotation(extent = [20, -70;40, -50], rotation =  -90);
      PetriNets.Synchronize Sync1(condLabel = "time>6") annotation(extent = [ -60, -76; -40, -56], rotation =  -90);
      PetriNets.Place10 P6 annotation(extent = [ -60, -100; -40, -80], rotation = 270);
    equation
      connect(Par1.outTransition1,P1.inTransition) annotation(points = [ -50,55; -50,12], style(color = 41));
      connect(T1.outTransition,P3.inTransition) annotation(points = [ -10,25; -10,12], style(color = 41));
      connect(P3.outTransition,T3.inTransition) annotation(points = [ -10, -11; -10.05, -19.95], style(color = 41));
      connect(P1.outTransition,Sync1.inTransition1) annotation(points = [ -50, -11; -50, -60], style(color = 41));
      connect(Sync1.outTransition,P6.inTransition) annotation(points = [ -50, -71; -50, -78], style(color = 41));
      connect(T2.outTransition,P4.inTransition) annotation(points = [70,25;70,12], style(color = 41));
      connect(P4.outTransition,T4.inTransition) annotation(points = [70, -11;69.95, -19.95], style(color = 41));
      connect(S1.outTransition,Par1.inTransition) annotation(points = [ -50.2,79; -50.05,66.05], style(color = 41));
      connect(T3.outTransition,P5.inTransition1) annotation(points = [ -10, -31; -10, -37;24, -37;24, -48], style(color = 41));
      connect(T4.outTransition,P5.inTransition2) annotation(points = [70, -31;70, -37;36, -37;36, -48], style(color = 41));
      connect(P2.outTransition2,T2.inTransition) annotation(points = [36,48.9;36,45;69.95,45;69.95,36.05], style(color = 41));
      connect(Par1.outTransition2,P2.inTransition) annotation(points = [ -44,55; -44,50; -25,50; -25,90;30,90;30,72], style(color = 41));
      connect(P5.outTransition,Sync1.inTransition2) annotation(points = [30, -71;30, -90;0, -90;0, -51; -44, -51; -44, -60], style(color = 41));
      connect(P2.outTransition1,T1.inTransition) annotation(points = [24,49;24,44; -10.05,44; -10.05,36.05], style(color = 41));
      Par1.condition = time > 1;
      T1.condition = time > 2;
      T2.condition = time > 3;
      T3.condition = time > 4;
      T4.condition = time > 5;
      Sync1.condition = time > 6;
      S1state = S1.state;
      P1state = P1.state;
      P2state = P2.state;
      P3state = P3.state;
      P4state = P4.state;
      P5state = P5.state;
      P6state = P6.state;
    end Parallel;
  end Examples;

When I tried to simulate this Examples package, I got an error message:


simulate(Examples)
record SimulationResult
    resultFile = "Simulation failed.
Error: Base class Modelica.Icons.Library not found in scope Examples
Error: Error occured while flattening model Examples
"
end SimulationResult;

Please tell me how to fix it. Your help is appreciated!
Thanks.

Re: Modelica PetriNets Examples

First of all, you cannot simulate a package. Second, you need to use
loadModel(Modelica)
loadModel(ModelicaAdditions)

Note that not all models in ModelicaAdditions work with MSL 3.1 and that some do not use valid Modelica code.

Re: Modelica PetriNets Examples

Thanks for your reply, I'm confused by some general things.
after I have loaded Modelica and ModelicaAdditions, I tried to use this model:

Code:


  model Place22 "Place with two input and two output transitions"
    parameter Boolean initialState = false "Initial value of state";
    Boolean state(final start = initialState) "State of place";
  protected
    Boolean newState(final start = initialState);
    annotation(Coordsys(extent = [ -100, -100;100,100], grid = [2,2], component = [20,20]), Window(x = 0.21, y = 0.03, width = 0.52, height = 0.7), Icon(Ellipse(extent = [ -100, -100;100,100], style(color = 41, fillColor = 7)), Line(points = [ -100,60; -80,60], style(color = 41)), Line(points = [ -100, -60; -80, -60], style(color = 41)), Line(points = [80, -60;100, -60], style(color = 41)), Line(points = [82,60;102,60], style(color = 41)), Text(extent = [0,99;0,159], string = "%name")), Diagram(Ellipse(extent = [ -100, -100;100,100], style(color = 41)), Line(points = [ -100,60; -80,60], style(color = 41)), Line(points = [ -100, -60; -80, -60], style(color = 41)), Line(points = [80,60;100,60], style(color = 41)), Line(points = [80, -60;100, -60], style(color = 41))));
  public
    Interfaces.FirePortOut outTransition1 annotation(extent = [100, -70;120, -50]);
    Interfaces.FirePortOut outTransition2 annotation(extent = [100,70;120,50]);
    Interfaces.SetPortIn inTransition1 annotation(extent = [ -140, -80; -100, -40]);
    Interfaces.SetPortIn inTransition2 annotation(extent = [ -140,80; -100,40]);
  equation
    state = pre(newState);
    newState = inTransition1.set or inTransition2.set or state and not (outTransition1.fire or outTransition2.fire);
    inTransition1.state = state;
    inTransition2.state = inTransition1.state or inTransition1.set;
    outTransition1.state = state;
    outTransition2.state = outTransition1.state and not outTransition1.fire;
  end Place22;

I simulated it using

Code:


simulate(Place22, startTime=0,stopTime=6.0);

Then when I tried to plot it, I don't see an "x" to plot. I was going to use something like

Code:


plot(x)

But after I have tried the variables declared in the model, none of them works.
Am I simulating a wrong model? If yes, could you offer a simple working model?
Thanks.

Re: Modelica PetriNets Examples

Well, I don't see any variable called x in your model. Looking through the API it also does not seem like it is possible to query the compiler for names that are available in the result-file. This should probably be enhanced current/smile

There are 0 guests and 0 other users also viewing this topic