bdi4jade

Initial comments.

2/21/2018 11:44:49 PM

Details

diff --git a/bdi-jade-extensions/src/bdi4jade/extension/remediation/reasoning/RemediationOptionGenerationFunction.java b/bdi-jade-extensions/src/bdi4jade/extension/remediation/reasoning/RemediationOptionGenerationFunction.java
index c6ecc0e..4e62f0e 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/remediation/reasoning/RemediationOptionGenerationFunction.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/remediation/reasoning/RemediationOptionGenerationFunction.java
@@ -11,6 +11,7 @@ import bdi4jade.belief.PredicateBelief;
 import bdi4jade.core.Capability;
 import bdi4jade.core.GoalUpdateSet;
 import bdi4jade.core.GoalUpdateSet.GoalDescription;
+import bdi4jade.core.Intention;
 import bdi4jade.event.GoalEvent;
 import bdi4jade.event.GoalListener;
 import bdi4jade.extension.remediation.goal.CauseEffectProblem;
@@ -20,6 +21,9 @@ import bdi4jade.extension.remediation.graph.AlternativeCauseSet;
 import bdi4jade.extension.remediation.graph.CauseEffectKnowledgeModel;
 import bdi4jade.extension.remediation.graph.CauseEffectRelationship;
 import bdi4jade.extension.remediation.logics.Fact;
+import bdi4jade.extension.remediation.logics.Predicate;
+import bdi4jade.extension.undo.GoalAchievementMetadata;
+import bdi4jade.extension.undo.RevertingCapability;
 import bdi4jade.goal.Goal;
 import bdi4jade.goal.GoalStatus;
 import bdi4jade.goal.NestedGoal;
@@ -81,18 +85,18 @@ public class RemediationOptionGenerationFunction implements OptionGenerationFunc
 			CauseEffectProblem cep = this.causeEffectProblems.get(goal);
 			CauseEffectRelationship cer = getCauseEffectKnowledgeModel().getCauseEffectRelationship(goal);
 			if (cep == null && cer != null) {
-				// TODO Here I need to create a new goal achievement metadata
-				// TODO Verify default values for GAMs
-				/*if (this.capability instanceof RevertingCapability) {
-					GoalAchievementMetadata gam = ((RevertingCapability) this.capability).createGoalAchievementMetadata(goal, null, true, 100,
-							100000);
-					Intention intention = this.getCapability.getIntentions().stream().filter(g -> g.getGoal().equals(goal))
-							.collect(Collectors.toList()).get(0);
-					gam.setIntention(intention);
-				}*/
-
 				cep = new CauseEffectProblem((PredicateGoal<?>) goal, cer, capability.getMyAgent(), parentGoal);
 				causeEffectProblems.put(cep.getEffectGoal(), cep);
+
+				// Here a new goal achievement metadata is created
+				if (this.capability instanceof RevertingCapability) {
+					for (Intention intention : this.capability.getMyAgent().getIntentions()) {
+						if (intention.getGoal().equals(goal)) {
+							((RevertingCapability) this.capability)
+									.createGoalAchievementMetadata((PredicateGoal<?>) goal, intention);
+						}
+					}
+				}
 			}
 
 		}
@@ -107,15 +111,12 @@ public class RemediationOptionGenerationFunction implements OptionGenerationFunc
 			// Algorithm 1 - lines 18-35
 			if (cep.getEffectGoalStatus() != null) {
 				if (knownCause(cep, cep.getCauseEffectRelationship())) {
-					/*if (this.capability instanceof RevertingCapability) {
-						ArrayList<Predicate> reversionTrigger = new ArrayList<>();
-						for (CauseFactorStatus causeFactor : cep.getCauseFactorStatus()) {
-							reversionTrigger.add(causeFactor.getFact().getPredicate());
-						}
-						GoalAchievementMetadata gam = ((RevertingCapability) this.capability).getGoalAchievementMetadata().get(cep.getEffectGoal());
-						gam.setReversionTrigger(reversionTrigger);
-					}*/
-					
+
+					// Reversion trigger is updated with current cause factor predicates
+					if (this.capability instanceof RevertingCapability) {
+						updateReversionTrigger(cep);
+					}
+
 					if (causeFinished(cep.getCauseFactorStatus())) {
 						setEndState(cep);
 						causeEffectProblems.remove(cep.getEffectGoal());
@@ -269,5 +270,15 @@ public class RemediationOptionGenerationFunction implements OptionGenerationFunc
 			}
 		}
 	}
+	
+	private void updateReversionTrigger(CauseEffectProblem cep) {
+		ArrayList<Predicate> reversionTrigger = new ArrayList<>();
+		for (CauseFactorStatus causeFactor : cep.getCauseFactorStatus()) {
+			reversionTrigger.add(causeFactor.getFact().getPredicate());
+		}
+		GoalAchievementMetadata gam = ((RevertingCapability) this.capability)
+				.getGoalAchievementMetadata().get(cep.getEffectGoal());
+		gam.setReversionTrigger(reversionTrigger);
+	}
 
 }
diff --git a/bdi-jade-extensions/src/bdi4jade/extension/undo/GoalAchievementMetadata.java b/bdi-jade-extensions/src/bdi4jade/extension/undo/GoalAchievementMetadata.java
index d4b4125..77242de 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/undo/GoalAchievementMetadata.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/undo/GoalAchievementMetadata.java
@@ -1,3 +1,25 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2018  João Faccin
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// 
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
 package bdi4jade.extension.undo;
 
 import java.util.ArrayList;
@@ -13,10 +35,19 @@ import bdi4jade.goal.GoalStatus;
 import bdi4jade.goal.PredicateGoal;
 import javafx.util.Pair;
 
+/**
+ * This class stores the information regarding changes performed during the
+ * achievement of a related {@link Goal} in order to allow such changes to be
+ * later reverted.
+ * 
+ * @author João Faccin
+ */
 public class GoalAchievementMetadata {
 
-	private Long addedTime;
+	private final static Integer MAX_EXECUTED_PLANS = 500;
+	private final static Integer MAX_TIME = 100000;
 	private Map<Predicate, List<Pair<Boolean, Long>>> beliefChangeTrace;
+	private Long createdTime;
 	private PredicateGoal<?> goal;
 	private Intention intention;
 	private Integer maxExecutedPlans;
@@ -25,12 +56,63 @@ public class GoalAchievementMetadata {
 	private List<Predicate> reversionTrigger;
 	private Boolean rollback;
 
-	public GoalAchievementMetadata(PredicateGoal<?> goal, List<Predicate> reversionTrigger, Boolean rollback,
-			Integer maxExecutedPlans, Integer maxTime) {
-		this.addedTime = System.currentTimeMillis();
+	/**
+	 * Initializes a goal achievement metadata with its related {@link Goal} and
+	 * {@link Intention}.
+	 * 
+	 * @param goal
+	 *            the goal related to the goal achievement metadata.
+	 * @param intention
+	 *            the intention related to the goal achievement metadata.
+	 */
+	public GoalAchievementMetadata(PredicateGoal<?> goal, Intention intention) {
+		this(goal, intention, true);
+	}
+
+	/**
+	 * Initializes a goal achievement metadata with its related {@link Goal} and
+	 * {@link Intention}. It also sets the rollback flag.
+	 * 
+	 * @param goal
+	 *            the goal related to the goal achievement metadata.
+	 * @param intention
+	 *            the intention related to the goal achievement metadata.
+	 * @param rollback
+	 *            a flag that indicates the desire of a rollback in case of a plan
+	 *            failure.
+	 */
+	public GoalAchievementMetadata(PredicateGoal<?> goal, Intention intention, Boolean rollback) {
+		this(goal, intention, rollback, null, MAX_EXECUTED_PLANS, MAX_TIME);
+	}
+
+	/**
+	 * Initializes a goal achievement metadata with its related goal and intention.
+	 * It sets a reversion trigger if it is not null, and a rollback flag.
+	 * 
+	 * @param goal
+	 *            the goal related to the goal achievement metadata.
+	 * @param intention
+	 *            the intention related to the goal achievement metadata.
+	 * @param rollback
+	 *            a flag that indicates the desire of a rollback in case of a plan
+	 *            failure.
+	 * @param reversionTrigger
+	 *            a list of {@link Predicate} that specifies the condition in which
+	 *            a reversion will be activated.
+	 * @param maxExecutedPlans
+	 *            the number of plans that can be executed after achieving the
+	 *            related goal before this goal achievement metadata is discarded.
+	 * @param maxTime
+	 *            the time that can pass after achieving the related goal before
+	 *            this goal achievement metadata is discarded.
+	 */
+	public GoalAchievementMetadata(PredicateGoal<?> goal, Intention intention, Boolean rollback,
+			List<Predicate> reversionTrigger, Integer maxExecutedPlans, Integer maxTime) {
+		// TODO Created time must be refactored to achieved time.
+		this.createdTime = System.currentTimeMillis();
 		this.beliefChangeTrace = new HashMap<>();
 		this.goal = goal;
-		this.intention = null;
+		this.intention = intention;
 		this.maxExecutedPlans = maxExecutedPlans;
 		this.maxTime = maxTime;
 		this.planCounter = 0;
@@ -42,6 +124,15 @@ public class GoalAchievementMetadata {
 		}
 	}
 
+	/**
+	 * Selects stored changes that must be actually reverted. It selects only those
+	 * changes that do not correspond to the goal itself and whose first and last
+	 * changed values are equal to each other.
+	 * 
+	 * @param beliefBase
+	 *            the belief base.
+	 * @return the list of {@link Predicate} to be reverted.
+	 */
 	public ArrayList<Predicate> filterBeliefChanges(BeliefBase beliefBase) {
 		ArrayList<Predicate> filteredBeliefs = new ArrayList<>();
 		PredicateGoal<?> goal = (PredicateGoal<?>) this.goal;
@@ -59,64 +150,145 @@ public class GoalAchievementMetadata {
 		return filteredBeliefs;
 	}
 
-	public Long getAddedTime() {
-		return addedTime;
-	}
-
+	/**
+	 * Returns the mapping of predicates and their corresponding list of changes.
+	 * 
+	 * @return the beliefChangeTrace.
+	 */
 	public Map<Predicate, List<Pair<Boolean, Long>>> getBeliefChangeTrace() {
 		return beliefChangeTrace;
 	}
 
+	/**
+	 * Returns the time in which the goal related to this goal achievement metadata
+	 * was achieved.
+	 * 
+	 * @return the createdTime.
+	 */
+	public Long getCreatedTime() {
+		return createdTime;
+	}
+
+	/**
+	 * Returns the {@link PredicateGoal} related to this goal achievement metadata.
+	 * 
+	 * @return the goal.
+	 */
 	public PredicateGoal<?> getGoal() {
 		return goal;
 	}
 
+	/**
+	 * Returns the {@link Intention} related to this goal achievement metadata.
+	 * 
+	 * @return the intention.
+	 */
 	public Intention getIntention() {
 		return intention;
 	}
 
+	/**
+	 * Returns the maximum number of successfully executed plans after the
+	 * achievement of the related goal before the reversion process becomes
+	 * deactivated.
+	 * 
+	 * @return the maxExecutedPlans.
+	 */
 	public Integer getMaxExecutedPlans() {
 		return maxExecutedPlans;
 	}
 
+	/**
+	 * Returns the maximum time passed since the achievement of the related goal
+	 * before the reversion process becomes deactivated.
+	 * 
+	 * @return the maxTime.
+	 */
 	public Integer getMaxTime() {
 		return maxTime;
 	}
 
+	/**
+	 * Returns the number of successfully executed plans after the achievement of
+	 * the related goal.
+	 * 
+	 * @return the planCounter.
+	 */
 	public Integer getPlanCounter() {
 		return planCounter;
 	}
 
+	/**
+	 * Return a list of predicates that indicates the condition in which the
+	 * reversion process is activated.
+	 * 
+	 * @return the reversionTrigger.
+	 */
 	public List<Predicate> getReversionTrigger() {
 		return reversionTrigger;
 	}
 
+	/**
+	 * Returns a boolean value that indicates the desire of a rollback in case of
+	 * plan failure.
+	 * 
+	 * @return true if the rollback is desired.
+	 */
 	public Boolean getRollback() {
 		return rollback;
 	}
 
+	/**
+	 * Increments the counter of successfully executed plans after the achievement
+	 * of the related goal.
+	 */
 	public void incrementPlanCounter() {
 		this.planCounter++;
 	}
 
+	/**
+	 * Returns a boolean value that indicates if the reversion process is activated.
+	 * It returns true if its trigger condition is achieved or a rollback is
+	 * triggered due to a plan failure.
+	 * 
+	 * @param beliefBase
+	 *            the {@link BeliefBase} in which reversionTrigger will be
+	 *            evaluated.
+	 * @return true if the reversion process is activated.
+	 */
 	public Boolean isReversionActivated(BeliefBase beliefBase) {
 		return isReversionTriggered(beliefBase) || isRollbackTriggered();
 	}
-	
+
+	/**
+	 * Returns a boolean value that indicates if reversion is deactivated. It
+	 * returns true if planCounter exceeds maxExecutedPlans or the time passed since
+	 * createdTime exceeds maxTime.
+	 * 
+	 * @return true if reversion is deactivated.
+	 */
 	public Boolean isReversionDeactivated() {
-		if (this.maxExecutedPlans != null) {
-			if (this.planCounter > this.maxExecutedPlans) {
-				return true;
-			}
+		if (this.planCounter > this.maxExecutedPlans) {
+			return true;
 		}
-		if (this.maxTime != null) {
-			if ((System.currentTimeMillis() - this.addedTime) > this.maxTime) {
-				return true;
-			}
+
+		if ((System.currentTimeMillis() - this.createdTime) > this.maxTime) {
+			return true;
 		}
-		return false;
+
+		return this.intention.getStatus().isFinished() && !this.intention.getStatus().equals(GoalStatus.ACHIEVED);
 	}
-	
+
+	/**
+	 * Returns a boolean value that indicates if the reversion process is activated
+	 * due to the achievement of its trigger condition. It returns true if every
+	 * predicate into reversionTrigger holds true in the given {@link BeliefBase}.
+	 * 
+	 * @param beliefBase
+	 *            the {@link BeliefBase} in which reversionTrigger will be
+	 *            evaluated.
+	 * @return true if reversionTrigger holds true in beliefBase.
+	 */
 	public Boolean isReversionTriggered(BeliefBase beliefBase) {
 		Boolean triggered = true;
 
@@ -126,22 +298,52 @@ public class GoalAchievementMetadata {
 				triggered = false;
 			}
 		}
-		
+
 		return triggered;
 	}
 
+	/**
+	 * Returns a boolean value that indicates if the reversion process is activated
+	 * due to a plan failure. It returns true if a plan fails to achieve the related
+	 * goal and a rollback is desired.
+	 * 
+	 * @return true if a rollback is triggered.
+	 */
 	public Boolean isRollbackTriggered() {
-		return this.rollback && this.intention != null && this.intention.getStatus().equals(GoalStatus.PLAN_FAILED);
+		return this.rollback && this.intention.getStatus().equals(GoalStatus.PLAN_FAILED);
 	}
 
+	/**
+	 * Sets the intention related to this goal achievement metadata.
+	 * 
+	 * @param intention
+	 *            the intention to be set.
+	 */
 	public void setIntention(Intention intention) {
 		this.intention = intention;
 	}
 
+	/**
+	 * Sets the reversion trigger that indicates the condition in which recorded
+	 * belief changes must be reverted.
+	 * 
+	 * @param reversionTrigger
+	 *            the reversionTrigger to be set.
+	 */
 	public void setReversionTrigger(List<Predicate> reversionTrigger) {
 		this.reversionTrigger = reversionTrigger;
 	}
 
+	/**
+	 * Records a change of the evaluation value of a given predicate, which was made
+	 * during the achievement of the goal related to this goal achievement metadata.
+	 * It also stores the time in which the change was recorded.
+	 * 
+	 * @param predicate
+	 *            the predicate whose evaluation value changed.
+	 * @param value
+	 *            the new evaluation value of the given predicate.
+	 */
 	public void trackBeliefChange(Predicate predicate, Boolean value) {
 		if (!this.beliefChangeTrace.containsKey(predicate)) {
 			this.beliefChangeTrace.put(predicate, new LinkedList<Pair<Boolean, Long>>());
diff --git a/bdi-jade-extensions/src/bdi4jade/extension/undo/reasoning/RevertingOptionGenerationFunction.java b/bdi-jade-extensions/src/bdi4jade/extension/undo/reasoning/RevertingOptionGenerationFunction.java
index 7784da3..b850fd7 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/undo/reasoning/RevertingOptionGenerationFunction.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/undo/reasoning/RevertingOptionGenerationFunction.java
@@ -1,3 +1,25 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2018  João Faccin
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// 
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
 package bdi4jade.extension.undo.reasoning;
 
 import java.util.ArrayList;
@@ -13,14 +35,25 @@ import bdi4jade.goal.Goal;
 import bdi4jade.goal.PredicateGoal;
 import bdi4jade.reasoning.OptionGenerationFunction;
 
+/**
+ * This class does blablabla.
+ * 
+ * @author João Faccin
+ */
 public class RevertingOptionGenerationFunction implements OptionGenerationFunction {
 
 	private Capability capability;
 
+	/**
+	 * @param capability
+	 */
 	public RevertingOptionGenerationFunction(Capability capability) {
 		setCapability(capability);
 	}
 
+	/* (non-Javadoc)
+	 * @see bdi4jade.reasoning.OptionGenerationFunction#generateGoals(bdi4jade.core.GoalUpdateSet)
+	 */
 	@Override
 	public void generateGoals(GoalUpdateSet goalUpdateSet) {
 		if (this.capability instanceof RevertingCapability) {
@@ -35,11 +68,11 @@ public class RevertingOptionGenerationFunction implements OptionGenerationFuncti
 
 						ArrayList<PredicateGoal<?>> reversionGoals = generateReversionGoals(filteredChanges,
 								this.capability.getBeliefBase());
-						
+
 						for (PredicateGoal<?> predicateGoal : reversionGoals) {
 							goalUpdateSet.generateGoal(predicateGoal, capability);
 						}
-						
+
 						for (Predicate predicate : filteredChanges) {
 							gam.getBeliefChangeTrace().remove(predicate);
 						}
@@ -53,6 +86,11 @@ public class RevertingOptionGenerationFunction implements OptionGenerationFuncti
 		}
 	}
 
+	/**
+	 * @param predicates
+	 * @param beliefBase
+	 * @return
+	 */
 	public ArrayList<PredicateGoal<?>> generateReversionGoals(ArrayList<Predicate> predicates, BeliefBase beliefBase) {
 		ArrayList<PredicateGoal<?>> reversionGoals = new ArrayList<>();
 
@@ -64,6 +102,9 @@ public class RevertingOptionGenerationFunction implements OptionGenerationFuncti
 		return reversionGoals;
 	}
 
+	/* (non-Javadoc)
+	 * @see bdi4jade.reasoning.ReasoningStrategy#setCapability(bdi4jade.core.Capability)
+	 */
 	@Override
 	public void setCapability(Capability capability) {
 		if (this.capability != null) {
diff --git a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingBDIAgent.java b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingBDIAgent.java
index 6bfb36d..8100f2f 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingBDIAgent.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingBDIAgent.java
@@ -1,3 +1,25 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2018  João Faccin
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// 
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
 package bdi4jade.extension.undo;
 
 import java.util.List;
@@ -11,6 +33,11 @@ import bdi4jade.extension.remediation.logics.Predicate;
 import bdi4jade.goal.Goal;
 import bdi4jade.goal.PredicateGoal;
 
+/**
+ * This class does blablabla.
+ * 
+ * @author João Faccin
+ */
 public class RevertingBDIAgent extends AbstractBDIAgent {
 
 	private static final long serialVersionUID = 7351855722581311736L;
@@ -23,10 +50,8 @@ public class RevertingBDIAgent extends AbstractBDIAgent {
 				if (dispatcher instanceof RevertingCapability) {
 					Intention intention = this.getIntentions().stream().filter(g -> g.getGoal().equals(goal))
 							.collect(Collectors.toList()).get(0);
-
-					GoalAchievementMetadata gam = ((RevertingCapability) dispatcher).createGoalAchievementMetadata(goal,
+					((RevertingCapability) dispatcher).createGoalAchievementMetadata((PredicateGoal<?>) goal, intention,
 							reversionTrigger, rollback, maxExecutedPlans, maxTime);
-					gam.setIntention(intention);
 				}
 			}
 			return true;
diff --git a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingCapability.java b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingCapability.java
index ea6acd7..00c9f06 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingCapability.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingCapability.java
@@ -1,3 +1,25 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2018  João Faccin
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// 
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
 package bdi4jade.extension.undo;
 
 import java.util.HashMap;
@@ -6,6 +28,7 @@ import java.util.Map;
 
 import bdi4jade.belief.PredicateBelief;
 import bdi4jade.core.Capability;
+import bdi4jade.core.Intention;
 import bdi4jade.event.BeliefEvent;
 import bdi4jade.event.BeliefEvent.Action;
 import bdi4jade.event.BeliefListener;
@@ -17,6 +40,11 @@ import bdi4jade.goal.Goal;
 import bdi4jade.goal.GoalStatus;
 import bdi4jade.goal.PredicateGoal;
 
+/**
+ * This class does blablabla.
+ * 
+ * @author João Faccin
+ */
 public class RevertingCapability extends Capability implements BeliefListener, GoalListener {
 
 	private static final long serialVersionUID = -5556551069331273755L;
@@ -40,10 +68,23 @@ public class RevertingCapability extends Capability implements BeliefListener, G
 		this.parentGoals.put(goal, parent);
 	}
 
-	public GoalAchievementMetadata createGoalAchievementMetadata(Goal goal, List<Predicate> reversionTrigger,
-			Boolean rollback, Integer maxExecutedPlans, Integer maxTime) {
-		GoalAchievementMetadata gam = new GoalAchievementMetadata((PredicateGoal<?>) goal, reversionTrigger, rollback,
-				maxExecutedPlans, maxTime);
+	public GoalAchievementMetadata createGoalAchievementMetadata(PredicateGoal<?> goal, Intention intention) {
+		GoalAchievementMetadata gam = new GoalAchievementMetadata(goal, intention);
+		addGoalAchievementMetadata(goal, gam);
+		return gam;
+	}
+
+	public GoalAchievementMetadata createGoalAchievementMetadata(PredicateGoal<?> goal, Intention intention,
+			Boolean rollback) {
+		GoalAchievementMetadata gam = new GoalAchievementMetadata(goal, intention, rollback);
+		addGoalAchievementMetadata(goal, gam);
+		return gam;
+	}
+
+	public GoalAchievementMetadata createGoalAchievementMetadata(PredicateGoal<?> goal, Intention intention,
+			List<Predicate> reversionTrigger, Boolean rollback, Integer maxExecutedPlans, Integer maxTime) {
+		GoalAchievementMetadata gam = new GoalAchievementMetadata((PredicateGoal<?>) goal, intention, rollback,
+				reversionTrigger, maxExecutedPlans, maxTime);
 		addGoalAchievementMetadata(goal, gam);
 		return gam;
 	}
@@ -54,7 +95,6 @@ public class RevertingCapability extends Capability implements BeliefListener, G
 			Object args = beliefEvent.getArgs();
 			if (args instanceof PredicateGoal<?>) {
 				PredicateGoal<?> goal = (PredicateGoal<?>) args;
-				// TODO Here, get the oldest reversible parent.
 				if (beliefEvent.getBelief() instanceof PredicateBelief<?>) {
 					PredicateBelief<?> belief = (PredicateBelief<?>) beliefEvent.getBelief();
 					Goal oldestParent = getOldestReversibleParent(goal);
@@ -66,6 +106,10 @@ public class RevertingCapability extends Capability implements BeliefListener, G
 		}
 	}
 
+	public Map<Goal, GoalAchievementMetadata> getGoalAchievementMetadata() {
+		return gams;
+	}
+
 	private Goal getOldestReversibleParent(Goal goal) {
 		Goal parent = null;
 		Goal aux = goal;
@@ -84,10 +128,6 @@ public class RevertingCapability extends Capability implements BeliefListener, G
 		return parent;
 	}
 
-	public Map<Goal, GoalAchievementMetadata> getGoalAchievementMetadata() {
-		return gams;
-	}
-
 	public Map<Goal, Goal> getParentGoals() {
 		return parentGoals;
 	}
diff --git a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingPlanBody.java b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingPlanBody.java
index 10bd48a..b1c1dce 100644
--- a/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingPlanBody.java
+++ b/bdi-jade-extensions/src/bdi4jade/extension/undo/RevertingPlanBody.java
@@ -1,24 +1,60 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2018  João Faccin
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// 
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
 package bdi4jade.extension.undo;
 
 import bdi4jade.goal.Goal;
 import bdi4jade.plan.planbody.BeliefGoalPlanBody;
 
+/**
+ * This class does blablabla.
+ * 
+ * @author João Faccin
+ */
 public abstract class RevertingPlanBody extends BeliefGoalPlanBody {
 
 	private static final long serialVersionUID = -678344739581158097L;
 
+	/* (non-Javadoc)
+	 * @see bdi4jade.plan.planbody.AbstractPlanBody#dispatchSubgoal(bdi4jade.goal.Goal)
+	 */
 	@Override
 	public boolean dispatchSubgoal(Goal subgoal) {
 		setParentGoal(subgoal);
 		return super.dispatchSubgoal(subgoal);
 	}
 
+	/* (non-Javadoc)
+	 * @see bdi4jade.plan.planbody.AbstractPlanBody#dispatchSubgoalAndListen(bdi4jade.goal.Goal)
+	 */
 	@Override
 	public boolean dispatchSubgoalAndListen(Goal subgoal) {
 		setParentGoal(subgoal);
 		return super.dispatchSubgoalAndListen(subgoal);
 	}
 
+	/**
+	 * @param subgoal
+	 */
 	private void setParentGoal(Goal subgoal) {
 		if (this.getCapability() instanceof RevertingCapability) {
 			RevertingCapability capability = (RevertingCapability) this.getCapability();