art-decomp 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -1,10 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
+ require 'rubygems' if RUBY_VERSION < '1.9'
5
+ require 'backports/1.9' if RUBY_VERSION < '1.9'
6
+
4
7
  require_relative '../lib/art-decomp'
5
8
 
6
9
  input_limit = ARGV.first.to_i.zero? ? 0 : ARGV.shift.to_i
7
10
 
11
+ $stdout.sync = true
12
+
8
13
  ARGV.each do |fsm_file|
9
14
  fsm = ArtDecomp::FSM.from_kiss fsm_file
10
15
  seps = fsm.beta_f.seps
@@ -14,7 +19,10 @@ ARGV.each do |fsm_file|
14
19
  puts fsm_file
15
20
  puts "X seps: #{input_seps.map(&:size).inspect}"
16
21
 
22
+ input_seps.each_with_index { |a, i| puts "#{i} insignificant" if a.empty? }
23
+
17
24
  (0...input_seps.size).pairs.to_a.each do |a, b|
25
+ next if input_seps[a].empty? or input_seps[b].empty?
18
26
  puts "#{a} ⊂ #{b}" if input_seps[a].proper_subset? input_seps[b]
19
27
  puts "#{a} = #{b}" if input_seps[a] == input_seps[b]
20
28
  puts "#{a} ⊃ #{b}" if input_seps[a].proper_superset? input_seps[b]
data/bin/ad-inputs CHANGED
@@ -8,6 +8,8 @@ require_relative '../lib/art-decomp'
8
8
 
9
9
  input_limit = ARGV.first.to_i.zero? ? 0 : ARGV.shift.to_i
10
10
 
11
+ $stdout.sync = true
12
+
11
13
  ARGV.each do |fsm_file|
12
14
  fsm = ArtDecomp::FSM.from_kiss fsm_file
13
15
  next if fsm.input_count < input_limit
@@ -8,10 +8,6 @@ module ArtDecomp class Decomposition
8
8
  [@fsm, @u, @v, @qu, @qv, @g] == [other.fsm, other.u, other.v, other.qu, other.qv, other.g]
9
9
  end
10
10
 
11
- def decomposable?
12
- @qu.size > 2
13
- end
14
-
15
11
  def disjoint?
16
12
  (@u & @v).empty?
17
13
  end
@@ -80,6 +76,10 @@ module ArtDecomp class Decomposition
80
76
  @v.size + @qv.pins <= archs.map(&:pins).max and @u.size + @qu.pins + @g.pins < @fsm.input_count + @fsm.beta_q.pins
81
77
  end
82
78
 
79
+ def symbolic?
80
+ @qu.size > 2
81
+ end
82
+
83
83
  def valid?
84
84
  @g.seps.subset?((@fsm.beta_x(@v) * @qv).seps) and @fsm.beta_f.seps.subset?((@fsm.beta_x(@u) * @qu * @g).seps)
85
85
  end
@@ -12,6 +12,7 @@ module ArtDecomp class Executable
12
12
  opt :uv, 'UV generator(s)', :default => ['Relevance']
13
13
  opt :qu, 'Qu generator(s)', :default => ['EdgeLabels']
14
14
  opt :qv, 'Qv generator(s)', :default => ['GraphColouring']
15
+ opt :binary, 'Compute binary decompositions', :default => false
15
16
  opt :non_disjoint, 'Compute non-disjoint decompositions', :default => false
16
17
  opt :deep_ndj, 'Compute deep non-dj decompositions', :default => false
17
18
  opt :log, 'Logging target', :type => :string
@@ -38,6 +39,7 @@ module ArtDecomp class Executable
38
39
  @fsm = FSM.from_kiss args.first
39
40
  @archs = opts[:archs].map { |s| Arch[*s.split('/').map(&:to_i)] }.to_set
40
41
  @iters = opts[:iters]
42
+ @binary = opts[:binary]
41
43
  @non_disjoint = opts[:non_disjoint]
42
44
  @deep_ndj = opts[:deep_ndj]
43
45
 
@@ -80,7 +82,7 @@ module ArtDecomp class Executable
80
82
  if dec.final? @archs
81
83
  this = cells + dec.g_cells(@archs) + dec.h_cells(@archs)
82
84
  @best = this if @best.nil? or this < @best
83
- elsif iters != 1 and dec.decomposable? and (@best.nil? or cells < @best)
85
+ elsif iters != 1 and (@binary or dec.symbolic?) and (@best.nil? or cells < @best)
84
86
  in_dir = "#{dir}/#{i}"
85
87
  Dir.mkdir in_dir
86
88
  decompositions(FSM.from_kiss(dec.h_kiss), iters - 1, in_dir, cells + dec.g_cells(@archs)).each do |in_dec, in_dir, in_i|
@@ -4,8 +4,11 @@ module ArtDecomp class FSM
4
4
  kiss = File.read kiss unless kiss.index "\n"
5
5
  inputs, outputs, state, next_state = [], [], [], []
6
6
  kiss.lines do |line|
7
- next unless line =~ /^\s*[01-]+\s+\S+\s+\S+\s+[01-]+\s*$/
8
- ins, st, nxt, outs = line.split
7
+ case line
8
+ when /^\s*[01-]+\s+\S+\s+\S+\s+[01-]+\s*$/ then ins, st, nxt, outs = *line.split
9
+ when /^\s*[01-]+\s+[01-]+\s*$/ then st, nxt, ins, outs = DontCare, DontCare, *line.split
10
+ else next
11
+ end
9
12
  inputs << ins.split(//).map(&:to_sym)
10
13
  outputs << outs.split(//).map(&:to_sym)
11
14
  state << (st == '*' ? DontCare : st.to_sym)
@@ -31,8 +34,7 @@ module ArtDecomp class FSM
31
34
  end
32
35
 
33
36
  def beta_f
34
- outs = @outputs.map { |output| Blanket.from_array output }
35
- outs.inject(:*) * Blanket.from_array(@next_state)
37
+ @outputs.map { |o| Blanket.from_array o }.inject(:*) * Blanket.from_array(@next_state)
36
38
  end
37
39
 
38
40
  def beta_q
@@ -98,10 +100,15 @@ module ArtDecomp class FSM
98
100
  st = @state.map { |e| e == DontCare ? '*' : e }
99
101
  nxt = @next_state.map { |e| e == DontCare ? '*' : e }
100
102
  div = Array.new @state.size, ' '
101
- cols = @inputs + [div, st, div, nxt, div] + @outputs
103
+ mid = truth_table? ? [div] : [div, st, div, nxt, div]
104
+ cols = @inputs + mid + @outputs
102
105
  KISS.new(cols.transpose.map(&:join)).formatted
103
106
  end
104
107
 
108
+ def truth_table?
109
+ @state.all? { |s| s == DontCare } and @next_state.all? { |ns| ns == DontCare }
110
+ end
111
+
105
112
  def x_encoding ins, rows
106
113
  ins.map { |i| encoding @inputs[i], rows }.join
107
114
  end
@@ -73,9 +73,9 @@ module ArtDecomp describe Decomposition do
73
73
  @b4 = mock Blanket, :pins => 4
74
74
  end
75
75
 
76
- it 'should properly report whether it’s decomposable further' do
77
- Decomposition.new(@fsm, Set[0], Set[1], @b1, @b, @b).should_not be_decomposable
78
- Decomposition.new(@fsm, Set[0], Set[1], @b2, @b, @b).should be_decomposable
76
+ it 'should report whether the resulting H block is an FSM' do
77
+ Decomposition.new(@fsm, Set[0], Set[1], @b1, @b, @b).should_not be_symbolic
78
+ Decomposition.new(@fsm, Set[0], Set[1], @b2, @b, @b).should be_symbolic
79
79
  end
80
80
 
81
81
  it 'should properly report whether it’s sensible, based on the target Archs and G and H blocks’ architectures' do
@@ -156,6 +156,6 @@ module ArtDecomp describe Executable do
156
156
  File.read(log.path).should =~ rex('final best decomposition: 0 cells')
157
157
  end
158
158
 
159
- # FIXME: add specs for --non-disjoint and --deep-ndj
159
+ # FIXME: add specs for --binary, --non-disjoint and --deep-ndj
160
160
 
161
161
  end end
@@ -5,13 +5,14 @@ module ArtDecomp describe FSM do
5
5
  context 'parsed from an example KISS file' do
6
6
 
7
7
  before do
8
+ @ex4 = FSM.from_kiss 'spec/fixtures/ex4'
8
9
  @fsm = FSM.from_kiss 'spec/fixtures/fsm'
9
10
  @lion = FSM.from_kiss 'spec/fixtures/lion'
10
11
  @mark1 = FSM.from_kiss 'spec/fixtures/mark1'
11
12
  @mc = FSM.from_kiss 'spec/fixtures/mc'
12
13
  @opus = FSM.from_kiss 'spec/fixtures/opus'
13
14
  @s8 = FSM.from_kiss 'spec/fixtures/s8'
14
- @s420 = FSM.from_kiss 'spec/fixtures/s420'
15
+ @tt = FSM.from_kiss 'spec/fixtures/truth_table'
15
16
  end
16
17
 
17
18
  it 'should parse both KISS files and strings' do
@@ -22,6 +23,12 @@ module ArtDecomp describe FSM do
22
23
  lambda { FSM.from_kiss 'spec/fixtures/ex5' }.should_not raise_error
23
24
  end
24
25
 
26
+ it 'should handle truth table files by faking a don’t-care state column' do
27
+ @tt.input_count.should == 4
28
+ @tt.output_count.should == 2
29
+ @tt.beta_q.should == Blanket[B[0,1,2,3]]
30
+ end
31
+
25
32
  it 'should properly report the number of inputs' do
26
33
  @opus.input_count.should == 5
27
34
  @lion.input_count.should == 2
@@ -56,6 +63,7 @@ module ArtDecomp describe FSM do
56
63
  @opus.to_kiss.should == File.read('spec/fixtures/opus.to_kiss')
57
64
  @lion.to_kiss.should == File.read('spec/fixtures/lion.to_kiss')
58
65
  @mc.to_kiss.should == File.read('spec/fixtures/mc.to_kiss')
66
+ @tt.to_kiss.should == File.read('spec/fixtures/truth_table')
59
67
  end
60
68
 
61
69
  it 'should return given inputs’ encoding for the given row(s)' do
@@ -132,13 +140,19 @@ module ArtDecomp describe FSM do
132
140
  end
133
141
 
134
142
  it 'should report its input relevance, and drop irrelevant inputs' do
143
+ @ex4.input_relevance.should == [nil, nil, nil, nil, 2, 1, 5, 4, 3]
135
144
  @fsm.input_relevance.should == [2, 1, 3, 0, nil, nil, nil, nil]
136
145
  @lion.input_relevance.should == [0, nil, nil, 1]
137
146
  @mark1.input_relevance.should == [nil, nil, nil, nil, 0, 3, 2, 4, 1]
138
147
  @mc.input_relevance.should == [nil, nil, 2, 1, 0]
139
148
  @opus.input_relevance.should == [nil, nil, nil, nil, 2, 3, 4, 0, 1]
140
149
  @s8.input_relevance.should == [3, 2, 1, 0, nil, nil, nil]
141
- @s420.input_relevance.should == [1, 0, 18, nil, nil, nil, nil, nil, 17, 16, 15, 14, 13]
150
+ @tt.input_relevance.should == [1, 3, 2]
151
+ end
152
+
153
+ it 'should report whether it’s a truth table or a full-blown FSM' do
154
+ @tt.should be_truth_table
155
+ @fsm.should_not be_truth_table
142
156
  end
143
157
 
144
158
  end
data/spec/fixtures/ex4 ADDED
@@ -0,0 +1,25 @@
1
+ .i 6
2
+ .o 9
3
+ .p 21
4
+ .s 14
5
+ 1----- 1 3 110000000
6
+ 1----- 3 2 000000000
7
+ 1----- 2 5 001000000
8
+ 1----- 5 7 000000000
9
+ 10---- 7 7 000000000
10
+ 11---- 7 11 100110000
11
+ 1----- 11 12 100100000
12
+ 1-1--- 12 8 000001100
13
+ 1-0--- 12 8 000000100
14
+ 1-0--- 8 3 110000000
15
+ 1-10-- 8 3 110000000
16
+ 1-11-- 8 4 110000000
17
+ 1---1- 4 13 000000010
18
+ 1---0- 4 13 000000000
19
+ 1----- 13 14 001000010
20
+ 1----- 14 6 000000000
21
+ 10---- 6 6 000000000
22
+ 11---- 6 9 100110000
23
+ 1----- 9 10 100100000
24
+ 1----1 10 3 110000101
25
+ 1----0 10 4 110000100
@@ -0,0 +1,4 @@
1
+ -0-- 01
2
+ -111 10
3
+ 01-0 00
4
+ 110- 00
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: art-decomp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Szotkowski
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 +01:00
12
+ date: 2009-12-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -76,8 +76,8 @@ description:
76
76
  email: p.szotkowski@tele.pw.edu.pl
77
77
  executables:
78
78
  - ad-validate
79
- - ad-compare
80
79
  - ad-console
80
+ - ad-analyse
81
81
  - ad-inputs
82
82
  - art-decomp
83
83
  extensions: []
@@ -90,7 +90,7 @@ files:
90
90
  - README
91
91
  - Rakefile
92
92
  - VERSION
93
- - bin/ad-compare
93
+ - bin/ad-analyse
94
94
  - bin/ad-console
95
95
  - bin/ad-inputs
96
96
  - bin/ad-validate
@@ -145,6 +145,7 @@ files:
145
145
  - spec/core/integer_spec.rb
146
146
  - spec/core/set_spec.rb
147
147
  - spec/core/string_spec.rb
148
+ - spec/fixtures/ex4
148
149
  - spec/fixtures/ex5
149
150
  - spec/fixtures/fsm
150
151
  - spec/fixtures/fsm.exp
@@ -164,8 +165,8 @@ files:
164
165
  - spec/fixtures/opus.amb.h
165
166
  - spec/fixtures/opus.h
166
167
  - spec/fixtures/opus.to_kiss
167
- - spec/fixtures/s420
168
168
  - spec/fixtures/s8
169
+ - spec/fixtures/truth_table
169
170
  - spec/spec.opts
170
171
  - spec/spec_helper.rb
171
172
  has_rdoc: true
data/spec/fixtures/s420 DELETED
@@ -1,142 +0,0 @@
1
- .i 19
2
- .o 2
3
- .p 137
4
- .s 18
5
- .r 1111111111111111
6
- 1----------------1- 1111111111111111 0000000000000000 11
7
- 1----------------00 1111111111111111 0000000000000000 10
8
- 1----------------01 1111111111111111 0000000000000000 11
9
- 0------------------ 1111111111111111 0000000000000000 10
10
- 10----------------1 0000000000000000 0001000000000000 01
11
- 10----------------0 0000000000000000 0001000000000000 00
12
- 00----------------- 0000000000000000 0000000000000000 00
13
- 01----------------1 0000000000000000 0000000000000000 00
14
- 11----------------1 0000000000000000 0000000000000000 01
15
- -1----------------0 0000000000000000 0000000000000000 00
16
- 0------------------ 0001000000000000 0000000000000000 00
17
- 11---------------1- 0001000000000000 0000000000000000 01
18
- 11---------------00 0001000000000000 0000000000000000 00
19
- 11---------------01 0001000000000000 0000000000000000 01
20
- 10---------------00 0001000000000000 0010000000000000 00
21
- 10---------------10 0001000000000000 0010000000000000 01
22
- 10----------------1 0001000000000000 0010000000000000 01
23
- 00----------------- 0010000000000000 0000000000000000 00
24
- 10--------------0-0 0010000000000000 0011000000000000 00
25
- 10--------------1-0 0010000000000000 0011000000000000 01
26
- 10----------------1 0010000000000000 0011000000000000 01
27
- 01----------------- 0010000000000000 0000000000000000 00
28
- 11--------------0-0 0010000000000000 0000000000000000 00
29
- 11--------------1-0 0010000000000000 0000000000000000 01
30
- 11----------------1 0010000000000000 0000000000000000 01
31
- 0------------------ 0011000000000000 0000000000000000 00
32
- 11---------------10 0011000000000000 0000000000000000 01
33
- 11---------------00 0011000000000000 0000000000000000 00
34
- 11----------------1 0011000000000000 0000000000000000 01
35
- 10---------------1- 0011000000000000 0100000000000000 01
36
- 10---------------01 0011000000000000 0100000000000000 01
37
- 10---------------00 0011000000000000 0100000000000000 00
38
- 10----------------1 0100000000000000 0101000000000000 01
39
- 10-------------0--0 0100000000000000 0101000000000000 00
40
- 10-------------1--0 0100000000000000 0101000000000000 01
41
- 00----------------- 0100000000000000 0000000000000000 00
42
- 01-------------0--1 0100000000000000 0000000000000000 00
43
- 11-------------0--1 0100000000000000 0000000000000000 01
44
- -1-------------0--0 0100000000000000 0000000000000000 00
45
- 01-------------1--- 0100000000000000 0000000000000000 00
46
- 11-------------1--- 0100000000000000 0000000000000000 01
47
- 0------------------ 0101000000000000 0000000000000000 00
48
- 11---------------10 0101000000000000 0000000000000000 01
49
- 11---------------00 0101000000000000 0000000000000000 00
50
- 11----------------1 0101000000000000 0000000000000000 01
51
- 10---------------10 0101000000000000 0110000000000000 01
52
- 10---------------00 0101000000000000 0110000000000000 00
53
- 10----------------1 0101000000000000 0110000000000000 01
54
- 0------------------ 0110000000000000 0000000000000000 00
55
- 11--------------1-0 0110000000000000 0000000000000000 01
56
- 11--------------0-0 0110000000000000 0000000000000000 00
57
- 11----------------1 0110000000000000 0000000000000000 01
58
- 10--------------1-- 0110000000000000 0111000000000000 01
59
- 10--------------0-0 0110000000000000 0111000000000000 00
60
- 10--------------0-1 0110000000000000 0111000000000000 01
61
- 0------------------ 0111000000000000 0000000000000000 00
62
- 11---------------1- 0111000000000000 0000000000000000 01
63
- 11---------------00 0111000000000000 0000000000000000 00
64
- 11---------------01 0111000000000000 0000000000000000 01
65
- 10---------------1- 0111000000000000 1000000000000000 01
66
- 10---------------01 0111000000000000 1000000000000000 01
67
- 10---------------00 0111000000000000 1000000000000000 00
68
- 00----------------- 1000000000000000 0000000000000000 00
69
- 10----------------1 1000000000000000 1001000000000000 01
70
- 10------------1---0 1000000000000000 1001000000000000 01
71
- 10------------0---0 1000000000000000 1001000000000000 00
72
- 01------------0---1 1000000000000000 0000000000000000 00
73
- 11------------0---1 1000000000000000 0000000000000000 01
74
- 11------------1---1 1000000000000000 0000000000000000 01
75
- 01------------1---1 1000000000000000 0000000000000000 00
76
- 11------------1---0 1000000000000000 0000000000000000 01
77
- 11------------0---0 1000000000000000 0000000000000000 00
78
- 01----------------0 1000000000000000 0000000000000000 00
79
- 00----------------- 1001000000000000 0000000000000000 00
80
- 10---------------1- 1001000000000000 1010000000000000 01
81
- 10---------------00 1001000000000000 1010000000000000 00
82
- 10---------------01 1001000000000000 1010000000000000 01
83
- 01----------------- 1001000000000000 0000000000000000 00
84
- 11---------------1- 1001000000000000 0000000000000000 01
85
- 11---------------01 1001000000000000 0000000000000000 01
86
- 11---------------00 1001000000000000 0000000000000000 00
87
- 00----------------- 1010000000000000 0000000000000000 00
88
- 10--------------1-- 1010000000000000 1011000000000000 01
89
- 10--------------0-1 1010000000000000 1011000000000000 01
90
- 10--------------0-0 1010000000000000 1011000000000000 00
91
- 01----------------- 1010000000000000 0000000000000000 00
92
- 11--------------1-0 1010000000000000 0000000000000000 01
93
- 11--------------0-0 1010000000000000 0000000000000000 00
94
- 11----------------1 1010000000000000 0000000000000000 01
95
- 00----------------- 1011000000000000 0000000000000000 00
96
- 10---------------00 1011000000000000 1100000000000000 00
97
- 10---------------10 1011000000000000 1100000000000000 01
98
- 10----------------1 1011000000000000 1100000000000000 01
99
- 01----------------- 1011000000000000 0000000000000000 00
100
- 11---------------10 1011000000000000 0000000000000000 01
101
- 11---------------00 1011000000000000 0000000000000000 00
102
- 11----------------1 1011000000000000 0000000000000000 01
103
- 00----------------- 1100000000000000 0000000000000000 00
104
- 10-------------0--1 1100000000000000 1101000000000000 01
105
- 10-------------0--0 1100000000000000 1101000000000000 00
106
- 10-------------1--- 1100000000000000 1101000000000000 01
107
- 11----------------1 1100000000000000 0000000000000000 01
108
- 01----------------1 1100000000000000 0000000000000000 00
109
- 11-------------0--0 1100000000000000 0000000000000000 00
110
- 11-------------1--0 1100000000000000 0000000000000000 01
111
- 01----------------0 1100000000000000 0000000000000000 00
112
- 0------------------ 1101000000000000 0000000000000000 00
113
- 10---------------1- 1101000000000000 1110000000000000 01
114
- 10---------------00 1101000000000000 1110000000000000 00
115
- 10---------------01 1101000000000000 1110000000000000 01
116
- 11---------------1- 1101000000000000 0000000000000000 01
117
- 11---------------00 1101000000000000 0000000000000000 00
118
- 11---------------01 1101000000000000 0000000000000000 01
119
- 10--------------1-- 1110000000000000 1111000000000000 01
120
- 10--------------0-0 1110000000000000 1111000000000000 00
121
- 10--------------0-1 1110000000000000 1111000000000000 01
122
- 00----------------- 1110000000000000 0000000000000000 00
123
- 01----------------- 1110000000000000 0000000000000000 00
124
- 11--------------1-- 1110000000000000 0000000000000000 01
125
- 11--------------0-0 1110000000000000 0000000000000000 00
126
- 11--------------0-1 1110000000000000 0000000000000000 01
127
- 01----------------- 1111000000000000 0000000000000000 00
128
- 11---------------00 1111000000000000 0000000000000000 00
129
- 11---------------10 1111000000000000 0000000000000000 01
130
- 11----------------1 1111000000000000 0000000000000000 01
131
- 00----------------- 1111000000000000 0000000100000000 00
132
- 10---------------10 1111000000000000 0000000100000000 01
133
- 10---------------00 1111000000000000 0000000100000000 00
134
- 10----------------1 1111000000000000 0000000100000000 01
135
- 00----------------- 0000000100000000 0000000000000000 00
136
- 10-----------1----- 0000000100000000 0001000000000000 01
137
- 10-----------0----0 0000000100000000 0001000000000000 00
138
- 10-----------0----1 0000000100000000 0001000000000000 01
139
- 01----------------- 0000000100000000 0000000000000000 00
140
- 11-----------1----0 0000000100000000 0000000000000000 01
141
- 11-----------0----0 0000000100000000 0000000000000000 00
142
- 11----------------1 0000000100000000 0000000000000000 01