dither 0.1.5 → 0.2.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/dither/mipog.rb DELETED
@@ -1,85 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Dither
4
- class MIPOG
5
- include Dither::IPOGHelper
6
-
7
- def maximize_unbound_coverage(i, test_case, pi)
8
- all_unbound = test_case.unbound
9
- .map { |a| a.create_params(params[a.i].length) }
10
- .flatten
11
-
12
- current_max = 0
13
- current_max_j = 0
14
- current_outer_param = all_unbound[0]
15
- current_matches = []
16
-
17
- all_unbound.each do |outer_param|
18
- test_case << outer_param
19
-
20
- (0...params[i].length).each do |j|
21
- current_param = params[i][j]
22
- test_case << current_param
23
- count = pi.count { |a| a.subset?(test_case) }
24
-
25
- if count > current_max
26
- current_max = count
27
- current_max_j = j
28
- current_outer_param = outer_param
29
- end
30
- test_case.delete(current_param)
31
- end
32
- test_case.delete(outer_param)
33
- end
34
-
35
- test_case << params[i][current_max_j]
36
- test_case << current_outer_param
37
- test_case.delete(unbound_param_pool[current_outer_param.i])
38
-
39
- current_matches
40
- end
41
-
42
- def run
43
- # add into test set a test for each combination of values
44
- # of the first t parameter
45
- test_set = comb
46
-
47
- (t...params.length).each do |i|
48
- # let pi
49
- # be the set of t-way combinations of values involving
50
- # parameter Pi and t -1 parameters among the first i – 1
51
- # parameters
52
- pi = comb_i(i)
53
-
54
- # horizontal extension for parameter i
55
- test_set.each do |test_case|
56
- if !test_case.contains_unbound?
57
- cover = maximize_coverage(i, test_case, pi)
58
- else
59
- cover = maximize_unbound_coverage(i, test_case, pi)
60
- end
61
-
62
- # remove covered combinations
63
- pi -= cover
64
- end
65
-
66
- # vertical extension for parameter i
67
- until pi.empty?
68
- pi.sort!
69
- test_case, coverage = maximize_vertical_coverage(i, pi[0].dup, pi)
70
- test_set << test_case.create_unbound(i)
71
- pi -= coverage
72
- end
73
- end
74
- test_set.map { |a| fill_unbound(a) }
75
- end
76
-
77
- def maximize_vertical_coverage(i, test_case, pi)
78
- coverage = [pi[0]]
79
- pi[1..-1].each do |a|
80
- coverage << a unless test_case.merge_without_conflict(i, a).nil?
81
- end
82
- [test_case, coverage]
83
- end
84
- end # MIPOG
85
- end # Dither
data/lib/dither/param.rb DELETED
@@ -1,19 +0,0 @@
1
-
2
- module Dither
3
- Param = Struct.new(:i, :j) do
4
- def <=>(param)
5
- return 1 if param.unbound?
6
-
7
- a = i <=> param.i
8
- if a == 0
9
- return j <=> param.j
10
- else
11
- return a
12
- end
13
- end
14
-
15
- def unbound?
16
- false
17
- end
18
- end # Param
19
- end # Dither
@@ -1,80 +0,0 @@
1
-
2
- module Dither
3
- class TestCase < Set
4
-
5
- attr_accessor :bound_param_pool, :unbound_param_pool
6
-
7
- def self.create(bound_param_pool, unbound_param_pool, params)
8
- test_case = TestCase.new(params)
9
- test_case.bound_param_pool = bound_param_pool
10
- test_case.unbound_param_pool = unbound_param_pool
11
- test_case
12
- end
13
-
14
- def contains_unbound?
15
- self.any?(&:unbound?)
16
- end
17
-
18
- def unbound
19
- self.select(&:unbound?)
20
- end
21
-
22
- def <=>(test_case)
23
- result = 0
24
- l = length <= test_case.length ? length : test_case.length
25
- self.zip(test_case)[0...l].each do |arr|
26
- first, second = arr
27
- result = first <=> second
28
- break if result != 0
29
- end
30
- result
31
- end
32
-
33
- def create_unbound(i)
34
- bound_params = self.reject(&:unbound?).map(&:i)
35
- ((0..i).to_a - bound_params).each do |a|
36
- self << unbound_param_pool[a]
37
- end
38
- self
39
- end
40
-
41
- def to_ipog_array(i)
42
- arr = Array.new(i)
43
- self.each do |param|
44
- arr[param.i] = param.j unless param.unbound?
45
- end
46
- arr
47
- end
48
-
49
- # return nil if there is a conflict
50
- # return self if no conflict
51
- def merge_without_conflict(i, test_case, &block)
52
- new_elements = []
53
- self.to_ipog_array(i).zip(test_case.to_ipog_array(i))
54
- .each_with_index do |arr, a|
55
- first, second = arr
56
-
57
- if first.nil? && second.nil?
58
- new_elements << unbound_param_pool[a]
59
- elsif (first == second) || second.nil?
60
- next
61
- elsif first.nil?
62
- new_elements << bound_param_pool[a][second]
63
- else
64
- return nil
65
- end
66
- end
67
-
68
- new_self = self.clone
69
- new_elements.each { |a| new_self << a }
70
-
71
- return nil if block_given? && block.call(new_self)
72
-
73
- new_elements.each do |a|
74
- self.delete(unbound_param_pool[a.i]) unless a.unbound?
75
- self << a
76
- end
77
- self
78
- end
79
- end # TestCase
80
- end # Dither
@@ -1,17 +0,0 @@
1
-
2
- module Dither
3
- UnboundParam = Struct.new(:i) do
4
- def <=>(param)
5
- return -1 unless param.unbound?
6
- i <=> param.i
7
- end
8
-
9
- def unbound?
10
- true
11
- end
12
-
13
- def create_params(j)
14
- (0...j).map { |a| Param.new(i, a) }
15
- end
16
- end # UnboundParam
17
- end # Dither