Last active
July 11, 2017 03:16
-
-
Save Maumagnaguagno/d9f201093bfaa65ddd17693d67bbc29c to your computer and use it in GitHub Desktop.
Scripts to request solver from planning.domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# More info at http://solver.planning.domains/ | |
import urllib2, json, sys | |
HELP = """planning.domains.py | |
Usage: | |
planning.domains.py domain.pddl problem.pddl [mode=save|compare plan] | |
Options | |
mode - specify if it saves to or compares with plan file | |
plan - specify plan file""" | |
if len(sys.argv) < 3: | |
print HELP | |
sys.exit(1) | |
else: | |
domain = open(sys.argv[1], 'r').read() | |
problem = open(sys.argv[2], 'r').read() | |
if len(sys.argv) > 4: | |
mode = sys.argv[3] | |
output = sys.argv[4] | |
else: | |
mode = None | |
# Request plan | |
req = urllib2.Request('http://solver.planning.domains/solve') | |
req.add_header('Content-Type', 'application/json') | |
resp = json.loads(urllib2.urlopen(req, json.dumps({'domain': domain, 'problem': problem})).read()) | |
# Get plan from request | |
# TODO empty plans are identified as error | |
plan = '\n'.join([act['name'] for act in resp['result']['plan']]) if resp['status'] == 'ok' else 'failure' | |
print 'Plan:\n', plan | |
# Save or compare output | |
if mode == 'save': | |
with open(output, 'w') as f: | |
f.write(plan) | |
elif mode == 'compare': | |
with open(output, 'r') as f: | |
if f.read() == plan: | |
print 'Plans are equal' | |
else: | |
print 'Plans are different' | |
sys.exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# More info at http://solver.planning.domains/ | |
require 'net/http' | |
require 'json' | |
HELP = 'planning.domains.rb | |
Usage: | |
planning.domains.rb domain.pddl problem.pddl [mode=save|compare plan] | |
Options | |
mode - specify if it saves to or compares with plan file | |
plan - specify plan file' | |
if ARGV.size < 2 | |
abort(HELP) | |
else | |
domain = IO.read(ARGV[0]) | |
problem = IO.read(ARGV[1]) | |
if ARGV.size == 4 | |
mode = ARGV[2] | |
output = ARGV[3] | |
else mode = nil | |
end | |
end | |
# Request plan | |
url = 'http://solver.planning.domains/solve' | |
uri = URI.parse(url) | |
req = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json') | |
req.body = JSON.fast_generate('domain' => domain, 'problem' => problem) | |
resp = JSON.load(Net::HTTP.new(uri.host, uri.port).request(req).body) | |
# Get plan from request | |
# TODO empty plans are identified as error | |
plan = resp['status'] == 'ok' ? resp['result']['plan'].map {|act| act['name']}.join("\n") : 'failure' | |
puts 'Plan:', plan | |
# Save or compare output | |
case mode | |
when 'save' then IO.write(output, plan) | |
when 'compare' | |
if IO.read(output) == plan then puts 'Plans are equal' | |
else abort('Plans are different') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment