Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InitialSolutionSolver
- include Evaluator
- def solve(instance, c)
- return [] if instance.empty?
- return [find_first_config(instance, c)] + solve(instance[1..-1],c)
- end
- def find_first_config(instance, c)
- first_config = instance.first.clone
- instance[1..-1].each do |config|
- puts config
- config.fixed.each do|tool|
- first_config.add(tool)
- return first_config if first_config.size == c
- end
- end
- first_config
- end
- end
- require "enumerator"
- class Config
- include Enumerable
- attr_accessor :name, :fixed, :variable
- def each(&block)
- @fixed.each{|i|yield i}
- end
- def initialize(name,numslots)
- @name = name
- @fixed = Array.new
- @variable = Array.new
- @maxsize = numslots
- end
- def full?
- size == @maxsize
- end
- def already_in_slot?(tool)
- fixed.include?(tool) || variable.include?(tool)
- end
- def add(tool)
- unless full? or already_in_slot?(tool)
- variable << tool
- end
- end
- def to_s
- "#{@name}: [#{(@fixed.collect{|e| e.to_s+'*'}.to_a + @variable.to_a).join(",").to_s}]"
- end
- alias :inspect :to_s
- def size
- @fixed.size + @variable.size
- end
- end
Add Comment
Please, Sign In to add comment