Plan.java
Go to the documentation of this file.
00001 /*
00002  * Copyright Dept. of Mathematics & Computer Science Univ. Paris-Descartes
00003  *
00004  * This software is governed by the CeCILL  license under French law and
00005  * abiding by the rules of distribution of free software.  You can  use,
00006  * modify and/ or redistribute the software under the terms of the CeCILL
00007  * license as circulated by CEA, CNRS and INRIA at the following URL
00008  * "http://www.cecill.info".
00009  *
00010  * As a counterpart to the access to the source code and  rights to copy,
00011  * modify and redistribute granted by the license, users are provided only
00012  * with a limited warranty  and the software's author,  the holder of the
00013  * economic rights,  and the successive licensors  have only  limited
00014  * liability.
00015  *
00016  * In this respect, the user's attention is drawn to the risks associated
00017  * with loading,  using,  modifying and/or developing or reproducing the
00018  * software by the user in light of its specific status of free software,
00019  * that may mean  that it is complicated to manipulate,  and  that  also
00020  * therefore means  that it is reserved for developers  and  experienced
00021  * professionals having in-depth computer knowledge. Users are therefore
00022  * encouraged to load and test the software's suitability as regards their
00023  * requirements in conditions enabling the security of their systems and/or
00024  * data to be ensured and,  more generally, to use and operate it in the
00025  * same conditions as regards security.
00026  *
00027  * The fact that you are presently reading this means that you have had
00028  * knowledge of the CeCILL license and that you accept its terms.
00029  */
00030 
00031 //package pddl4j.graphplan;
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 }


tug_ist_diagnosis_repair
Author(s): Safdar Zaman
autogenerated on Mon Jan 6 2014 11:51:12