Class | ConstraintSolver::Solution |
In: |
lib/Solution.rb
|
Parent: | Object |
merit | [R] | |
variables | [R] |
Initialises a new solution with a list of variables. The variables must all have values assigned to them. Optionally, a map to map domain values of variables to their merit can be spcified.
# File lib/Solution.rb, line 11 def initialize(variables, meritMap={}) if not variables.kind_of?(Array) variables = Array.new([ variables ]) end if ((variables.collect { |var| var.assigned? }).foldLeft(Proc.new { |a,b| a & b })) @variables = Array.new variables.each { |variable| @variables << variable.dup } else raise ArgumentError, "All variables must have values assigned to them!" end @merit = 0 @variables.each { |var| @merit += meritMap[var.value] ? var.merit * meritMap[var.value] : var.merit } end
# File lib/Solution.rb, line 39 def ==(solution) return false unless solution.kind_of?(Solution) @variables == solution.variables and @merit == solution.merit end