Results 1 to 3 of 3
  1. #1
    Miss is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default The One Simulator

    I am using The One Simulator to run some cars in the environment. After some time period the cars send beacons in the environment and the access points (stationary points on the map) receive the beacons and make logs for the statistics part. This is part of my project.

    I have realized that the simulator becomes very slow with time. I have tried to improve on the code, like using hashmap and better data structures but nothing seems to be good enough :(

    Can someone please help me out ?
    Please let me know if anyone wants me to provide more information about it .....

    Thanks ^_^

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: The One Simulator

    Please let me know if anyone wants me to provide more information about it .....
    I might be the only one, but I do not know what 'The One Simulator' is, what you mean by cars, beacons, environment, access points, etc...as this is a java forum, do you have a java specific question?

  3. #3
    Miss is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: The One Simulator

    Thanks for getting back with me. I have a set of functions that is called multiple times and at regular intervals. These functions are slowing down my simulation. Could you help me improve the code ?
    The following code is called like 100 to 200 times. It starts off finishing faster but with time the computations sow down the system ... I have just written the important part of the code right now so its easy to read .. lemme know if I should post something else as well....

    Java Code:
    // A new entry
    
    			mapList = new ArrayList<Object>();
    			
    			mapList.add(toNode);
    			mapList.add(time);
    			mapList.add(time);
    			
    			map.put(fromNode, mapList);
    
    // Existing entry
    				getAPFromDTNHostUrbanProject(prevToNode).updateTime(endTime-startTime); // one line code
    				getAPFromDTNHostUrbanProject(prevToNode).updateCarCount(); // one line code
    				getAPFromDTNHostUrbanProject(prevToNode).updateAverage(); // one line division computation
    				getAPFromDTNHostUrbanProject(prevToNode).updateAPList(toNode); // function 1 below
    				
    				// Calculate the new norms
    				newAvgNorm = getAverageNorm(); // function 2 below
    				newFreqNorm = getFrequencyNorm(); // function 3 below
    
    				averageNormList.add(newAvgNorm);
    				frequencyNormList.add(newFreqNorm);
    				
    				if((diff(oldAvgNorm, newAvgNorm)!=0 && diff(oldAvgNorm, newAvgNorm) < thresholdForAverage) && 
    						(diff(oldFreqNorm, newFreqNorm)!=0 && diff(oldFreqNorm, newFreqNorm) < thresholdForFrequency))
    				{
    					simStop = true;
    				}
    			
    				// update old Norms
    				oldAvgNorm = newAvgNorm;
    				oldFreqNorm = newFreqNorm;
    				
    				// update the toNode, startTime and endTime
    				mapList.set(toNodeIndex, toNode);
    				mapList.set(startTimeIndex, time);
    				mapList.set(endTimeIndex, time);
    		
                      	// update the new mapList in the hashMap
    			map.remove(fromNode);
    			map.put(fromNode, mapList);
    
    //function 1
    public void updateAPList(DTNHostUrbanProject newAP) 
    	{
    		ArrayList values = new ArrayList();
    		if(freqMap.containsKey(newAP))
    		{
    			values = (ArrayList)freqMap.get(newAP);
    			
    			int oldCarCount = (Integer)values.get(CountOfCarsIndex);
    			int newCarCount = oldCarCount + 1;
    			
    			double newFreq = newCarCount/(double)totalCarsPassed;
    			
    			values.set(CountOfCarsIndex, newCarCount);
    			values.set(frequencyForAPIndex, newFreq);
    			
    			freqMap.remove(newAP);
    		}
    		else
    		{
    			values.add(1);
    			values.add(1/(double)totalCarsPassed);
    			
    			// Add the AP in the Inflow of the newAP
    			newAP.AddToInflowList(this.getNode());
    		}
    		freqMap.put(newAP, values);
    	}
    	
    //function 2
    private double getAverageNorm()
    	{
    		finalAns = 0.0;
    		Iterator it = listOfAP.entrySet().iterator();
    		while(it.hasNext())
    		{
    			Map.Entry<DTNHostUrbanProject, AP> mapEntry = (Map.Entry<DTNHostUrbanProject, AP>) it.next();
    			AP ap = mapEntry.getValue();
    			ans = ap.getAverage();
    			finalAns = finalAns + (ans*ans);
    		}
    		return Math.sqrt(finalAns);
    	}
    	
    //function 3
    private double getFrequencyNorm()
    	{
    		finalAns = 0.0;
    		Iterator listOfAPIterator = listOfAP.entrySet().iterator();
    		while(listOfAPIterator.hasNext())
    		{
    			Map.Entry<Object, Object> APmapEntry = (Map.Entry<Object, Object>)listOfAPIterator.next();
    			AP ap = (AP)APmapEntry.getValue();
    			
    			ans = 0.0;
    			freqMap = ap.getFrequencyMap();
    			Iterator freqMapIterator = freqMap.entrySet().iterator();
    			while(freqMapIterator.hasNext())
    			{
    				Map.Entry<Object, Object> freqmapEntry = (Map.Entry<Object, Object>)freqMapIterator.next();
    				values = (ArrayList)freqmapEntry.getValue();
    				if(values.size()==0)
    				{
    					ans = ans + 0;
    				}
    				else
    				{
    					freq = (Double)values.get(freqIndex);
    					ans = ans + (freq*freq);
    				}
    			}
    			finalAns = finalAns + ans;
    		}
    		return Math.sqrt(finalAns);
    	}
    Last edited by Miss; 11-27-2012 at 08:50 PM.

Similar Threads

  1. The ONE Simulator
    By TacoZ in forum New To Java
    Replies: 4
    Last Post: 02-15-2012, 06:05 AM
  2. Ant Colony Simulator
    By KevinWorkman in forum Reviews / Advertising
    Replies: 3
    Last Post: 12-14-2011, 08:19 PM
  3. I need help with a gravity simulator!
    By Karly_Kute_X in forum New To Java
    Replies: 5
    Last Post: 12-10-2011, 06:40 PM
  4. Building a HSM Simulator
    By stunnaz101 in forum Advanced Java
    Replies: 0
    Last Post: 03-23-2010, 10:01 AM
  5. Traffic simulator
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 03-12-2008, 03:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •