
jadex.bdi.examples.cleanerworld_classic.environment.UpdateEnvironmentPlan 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.environment;
import jadex.bdi.examples.cleanerworld_classic.Chargingstation;
import jadex.bdi.examples.cleanerworld_classic.Cleaner;
import jadex.bdi.examples.cleanerworld_classic.Environment;
import jadex.bdi.examples.cleanerworld_classic.RequestCompleteVision;
import jadex.bdi.examples.cleanerworld_classic.Vision;
import jadex.bdi.examples.cleanerworld_classic.Waste;
import jadex.bdi.examples.cleanerworld_classic.Wastebin;
import jadex.bdi.runtime.GoalFailureException;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;
import jadex.bridge.fipa.Done;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.df.IDF;
import jadex.bridge.service.types.df.IDFComponentDescription;
import jadex.bridge.service.types.df.IDFServiceDescription;
/**
* Update the environment belief.
*/
public class UpdateEnvironmentPlan extends Plan
{
//-------- conctructors --------
/**
* Create a new plan.
*/
public UpdateEnvironmentPlan()
{
getLogger().info("Created: "+this);
}
//-------- methods --------
/**
* The plan body.
*/
public void body()
{
while(true)
{
// Search and store the environment agent.
if(getBeliefbase().getBelief("environmentagent").getFact()==null)
searchEnvironmentAgent();
if(getBeliefbase().getBelief("environmentagent").getFact()==null)
{
// If no environment agent found, wait a while before trying again.
waitFor(5000);
}
else
{
RequestCompleteVision rv = new RequestCompleteVision();
IGoal rg = createGoal("rp_initiate");
rg.getParameter("receiver").setValue(getBeliefbase().getBelief("environmentagent").getFact());
rg.getParameter("action").setValue(rv);
rg.getParameter("ontology").setValue("cleaner_ontology");
//rg.getParameter("language").setValue(SFipa.FIPA_SL0);
try
{
dispatchSubgoalAndWait(rg);
Environment env = (Environment)getBeliefbase().getBelief("environment").getFact();
env.clear();
Vision vision = ((RequestCompleteVision)((Done)rg.getParameter("result").getValue()).getAction()).getVision();
Cleaner[] cleaners = vision.getCleaners();
for(int i=0; i1)
System.out.println("WARNING: more than environment agent found.");
}
}
}
catch(GoalFailureException gfe)
{
getLogger().warning("DF search failed: "+gfe);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy