-
Notifications
You must be signed in to change notification settings - Fork 1
Coupled
Coupled models describes a system as a network of components coupled together. These components are in the modular form, which means their interactions are restricted to happen through identified ports with a preestablished connection.
Coupled models are themselves modular models, which means they also have input and output ports. Thus, it is possible to build a hierarchy of models shaped as a tree, which helps modellers managing complexity.
Coupled models are defined under the Quartz::CoupledModel class.
They can either be instantiated directly or inherited.
In both cases, the API to add sub-models and coupling them is identical.
We will re-use our running example from the atomic model page to connect models.
Adding sub-models is done using the #add_child method or the #<< alias method.
In the example below we build a model of a store, with 2 cashiers and 2 client queues:
class SmallStoreModel < Quartz::CoupledModel
def after_initialize
cashier1 = Cashier.new("cashier1")
cashier2 = Cashier.new("cashier2")
queue1 = Clients.new("queue1")
queue2 = Clients.new("queue2")
counter = Counter.new("counter")
self << cashier1 << cashier2 << queue1 << queue2 << counter
end
endNow we need to couple output ports with input ports between sub-models, using the #attach method, which expects an output port and a target input port:
attach(sender.output_port("out"), receiver.input_port("in"))or using port names instead of a reference to the ports:
attach "output_port_name", to: "input_port_name", between: sender, and: receiver
# or also
attach "output_port_name", to: "input_port_name", between: "sender_name", and: "receiver_name"