Chris Ruhl
Chris Ruhl

Reputation: 41

SystemModeler Connector Weight

I need to create a Weighted Graph using the SystemModeler/OpenModelica interface. The first step of our process will skip the SystemModeler simulation, and pass the model to Mathematica for processing.

My question is about adding attributes to a connector in the System Modeler GUI:

I need to draw a model such that: State A is connected to State B and State C, with a weight of .7 for the path to B, and .3 for the path to C. I need to create an object to hold the weight and associate it with the connector.

I also need to warn when connectors from a given state do not add to 1.

Where do I start?

Upvotes: 2

Views: 89

Answers (1)

Patrik Ekenberg
Patrik Ekenberg

Reputation: 21

As connections in Modelica themselves does not hold any information, rather passing along information from the blocks that it connects, I believe you have two options:

  1. Put a component between two nodes that specifies the weight of the connection.
  2. Have a defined input and output from each node where the output from a node specifies the weight of the connection, and the inputs on a node are summed to check that they equal 1.

Here is an example of how you could do the latter:

model WeightedGraph
  model Node
    Modelica.Blocks.Interfaces.RealInput u[nin];
    Modelica.Blocks.Interfaces.RealOutput y[size(k, 1)];
    Real usum;
    parameter Real k[:] = {0};
    parameter Integer nin = 0;
  equation
    y = k;
    usum = sum(u);
  end Node;
  Node A(nin = 0, k = {0.7});
  Node B(nin = 1, k = {0.3});
  Node C(nin = 1);
equation
  connect(A.y[1], B.u[1]);
  connect(B.y[1], C.u[1]);
end WeightedGraph;

The number of inputs into your component need to be specified using the nin parameter. The number outputs will be equal to the length of k, which is a list where you specify a weight of each connection. You could for example check that ysum adds to 1 using assert or if you wanted to do that in Mathematica.

Upvotes: 2

Related Questions