Sha256: fd004fcb5bafc2f64fafdddfd617fd5d1f0091198ad5ab989ee96ab9185d5dfc
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
#!/usr/bin/ruby module ConstraintSolver # Representation of a constraint satisfaction problem. class Problem attr_reader :variables, :constraints, :meritMap, :firstSolution, :maxViolation # Creates a new instances of a constraint satisfaction problem. # The constructor takes the lists of variables and constraints as parameters. # Optionally, a map that maps domain elements to their merit, # a boolean indicating whether to sop solving after a solution has # been found, and a number designating the maximum cost for constraint # violation that can be accepted can be specified. def initialize(variables, constraints, meritMap={}, firstSolution=false, maxViolation=0) if not variables.kind_of?(Array) variables = [ variables ] end if not constraints.kind_of?(ConstraintList) constraints = ConstraintList.new([ constraints ]) end if variables.empty? or constraints.empty? raise ArgumentError, "Variables and constraints must not be empty!" end @variables = variables @constraints = constraints @meritMap = meritMap @firstSolution = firstSolution @maxViolation = maxViolation end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ConstraintSolver-0.1 | lib/Problem.rb |