rachinations 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d453a7d9164b1dd29813252604b256fc8219f3c
4
- data.tar.gz: 4ac7305c010e2b43d2488bceaab5aecf30f2db72
3
+ metadata.gz: 2d592dfefebc0ebf34afbfdf48a8dae98cae4943
4
+ data.tar.gz: f941250a99df6971c9e36b13a3b46edd8dd1615c
5
5
  SHA512:
6
- metadata.gz: 79580ad9cd32113ee03fb3ca7dbe6d6a64cd3de6f40eb98823a8a4337931c34634046f7515071b67c38c82fc66cdbd7cbf29d2e1ed4a66f7c5ffef13ec719354
7
- data.tar.gz: e565c119969a4c534adf4b7c6843d9cea5e5e5ef5548438e58152c40c6418f1118cb862b128ec6924fa19e39d05ed4da1186a3fdbc9fa0c3aa17a38750e7f97b
6
+ metadata.gz: b3f7d29e20cef453c105a4239b24a57fd9cdafac36935551a4eed02cc47cec18dbf552e2823474fe491c8713da914ffc10865b71a60b8c944034f797da74b7e9
7
+ data.tar.gz: e4c0f8b8090a1d88a0058a2d8499522143f80008621b4e36971515ea09a0eaafab04219b0f4f32582595c5aab96318b4c774c2d459f18437672a55e2a174a89f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rachinations (0.0.7)
4
+ rachinations (0.0.8)
5
5
  activesupport (= 3.0.0)
6
6
  fraction (= 0.3.2)
7
7
  i18n (= 0.6.11)
data/README.md CHANGED
@@ -189,8 +189,182 @@ All you need to do is write your diagram in a file whose name ends in `.rb` and
189
189
  end
190
190
  ```
191
191
 
192
- ### Full DSL specification
193
- **TODO**
192
+ ## Full DSL specification
193
+
194
+ ### Diagram creation
195
+
196
+ **Supported options**
197
+
198
+ - `name`
199
+ - Optional
200
+ - Type: IDENTIFIER
201
+ - Default value: `Nil`
202
+ - *Note*: If present, this option must be the first one given.
203
+
204
+ - `mode`
205
+ - Optional
206
+ - Supported values: `:default`, `:silent` and `:verbose`
207
+ - Default value: `:default`
208
+
209
+ **Examples**
210
+ - TODO
211
+
212
+
213
+ ### Pools, Sources and Sinks
214
+
215
+ **Supported options**
216
+
217
+ - `name`
218
+ - Optional
219
+ - Type: IDENTIFIER
220
+ - Default value: `Nil`
221
+ - *Note*: If present, this option must be the first one given.
222
+
223
+ - `initial_value`
224
+ - Optional
225
+ - Type: NATURAL
226
+ - Default value: `0`
227
+ - *Note*: Only applicable to Pools.
228
+
229
+ - `mode`
230
+ - Optional
231
+ - Supported values: `:push_any`, `:pull_any`, `:push_all` and `:pull_all`
232
+ - Default value: `:push_any` for Sources, `:pull_any` for Pools and Sinks.
233
+
234
+ - `activation`
235
+ - Optional
236
+ - Supported values: `:passive`, `:automatic` and `:start`
237
+ - Default value: `:automatic` for Sources, `:passive` for Pools and Sinks.
238
+
239
+ - `condition`
240
+ - Optional
241
+ - Type: EXPRESSION
242
+ - Default value: `expr{ true }` (always evaluates to `true`)
243
+
244
+ - `triggers`
245
+ - Optional
246
+ - Type: IDENTIFIER
247
+ - Default: `Nil`
248
+ - *Note*: If present, it must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
249
+
250
+ - `triggered_by`
251
+ - Optional
252
+ - Type: IDENTIFIER
253
+ - Default: `Nil`
254
+ - *Note*: If present, it must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
255
+
256
+ **Examples**
257
+ - TODO
258
+
259
+ ### Gates
260
+
261
+ **Supported options**
262
+
263
+ - `name`
264
+ - Optional
265
+ - Type: IDENTIFIER
266
+ - Default value: `Nil`
267
+ - *Note*: If present, this option must be the first one given.
268
+
269
+ - `mode`
270
+ - Optional
271
+ - Supported values: `:probabilistic` and `:deterministic`
272
+ - Default value: `:deterministic`
273
+
274
+ - `activation`
275
+ - Optional
276
+ - Supported values: `:passive`, `:automatic` and `:start`
277
+ - Default value: `:passive`
278
+
279
+ - `condition`
280
+ - Optional
281
+ - Type: EXPRESSION
282
+ - Default value: `expr{ true }` (always evaluates to `true`)
283
+
284
+ - `triggers`
285
+ - Optional
286
+ - Type: IDENTIFIER
287
+ - Default: `Nil`
288
+ - *Note*: If present, it must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
289
+
290
+ - `triggered_by`
291
+ - Optional
292
+ - Type: IDENTIFIER
293
+ - Default: `Nil`
294
+ - *Note*: If present, it must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
295
+
296
+ **Examples**
297
+ - TODO
298
+
299
+ ### Converters
300
+
301
+ **Supported options**
302
+
303
+ - `name`
304
+ - Optional
305
+ - Type: IDENTIFIER
306
+ - Default value: `Nil`
307
+ - *Note*: If present, this option must be the first one given.
308
+
309
+ - `mode`
310
+ - Optional
311
+ - Supported values: `:push_any`, `:pull_any`, `:push_all` and `:pull_all`
312
+ - Default value: `:push_all`
313
+
314
+ - `activation`
315
+ - Optional
316
+ - Supported values: `:passive`, `:automatic` and `:start`
317
+ - Default value: `:passive`
318
+
319
+
320
+ **Examples**
321
+ - TODO
322
+
323
+ ### Edges
324
+
325
+ **Supported options**
326
+
327
+ - `name`
328
+ - Optional
329
+ - Type: IDENTIFIER
330
+ - Default value: `Nil`
331
+ - *Note*: If present, this option must be the first one given.
332
+
333
+ - `from`
334
+ - Required
335
+ - Type: IDENTIFIER
336
+ - *Note*: It must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
337
+
338
+ - `to`
339
+ - Required
340
+ - Type: IDENTIFIER
341
+ - *Note*: It must be the name of a Diagram element that already exists or that will be added until the end of Diagram definition.
342
+
343
+ - `label`
344
+ - Optional
345
+ - Type: POSITIVE REAL
346
+ - Default value: `1`
347
+
348
+ **Examples**
349
+ - TODO
350
+
351
+ ### Stop conditions
352
+
353
+ **Supported options**
354
+
355
+ - `name`
356
+ - Optional if this is the only stop condition in the whole Diagram. Required otherwise.
357
+ - Type: IDENTIFIER
358
+ - Default value: `Nil`
359
+ - *Note*: If present, this option must be the first one given.
360
+
361
+ - `condition`
362
+ - Required
363
+ - Type: EXPRESSION
364
+
365
+ **Examples**
366
+ - TODO
367
+
194
368
 
195
369
 
196
370
 
@@ -13,6 +13,8 @@ require 'rachinations/extras/fifo'
13
13
 
14
14
  require 'rachinations/domain/diagrams/diagram'
15
15
  require 'rachinations/domain/diagrams/verbose_diagram'
16
+ require 'rachinations/domain/diagrams/default_diagram'
17
+ require 'rachinations/domain/diagrams/silent_diagram'
16
18
  require 'rachinations/domain/diagrams/non_deterministic_diagram'
17
19
  require 'rachinations/dsl/diagram_shorthand_methods'
18
20
  require 'rachinations/dsl/bootstrap'
@@ -0,0 +1,5 @@
1
+ require 'rachinations/domain/modules/diagrams/default'
2
+
3
+ class DefaultDiagram < Diagram
4
+ include ::Default
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'rachinations/domain/modules/diagrams/silent'
2
+
3
+ class SilentDiagram < Diagram
4
+
5
+ include ::Silent
6
+
7
+ end
@@ -1,5 +1,3 @@
1
- # require 'fraction'
2
-
3
1
  module NumberModifiers
4
2
 
5
3
  # allow user to modify Numbers in order to express
@@ -0,0 +1,49 @@
1
+ module Default
2
+
3
+ @time = nil
4
+ @last_round = 0
5
+
6
+ def before_run
7
+
8
+ @time = Time.now
9
+
10
+ print "\n\033[1;32m===== INITIAL STATE =====\e[00m\n\n"
11
+
12
+ puts self
13
+ end
14
+
15
+ def after_run
16
+
17
+ total_time = ( Time.now - @time )
18
+
19
+ total_rounds = @last_round
20
+
21
+ print "\033[1;32m====== FINAL STATE ======\e[00m\n\n"
22
+
23
+ puts self
24
+
25
+ print "\033[1;31m========== END ==========\e[00m\n\n"
26
+
27
+ print "Diagram '#{name}' ran for #{total_rounds} rounds.\n"
28
+
29
+ if total_time < 1.0
30
+ print "Total time elapsed: #{(total_time*1000).to_i} milliseconds.\n"
31
+ else
32
+ print "Total time elapsed: #{total_time.to_i} seconds.\n"
33
+ end
34
+
35
+
36
+ end
37
+
38
+ def before_round(round_no)
39
+ end
40
+
41
+ def after_round (round_no)
42
+ @last_round = round_no
43
+ end
44
+
45
+ def sanity_check_message
46
+ print "\033[1;31m= SAFEGUARD CONDITION REACHED - ABORTING EXECUTION =\e[00m\n\n"
47
+ end
48
+
49
+ end
@@ -0,0 +1,18 @@
1
+ module Silent
2
+
3
+ def before_run
4
+ end
5
+
6
+ def after_run
7
+ end
8
+
9
+ def before_round(round_no)
10
+ end
11
+
12
+ def after_round (round_no)
13
+ end
14
+
15
+ def sanity_check_message
16
+ end
17
+
18
+ end
@@ -1,18 +1,38 @@
1
1
  module Verbose
2
2
 
3
+ @time = nil
4
+ @last_round = 0
3
5
 
4
6
  def before_run
7
+
8
+ @time = Time.now
9
+
5
10
  print "\n\033[1;32m===== INITIAL STATE =====\e[00m\n\n"
6
11
 
7
12
  puts self
8
13
  end
9
14
 
10
15
  def after_run
16
+
17
+ total_time = ( Time.now - @time )
18
+
19
+ total_rounds = @last_round
20
+
11
21
  print "\033[1;32m====== FINAL STATE ======\e[00m\n\n"
12
22
 
13
23
  puts self
14
24
 
15
25
  print "\033[1;31m========== END ==========\e[00m\n\n"
26
+
27
+ print "Diagram '#{name}' ran for #{total_rounds} rounds.\n"
28
+
29
+ if total_time < 1.0
30
+ print "Total time elapsed: #{(total_time*1000).to_i} milliseconds."
31
+ else
32
+ print "Total time elapsed: #{total_time.to_i} seconds."
33
+ end
34
+
35
+
16
36
  end
17
37
 
18
38
  def before_round(round_no)
@@ -20,6 +40,7 @@ module Verbose
20
40
  end
21
41
 
22
42
  def after_round (round_no)
43
+ @last_round = round_no
23
44
  puts self
24
45
  end
25
46
 
@@ -13,8 +13,10 @@ module DSL
13
13
  raise BadDSL, "Unknown diagram mode: #{mode.to_s}" unless supported_modes.include? mode
14
14
 
15
15
  # right now silent and default are the same thing
16
- if mode == :default || mode == :silent
17
- dia= Diagram.new(Parser.validate_name!(name))
16
+ if mode == :default
17
+ dia= DefaultDiagram.new(Parser.validate_name!(name))
18
+ elsif mode == :silent
19
+ dia = SilentDiagram.new(Parser.validate_name!(name))
18
20
  elsif mode == :verbose || mode == 'verbose'
19
21
  dia = VerboseDiagram.new(Parser.validate_name!(name))
20
22
  end
@@ -1,3 +1,3 @@
1
1
  module Rachinations
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -184,7 +184,7 @@ describe 'Diagrams with gates' do
184
184
 
185
185
  it 'probabilistic gates send resources in a non-deterministic way' do
186
186
 
187
- no_of_turns = 100
187
+ no_of_turns = 800
188
188
 
189
189
  d = Diagram.new
190
190
 
@@ -204,9 +204,9 @@ describe 'Diagrams with gates' do
204
204
  d.run! no_of_turns
205
205
 
206
206
  # have to deal with probabilities here
207
- expect(d.get_node('p1').resource_count).to be_within(10).of(50)
208
- expect(d.get_node('p2').resource_count).to be_within(10).of(25)
209
- expect(d.get_node('p3').resource_count).to be_within(10).of(25)
207
+ expect(d.get_node('p1').resource_count).to be_within(50).of(400)
208
+ expect(d.get_node('p2').resource_count).to be_within(50).of(200)
209
+ expect(d.get_node('p3').resource_count).to be_within(50).of(200)
210
210
 
211
211
  # this should work in most cases
212
212
  expect(d.get_node('p2').resource_count).not_to eq(d.get_node('p3').resource_count)
@@ -319,12 +319,12 @@ describe Diagram do
319
319
  pool 'p1'
320
320
  pool 'p2'
321
321
  pool 'p3'
322
- sink 's2', :automatic, condition: expr{ p2.resource_count > 30 }
322
+ sink 's2', :automatic, condition: expr { p2.resource_count > 30 }
323
323
  edge from: 's1', to: 'g1'
324
324
  edge from: 'g1', to: 'p1'
325
- edge 2,from:'g1', to:'p2'
326
- edge from:'g1', to:'p3'
327
- edge from:'p3', to:'s2'
325
+ edge 2, from: 'g1', to: 'p2'
326
+ edge from: 'g1', to: 'p3'
327
+ edge from: 'p3', to: 's2'
328
328
 
329
329
  end
330
330
 
@@ -362,6 +362,42 @@ describe Diagram do
362
362
 
363
363
  end
364
364
 
365
+ it 'diagram output modes' do
366
+ # making sure it doesn't just terminate and print nothing!
367
+
368
+ expect {
369
+
370
+ d=diagram 'a_diagram', mode: :default do
371
+ source 's'
372
+ edge from: 's', to: 'p'
373
+ pool 'p'
374
+ end
375
+ d.run 100
376
+ }.to output(/total\stime\selapsed/i).to_stdout
377
+
378
+
379
+ expect {
380
+
381
+ d=diagram 'a_diagram', mode: :silent do
382
+ source 's'
383
+ edge from: 's', to: 'p'
384
+ pool 'p'
385
+ end
386
+ d.run 100
387
+ }.to output("").to_stdout
388
+
389
+ expect {
390
+
391
+ d=diagram 'a_diagram', mode: :verbose do
392
+ source 's'
393
+ edge from: 's', to: 'p'
394
+ pool 'p'
395
+ end
396
+ d.run 20
397
+ }.to output(/round/i).to_stdout # in search of a better regex...
398
+
399
+ end
400
+
365
401
  end
366
402
 
367
403
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rachinations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Almeida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -169,8 +169,10 @@ files:
169
169
  - README.md
170
170
  - Rakefile
171
171
  - lib/rachinations.rb
172
+ - lib/rachinations/domain/diagrams/default_diagram.rb
172
173
  - lib/rachinations/domain/diagrams/diagram.rb
173
174
  - lib/rachinations/domain/diagrams/non_deterministic_diagram.rb
175
+ - lib/rachinations/domain/diagrams/silent_diagram.rb
174
176
  - lib/rachinations/domain/diagrams/verbose_diagram.rb
175
177
  - lib/rachinations/domain/edge_collection.rb
176
178
  - lib/rachinations/domain/edges/edge.rb
@@ -185,6 +187,8 @@ files:
185
187
  - lib/rachinations/domain/modules/common/refiners/number_modifiers.rb
186
188
  - lib/rachinations/domain/modules/common/refiners/proc_convenience_methods.rb
187
189
  - lib/rachinations/domain/modules/common/schedulable_tasks.rb
190
+ - lib/rachinations/domain/modules/diagrams/default.rb
191
+ - lib/rachinations/domain/modules/diagrams/silent.rb
188
192
  - lib/rachinations/domain/modules/diagrams/verbose.rb
189
193
  - lib/rachinations/domain/node_collection.rb
190
194
  - lib/rachinations/domain/nodes/converter.rb