0

I am new to Modelica, and I am wondering if it is possible to write a kind of dynamic programming equation. Assume time is discretized by an integer i, and in my specific application x is boolean and f is a boolean function of x.

x(t_i) = f(x(t_{i+d}))

Where d can be a positive or negative integer. Of course, I would initialize x accordingly, either true or false.

Any help or references would be greatly appreciated!

jackfrost9p
  • 243
  • 3
  • 10

2 Answers2

2

It is possible. In Modelica the discretization in time is usually carried on by the compiler, you have to take care of the equations (continous dynamics). Otherwise, if you want to generate events at discrete time points, you can do it using when statements. I suggest you to take a look at Introduction to Object-Oriented Modeling and Simulation with OpenModelica (PDF format, 6.6 MB) - a more recent tutorial (2012) by Peter Fritzson. There is a section that on Discrete Events and Hybrid Systems, that should clarify how to implement your equations in Modelica. Below you can find an example from that tutorial about the model of a bouncing ball, as you can see discretization in time is not considered when you write your dynamic equations. So the continous model of the ball v=der(s), a=der(v) and than the discrete part inside the when clause that handles the contact with the ground:

model BouncingBall "the bouncing ball model"
  parameter Real g=9.81; //gravitational acc.
  parameter Real c=0.90; //elasticity constant
  Real height(start=10),velocity(start=0);
equation
  der(height) = velocity;
  der(velocity)=-g;
  when height<0 then
    reinit(velocity, -c*velocity);
  end when;
end BouncingBall;

Hope this helps, Marco

Marco Romanoni
  • 471
  • 2
  • 9
0

If I understand your question, you want to use the last n evaluations of x to determine the next value of x. If so, this code shows how to do this:

model BooleanHistory
  parameter Integer n=10 "How many points to keep";
  parameter Modelica.SIunits.Time dt=1e-3;
protected 
  Boolean x[n];
  function f
    input Integer n;
    input Boolean past[n-1];
    output Boolean next;
  algorithm 
    next :=not past[1]; // Example
  end f;
initial equation 
  x = {false for i in 1:n};
equation 
  when sample(0,dt) then
    x[2:n] =  pre(x[1:(n-1)]);
    x[1] =  f(n, x[2:n]);
  end when;
end BooleanHistory;
Michael Tiller
  • 9,291
  • 3
  • 26
  • 41