summaryrefslogtreecommitdiff
path: root/utils/PDDLtoSANetTranslator/PDDLParser/src/PDDLtoSAN.java
blob: 7ed80fbefe801464e7fd5f567c1be02f1ab832bc (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Properties;

import Translator.PDDL_Translator;

import pddl4j.Domain;
import pddl4j.ErrorManager;
import pddl4j.PDDLObject;
import pddl4j.Parser;
import pddl4j.Problem;
import pddl4j.RequireKey;
import pddl4j.Source;
import pddl4j.ErrorManager.Message;

public class PDDLtoSAN {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
//		if(args.length != 5){
//			System.out.println("Wrong number of arguments: "+args.length);
//			System.exit(0);
//		}
//
//		String domain_path = args[0];
//		String problem_path = args[1];
//		boolean include_init = new Boolean(args[2]);
//		int cond_combine = new Integer(args[3]);
//		String output_name = args[4];
		
		String domain_path = "hanoi.pddl";
		String problem_path = "hanoi-pb1.pddl";
		boolean include_init = false;
		int cond_combine = 4;
		String output_name = "ferry-orig-pruned";
		
		Domain domain = null;
		Problem problem = null;

		Properties options = new Properties();
		options.put("source", Source.V3_0);
		options.put(RequireKey.STRIPS, true);
		options.put(RequireKey.TYPING, true);
		options.put(RequireKey.EQUALITY, true);
		options.put(RequireKey.NEGATIVE_PRECONDITIONS, true);
		options.put(RequireKey.DISJUNCTIVE_PRECONDITIONS, true);
		options.put(RequireKey.CONDITIONAL_EFFECTS, true);
		// options.put(RequireKey.EXISTENTIAL_PRECONDITIONS, true);
		// options.put(RequireKey.UNIVERSAL_PRECONDITIONS, true);

		Parser parser = new Parser(options);

		File domain_file = new File(domain_path);
		File problem_file = new File(problem_path);

		try {
			domain = parser.parse(domain_file);
		} catch (FileNotFoundException e) {
			System.out.println("Error: domain file "+domain_file+" not found");
			System.exit(0);
		}
		
		try {
			problem = parser.parse(problem_file);
		} catch (FileNotFoundException e) {
			System.out.println("Error: problem file "+problem_file+" not found");
			System.exit(0);
		}
			
		PDDLObject obj = parser.link(domain, problem);
	
		ErrorManager mgr = parser.getErrorManager();
			
		if (mgr.contains(Message.ERROR)) {
			mgr.print(Message.ALL);
		}
		else {
			mgr.print(Message.WARNING);
	
			System.out.println();
			System.out.println("Translating:");
			
			PDDL_Translator n = new PDDL_Translator(obj, cond_combine, include_init);
			
			System.out.println("Done translating");
			System.out.println("  SAN number of conditions: "+ n.getConditonNodeCount());
			System.out.println("  SAN number of actions: " + n.getActionNodeCount());

			n.printSAN();
			n.write_SAN_to_xml(output_name+"-san.xml");
			n.write_TM_to_xml(output_name+"-tm.xml");
			n.write_goals_to_file(output_name+"-goals");
		}
	}
}