Class: ConstraintSolver::Problem
- Inherits:
-
Object
- Object
- ConstraintSolver::Problem
- Defined in:
- lib/Problem.rb
Overview
Representation of a constraint satisfaction problem.
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#firstSolution ⇒ Object
readonly
Returns the value of attribute firstSolution.
-
#maxViolation ⇒ Object
readonly
Returns the value of attribute maxViolation.
-
#meritMap ⇒ Object
readonly
Returns the value of attribute meritMap.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(variables, constraints, meritMap = {}, firstSolution = false, maxViolation = 0) ⇒ Problem
constructor
Creates a new instances of a constraint satisfaction problem.
Constructor Details
#initialize(variables, constraints, meritMap = {}, firstSolution = false, maxViolation = 0) ⇒ Problem
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/Problem.rb', line 13 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 |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
6 7 8 |
# File 'lib/Problem.rb', line 6 def constraints @constraints end |
#firstSolution ⇒ Object (readonly)
Returns the value of attribute firstSolution.
6 7 8 |
# File 'lib/Problem.rb', line 6 def firstSolution @firstSolution end |
#maxViolation ⇒ Object (readonly)
Returns the value of attribute maxViolation.
6 7 8 |
# File 'lib/Problem.rb', line 6 def maxViolation @maxViolation end |
#meritMap ⇒ Object (readonly)
Returns the value of attribute meritMap.
6 7 8 |
# File 'lib/Problem.rb', line 6 def meritMap @meritMap end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
6 7 8 |
# File 'lib/Problem.rb', line 6 def variables @variables end |