mgmg 1.8.1 → 1.8.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3698312de546d3f9a7eac1aadd6024ae8132a8c58f97c041fa07b788828a3bcc
4
- data.tar.gz: 19d8263ccfd11a476472868a8420959cccc356bbd7f69fcf619f831fde589794
3
+ metadata.gz: 67f8cb095fc1716b95438a8eda538d4318811ee2f204c93a75c78b6814951f37
4
+ data.tar.gz: e17d1ae24f42c252332ae48ab8698faa1c79d1315bf3cd686fa6ee8fd9a8e306
5
5
  SHA512:
6
- metadata.gz: c0edb6042eb1fccbe9d6b4761afd1a2ad0814910850b2664325d20f109fe9d6805cf28aab5d25b363842cde62dce3e1739319668446e912b6a15d94e2043654f
7
- data.tar.gz: 70ed1f01ca7bfd7ef4be9fc886f74f2049d466cc73e2fb79276dd9768d40bed0232119cde2a177def7721f677271ff602b71d3231d207a94a5850fcd82844b8a
6
+ metadata.gz: 9289ac21117cfc2d1177e17c3a5ad8b1b329800013959a7261f9b16b9d399e6f4820ec6d6f5b3cce51deaa11dbf0b9a2285ee6ed5f5a9131d657821d531f3203
7
+ data.tar.gz: d9c86b0ce3d605d52e574ca63722f56d23e6d07f7f3e46bf105abc321620edcc8eae5f5e29b00ac4866976e51eafc6a363d5761029891bde0cc8566b48ff67ee
data/CHANGELOG.md CHANGED
@@ -194,3 +194,6 @@
194
194
  - `Mgmg::Recipe`に`name`属性を追加.`String/Enumerable#to_recipe`の際,キーワード引数`name`を追加することで設定できる.
195
195
  - `Mgmg.#efficient_list` を追加.
196
196
  - `Enumerable#build`,`Enumerable#search`で意図せぬ例外が発生していた問題を修正.
197
+
198
+ ## 1.8.2 2022/11/21
199
+ - オプション`cut_exp`で探索が打ち切られる場合に,`Mgmg::SearchCutException`でない例外が発生する場合があったバグを修正.
data/lib/mgmg/recipe.rb CHANGED
@@ -86,16 +86,24 @@ module Mgmg
86
86
  raise BrokenRecipeError
87
87
  end
88
88
  end
89
- def show(smith=-1, armor=smith, comp=armor.tap{armor=smith}, para: @para, **kw)
89
+ def show(smith=-1, armor=smith, comp=armor.tap{armor=smith}, para: @para, search: nil, find_max: nil, **kw)
90
90
  opt = temp_opt(**kw)
91
- smith, armor, comp = opt.smith_min, opt.armor_min, opt.comp_min if smith.nil?
92
- case @recipe
93
- when String
94
- @recipe.show(smith, comp, para:, name: @name, opt:)
95
- when Enumerable
96
- @recipe.show(smith, armor, comp, para:, name: @name, opt:)
91
+ if search
92
+ sc = @recipe.search(para, search, opt:)
93
+ @recipe.show(*sc, para:, name: @name, opt:)
94
+ elsif find_max
95
+ sc = @recipe.search(para, find_max, opt:)
96
+ @recipe.show(*sc, para:, name: @name, opt:)
97
97
  else
98
- raise BrokenRecipeError
98
+ smith, armor, comp = opt.smith_min, opt.armor_min, opt.comp_min if smith.nil?
99
+ case @recipe
100
+ when String
101
+ @recipe.show(smith, comp, para:, name: @name, opt:)
102
+ when Enumerable
103
+ @recipe.show(smith, armor, comp, para:, name: @name, opt:)
104
+ else
105
+ raise BrokenRecipeError
106
+ end
99
107
  end
100
108
  end
101
109
  def search(target, para: @para, **kw)
data/lib/mgmg/search.rb CHANGED
@@ -69,6 +69,7 @@ class String
69
69
  [exp_best, ret]
70
70
  end
71
71
  def search(para, target, opt: Mgmg::Option.new)
72
+ org_cut_exp = opt.cut_exp
72
73
  opt = opt.dup.set_default(self)
73
74
  opt_nocut = opt.dup; opt_nocut.cut_exp = Float::INFINITY
74
75
  begin
@@ -109,6 +110,7 @@ class String
109
110
  end
110
111
  end
111
112
  exp_best = opt.cut_exp
113
+ values = values.filter(&:finite?)
112
114
  diff = values.max-values.min
113
115
  if 0 < diff
114
116
  opt.cut_exp = exp_best + diff*opt.fib_ext[0]
@@ -124,8 +126,8 @@ class String
124
126
  end
125
127
  end
126
128
  if ret.nil?
127
- max = opt.irep.para_call(para, *find_max(para, opt.cut_exp, opt:))
128
- raise Mgmg::SearchCutException, "the maximum output with given cut_exp=#{opt.cut_exp.comma3} is #{max.comma3}, which does not reach given target=#{target.comma3}"
129
+ max = opt.irep.para_call(para, *find_max(para, org_cut_exp, opt:))
130
+ raise Mgmg::SearchCutException, "the maximum output with given cut_exp=#{org_cut_exp.comma3} is #{max.comma3}, which does not reach given target=#{target.comma3}"
129
131
  end
130
132
  ret
131
133
  end
@@ -178,6 +180,7 @@ class String
178
180
  values = [values[1], values[2], cur, values[3]]
179
181
  end
180
182
  end
183
+ values = values.filter(&:finite?)
181
184
  diff = values.max-values.min
182
185
  if 0 < diff
183
186
  th = max - diff*opt.fib_ext[1]
@@ -338,6 +341,7 @@ module Enumerable
338
341
  [exp_best, ret]
339
342
  end
340
343
  def search(para, target, opt: Mgmg::Option.new)
344
+ org_cut_exp = opt.cut_exp
341
345
  opt = opt.dup.set_default(self)
342
346
  begin
343
347
  opt.comp_min = comp_search(para, target, opt.smith_max, opt.armor_max, opt:)
@@ -377,6 +381,7 @@ module Enumerable
377
381
  end
378
382
  end
379
383
  exp_best = opt.cut_exp
384
+ values = values.filter(&:finite?)
380
385
  diff = values.max-values.min
381
386
  if 0 < diff
382
387
  opt.cut_exp = exp_best + diff*opt.fib_ext[0]
@@ -392,8 +397,8 @@ module Enumerable
392
397
  end
393
398
  end
394
399
  if ret.nil?
395
- max = opt.irep.para_call(para, *find_max(para, opt.cut_exp, opt:))
396
- raise Mgmg::SearchCutException, "the maximum output with given cut_exp=#{opt.cut_exp.comma3} is #{max.comma3}, which does not reach given target=#{target.comma3}"
400
+ max = opt.irep.para_call(para, *find_max(para, org_cut_exp, opt:))
401
+ raise Mgmg::SearchCutException, "the maximum output with given cut_exp=#{org_cut_exp.comma3} is #{max.comma3}, which does not reach given target=#{target.comma3}"
397
402
  end
398
403
  ret
399
404
  end
@@ -444,6 +449,7 @@ module Enumerable
444
449
  cur = cur_i if cur < cur_i
445
450
  end
446
451
  end
452
+ a_vals = a_vals.filter(&:finite?)
447
453
  diff = a_vals.max-a_vals.min
448
454
  if 0 < diff
449
455
  th = max - diff*opt.fib_ext[1]
@@ -486,6 +492,7 @@ module Enumerable
486
492
  values = [values[1], values[2], cur, values[3]]
487
493
  end
488
494
  end
495
+ values = values.filter(&:finite?)
489
496
  diff = values.max-values.min
490
497
  if 0 < diff
491
498
  th = max - diff*opt.fib_ext[1]
data/lib/mgmg/utils.rb CHANGED
@@ -166,6 +166,7 @@ module Mgmg
166
166
  end
167
167
  end
168
168
  module_function def invexp2(exp, comp)
169
+ raise ArgumentError, "exp must be finite" unless exp.finite?
169
170
  begin
170
171
  ret = Math.sqrt(exp - (2*((comp-1)**2)) - 3).floor + 2
171
172
  rescue Math::DomainError
@@ -178,6 +179,7 @@ module Mgmg
178
179
  end
179
180
  end
180
181
  module_function def invexp2c(exp, s)
182
+ raise ArgumentError, "exp must be finite" unless exp.finite?
181
183
  begin
182
184
  ret = Math.sqrt((exp - (((s-1)**2)) - 3).quo(2)).floor + 2
183
185
  rescue Math::DomainError
@@ -190,6 +192,7 @@ module Mgmg
190
192
  end
191
193
  end
192
194
  module_function def invexp3(exp, sa, comp)
195
+ raise ArgumentError, "exp must be finite" unless exp.finite?
193
196
  return invexp2(exp, comp) if sa < 0
194
197
  begin
195
198
  ret = Math.sqrt(exp - ((sa-1)**2) - (2*((comp-1)**2)) - 4).floor + 2
@@ -203,6 +206,7 @@ module Mgmg
203
206
  end
204
207
  end
205
208
  module_function def invexp3c(exp, smith, armor)
209
+ raise ArgumentError, "exp must be finite" unless exp.finite?
206
210
  if smith < 0
207
211
  return invexp2c(exp, armor)
208
212
  elsif armor < 0
data/lib/mgmg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mgmg
2
- VERSION = "1.8.1"
2
+ VERSION = "1.8.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mgmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KAZOON
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-19 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler