Class: ConstraintSolver::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/Problem.rb

Overview

Representation of a constraint satisfaction problem.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#constraintsObject (readonly)

Returns the value of attribute constraints.



6
7
8
# File 'lib/Problem.rb', line 6

def constraints
  @constraints
end

#firstSolutionObject (readonly)

Returns the value of attribute firstSolution.



6
7
8
# File 'lib/Problem.rb', line 6

def firstSolution
  @firstSolution
end

#maxViolationObject (readonly)

Returns the value of attribute maxViolation.



6
7
8
# File 'lib/Problem.rb', line 6

def maxViolation
  @maxViolation
end

#meritMapObject (readonly)

Returns the value of attribute meritMap.



6
7
8
# File 'lib/Problem.rb', line 6

def meritMap
  @meritMap
end

#variablesObject (readonly)

Returns the value of attribute variables.



6
7
8
# File 'lib/Problem.rb', line 6

def variables
  @variables
end