Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package jadex.bdi.planlib;
  
 
 import java.util.Map;
 import java.util.Set;

Default bdi agent vision processor. Updates the agent's beliefsets according to the percepts of new/disappeared waste.
 
 {
 	//-------- constants --------
 
The percept types property.
 
 	public static String PROPERTY_PERCEPTTYPES = "percepttypes";


The add action.
 
 	public static String ADD = "add";

The remove action.
 
 	public static String REMOVE = "remove";

The remove_outdated action (checks all entries in the belief set, if they should be seen, but are no longer there).
 
 	public static String REMOVE_OUTDATED = "remove_outdated";

The set action.
 
 	public static String SET = "set";

The unset action (sets a belief fact to null).
 
 	public static String UNSET = "unset";

The maxrange property.
 
 	public static String PROPERTY_MAXRANGE = "range";

The maxrange property.
 
 	public static String PROPERTY_RANGE = "range_property";
 
 	//-------- attributes --------
 	
The percepttypes infos.
 
 	protected Map percepttypes;
 	
 	//-------- methods --------
 	
Process a new percept.

Parameters:
space The space.
type The type.
percept The percept.
agent The agent identifier.
agent The avatar of the agent (if any).
 
 	public void processPercept(final IEnvironmentSpace spacefinal String typefinal Object perceptfinal IComponentDescription agentfinal ISpaceObject avatar)
 	{
 		boolean	invokefalse;
 		final String[][] metainfos = getMetaInfos(type);
 		for(int i=0; !invoke && metainfos!=null && i<metainfos.lengthi++)
 		{
 			invoke.equals(metainfos[i][0])
 				|| .equals(metainfos[i][0])
 				|| .equals(metainfos[i][0])
 				|| .equals(metainfos[i][0])
 				|| .equals(metainfos[i][0]) && percept.equals(avatar);
 		}
 		
 		if(invoke)
 		{
 			// HACK!!! todo
 			{
 				public void resultAvailable(Object result)
 				{
					{
						public void exceptionOccurred(Exception exception)
						{
							exception.printStackTrace();
						}
						public void resultAvailable(Object result)
						{
							final IBDIExternalAccess exta = (IBDIExternalAccess)result;
							for(int i=0; i<metainfos.lengthi++)
							{
								final IParsedExpression	condmetainfos[i].length==2 ? null
									: (IParsedExpression)getProperty(metainfos[i][2]);
								final SimpleValueFetcher fetcher = new SimpleValueFetcher();
								if(cond!=null)
								{
//									fetcher	= new SimpleValueFetcher();
									fetcher.setValue("$space"space);
									fetcher.setValue("$percept"percept);
									fetcher.setValue("$avatar"avatar);
									fetcher.setValue("$type"type);
									fetcher.setValue("$aid"agent);
									fetcher.setValue("$scope"exta);
								}
								final String name = metainfos[i][1];
								if(.equals(metainfos[i][0]))
								{
									{
										{
											Object[]	factsscope.getBeliefbase().getBeliefSet(name).getFacts();
											if(cond!=null)
												fetcher.setValue("$facts"facts);
											if(!SUtil.arrayContains(factspercept) && (cond==null || evaluate(condfetcher)))
											{
												scope.getBeliefbase().getBeliefSet(name).addFact(percept);
//												System.out.println("added: "+percept+" to: "+belset);
											}
											return null;
										}
									});
								}
								else if(.equals(metainfos[i][0]))
								{
									{
										@XMLClassname("remove")
										{
											Object[]	factsscope.getBeliefbase().getBeliefSet(name).getFacts();
											if(cond!=null)
												fetcher.setValue("$facts"facts);
											if(SUtil.arrayContains(factspercept) && (cond==null || evaluate(condfetcher)))
											{
												scope.getBeliefbase().getBeliefSet(name).removeFact(percept);
//												System.out.println("removed: "+percept+" from: "+belset);
											}
											return null;
										}
									});
								}
								else if(.equals(metainfos[i][0]))
								{
									{
										{
											Object	factscope.getBeliefbase().getBelief(name).getFact();
											if(cond!=null)
												fetcher.setValue("$fact"fact);
											if(cond==null || evaluate(condfetcher))
											{
												scope.getBeliefbase().getBelief(name).setFact(percept);
//												System.out.println("set: "+percept+" on: "+belset);
											}
											return null;
										}
									});
								}
								else if(.equals(metainfos[i][0]))
								{
									{
										@XMLClassname("unset")
										{
											Object	factscope.getBeliefbase().getBelief(name).getFact();
											if(cond!=null)
												fetcher.setValue("$fact"fact);
											if(cond==null || evaluate(condfetcher))
											{
												scope.getBeliefbase().getBelief(name).setFact(null);
//												System.out.println("unset: "+percept+" on: "+belset);
											}
											return null;
										}
									});
								}
								else if(.equals(metainfos[i][0]) && percept.equals(avatar))
								{
									{
										@XMLClassname("removeoutdated")
										{
											Object[]	factsscope.getBeliefbase().getBeliefSet(name).getFacts();
											if(cond!=null)
												fetcher.setValue("$facts"facts);
											if(cond==null || evaluate(condfetcher))
											{
												IVector1 visiongetRange(avatar);
												Space2D	space2d	= (Space2D)space;
												ISpaceObject[]	known	= (ISpaceObject[])facts;
												Set	seen = space2d.getNearObjects(myposvision);
												for(int j=0; j<known.lengthj++)
												{
													// Hack!!! Shouldn't react to knownpos==null
													if(!seen.contains(known[j]) && (knownpos==null || !vision.less(space2d.getDistance(myposknownpos))))
													{
//														System.out.println("Removing disappeared object: "+percept+", "+known[j]);
														scope.getBeliefbase().getBeliefSet(name).removeFact(known[j]);
													}
												}
											}
											return null;
										}
									});
								}
							}
						}
					});
				}
				public void exceptionOccurred(Exception exception)
				{
					exception.printStackTrace();
				}
			});
		}
	}

Get the percept types defined for this generator.

Returns:
The percept types.
	protected Object[] getPerceptTypes()
	{
	}

Get meta infos about a percept type.
	protected String[][] getMetaInfos(String percepttype)
	{
		if(==null)
		{
			this. = new HashMap();
			Object[] percepttypes = getPerceptTypes();
			for(int i=0; i<percepttypes.lengthi++)
			{
				String[]	per = (String[])percepttypes[i];
				String[][]	newmisper.length==3 ? new String[][]{{per[1], per[2]}} : new String[][]{{per[1], per[2], per[3]}};
				String[][]	oldmis	= (String[][])this..get(per[0]);
				if(oldmis!=null)
					newmis	= (String[][])SUtil.joinArrays(oldmisnewmis);
				this..put(per[0], newmis);
			}
		}
		return (String[][]).get(percepttype);
	}
	// Todo: unify range handling!?
Get the range.

Returns:
The range.
	protected IVector1 getRange(ISpaceObject avatar)
	{
		return tmp==nullgetDefaultRange(): tmp instanceof Numbernew Vector1Double(((Number)tmp).doubleValue()): (IVector1)tmp;
	}

Get the default range.

Returns:
The range.
	{
		return tmp==null.tmp instanceof Numbernew Vector1Double(((Number)tmp).doubleValue()): (IVector1)tmp;
	}

Get the range property name.

Returns:
The range property name.
	{
		return tmp==null"range": (String)tmp;
	}

Evaluate a condition.

Parameters:
exp The expression.
fetcher The value fetcher.
	protected boolean	evaluate(IParsedExpression expIValueFetcher fetcher)
	{
		boolean	retfalse;
		try
		{
			ret	= ((Boolean)exp.getValue(fetcher)).booleanValue();
		}
		catch(Exception e)
		{
		}
		return ret;
	}
New to GrepCode? Check out our FAQ X