activecube 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/activecube/processor/optimizer.rb +26 -80
- data/lib/activecube/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c91dca78a440d0db5b8b0a28531d4c922a9dc81062aad663052afd671a500d
|
4
|
+
data.tar.gz: da104891e98f8cfcb14f91dcc74db0a2e418209e1380baf93a4a03d9653454d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d381b939daec89b03e758a595959fa903ace82f958402c6b7a595b00e28fa1a16593201dc6daec6af99d79faa4e82ab4f76a81c153780eaf890cdc853edbd11b
|
7
|
+
data.tar.gz: d9e9c8d31921dbb6fa43843a35da245594de76182bf85ee207d1bfd19d92ad099ffbe74391ddd0b08d4f3c34aaf443d21a5cbc8b31321a1ae7aa030e88fe1b35
|
data/Gemfile.lock
CHANGED
@@ -18,7 +18,7 @@ module Activecube::Processor
|
|
18
18
|
@tables_count = cost_matrix.map(&:count).max
|
19
19
|
@metrics_count = cost_matrix.count
|
20
20
|
|
21
|
-
tables_count==1 ? [0]*metrics_count : do_optimize
|
21
|
+
(tables_count==1 || metrics_count==0) ? [0]*metrics_count : do_optimize
|
22
22
|
|
23
23
|
end
|
24
24
|
|
@@ -27,95 +27,41 @@ module Activecube::Processor
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
30
|
+
def generate_variants vs, metric_i
|
31
31
|
|
32
|
-
|
32
|
+
return vs if metric_i==metrics_count
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
metric_tables = cost_matrix[metric_i].map.with_index do |c, index|
|
35
|
+
[index] if c
|
36
|
+
end.compact
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
vsnew = if metric_i==0
|
39
|
+
metric_tables
|
40
|
+
else
|
41
|
+
arry = []
|
42
|
+
vs.each do |v|
|
43
|
+
metric_tables.each{|newv|
|
44
|
+
arry << (v + newv)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
arry
|
48
|
+
end
|
40
49
|
|
41
|
-
|
42
|
-
iterates
|
50
|
+
generate_variants vsnew, metric_i+1
|
43
51
|
|
44
|
-
@tables_by_metrics
|
45
52
|
end
|
46
53
|
|
47
|
-
def
|
48
|
-
|
54
|
+
def cost_for variant
|
55
|
+
variant.each_with_index.group_by(&:first).collect do |table_index, arry|
|
56
|
+
arry.map(&:second).map{|metric_index| cost_matrix[metric_index][table_index] }.max
|
57
|
+
end.sum
|
49
58
|
end
|
50
59
|
|
51
|
-
def
|
52
|
-
|
53
|
-
@metrics_index_sorted.collect do |m_i|
|
54
|
-
|
55
|
-
table_index_cost = (0...tables_count).map{|c_i| [c_i,
|
56
|
-
cost_matrix[m_i][c_i] || UNLIM_COST,
|
57
|
-
(@tables_by_metrics.include?(c_i) ? -cost_matrix[@tables_by_metrics.index(c_i)][c_i] : 0)
|
58
|
-
]}.sort_by(&:third).sort_by(&:second)
|
59
|
-
|
60
|
-
@tables_by_metrics[m_i] = table_index_cost.first.first
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def iterates
|
66
|
-
|
67
|
-
steps = [@tables_by_metrics]
|
68
|
-
|
69
|
-
(1..MAX_ITERATIONS).each do |iteration|
|
70
|
-
|
71
|
-
step = []
|
72
|
-
prev_step = steps.last
|
73
|
-
|
74
|
-
prev_step.each_with_index {|c_i, m_i|
|
75
|
-
|
76
|
-
table_included_times = prev_step.select{|c| c==c_i }.count
|
77
|
-
old_cost = cost_matrix[m_i][c_i]
|
78
|
-
new_c_i = (0...tables_count).detect{|c_n|
|
79
|
-
new_cost = cost_matrix[m_i][c_n]
|
80
|
-
next if c_i==c_n || new_cost.nil?
|
81
|
-
new_table_included_times = prev_step.select{|c| c==c_n }.count
|
82
|
-
|
83
|
-
if old_cost.nil?
|
84
|
-
# if we have non indexed table now
|
85
|
-
true
|
86
|
-
elsif table_included_times>1
|
87
|
-
if new_table_included_times>0
|
88
|
-
# table to used table if
|
89
|
-
# cost now > new cost
|
90
|
-
old_cost > new_cost
|
91
|
-
else
|
92
|
-
# table to unused table if
|
93
|
-
# cost now > new cost + max other cost in table now
|
94
|
-
old_cost > new_cost + ( prev_step.select.with_index{|c,i| c==c_i && i!=m_i }.map{|c| cost_matrix[m_i][c]}.max || UNLIM_COST )
|
95
|
-
end
|
96
|
-
else
|
97
|
-
if new_table_included_times>0
|
98
|
-
# unused table to table if
|
99
|
-
# new cost < cost now + max other cost in new table
|
100
|
-
old_cost > new_cost - ( prev_step.select{|c| c==c_n }.map{|c| cost_matrix[m_i][c]}.max || UNLIM_COST )
|
101
|
-
else
|
102
|
-
# unused to unused
|
103
|
-
# cost now > new cost
|
104
|
-
old_cost > new_cost
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
}
|
109
|
-
|
110
|
-
step << (new_c_i || c_i)
|
111
|
-
|
112
|
-
}
|
113
|
-
|
114
|
-
break if steps.include? step
|
115
|
-
steps << step
|
116
|
-
end
|
60
|
+
def do_optimize
|
117
61
|
|
118
|
-
|
62
|
+
variants = generate_variants [], 0
|
63
|
+
variant_costs = variants.map{|v| cost_for v}
|
64
|
+
variants[variant_costs.each_with_index.min.second]
|
119
65
|
|
120
66
|
end
|
121
67
|
|
data/lib/activecube/version.rb
CHANGED