
jadex.bdi.examples.cleanerworld_classic.cleaner.CleanUpWastePlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The newest version!
package jadex.bdi.examples.cleanerworld_classic.cleaner;
import jadex.bdi.examples.cleanerworld_classic.Waste;
import jadex.bdi.examples.cleanerworld_classic.Wastebin;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;
/**
* Clean-up some waste.
*/
public class CleanUpWastePlan extends Plan
{
//-------- constructors --------
/**
* Create a new plan.
*/
public CleanUpWastePlan()
{
// getLogger().info("Created: "+this);
}
//-------- methods --------
/**
* The plan body.
*/
public void body()
{
//System.out.println("Clean-up waste plan started.");
if(getBeliefbase().getBelief("carriedwaste").getFact()==null)
{
Waste waste = (Waste)getParameter("waste").getValue();
// the following is only for debugging
// if(waste==null)
// {
// RProcessGoal proc = (RProcessGoal)((ElementWrapper)getRootGoal()).unwrap();
// IRGoal orig = proc.getProprietaryGoal();
// throw new RuntimeException("Waste is null: " + proc.getParameter("waste") + ", "+orig.getParameter("waste"));
// }
//System.out.println("Pickup goal created.");
IGoal pickup = createGoal("achievepickupwaste");
pickup.getParameter("waste").setValue(waste);
dispatchSubgoalAndWait(pickup);
}
boolean dropped = false;
while(!dropped)
{
// Move to a not full waste-bin
IGoal findbin = createGoal("querywastebin");
dispatchSubgoalAndWait(findbin);
Wastebin wastebin = (Wastebin)findbin.getParameter("result").getValue();
// Retry, when wastebin is full in meantime.
try
{
IGoal drop = createGoal("achievedropwaste");
drop.getParameter("wastebin").setValue(wastebin);
dispatchSubgoalAndWait(drop);
dropped = true;
}
// catch(GoalFailureException e){}
catch(RuntimeException e)
{
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy