[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/directory TraceAnalyser.java, 1.21, 1.22

Chien-Liang Fok chien-liang at users.sourceforge.net
Fri May 19 13:07:47 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/directory
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28720/edu/wustl/mobilab/directory

Modified Files:
	TraceAnalyser.java 
Log Message:


Index: TraceAnalyser.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/directory/TraceAnalyser.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** TraceAnalyser.java	2 May 2006 00:27:52 -0000	1.21
--- TraceAnalyser.java	19 May 2006 20:07:44 -0000	1.22
***************
*** 13,16 ****
--- 13,26 ----
  	static final int MAX_AGENT_NUM = 2; // max number of agents within a GetAgentsResults message.
  
+ 	/**
+ 	 *  These are the possible values of the "success" variable within
+ 	 *  a QUERY_GET_LOCATION_RESULTS_RECEIVED traceline.
+ 	 */
+ 	public static final int INVALID = 1;
+ 	public static final int VALID = 2;
+ 	public static final int COARSE = 4;
+ 	
+ 	public static final int NO_ANSWER = 3;
+ 	
  	private boolean debug;
  	private Vector<TraceLine> trace = new Vector<TraceLine>();
***************
*** 42,47 ****
  	private void analyze() {		
  		
! 		int numGoodQueries = 0, numBadQueries = 0, numFailedQueries = 0; //, numErrors = 0;
! 		int numQueryMessages = 0, numResultsMessages = 0, numLocationUpdateMessages = 0;
  		double errorSum = 0;
  		
--- 52,57 ----
  	private void analyze() {		
  		
! 		int numRcvdAccurate = 0, numRcvdInaccurate = 0, numDontKnow = 0, numNoAns = 0; //, numErrors = 0;
! 		int numQueryMessages = 0, numResultsMessages = 0, numLocationUpdateMessages = 0, numCoarse = 0;
  		double errorSum = 0;
  		
***************
*** 105,228 ****
  			if (line.action.equals("QUERY_GET_LOCATION_RESULTS_RECEIVED")) {
  				if (line.agentID == QUERIER_AGENT_ID) {
! 					if (line.success) {
  						AgillaLocation intruderLoc = agentLocTable.get(new AgillaAgentID(INTRUDER_AGENT_ID));
  						if (line.loc.equals(intruderLoc))
! 							numGoodQueries++;
  						else {
  							log(line.timeStamp +" Qid: " + line.qid + " Bad Result: (" + line.loc.getx() + ", " + line.loc.gety() + "), Reality: (" + intruderLoc.getx() + ", " + intruderLoc.gety()  + "), Dist: " + line.loc.dist(intruderLoc));
! 							numBadQueries++;
  							errorSum += line.loc.dist(intruderLoc);
  						}
! 					} else {
! 						log(line.timeStamp + " Qid: " + line.qid + " Result contained FAIL");
! 						numFailedQueries++;
  					}
  				}
  			}
  			
! 			if (line.action.equals("QUERY_GET_CLOSEST_AGENT_RESULTS_RECEIVED")) {
! 				if (line.agentID == QUERIER_AGENT_ID) {	
! 					if (line.success) {						
! 						AgillaLocation qLoc = agentLocTable.get(new AgillaAgentID(QUERIER_AGENT_ID));
! 						
! 						// Check to see whether there is an agent at the specified location
! 						if (agentLocTable.containsValue(line.loc)) {							
! 							double closestDist = qLoc.dist(line.loc);
! 							
! 							// See if there are any agents closer to the specified agent
! 							AgillaLocation closestNode = findClosestAgent(qLoc);
! 							if (closestNode.dist(qLoc) < closestDist) {
! 								log("Detected a bad GetClosestAgent result:");
! 								log("\tQuerier location: " + qLoc);
! 								log("\tReported closest agent location: " + line.loc + " (" + closestDist + ")");
! 								log("\tEven closer agent at: (" + closestNode.getx() + ", " + closestNode.gety() + "), dist = " + closestNode.dist(qLoc));
! 								numBadQueries++;
! 								errorSum += closestDist - closestNode.dist(qLoc);
! 							} else {
! 								numGoodQueries++;								
! 							}
! 						} else {
! 							log(line.timeStamp + " GetClosestAgent returned (" + line.loc.getx() + ", " + 
! 									line.loc.gety() + ") at which there is no agent.");
! 							AgillaLocation closestAgent = findClosestAgent(qLoc);
! 							double error = Math.abs(qLoc.dist(line.loc) - qLoc.dist(closestAgent));
! 							log("\tError amount: " + error);
! 							numBadQueries++;
! 							errorSum += error;
! 						}
! 					} else
! 						numFailedQueries++;
! 				}
! 			}
  			
! 			if (line.action.equals("QUERY_GET_AGENTS_ISSUED")) {
! 				Integer qid = new Integer(line.qid);
! 				if (!getAgentsResultsTable.containsKey(qid)) {
! 					getAgentsResultsTable.put(qid, new GetAgentsResults(line.qid));
! 				}				
! 			}
  			
! 			if (line.action.equals("QUERY_GET_AGENTS_RESULT_RECEIVED_DATA")) {
! 				if (line.agentID == QUERIER_AGENT_ID) {
! 					TraceLineGetAgents currLine = (TraceLineGetAgents)line;
! 					Integer qid = new Integer(currLine.qid);
! 					
! 					// Create a GetAgentsResults object for storing the results
! 					// if one does not already exist.
! 					if (!getAgentsResultsTable.containsKey(qid)) {
! 						//getAgentsResultsTable.put(qid, new GetAgentsResults(currLine.qid));
! 						System.err.println("ERROR: Received GET_AGENTS data without first receiving an ISSUED command.");
! 						System.exit(1);
! 					}
! 					
! 					
! 					GetAgentsResults result = getAgentsResultsTable.get(qid);
! 					if (result != null) {
! 						int count = currLine.numAgents;
! 						if (count > MAX_AGENT_NUM)
! 							count = MAX_AGENT_NUM;
! 						for (int j = 0; j < count; j++) {
! 							AgillaAgentID aID = currLine.agentids.get(j);
! 							AgillaLocation loc = currLine.agentLocs.get(j);
! 							AgillaLocation actualLoc = agentLocTable.get(aID);
! 							if (actualLoc == null) {
! 								System.err.println("ERROR: could not get location of agent " + aID);
! 								System.exit(0);
! 							}
! 							result.add(new GetAgentsResultsEntry(aID, loc, actualLoc));
! 						}					
! 					} else
! 						log("ERROR: could not get GetAgentsResults message for qid = " + qid);
! 					
! 				}
! 			}				
  			
  		}
  		
! 		log("getAgentsResultsTable.size() = " + getAgentsResultsTable.size());
! 		// Analyze the results of the GetAgents Query
! 		for (Enumeration<GetAgentsResults> e = getAgentsResultsTable.elements(); e.hasMoreElements();) {
! 			GetAgentsResults result = e.nextElement();
! 			
! 			if (result.numResults() == 0)
! 				numFailedQueries++;
! 			else if (result.numResults() != NUM_INTRUDER_AGENTS || result.errorSum() != 0) {
! 				//System.out.println("result.numResults() = " + result.numResults());
! 				//System.out.println("NUM_INTRUDER_AGENTS = " + NUM_INTRUDER_AGENTS);
! 				//System.out.println("result.errorSum() = " + result.errorSum());
! 				numBadQueries++;
! 			} else
! 				numGoodQueries++;
! 			
! 			errorSum += result.errorSum();			
! 		}
  		
! 		System.out.println("\nQuery Statistics:  Good: " + numGoodQueries + ", Bad: " + numBadQueries + ", Failed: " + numFailedQueries);
! 		System.out.println("Total Number of Queries: " + (numGoodQueries + numBadQueries + numFailedQueries));
  		System.out.println("Number of Query Messages: " + numQueryMessages);
  		System.out.println("Number of Results Messages: " + numResultsMessages);
  		System.out.println("Number of Location Update Messages: " + numLocationUpdateMessages);
! 		System.out.println("Overall Average Error (hops): " + ((numGoodQueries+numBadQueries) == 0 ? 0 : errorSum/(numGoodQueries+numBadQueries)));
! 		System.out.println("Average Error (hops): " + (numBadQueries == 0 ? 0 : errorSum/numBadQueries));
  		//System.out.println("Number of Errors: " + numErrors);
  	}
--- 115,248 ----
  			if (line.action.equals("QUERY_GET_LOCATION_RESULTS_RECEIVED")) {
  				if (line.agentID == QUERIER_AGENT_ID) {
! 					if (line.success == NO_ANSWER) {									
! 						log(line.timeStamp + " Qid: " + line.qid + " Result contained FAIL");
! 						numNoAns++;
! 												
! 					} else if ((line.success & INVALID) > 0) {
! 						numDontKnow++;
! 					} else if ((line.success & VALID) > 0) {
  						AgillaLocation intruderLoc = agentLocTable.get(new AgillaAgentID(INTRUDER_AGENT_ID));
  						if (line.loc.equals(intruderLoc))
! 							numRcvdAccurate++;
  						else {
  							log(line.timeStamp +" Qid: " + line.qid + " Bad Result: (" + line.loc.getx() + ", " + line.loc.gety() + "), Reality: (" + intruderLoc.getx() + ", " + intruderLoc.gety()  + "), Dist: " + line.loc.dist(intruderLoc));
! 							numRcvdInaccurate++;
  							errorSum += line.loc.dist(intruderLoc);
  						}
! 						if ((line.success & COARSE) > 0) {
! 							numCoarse++;
! 						}
  					}
  				}
  			}
  			
! //			if (line.action.equals("QUERY_GET_CLOSEST_AGENT_RESULTS_RECEIVED")) {
! //				if (line.agentID == QUERIER_AGENT_ID) {	
! //					if (line.success == 1) {						
! //						AgillaLocation qLoc = agentLocTable.get(new AgillaAgentID(QUERIER_AGENT_ID));
! //						
! //						// Check to see whether there is an agent at the specified location
! //						if (agentLocTable.containsValue(line.loc)) {							
! //							double closestDist = qLoc.dist(line.loc);
! //							
! //							// See if there are any agents closer to the specified agent
! //							AgillaLocation closestNode = findClosestAgent(qLoc);
! //							if (closestNode.dist(qLoc) < closestDist) {
! //								log("Detected a bad GetClosestAgent result:");
! //								log("\tQuerier location: " + qLoc);
! //								log("\tReported closest agent location: " + line.loc + " (" + closestDist + ")");
! //								log("\tEven closer agent at: (" + closestNode.getx() + ", " + closestNode.gety() + "), dist = " + closestNode.dist(qLoc));
! //								numBadQueries++;
! //								errorSum += closestDist - closestNode.dist(qLoc);
! //							} else {
! //								numGoodQueries++;								
! //							}
! //						} else {
! //							log(line.timeStamp + " GetClosestAgent returned (" + line.loc.getx() + ", " + 
! //									line.loc.gety() + ") at which there is no agent.");
! //							AgillaLocation closestAgent = findClosestAgent(qLoc);
! //							double error = Math.abs(qLoc.dist(line.loc) - qLoc.dist(closestAgent));
! //							log("\tError amount: " + error);
! //							numBadQueries++;
! //							errorSum += error;
! //						}
! //					} else
! //						numFailedQueries++;
! //				}
! //			}
  			
! //			if (line.action.equals("QUERY_GET_AGENTS_ISSUED")) {
! //				Integer qid = new Integer(line.qid);
! //				if (!getAgentsResultsTable.containsKey(qid)) {
! //					getAgentsResultsTable.put(qid, new GetAgentsResults(line.qid));
! //				}				
! //			}
  			
! //			if (line.action.equals("QUERY_GET_AGENTS_RESULT_RECEIVED_DATA")) {
! //				if (line.agentID == QUERIER_AGENT_ID) {
! //					TraceLineGetAgents currLine = (TraceLineGetAgents)line;
! //					Integer qid = new Integer(currLine.qid);
! //					
! //					// Create a GetAgentsResults object for storing the results
! //					// if one does not already exist.
! //					if (!getAgentsResultsTable.containsKey(qid)) {
! //						//getAgentsResultsTable.put(qid, new GetAgentsResults(currLine.qid));
! //						System.err.println("ERROR: Received GET_AGENTS data without first receiving an ISSUED command.");
! //						System.exit(1);
! //					}
! //					
! //					
! //					GetAgentsResults result = getAgentsResultsTable.get(qid);
! //					if (result != null) {
! //						int count = currLine.numAgents;
! //						if (count > MAX_AGENT_NUM)
! //							count = MAX_AGENT_NUM;
! //						for (int j = 0; j < count; j++) {
! //							AgillaAgentID aID = currLine.agentids.get(j);
! //							AgillaLocation loc = currLine.agentLocs.get(j);
! //							AgillaLocation actualLoc = agentLocTable.get(aID);
! //							if (actualLoc == null) {
! //								System.err.println("ERROR: could not get location of agent " + aID);
! //								System.exit(0);
! //							}
! //							result.add(new GetAgentsResultsEntry(aID, loc, actualLoc));
! //						}					
! //					} else
! //						log("ERROR: could not get GetAgentsResults message for qid = " + qid);
! //					
! //				}
! //			}				
  			
  		}
  		
! //		log("getAgentsResultsTable.size() = " + getAgentsResultsTable.size());
! //		// Analyze the results of the GetAgents Query
! //		for (Enumeration<GetAgentsResults> e = getAgentsResultsTable.elements(); e.hasMoreElements();) {
! //			GetAgentsResults result = e.nextElement();
! //			
! //			if (result.numResults() == 0)
! //				numFailedQueries++;
! //			else if (result.numResults() != NUM_INTRUDER_AGENTS || result.errorSum() != 0) {
! //				//System.out.println("result.numResults() = " + result.numResults());
! //				//System.out.println("NUM_INTRUDER_AGENTS = " + NUM_INTRUDER_AGENTS);
! //				//System.out.println("result.errorSum() = " + result.errorSum());
! //				numBadQueries++;
! //			} else
! //				numGoodQueries++;
! //			
! //			errorSum += result.errorSum();			
! //		}
  		
! //		System.out.println("\nQuery Statistics:  Good: " + numGoodQueries + ", Bad: " + numBadQueries + ", Failed: " + numFailedQueries);
! //		System.out.println("Total Number of Queries: " + (numGoodQueries + numBadQueries + numFailedQueries));
! 		System.out.println("\nQuery Statistics:  Accurate: " + numRcvdAccurate+ ", Inaccurate: " + numRcvdInaccurate 
! 				+ ", Unknown: " + numDontKnow + ", Timeout: " + numNoAns);
  		System.out.println("Number of Query Messages: " + numQueryMessages);
  		System.out.println("Number of Results Messages: " + numResultsMessages);
  		System.out.println("Number of Location Update Messages: " + numLocationUpdateMessages);
! 		System.out.println("Average Error: " + (numRcvdInaccurate == 0 ? 0 : errorSum/numRcvdInaccurate));
! 		System.out.println("Number of Coarse Results: " + numCoarse);
! //		System.out.println("Overall Average Error (hops): " + ((numGoodQueries+numBadQueries) == 0 ? 0 : errorSum/(numGoodQueries+numBadQueries)));
! //		System.out.println("Average Error (hops): " + (numBadQueries == 0 ? 0 : errorSum/numBadQueries));
  		//System.out.println("Number of Errors: " + numErrors);
  	}
***************
*** 304,308 ****
  		int agentID, nodeID, qid;
  		String action; 
! 		boolean success;
  		AgillaLocation loc;
  		
--- 324,328 ----
  		int agentID, nodeID, qid;
  		String action; 
! 		int success;
  		AgillaLocation loc;
  		
***************
*** 338,342 ****
  			sIndex = eIndex;
  			eIndex = line.indexOf(" ", sIndex+1);
! 			success = (Integer.valueOf(line.substring(sIndex+1, eIndex)) == 1);
  			//log("success = " + success);
  			
--- 358,362 ----
  			sIndex = eIndex;
  			eIndex = line.indexOf(" ", sIndex+1);
! 			success = Integer.valueOf(line.substring(sIndex+1, eIndex));
  			//log("success = " + success);
  			
***************
*** 364,368 ****
  		public String toString() {
  			return "TRACE: " + agentID + " " + nodeID + " " + timeStamp + " " +  
! 				action + " " + qid + " " + (success ? "SUCCESS" : "FAIL") + " " + 
  				loc.getx() + " " + loc.gety();
  		}
--- 384,388 ----
  		public String toString() {
  			return "TRACE: " + agentID + " " + nodeID + " " + timeStamp + " " +  
! 				action + " " + qid + " " + success + " " + 
  				loc.getx() + " " + loc.gety();
  		}



More information about the Tinyos-contrib-commits mailing list