-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hype.rb
executable file
·82 lines (74 loc) · 2.27 KB
/
Hype.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby
#-----------------------------------------------
# Hype
#-----------------------------------------------
# Mau Magnaguagno
#-----------------------------------------------
# Planning description converter
#-----------------------------------------------
require_relative 'UJSHOP_Parser'
require_relative 'UHyper_Compiler'
module Hype
extend self
HELP = " Usage:
Hype domain problem [output] [max plans=-1(all)] [min probability=0]\n
Output:
rb - generate Ruby files to HyperTensioN U(default)
run - same as rb with execution
debug - same as run with execution log"
#-----------------------------------------------
# Parse
#-----------------------------------------------
def parse(domain, problem)
raise 'Incompatible extensions between domain and problem' if File.extname(domain) != File.extname(problem)
@parser = UJSHOP_Parser
@parser.parse_domain(domain)
@parser.parse_problem(problem)
end
#-----------------------------------------------
# Compile
#-----------------------------------------------
def compile(domain, problem, type = 'rb')
compiler = UHyper_Compiler
args = [
@parser.domain_name,
@parser.problem_name,
@parser.operators,
@parser.methods,
@parser.predicates,
@parser.state,
@parser.tasks,
@parser.axioms,
@parser.rewards,
@parser.attachments
]
data = compiler.compile_domain(*args)
File.write("#{domain}.#{type}", data) if data
data = compiler.compile_problem(*args << File.basename(domain))
File.write("#{problem}.#{type}", data) if data
end
end
#-----------------------------------------------
# Main
#-----------------------------------------------
if $0 == __FILE__
begin
if ARGV.size < 2 or ARGV[0] == '-h'
puts Hype::HELP
elsif not File.exist?(domain = ARGV.shift)
abort("Domain not found: #{domain}")
elsif not File.exist?(problem = ARGV.shift)
abort("Problem not found: #{problem}")
else
type = ARGV[0]
t = Time.now.to_f
Hype.parse(domain, problem)
Hype.compile(domain, problem)
require File.expand_path(problem) if type == 'run' or type == 'debug'
puts "Total time: #{Time.now.to_f - t}s"
end
rescue
puts $!, $@
exit(2)
end
end