Method: ConstraintSolver::AllDifferentConstraint#revise_decomposed_local

Defined in:
lib/AllDifferentConstraint.rb

#revise_decomposed_localObject Also known as: revise



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/AllDifferentConstraint.rb', line 68

def revise_decomposed_local
    revisedVariables = []
    wipeout = false
    pruneList = Set.new
    assignedVariables, unassignedVariables = @variables.partition { |var| var.assigned? }
    pruneList.merge(assignedVariables.collect { |var| var.value })
    unassignedVariables.find_all { |var| var.domain.include_any?(pruneList) }.each { |var|
	begin
	    var.domain.prune(pruneList)
	rescue DomainWipeoutException
	    wipeout = true
	end
	revisedVariables << var
	break if wipeout
    }
    unless wipeout
	workQueue = unassignedVariables.find_all { |var| var.domain.size == 1 }
	while not workQueue.empty?
	    currentVariable = workQueue.shift
	    currentValue = currentVariable.domain.first
	    ((unassignedVariables - [ currentVariable ]).find_all { |var|
		var.domain.include?(currentValue)
	    }).each { |var|
		begin
		    var.domain.prune(currentValue)
		rescue DomainWipeoutException
		    wipeout = true
		end
		revisedVariables << var
		break if wipeout
		workQueue << var if var.domain.size == 1
	    }
	end

	unless wipeout
	    # check satisfiability
	    valueList = Set.new
	    unassignedVariables.each { |var|
		valueList.merge(var.values)
	    }
	    if unassignedVariables.size > valueList.size
		wipeout = true
	    end
	end
    end
    return revisedVariables, 0, wipeout
end