Sha256: 7472770d4b7e460e5d430e42e987d9475165e33b30ff909e2dafffe4782e3e6a
Contents?: true
Size: 648 Bytes
Versions: 5
Compression:
Stored size: 648 Bytes
Contents
module Music module Performance module Optimization def self.linking unlinked, untargeted n = [unlinked.size, untargeted.size].min bestsol = nil bestscore = Float::INFINITY unlinked.combination(n).each do |comb| untargeted.permutation(n).each do |perm| score = 0 n.times do |i| score += perm[i].diff(comb[i]).abs end if score < bestscore bestsol = [ comb, perm ] bestscore = score end end end solution = {} n.times do |i| solution[ bestsol[0][i] ] = bestsol[1][i] end return solution end end end end
Version data entries
5 entries across 5 versions & 1 rubygems