-
Notifications
You must be signed in to change notification settings - Fork 1
/
sim_process_dsl.rb
58 lines (45 loc) · 1.05 KB
/
sim_process_dsl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rbsim'
require 'tcpn'
class CPU
attr_accessor :node, :performance
def initialize(node, performance)
@node, @performance = node, performance
end
end
class CPUToken < CPU
include TCPN::TokenMethods
end
hlmodel = RBSim.dsl do
new_process :worker do
on_event :data do |volume|
delay_for 100
cpu do |c|
12/c.performance
end
end
delay_for 100
cpu do |cpu|
100/cpu.performance
end
register_event :data, 1000
end
end
process_token = hlmodel.processes[:worker]
process_token.node = :node01
cpu_token = CPUToken.new(:node01, 10)
tcpn = TCPN.read 'lib/tcpn/model/application.rb'
tcpn.add_marking_for 'CPU', cpu_token
tcpn.add_marking_for 'process', process_token
sim = TCPN.sim tcpn
transitions = []
sim.cb_for :transition, :after do |t, e|
transitions << e.transition
puts "==> FIRING: #{e.transition} #{e.binding.map { |k, v| "#{k}: #{v}"}.join ',' }"
#puts model.marking
end
sim.run
p transitions
puts " MARKING ".center(70, '=')
tcpn.marking.each do |p, m|
puts "#{p}: #{m}"
end