1919 * precondition and an effect.
2020 *
2121 * @author samagra
22+ * @author Ruediger Lunde
2223 */
2324public class ActionSchema {
2425
@@ -27,51 +28,75 @@ public class ActionSchema {
2728 */
2829 public final static String NO_OP = "No-op" ;
2930
30- List <Term > variables ;// list of variables
31- List <Literal > precondition ; //PRECONDITION: treated as a conjunction of fluents
32- List <Literal > effects ; // EFFECT: treated as a conjunction of fluents
31+ List <Term > variables ; // list of variables
32+ List <Literal > precondition ; // PRECONDITION: treated as a conjunction of fluents
33+ List <Literal > effect ; // EFFECT: treated as a conjunction of fluents
3334 List <Literal > effectsPositiveLiterals ;
3435 List <Literal > effectsNegativeLiterals ;
35- private final String name ;// action name
36+ private final String name ; // action name
3637
37- public ActionSchema (String name , List <Term > variables , List <Literal > precondition , List <Literal > effects ) {
38+ public ActionSchema (String name , List <Term > variables , List <Literal > precondition , List <Literal > effect ) {
3839 if (variables == null )
3940 variables = new ArrayList <>();
4041 this .name = name ;
4142 this .variables = variables ;
4243 this .precondition = precondition ;
43- this .effects = effects ;
44+ this .effect = effect ;
4445 effectsNegativeLiterals = new ArrayList <>();
4546 effectsPositiveLiterals = new ArrayList <>();
4647 this .sortEffects ();
4748 }
4849
49- public ActionSchema (String name , List <Term > variables , String precondition , String effects ) {
50- this (name , variables , Utils .parse (precondition ), Utils .parse (effects ));
50+ public ActionSchema (String name , List <Term > variables , String precondition , String effect ) {
51+ this (name , variables , Utils .parse (precondition ), Utils .parse (effect ));
5152 }
5253
5354 private void sortEffects () {
54- for (Literal effect : effects ) {
55- if (effect .isNegativeLiteral ())
56- effectsNegativeLiterals .add (effect );
55+ for (Literal eff : effect ) {
56+ if (eff .isNegativeLiteral ())
57+ effectsNegativeLiterals .add (eff );
5758 else
58- effectsPositiveLiterals .add (effect );
59+ effectsPositiveLiterals .add (eff );
5960 }
6061 }
6162
63+ public String getName () {
64+ return name ;
65+ }
66+
67+ public List <Term > getVariables () {
68+ return variables ;
69+ }
70+
71+ public List <Literal > getPrecondition () {
72+ return precondition ;
73+ }
74+
75+ public List <Literal > getEffect () {
76+ return effect ;
77+ }
78+
79+ public List <Literal > getEffectsPositiveLiterals () {
80+ return effectsPositiveLiterals ;
81+ }
82+
83+ public List <Literal > getEffectsNegativeLiterals () {
84+ return effectsNegativeLiterals ;
85+ }
86+
6287 @ Override
6388 public String toString () {
6489 StringBuilder result = new StringBuilder ();
6590 result .append ("Action(" ).append (this .getName ()).append (")\n \t PRECOND:" );
6691 String and = "" ;
67- for (Literal precond : getPrecondition () ) {
68- result .append (and ).append (precond );
92+ for (Literal pre : precondition ) {
93+ result .append (and ).append (pre );
6994 and = "^" ;
7095 }
7196 result .append ("\n \t EFFECT:" );
7297 and = "" ;
73- for (Literal effect : getEffects () ) {
74- result .append (and ).append (effect );
98+ for (Literal eff : effect ) {
99+ result .append (and ).append (eff );
75100 and = "^" ;
76101 }
77102 return result .toString ();
@@ -81,22 +106,22 @@ public String toString() {
81106 public boolean equals (Object obj ) {
82107 if (this == obj )
83108 return true ;
84- if (!( obj instanceof ActionSchema ))
109+ if (obj == null || getClass () != obj . getClass ( ))
85110 return false ;
86111 return this .getName ().equals (((ActionSchema ) obj ).getName ()) &&
87112 this .getPrecondition ().containsAll (((ActionSchema ) obj ).getPrecondition ())
88113 && ((ActionSchema ) obj ).getPrecondition ().containsAll (this .getPrecondition ())
89- && this .getEffects ().containsAll (((ActionSchema ) obj ).getEffects ())
90- && ((ActionSchema ) obj ).getEffects ().containsAll (this .getEffects ());
114+ && this .getEffect ().containsAll (((ActionSchema ) obj ).getEffect ())
115+ && ((ActionSchema ) obj ).getEffect ().containsAll (this .getEffect ());
91116 }
92117
93118 @ Override
94119 public int hashCode () {
95120 int hashCode = 17 ;
96- for (Literal preCo : this . getPrecondition () )
97- hashCode = 37 * hashCode + preCo .hashCode ();
98- for (Literal effect : this . getEffects () )
99- hashCode = 37 * hashCode + effect .hashCode ();
121+ for (Literal literal : precondition )
122+ hashCode = 37 * hashCode + literal .hashCode ();
123+ for (Literal literal : effect )
124+ hashCode = 37 * hashCode + literal .hashCode ();
100125 for (Term var : this .getVariables ())
101126 hashCode = 37 * hashCode + var .hashCode ();
102127 return hashCode ;
@@ -109,37 +134,31 @@ public int hashCode() {
109134 * @return A ground action.
110135 */
111136 public ActionSchema getActionBySubstitution (List <Constant > constants ) {
112- List <Literal > precondList = this .getPrecondition ();
113- List <Term > vars = this .getVariables ();
114- List <Literal > effectList = this .getEffects ();
115- List <Literal > newPrecond = new ArrayList <>();
116- List <Literal > newEffects = new ArrayList <>();
117- for (Literal precondition : precondList ) {
137+ List <Literal > newPrecondition = new ArrayList <>();
138+ List <Literal > newEffect = new ArrayList <>();
139+ for (Literal pre : precondition ) {
118140 List <Term > newTerms = new ArrayList <>();
119- for (Term variable : precondition .getAtomicSentence ().getArgs ()) {
141+ for (Term variable : pre .getAtomicSentence ().getArgs ()) {
120142 if (variable instanceof Variable ) {
121- newTerms .add (constants .get (vars .lastIndexOf (variable )));
143+ newTerms .add (constants .get (variables .lastIndexOf (variable )));
122144 } else
123145 newTerms .add (variable );
124146 }
125- newPrecond .add (new Literal (new
126- Predicate (precondition .getAtomicSentence ().getSymbolicName (),
127- newTerms ), precondition .isNegativeLiteral ()));
147+ newPrecondition .add (new Literal (new Predicate (pre .getAtomicSentence ().getSymbolicName (), newTerms ),
148+ pre .isNegativeLiteral ()));
128149 }
129- for (Literal effect : effectList ) {
150+ for (Literal eff : effect ) {
130151 List <Term > newTerms = new ArrayList <>();
131- for (Term variable :
132- effect .getAtomicSentence ().getArgs ()) {
152+ for (Term variable : eff .getAtomicSentence ().getArgs ()) {
133153 if (variable instanceof Variable )
134- newTerms .add (constants .get (vars .lastIndexOf (variable )));
154+ newTerms .add (constants .get (variables .lastIndexOf (variable )));
135155 else
136156 newTerms .add (variable );
137157 }
138- newEffects .add (new Literal (new
139- Predicate (effect .getAtomicSentence ().getSymbolicName (),
140- newTerms ), effect .isNegativeLiteral ()));
158+ newEffect .add (new Literal (new
159+ Predicate (eff .getAtomicSentence ().getSymbolicName (), newTerms ), eff .isNegativeLiteral ()));
141160 }
142- return new ActionSchema (this .getName (), null , newPrecond , newEffects );
161+ return new ActionSchema (this .getName (), null , newPrecondition , newEffect );
143162 }
144163
145164 /**
@@ -149,11 +168,11 @@ public ActionSchema getActionBySubstitution(List<Constant> constants) {
149168 */
150169 public List <Constant > getConstants () {
151170 List <Constant > constants = new ArrayList <>();
152- for (Constant constant : extractConstant (getPrecondition () )) {
171+ for (Constant constant : extractConstant (precondition )) {
153172 if (!constants .contains (constant ))
154173 constants .add (constant );
155174 }
156- for (Constant constant : extractConstant (getEffects () )) {
175+ for (Constant constant : extractConstant (effect )) {
157176 if (!constants .contains (constant ))
158177 constants .add (constant );
159178 }
@@ -170,28 +189,4 @@ public List<Constant> extractConstant(List<Literal> list) {
170189 }
171190 return result ;
172191 }
173-
174- public String getName () {
175- return name ;
176- }
177-
178- public List <Term > getVariables () {
179- return variables ;
180- }
181-
182- public List <Literal > getPrecondition () {
183- return precondition ;
184- }
185-
186- public List <Literal > getEffects () {
187- return effects ;
188- }
189-
190- public List <Literal > getEffectsPositiveLiterals () {
191- return effectsPositiveLiterals ;
192- }
193-
194- public List <Literal > getEffectsNegativeLiterals () {
195- return effectsNegativeLiterals ;
196- }
197192}
0 commit comments