Class: QuineMc::EPi_List
- Inherits:
-
Array
- Object
- Array
- QuineMc::EPi_List
- Defined in:
- lib/quine_mc/epi_list.rb
Instance Attribute Summary collapse
-
#pi_list ⇒ Object
Returns the value of attribute pi_list.
-
#pi_table ⇒ Object
Returns the value of attribute pi_table.
Instance Method Summary collapse
- #cost(c, h) ⇒ Object
- #dominated_rows ⇒ Object
- #expand_r(exp) ⇒ Object
- #expand_s(sum) ⇒ Object
- #get_solution(m) ⇒ Object
-
#initialize(m, d, n_l) ⇒ EPi_List
constructor
A new instance of EPi_List.
- #petrick ⇒ Object
- #reduce ⇒ Object
Constructor Details
Instance Attribute Details
#pi_list ⇒ Object
Returns the value of attribute pi_list.
6 7 8 |
# File 'lib/quine_mc/epi_list.rb', line 6 def pi_list @pi_list end |
#pi_table ⇒ Object
Returns the value of attribute pi_table.
6 7 8 |
# File 'lib/quine_mc/epi_list.rb', line 6 def pi_table @pi_table end |
Instance Method Details
#cost(c, h) ⇒ Object
64 65 66 67 68 |
# File 'lib/quine_mc/epi_list.rb', line 64 def cost(c, h) price = c.size c.each {|i| price += @n_l - Math.log(h[i].length)/Math.log(2)} return price end |
#dominated_rows ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/quine_mc/epi_list.rb', line 36 def dominated_rows removed = false #puts @pi_table.inspect (@pi_table.values.flatten(1) - self).each do |c1| (@pi_table.values.flatten(1) - self).each do |c2| if QuineMc::Cube.new(c1 & @pi_table.keys).strict_subset?(Cube.new(c2 & @pi_table.keys)) @pi_table.each {|k,v| v.delete_if {|i| i == c1}} removed = true end end end (removed)? reduce : petrick end |
#expand_r(exp) ⇒ Object
74 75 76 77 |
# File 'lib/quine_mc/epi_list.rb', line 74 def (exp) if exp.length == 1 then return [[exp[0][0]],[exp[0][1]]] end exp.length == 2 ? exp[0].product(exp[1]) : exp[0].product((exp[1..exp.length])) end |
#expand_s(sum) ⇒ Object
70 71 72 |
# File 'lib/quine_mc/epi_list.rb', line 70 def (sum) (sum).each {|x| x.flatten!; x.sort!; x.uniq!} end |
#get_solution(m) ⇒ Object
14 15 16 17 18 |
# File 'lib/quine_mc/epi_list.rb', line 14 def get_solution(m) @pi_table = Hash.new {|h,k| h[k] = @pi_list.reject {|e| !e.include?(k)}} m.each {|i| @pi_table[i]} reduce end |
#petrick ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/quine_mc/epi_list.rb', line 50 def petrick cube_i = Hash[@pi_table.values.flatten(1).uniq.zip((0...@pi_table.values.flatten(1).uniq.length).to_a)] product = [] @pi_table.each do |k,v| temp = [] v.each {|x| temp << cube_i[x]} product << temp end choices = (product).uniq cube_i = cube_i.invert answer = choices.min {|a,b| cost(a, cube_i) <=> cost(b, cube_i)} answer.each {|i| push(cube_i[i])} end |
#reduce ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/quine_mc/epi_list.rb', line 20 def reduce (@pi_table.empty?)? (return true) : size = 0 while size != @pi_table.size size = @pi_table.size @pi_table.each do |k,v| if v.length == 1 push(v[0]) v[0].each {|i| @pi_table.delete(i)} end end end (@pi_table.empty?)? (return true) : dominated_rows end |