cubeND.rb
# Accept a Domain as an argument and return an Array of subdomains
Accept a Domain as an argument and return an Array of subdomains
Accept a Domain as an argument and return an Array of subdomains
def recursive_bipart(domain, depth)
  sizes   = []
  domains = [ domain ]
  lower_bound = 0
  upper_bound = 0
  for l in 0 ... depth
    lower_bound.upto upper_bound do |i|
      left, right, separator = bipart(domains[i])
      sizes[i] = separator.volume
      domains[i] = separator
      domains[2 * i + 1] = left
      domains[2 * i + 2] = right
    end
    lower_bound = 2 * lower_bound + 1
    upper_bound = 2 * upper_bound + 2
  end
  length = 2 ** depth
  sizes[lower_bound, length] = domains[lower_bound, length].map(&:volume);
  until domains[lower_bound, length].any? { |d| d.volume < 3 }
    lower_bound.upto upper_bound do |i|
      left, right, separator = bipart(domains[i])
      domains[i] = separator
      domains[2 * i + 1] = left
      domains[2 * i + 2] = right
    end
    length = 2 * length
    lower_bound = 2 * lower_bound + 1
    upper_bound = 2 * upper_bound + 2
  end
  return domains, sizes
end
def recursive_bipart ( domain , depth ) sizes = [ ] domains = [ domain ] lower_bound = 0 upper_bound = 0 for l in 0 ... depth lower_bound . upto upper_bound do | i | left , right , separator = bipart ( domains [ i ] ) sizes [ i ] = separator . volume domains [ i ] = separator domains [ 2 * i + 1 ] = left domains [ 2 * i + 2 ] = right end lower_bound = 2 * lower_bound + 1 upper_bound = 2 * upper_bound + 2 end length = 2 ** depth sizes [ lower_bound , length ] = domains [ lower_bound , length ] . map ( & :volume ) ; until domains [ lower_bound , length ] . any? { | d | d . volume < 3 } lower_bound . upto upper_bound do | i | left , right , separator = bipart ( domains [ i ] ) domains [ i ] = separator domains [ 2 * i + 1 ] = left domains [ 2 * i + 2 ] = right end length = 2 * length lower_bound = 2 * lower_bound + 1 upper_bound = 2 * upper_bound + 2 end return domains , sizes end
Accept a Domain as an argument and return an Array of subdomains
Accept a Domain as an argument and return an Array of subdomains
# Perform bipart until require depth # Update the size of each leaf domains # Continue to perform bipart for fill reduce reorder # Update bounds # Return a tree of domains & sizes
domain
<not_specific>
depth
<not_specific>