}
Constant c= new Constant();
System.out.println("dimensione heap:"+Runtime.getRuntime().freeMemory()/(1024*1024)+" MB\n ");
HashMap<Float, ArrayList<Vehicle>> time_map = null;
HashMap<String, TreeMap<Float, Vehicle>> all_vehicles = null;
PacketDiscarding discarding=null;
int i;
for(i=1;i<=max;i++){
time_map = new HashMap<Float, ArrayList<Vehicle>>();
all_vehicles = new HashMap<String, TreeMap<Float, Vehicle>>();
/**============= Parsing of input file ====================================**/
System.out.println(" Start parsing file: "+i+"dimensione heap:"+Runtime.getRuntime().freeMemory()/(1024*1024)+" MB\n ");
JAXBElement<VtypeprobesType> elem_v = null;
ParseXML parser=new ParseXML(c,i,piccolo,time_map,all_vehicles,keymapHashMap);
elem_v=null;
System.out.println(" end parsing file: "+i);
c.printMemory();
parser=null;
System.gc();
Runtime.getRuntime().gc();
Runtime.getRuntime().gc();
System.out.println(" gc after parsing file: "+i);
c.printMemory();
/**============= sending and receiving packets simulation =================**/
Simulation2 sim=new Simulation2(time_map,all_vehicles,c); //passo mappe
System.out.println("New Simulation dimensione heap:");
c.printMemory();
sim.simulationSent(); //simulazione invio-ricezione
System.out.println("Sim Sent dimensione heap:");
c.printMemory();
/**============= discarding strategy =======================================**/
/**random -->*/ //discarding=new random("Random",this.c.getRatio());
/**distance based -->*/ discarding=new distanceBased("Distance based",c.getRange(),c.getRange_ratio());
System.out.println("New Discarding dimensione heap:");
c.printMemory();
List<Float> list=new ArrayList<Float>(); //per scorrere i tempi in modo ordinato
list.addAll(time_map.keySet());
Collections.sort(list);
stat=new Statistics(c, old_stat);
System.out.println("NEW statistic dimensione heap:");
c.printMemory();
stat.setTotTime(list.size());
stat.setAllVehicles(all_vehicles);
stat.setTecnicaScarto(discarding.getNameStrategy());
int countVehicles=0;
for(Float iter:list){ //tempi
int countLogged=0;
int countDiscarded=0;
for(Vehicle v:time_map.get(iter)){ //veicoli
countVehicles++;
discarding.discard(v); //scarto
countLogged=countLogged+v.getNumLoggedPacket();
countDiscarded=countDiscarded+v.getNumDiscardedPacket();
}//fine veicoli
/**============= statistics =======================================**/
stat.Packets(iter, countLogged, countDiscarded,time_map.get(iter));
stat.NumLog_SamePacket(time_map.get(iter), iter);
stat.VehicleThatReceived(time_map.get(iter), iter);
old_stat=stat.getResult();
}//fine tempi
System.out.println("count ogg veicoli...............:"+countVehicles);
stat.setTotOggVehicles(countVehicles);
stat.Logged_from_a_Vehicle(); //salva solo info in una mappa, non serve per calcolo medie
stat.ConsecutiveDiscarded(); //pacchetti scartati consecutivamente
stat.TotLogged_discarded(discarding.getNumTotLogged(), discarding.getNumTotDiscarded(),discarding.getNumTotPacket());
System.out.println(" PRima free memoria allocata: ");
c.printMemory();
/**================== free =================**/
old_stat=stat.getResult();
sim.svuota();
discarding.svuota();
// svuota(time_map,all_vehicles);
time_map=null;
all_vehicles=null;
System.gc();//suggerisce esecuzione garbage collector
}