18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/longjing/logging.rb', line 18
def log(event=nil, *args, &block)
case event
when :exploring
state = args[0]
logger.debug { "\n\nExploring: #{state}\n=======================" }
when :action
action, result = args
logger.debug { "\nAction: #{action.signature}\n-----------------------" }
logger.debug { "=> #{result}" }
when :heuristic
new_state, solution, dist, best = args
logger.debug {
buf = ""
solution[0].reverse.each_with_index do |a, i|
buf << " #{i}. [#{a.map(&:signature).join(", ")}]\n"
end
"Relaxed plan (cost: #{dist}):\n#{buf}\n helpful actions: #{solution[1] ? solution[1].map(&:signature).join(", ") : '[]'}"
}
if dist < best
logger.debug { "Add to plan #{new_state.path.last.signature}, cost: #{dist}" }
else
logger.debug { "Add to frontier" }
end
when :facts
args[0].each_slice(3) do |group|
logger.info { " #{group.map(&:to_s).join(' ')}"}
end
when :problem
prob = args[0]
logger.info {
"Problem: #{prob[:problem]}, domain: #{prob[:domain]}"
}
logger.info {
"Requirements: #{prob[:requirements].join(', ')}"
}
log(:problem_stats, prob)
when :problem_stats
prob = args[0]
logger.info { "# types: #{Array(prob[:types]).size}" }
logger.info { "# predicates: #{prob[:predicates].size}" }
logger.info { "# object: #{prob[:objects].size}" }
logger.info { "# actions: #{prob[:actions].size}" }
when NilClass
logger.info(&block)
end
end
|