Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import java.util.ArrayList;
00034 import java.util.Iterator;
00035 import java.util.LinkedHashSet;
00036 import java.util.Set;
00037
00038 import pddl4j.exp.AtomicFormula;
00039 import pddl4j.exp.term.Term;
00040
00047 public final class Plan implements Iterable<Set<AtomicFormula>> {
00048
00052 public static final Plan FAILURE = null;
00056 public static final Plan EMPTY = new Plan();
00057
00061 private int size;
00062
00066 public ArrayList<Set<AtomicFormula>> actions;
00067
00071 public Plan() {
00072 this.actions = new ArrayList<Set<AtomicFormula>>();
00073 this.size = 0;
00074 }
00075
00084 public boolean add(AtomicFormula op_name, int k) {
00085 int layers = this.actions.size();
00086 if (k >= layers) {
00087 int addLayers = k - layers + 1;
00088 for (int i = 0; i < addLayers; i++) {
00089 this.actions.add(new LinkedHashSet<AtomicFormula>());
00090 }
00091 }
00092 Set<AtomicFormula> ak = this.actions.get(k);
00093 boolean added = ak.add(op_name);
00094 if (added) this.size++;
00095 return added;
00096 }
00097
00104 public Set<AtomicFormula> get(int k) {
00105 return this.actions.get(k);
00106 }
00107
00113 public int layers() {
00114 return this.actions.size();
00115 }
00116
00122 public int size() {
00123 return this.size;
00124 }
00125
00131 public Iterator<Set<AtomicFormula>> iterator() {
00132 return this.actions.iterator();
00133 }
00134
00145 public boolean equals(Object obj) {
00146 if (obj != null && this.getClass().equals(obj.getClass())) {
00147 Plan other = (Plan) obj;
00148 return this.actions.equals(other.actions);
00149 }
00150 return false;
00151 }
00152
00160 public int hashCode() {
00161 return this.actions.hashCode();
00162 }
00163
00169 public String toString() {
00170 StringBuffer buffer = new StringBuffer();
00171 int i = 0;
00172 for (Set<AtomicFormula> layer : this) {
00173 StringBuffer str = new StringBuffer();
00174 buffer.append("time step " + i + ":");
00175 int j = 0;
00176 for (AtomicFormula action : layer) {
00177 StringBuffer as = new StringBuffer();
00178 as.append(action.getPredicate().toUpperCase());
00179 for (Term parameter : action) {
00180 as.append(" " + parameter.getImage().toUpperCase());
00181 }
00182 if (j > 0) str.append(" ");
00183 str.append(as.toString());
00184 if (j < layer.size() - 1) str.append("\n");
00185 j++;
00186 }
00187 buffer.append(str.toString());
00188 i++;
00189 }
00190 return buffer.toString();
00191 }
00192 }