Changeset 38


Ignore:
Timestamp:
Dec 27, 2009, 10:04:45 AM (14 years ago)
Author:
(none)
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • proiecte/ptvs/src/vnsim/core/Engine.java

    r31 r38  
    2323import vnsim.applications.ezcab.EzcabClient;
    2424import vnsim.applications.trafficview.SimulatedCarInfo;
    25 import vnsim.applications.vitp.CarRunningVITP;
    26 import vnsim.applications.vitp.predefinedqueries.PredefinedQueries;
    27 import vnsim.applications.vitp.predefinedqueries.QueryByLocation;
    28 import vnsim.applications.vitp.predefinedqueries.QueryByVehicleId;
    2925import vnsim.core.events.CleanupEvent;
    3026import vnsim.core.events.Event;
     
    106102        DataInputStream dis = null;
    107103
    108         public int fps;
    109 
    110         ArrayList<Event> eventQueue = null;
     104        public static int fps;
     105
     106        static ArrayList<Event> eventQueue = null;
     107       
     108        /**
     109         * Mihaela Teler
     110         * de fiecare data cand vreau sa fac o adaugare in eventQueue, intai verific punctul de unde vine evenimentul si astfel asignez
     111         * un thread pt procesarea ulterioara a acelui eveniment(cand va fi scos din coada..)
     112         * folosesc un singur eventQueue dar modific clasa Event sa contina si o referinta la un Thread
     113         */
     114       
    111115
    112116        //Petroaca - the DSRC emergency channel
     
    115119        public boolean pauseFlag = true;
    116120
    117         boolean doneFlag = false,doneFlagEmergency=false;
    118 
    119         public ArrayList<SimulatedCarInfo> cars = null;
    120 
    121         public int crtTime = 0;
     121        static boolean doneFlag = false;
     122
     123        boolean doneFlagEmergency=false;
     124
     125        public static ArrayList<SimulatedCarInfo> cars = null;
     126
     127        public static int crtTime = 0;
    122128
    123129        public long t0 = 0L;
     
    127133        boolean runtimeMobility;
    128134
    129         public boolean disableComm = false;
     135        public static boolean disableComm = false;
    130136
    131137        File fText = null, fBin = null;
     
    138144        double lastSimSecond = 0.0;
    139145       
    140         int eventsTime = 0, mobilityTime = 0, cleanupTime = 0, netTime = 0, codeTime = 0;
    141         int schedTime = 0,  moveTime = 0, semTime = 0;
     146        int eventsTime = 0, mobilityTime = 0;//, netTime = 0, codeTime = 0;
     147
     148        static int cleanupTime = 0;
     149        static int netTime = 0;
     150        static int codeTime = 0;
     151        static int schedTime = 0;
     152
     153        int moveTime = 0;
     154
     155        static int semTime = 0;
    142156
    143157        public double maxControlDelay = 0;
     
    194208        public void init() {
    195209
    196 //              try{
    197 //                      File f=new File(".//maps//map//apaca.map");
    198 //                      if(!f.exists()) {
    199 //                              System.out.println("NOT EXIST!");
    200 //                              Globals.map = new trafficview.object.Map(".//maps\\rt\\apaca.RT1",".\\maps\\rt\\apaca.RT2");
    201 //                             
    202 ////                            Globals.map = new trafficview.object.Map(".\\maps\\rt\\Intersectie.RT1","Intersectie.RT2");
    203 //                              // Globals.map = new trafficview.object.Map("Autostrada.RT1","Autostrada.RT2");
    204 //                             
    205 ////                            Globals.map = new trafficview.object.Map("TGR34023_2.RT1","TGR34023_2.RT2");
    206 //                              ObjectOutputStream oos=new ObjectOutputStream(new
    207 //                                              FileOutputStream(".\\maps\\map\\apaca.map"));
    208 //                              oos.writeObject(Globals.map);
    209 //                      } else {
    210 //                              System.out.println("EXIST!");
    211 //                              ObjectInputStream ois=new ObjectInputStream(new
    212 //                                              FileInputStream(".\\maps\\map\\apaca.map"));
    213 //                              Globals.map=(trafficview.object.Map)ois.readObject();
    214 //                      }
    215 //              }catch(Exception e){
    216 //                      System.err.println("Error reading map;");
    217 //                      e.printStackTrace();
    218 //                      System.exit(0);
    219 //              }
    220 //               MapLoader.loadMap();
    221                
    222 
    223210                Map map = Globals.map;
     211               
     212                //System.out.println("roads.size: "+map.roads.size()+" : "+map.roads.get(0).getName());
     213               
     214                //Road road = (Road)map.roads.get(0);
     215               
     216                //System.out.println("road.points: "+road.points);
     217               
     218                //System.out.println("strada:"+road.getName()+":"+" road.crosses.size(): "+road.crosses.size());
     219               
     220                       
     221                ArrayList<Intersection> intersectii = map.allIntersections;
     222                for(int q=0;q<intersectii.size();q++){
     223                        System.out.println("intersectia "+q+": "+" nume: "+intersectii.get(q).toString()+" "+intersectii.get(q).getMapPoint());
     224                }
     225               
     226                System.out.println(".........................aici4.........");
     227               
     228                //***************************************************************
     229               
    224230                if (map.roads.get(0).getName().startsWith("Iuliu") || map.roads.get(0).getName().startsWith("Dr"))
    225231                {
    226        
     232                       
    227233                        Globals.monitorWTL = (WirelessTrafficLight)map.allIntersections.get(1);
    228234                }
     
    271277                // init cars and events
    272278                eventQueue = new ArrayList<Event>();
    273        
     279               
     280               
    274281                cars = new ArrayList<SimulatedCarInfo>();
    275282               
     
    277284
    278285                //Petroaca - if DSRC simulation then initialize the emergency event queue
    279                 if(this.simulationProtocol==Globals.PROTOCOL_DSRC)
     286                if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC)
    280287                        eventQueueEmergency = new ArrayList<Event>();
    281288               
     
    290297                }
    291298
    292                 synchronized (eventQueue)
    293                 {
    294                         eventQueue.add(new GPSEvent(0));
    295                        
    296                         eventQueue.add(new CleanupEvent(1));
    297                         Iterator<SimulatedCarInfo> it = cars.iterator();
    298                         while (it.hasNext())
    299                         {
    300                                 SimulatedCarInfo r = it.next();
    301                                 int t = 4 + random.nextInt(Globals.executionFPS / 3);
    302                                 schedEvent(new SendEvent(4, r,
    303                                                 SimulatedCarInfo.STANDARD_MESSAGE_ID));
    304                         }
    305                        
    306                         /* Szekeres A. START_MODIFY - add broadcast event for each traffic light*/
    307                         for(int i=0;i<Globals.map.allIntersections.size();i++) {
    308                                 Intersection sender = Globals.map.allIntersections.get(i);
    309                                 if (sender instanceof EmissionsTrafficLight)
     299                /**
     300                 * Mihaela Teler
     301                 * inainte sa adaug evenimentul aflu pozitia de unde vine..
     302                 */
     303                synchronized (eventQueue) {
     304                       
     305                                // exceptie pt evenimentele GPS si Cleanup.. pe acestea le proceseaza threadul main
     306                                eventQueue.add(new GPSEvent(0));
     307                                                               
     308                                eventQueue.add(new CleanupEvent(1));
     309                               
     310                                Iterator<SimulatedCarInfo> it = cars.iterator();
     311                                while (it.hasNext())
    310312                                {
    311                                         ((EmissionsTrafficLight)sender).init();
    312                                         schedEvent(new SendEvent(4, (EmissionsTrafficLight)sender, (int)Globals.PROT_TL_FEEDBACK));
    313                                 }
    314                         }                       
    315                         /* Szekeres A. STOP_MODIFY */
    316                        
    317                 }
    318 
     313                                        System.out.println("nu ai cum sa intri pe aici!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! cars este vida");
     314                                        SimulatedCarInfo r = it.next();
     315                                        schedEvent(new SendEvent(4, r, SimulatedCarInfo.STANDARD_MESSAGE_ID));
     316                                        System.out.println("add in the queue..");
     317                                }
     318                               
     319                                /* Szekeres A. START_MODIFY - add broadcast event for each traffic light*/
     320                                for(int i=0;i<Globals.map.allIntersections.size();i++) {
     321                                        Intersection sender = Globals.map.allIntersections.get(i);
     322                                        if (sender instanceof EmissionsTrafficLight)
     323                                        {
     324                                                ((EmissionsTrafficLight)sender).init();
     325                                                schedEvent(new SendEvent(4, (EmissionsTrafficLight)sender, (int)Globals.PROT_TL_FEEDBACK));
     326                                        }
     327                                }                       
     328                                /* Szekeres A. STOP_MODIFY */
     329                }
     330               
     331               
    319332                try
    320333                {
     
    341354                }
    342355
    343                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
     356                if (Engine.simulationType == RoutingConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
    344357                        DelayRecord.initDelays();
    345358                        this.infrastructure=new ArrayList<SimulatedCarInfo>();
     
    347360                        InfrastructureNode.createInfrastructureNodes();
    348361                }
    349                 /*if (Engine.simulationType == RoutingConstants.DYNAMIC_CITY_ROUTE) {
    350                         RoadSegmentCost.initRoadSegmentsCost();
    351                         this.infrastructure=new ArrayList<SimulatedCarInfo>();
    352                         //create a fixed node for every intersection
    353                         IntersectionNode.createIntersectionNodes();
    354                 }*/
    355362
    356363                //Petroaca - instantiate the ricean propagation module
     
    358365                {
    359366                  if(Engine.propagationModel==Globals.RICEAN)
    360                         this.riceanModule=new Ricean(Globals.RICEAN_FILE_NAME,true);
     367                        Engine.riceanModule=new Ricean(Globals.RICEAN_FILE_NAME,true);
    361368                }
    362369                catch(IOException ioe){System.out.println("Ricean file io error:"+ioe.getMessage());System.exit(1);}
    363                 // System.out.println("Engine initialized - "+eventQueue.size()+"
    364                 // events");
    365                 // System.out.println("CARS:");
    366                 // System.out.println(cars);
    367                 // System.out.println("Events:");
    368                 // System.out.println(eventQueue);
    369                
    370 //              Road r = Globals.map.roads.get(5);
    371 //              Point p = r.points.get(10900);
    372 //              int i = 10899;
    373 //              while (true){
    374 //                      Point px = r.points.get(i);
    375 //                      i--;
    376 //                      if (p.getDistance() - px.getDistance() > 10)
    377 //                              break;
    378 //              }
    379 //              System.out.println(i + " " +(p.getDistance() - r.points.get(i).getDistance()));
     370               
     371                System.out.println(">>> Engine initialized - "+eventQueue.size()+" events in the queue");
     372                System.out.println("CARS:"+cars);
     373                System.out.println("Events:"+eventQueue);
     374                 
     375               
     376                System.out.println();
     377               
     378                Road r = Globals.map.roads.get(1);
     379                System.out.print("road:"+r.getName());
     380                System.out.println("  r.points.size():"+r.points.size());
     381               
     382                Point p1 = r.points.get(r.points.size()-1);
     383                System.out.println(p1);
     384                Point p2 = r.points.get(r.points.size()-2);
     385                System.out.println(p2);
     386               
     387                System.out.println("distanta: " +(p1.getDistance() - p2.getDistance()));
     388                System.out.println("distanta: " +GPSutil.distance(p1, p2));
     389                System.out.println("__________________end init____________________________\n");
     390                               
    380391
    381392        }
     
    390401
    391402                //Petroaca - if DSRC simulation also reset the emergency channel
    392                 if(this.simulationProtocol==Globals.PROTOCOL_DSRC)
     403                if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC)
    393404                        eventQueueEmergency = new ArrayList<Event>();
    394405               
     
    413424                                while (it.hasNext()) {
    414425                                        SimulatedCarInfo r = it.next();
    415                                         schedEvent(new SendEvent(crtTime + 2, r,
    416                                                         SimulatedCarInfo.STANDARD_MESSAGE_ID));
     426                                        schedEvent(new SendEvent(crtTime + 2, r, SimulatedCarInfo.STANDARD_MESSAGE_ID));
    417427                                }
    418428                        }
     
    420430               
    421431//              Petroaca - if DSRC simulation also reset the emergency channel
    422                 if(this.simulationProtocol==Globals.PROTOCOL_DSRC)
     432                if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC)
    423433                        eventQueueEmergency = new ArrayList<Event>();
    424434        }
     
    428438         *
    429439         */
    430         public void play()
    431         {
     440        public void play() {
    432441                // supposed to be in the init()
    433442                // between init and play() Globals.map.allIntersections is changing
    434443                // need to find a fix
     444               
    435445                if (Engine.simulationType == RoutingConstants.DYNAMIC_CITY_ROUTE) {
    436446                        CityTrafficLight.upgradeToCityTL();
     
    441451                        server.init();
    442452                }
    443                 //
     453               
    444454                prevRealSec = t0 = System.currentTimeMillis();
    445455                pauseFlag = false;
     
    480490        long lastTime = -1;
    481491       
     492        ////////////////////////////////////// step ///////////////////////////////////////////////////////////
    482493        /**
    483494         * Process the events for the current step of the simulation
    484495         *
    485496         */
     497       
     498        static int cnt = 0;
     499       
    486500        public void step() {
    487                 int cnt = 0;
     501               
    488502               
    489503                if(Globals.SOCIALNETWORK == 1){
    490504                        double sec = vnsim.socialNet.GlobalNetwork.nextReconfigurationTime*Globals.SECOND;
    491 //                      if(crtTime == sec){
    492 //                              int ret=JOptionPane.showConfirmDialog(null, "au trecut "+sec+" secunde");
    493 //                              //vnsim.vehicular.generator.Mobility.events = new SortedEventsVector();
    494 //                              Scenario s = vnsim.socialNet.Main.recofigurare();
    495 //                              try {
    496 //                                      vnsim.socialNet.Main.addCarEvents(s,crtTime);
    497 //                              } catch (Exception ex) {
    498 //                                      JOptionPane.showMessageDialog(null, "<html>ERROR! Map structure has been modified<br> Try rebuilding the map " + s.mapFileName +"!</html>");
    499 //                              }
    500 //                      }
    501                 }
    502                
    503                 if (crtTime >  3.5 * Globals.HOUR){
     505                }
     506                       
     507                if (crtTime >  3.5 * Globals.HOUR){     //nu rulez mai mult de 3 ore juma
    504508                        doneFlag = true;
    505509                        System.exit(0);
     
    533537               
    534538                if (crtTime % Globals.MINUTE == 0){
    535                         System.out.println((crtTime / Globals.MINUTE) + " sim min;\t" +
    536                         "packets: "+ Globals.packets +"\t" +
    537                         " collided: "+Globals.collided +
    538                         " lost: " + Globals.lost+
    539                         " interfered: " + Globals.interfered+
    540                         " max range: " + Globals.maxRange);
    541                        
    542                         Globals.pw.println((crtTime / Globals.MINUTE) + " sim min;\t" +
    543                                         "packets: "+ Globals.packets +"\t" +
    544                                         " collided: "+Globals.collided +
    545                                         " lost: " + Globals.lost+
    546                                         " interfered: " + Globals.interfered+
    547                                         " max range: " + Globals.maxRange);
     539
    548540                        Globals.packets = 0;
    549541                        Globals.collided = 0;
    550542                        Globals.lost = 0;
    551543                       
    552 //                      System.out.println((crtTime / Globals.MINUTE) + " sim min;\t" +
    553 //                                      "simulation time: "+ (System.currentTimeMillis() - t0) +"\t" +
    554 //                                      " cars: "+cars.size() +
    555 //                                      " created " + created);
    556                         Globals.pw.println((crtTime / Globals.MINUTE) +
    557                                         " global volume: " + Globals.volume * 60+
    558                                         " global demand: " + Globals.demand * 60);
     544                        System.out.println((crtTime / Globals.MINUTE) + " sim min;\t" +
     545                                        "simulation time: "+ (System.currentTimeMillis() - t0) +"\t" +
     546                                        " cars: "+cars.size() + " created " + created);
     547
    559548                        Globals.volume = 0;
    560549                        Globals.demand = 0;
    561550                       
    562551                        //Petroaca
    563                         if(this.simulationProtocol==Globals.PROTOCOL_DSRC)
     552                        if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC)
    564553                        {
    565                                 /*System.out.print("\n");
    566                                 System.out.println("DSRC DATA------------------------------");
    567                                 System.out.println((crtTime / Globals.MINUTE)+ " min\t" + "weak :"+Globals.DSRC_PACKETS_LOST_WEAK+
    568                                                 " collided :"+Globals.DSRC_PACKETS_LOST_COLLISION+" ok: "+Globals.DSRC_PACKETS_RECEIVED_OK+
    569                                                 " lost Tx :"+Globals.DSRC_PACKETS_LOST_TX+" lost Rx :"+Globals.DSRC_PACKETS_LOST_RX+
    570                                                 "lost per :"+Globals.DSRC_PACKETS_LOST_PER+" lost corrupted :"+Globals.DSRC_PACKETS_LOST_CORRUPTED
    571                                                 +" total packets: "+Globals.DSRC_PACKETS_TOTAL);
    572                                 System.out.println("send faliure Rx:"+Globals.DSRC_PACKETS_SEND_FALIURE_RX+" send faliure noise:"+Globals.DSRC_PACKETS_SEND_FALIURE_NOISE
    573                                                 );
    574                                 */
    575554                                DSRCStatistics.addStatistic(new DSRCStatisticComponent(0,Globals.DSRC_PACKETS_LOST_WEAK,Globals.DSRC_PACKETS_TOTAL,Globals.DSRC_PACKETS_LOST_CORRUPTED,Globals.DSRC_PACKETS_LOST_COLLISION,Globals.DSRC_PACKETS_LOST_TX,Globals.DSRC_PACKETS_LOST_RX,Globals.DSRC_PACKETS_LOST_PER,Globals.DSRC_PACKETS_RECEIVED_OK
    576555                                                ,0,0,Globals.CUMMULATIVE_PACKETS_FV,Globals.CUMMULATIVE_PACKETS_NFV,Globals.CUMMULATIVE_PACKETS_LAV,Globals.CUMMULATIVE_PACKETS_RAV,Globals.IRT_FV,Globals.IRT_NFV,Globals.IRT_LAV,Globals.IRT_RAV,0,0,0,0,this.cars.size(),Globals.EMERGENCY_RECEIVED,Globals.EMERGENCY_SENT));
     
    589568                                Globals.DSRC_SEND=0;
    590569                               
    591                                 System.out.println((crtTime / Globals.MINUTE)+ " min\t"+"FV:"+Globals.CUMMULATIVE_PACKETS_FV+" NFV:"+Globals.CUMMULATIVE_PACKETS_NFV+" LAV:"+Globals.CUMMULATIVE_PACKETS_LAV+" RAV:"+Globals.CUMMULATIVE_PACKETS_RAV+" EMERGENCY_RECV:"+Globals.EMERGENCY_RECEIVED+" EMERGENCY_SENT:"+Globals.EMERGENCY_SENT);
     570                                //System.out.println((crtTime / Globals.MINUTE)+ " min\t"+"FV:"+Globals.CUMMULATIVE_PACKETS_FV+" NFV:"+Globals.CUMMULATIVE_PACKETS_NFV+" LAV:"+Globals.CUMMULATIVE_PACKETS_LAV+" RAV:"+Globals.CUMMULATIVE_PACKETS_RAV+" EMERGENCY_RECV:"+Globals.EMERGENCY_RECEIVED+" EMERGENCY_SENT:"+Globals.EMERGENCY_SENT);
    592571                               
    593572                                Globals.CUMMULATIVE_PACKETS_RAV=0;
     
    608587                        if (lastTime == -1)
    609588                                lastTime = t0;
    610                         long realTime = t1 - lastTime;
    611589                        lastTime = t1;
    612 //                      Globals.pw.println("\n-----");
    613 //                      Globals.pw.println("5 virtual minutes = " + (double)realTime/1000);
    614 //                      Globals.pw.println("density [veh/km] = " + (double) cars.size()/10);
    615 //                      Globals.pw.println("events: " + (double) (100 * (eventsTime - codeTime - cleanupTime))
    616 //                                      / realTime);
    617 //                      Globals.pw.println("mobility: " + (double) (100 * mobilityTime)
    618 //                                      / realTime);
    619 //                      Globals.pw.println("code: " + (double) (100 * codeTime + cleanupTime) / realTime);
    620 //                      Globals.pw.println("-----");
    621590
    622591                        eventsTime = 0;
     
    625594                        mobilityTime = 0;
    626595                       
    627                         Globals.pw.println( "\n" + (crtTime / Globals.MINUTE) + " " +
    628                                         " " + fincars +
    629                                         " "+ (totalControlDelay/fincars) +
    630                                         " "+ (maxControlDelay) +
    631                                         " "+ ( ( totalEM.fc * 100) / (1000 * totalkm)) +
    632                                         " "+ (totalEM.fc / fincars) +
    633                                         " "+ (totalEM.co2 / fincars) +
    634                                         " "+ (totalEM.co / fincars) +
    635                                         " "+ (totalEM.hc / fincars) +
    636                                         " "+ (totalEM.nox / fincars)
    637                                         );
    638596                        Globals.pw.flush();
    639597                       
     
    647605                        Globals.demo.st.addInfo("NOx: " + dec1((totalEM.nox * 20 )/ 1000)+" kg/h");
    648606                       
    649                        
    650 
    651                         Globals.pwxc.println( (crtTime / Globals.MINUTE) + " " +
    652                                         " " + fincars +
    653                                         " "+ (totalControlDelay/fincars) +
    654                                         " "+ (maxControlDelay) +
    655                                         " "+ ( (totalEM.fc * 100) / ( 1000 * totalkm)) +
    656                                         " "+ (totalEM.fc / crossedCars) +
    657                                         " "+ (totalEM.co2 / crossedCars) +
    658                                         " "+ (totalEM.co / crossedCars) +
    659                                         " "+ (totalEM.hc / crossedCars) +
    660                                         " "+ (totalEM.nox / crossedCars) +
    661                                         " "+ crossedCars
    662                                         );
    663                         Globals.pwxc.flush();
     607
    664608                        if (fincars>0) {
    665609                                Globals.pwxc.println( "min " + (crtTime / Globals.MINUTE) +
     
    677621                                Globals.pwxc.flush();
    678622                        }
    679                         //fincars = 0;
    680                         //crossedCars = 0;
    681                         //totalkm = 0;
    682                         //totalEM = new EmissionsResults();
    683                         //totalControlDelay = 0;
    684                         //maxControlDelay = 0;
    685623                }               
    686624               
    687625               
    688 //              if (crtTime % Globals.SECOND == 0)
    689 //                     
    690 //                      if (crtTime % (Globals.executionFPS / Globals.FPS) == 0)
    691626                if (startedWithGUI) {
    692627                        Globals.demo.st.setCount(crtTime);
     
    695630                        //Globals.demo.st.setSemTime(mycnt);
    696631                        Globals.demo.st.setNrEvents(eventQueue.size());
    697                         Globals.demo.st.setCarsNo(cars.size());
     632                        Globals.demo.st.setCarsNo(cars.size());                 
    698633                }
    699634               
     
    702637//              Petroaca - if DSRC simualtion play the events in emergency channel as well
    703638               
    704                 if(this.simulationProtocol==Globals.PROTOCOL_DSRC && Globals.MULTI_CHANNEL)
     639                if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC && Globals.MULTI_CHANNEL)
    705640                {
    706641                        while (true) {
     
    719654                }
    720655               
     656                /**
     657                 * Mihaela Teler
     658                 * vreau sa aflu cate intersectii am
     659                 * voi avea tot atatea threaduri
     660                 */
     661                Map map = Globals.map;
     662                ArrayList<Intersection> intersectii = map.allIntersections;
     663                int numThreads=intersectii.size();
     664               
     665                EventProcessingThread processingThreads[] = new EventProcessingThread[numThreads];
     666               
     667               
    721668                while (true) {
     669                       
    722670                        if (eventQueue.size() == 0) {
    723671                                doneFlag = true;
     
    725673                        }
    726674                       
     675                        // extrag un eveniment din coada !!!!! acum doar il extrag.. cand intru in playEvent il si scot cu remove(0)
    727676                        Event e = (Event) eventQueue.get(0);
    728                         if (e.getTime() == crtTime) {
     677                        System.out.println("--- no of events in the queue:"+eventQueue.size() );
     678                       
     679                        /**
     680                         * Mihaela Teler
     681                         * vector de threaduri pt procesare evenimente in functie de locatie
     682                         * procesez folosind threaduri doar evenimentele send si receive
     683                         */
     684                       
     685               
     686                        if((e instanceof SendEvent) || (e instanceof ReceiveEvent)){
     687                               
     688                                /**
     689                                 * Mihaela Teler
     690                                 * aflu locatia evenimentului
     691                                 */                     
     692                                Road r = null;
     693                                Point p = null;
     694                                if(e instanceof SendEvent){
     695                                        SendEvent se=(SendEvent)e;
     696                                        r = (Road) Globals.map.roads.get(se.sender.getRoadIdx());       //aflu strada pe care se afla senderul
     697                                        p = (Point) r.points.get(se.sender.getPointIdx());                      //aflu punctul unde se afla senderul
     698                                }
     699                                if(e instanceof ReceiveEvent){
     700                                        ReceiveEvent re=(ReceiveEvent)e;
     701                                        r = (Road) Globals.map.roads.get(re.sender.getRoadIdx());
     702                                        p = (Point) r.points.get(re.sender.getPointIdx());
     703                                }
     704                               
     705                                //System.out.println("p:"+p);
     706                               
     707                                /**
     708                                 * Mihaela Teler
     709                                 * parcurg toate intersectiile si o gasesc pe cea mai apropiata
     710                                 */
     711                                double MIN_DIST=Double.MAX_VALUE;
     712                                int indexClosestIntersection=0;
     713                                double distanta;
     714                                for(int i=0;i<intersectii.size();i++){
     715                                        Intersection intersectie = intersectii.get(i);
     716                                        if(r.getPoints().contains(intersectie.getMapPoint())){ //iau in calcul doar intersectiile aflate pe strada pe care sunt
     717                                                distanta=GPSutil.distance(p, intersectie.getMapPoint());
     718                                                if (distanta < MIN_DIST){
     719                                                        MIN_DIST=distanta;
     720                                                        indexClosestIntersection=i;                                             
     721                                                }
     722                                        }
     723                                               
     724                                }
     725                                /**
     726                                 * Mihaela Teler
     727                                 * acum trebuie sa asignez un thread sa proceseze
     728                                 */
     729                               
     730                                if(e instanceof SendEvent){
     731                                        processingThreads[indexClosestIntersection] = new SendEventProcessingThread(e,crtTime);
     732                                }
     733                                else processingThreads[indexClosestIntersection] = new ReceiveEventProcessingThread(e,crtTime);
     734                               
     735                                // nu e bine cu apelul lui run pt ca practic nu se porneste un thread nou ci
     736                                // se apeleaza metoda run ca orice alta metoda dintr-o clasa, executia este secventiala..
     737                               
     738                                if (e.getTime() == crtTime) {
     739                                        System.out.println("Processing thread "+indexClosestIntersection+" from intersection "+intersectii.get(indexClosestIntersection));
     740                                        //processingThreads[indexClosestIntersection].start();// cu start nu merge ... why????
     741                                        processingThreads[indexClosestIntersection].run();
     742                                        cnt++;
     743                                }
     744                                else
     745                                        break;
     746                        }
     747                       
     748                        else if (e.getTime() == crtTime) {
    729749                                playEvent();
    730750                                cnt++;
    731751                        } else
    732752                                break;
     753                       
     754                       
    733755                }
    734756               
     
    743765                        else
    744766                                generateScenarioPhase();
     767               
    745768                checkCreateNewCars();
    746769               
     
    749772                mobilityTime += t4 - t3;
    750773
    751                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
     774                if (Engine.simulationType == RoutingConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
    752775                        if (crtTime % 100 == 0) {
    753776                                for (int i = 0; i < this.infrastructure.size(); i++) {
    754777                                       
    755                                         ((InfrastructureNode) this.infrastructure.get(i))
    756                                                         .updateDelays();
     778                                        ((InfrastructureNode) this.infrastructure.get(i)).updateDelays();
    757779                                }
    758780                        }
     
    764786                        server.step(crtTime);
    765787                }
    766 
    767 //              if (crtTime % Globals.MINUTE == 0){
    768 //                      System.out.println("[Engine - step()] ");
    769 //                      System.out.println("\ntotal: " + (double)(t4 - t0)/1000);
    770 //                      System.out.println("events: " + (double) (100 * eventsTime)
    771 //                                      / (t4 - t0));
    772 //                      System.out.println("mobility: " + (double) (100 * mobilityTime)
    773 //                                      / (t4 - t0));
    774 //                      System.out.println("code: " + (double) (100 * codeTime)
    775 //                                      / (t4 - t0));
    776 //                     
    777 //              }
    778                 // System.out.println();
    779                 // System.out.println("crtTime "+crtTime);
    780                 // System.out.println("CARS:");
    781                 // System.out.println(cars);
    782                 // System.out.println("Events:");
    783                 // System.out.println(eventQueue);
    784 
    785                 //checkInjectQueries();
    786 
    787 //              if (crtTime % Globals.SECOND == 0){
    788 //                     
    789 //                      if (crtTime % (Globals.executionFPS / Globals.FPS) == 0)
    790 //                              if (withGUI) {
    791 //                                      synchronized (Globals.mutex){
    792 //                                              Globals.flag = 1;
    793 //                                              Globals.mutex.notify();
    794 //                                      }
    795 //                              }
    796 //              }else
    797 //                      synchronized (Globals.mutex){
    798 //                              Globals.mutex.notify();
    799 //                      }
    800 
    801         }
    802 
    803         /**
    804          * VITP.
    805          *
    806          */
    807         private void checkInjectQueries() {
    808 //              should inject some queries?
    809                 vnsim.applications.vitp.predefinedqueries.Query q=PredefinedQueries.queries.get(crtTime);
    810                 if(q!=null)
    811                 {
    812                         if(q instanceof QueryByVehicleId) {
    813                                 //look for the vehicle with the specified id
    814                                 Iterator<SimulatedCarInfo> it = cars.iterator();
    815                                 while (it.hasNext()) {
    816                                         SimulatedCarInfo r = it.next();
    817                                         if(r.getVehicleId()==((QueryByVehicleId)q).vehicleId)
    818                                         {
    819                                                 //inject the query
    820                                                 CarRunningVITP x = (CarRunningVITP)r;
    821                                                 if(!x.isEquipped)
    822                                                         continue; //look for an equipped vehicle
    823                                                 x.p.postMessageFromAbove(q.req);
    824                                                 System.out.println("QUERY INJECTED; CRTTIME="+crtTime);
    825                                                 break;
    826                                         }       
    827                                 }
    828                         } else if(q instanceof QueryByLocation) {
    829                                 //look for a vehicle in the specified location
    830                                 int roadIdx=((QueryByLocation)q).roadIdx;
    831                                 int pointIdx=((QueryByLocation)q).pointIdx;
    832 
    833                                 Iterator<SimulatedCarInfo> it = cars.iterator();
    834                                 while (it.hasNext()) {
    835                                         SimulatedCarInfo r = it.next();
    836                                         if(r.getRoadIdx()==roadIdx && r.getPointIdx()<pointIdx+5 && r.getPointIdx()>pointIdx-5) {                                       
    837                                                 CarRunningVITP x = (CarRunningVITP)r;
    838                                                 if(!x.isEquipped)
    839                                                         continue; //look for an equipped vehicle
    840                                                 x.p.postMessageFromAbove(q.req);
    841                                                 System.out.println("QUERY INJECTED; CRTTIME="+crtTime);
    842                                                
    843 //                                              Road road=Globals.map.roads.get(r.getRoadIdx());
    844 //
    845 //                                              Point p1=road.points.get(r.getPointIdx());
    846 //                                              Point p2=road.points.get(q.req.getDest().pt1);
    847 //
    848 //      //                                      System.out.println("P1="+r.getPointIdx());
    849 //      //                                      System.out.println("P2="+q.req.getDest().pt1);
    850 //      //
    851 //      //                                      System.out.println("AWAY="+(p1.getDistance()-p2.getDistance()));
    852 //     
    853 //                                              Statistics.setQueryDistance(MessageIndexModule.index, (p1.getDistance()-p2.getDistance()));
    854 //                                              Statistics.setInitialTime(MessageIndexModule.index, crtTime);
    855                                                 break;
    856                                         }
    857                                 }
    858                         }
    859                 }
    860         }
     788        }
     789        //////////////////////////////////////////////end metoda step////////////////////////////////////
    861790
    862791        static Random random = new Random();
     
    868797         *
    869798         */
    870         private void checkCreateNewCars()
    871         {
     799        private void checkCreateNewCars(){
    872800
    873801                int percent;
     
    929857                                //one vehicle on each lane
    930858
    931 //                              double offset=4*random.nextDouble();
    932 //                              System.out.println("OFFSET="+offset);
    933 
    934859                                Personality personality;
    935860                                rand=(random.nextDouble())*100;
     
    950875                                                        roadIndexDst, pointIndexDst, r.route);
    951876                                       
    952                                         System.out.println("Finished creating new car");
     877                                        System.out.println("Finished creating new car "+car);
     878                                       
    953879                                        double d =0;
    954880                                        if(car!=null)
     
    957883                                                // closer than 5 meters --> do not create
    958884                                                // System.out.println("Skipping creation...");
    959                                                 Globals.map.roads.get(car.getRoadIdx()).carsOnThisRoad
    960                                                                 .remove(car.ID);
     885                                                Globals.map.roads.get(car.getRoadIdx()).carsOnThisRoad.remove(car.ID);
    961886                                                continue;
    962887                                        }
    963888                                }
    964889
    965                                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_SELF_ROUTE) {
     890                                if (Engine.simulationType == RoutingConstants.DYNAMIC_SELF_ROUTE) {
    966891                                        System.out.println("Dynamic; we are here");
    967892                                        percent = random.nextInt(100);
     
    983908                                                // closer than 10 meters --> do not create
    984909                                               
    985                                                 Globals.map.roads.get(car.getRoadIdx()).carsOnThisRoad
    986                                                                 .remove(car.ID);                                               
     910                                                Globals.map.roads.get(car.getRoadIdx()).carsOnThisRoad.remove(car.ID);                                         
    987911                                                continue;
    988912                                        }
    989913
    990914                                }
    991                                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
     915                                if (Engine.simulationType == RoutingConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
    992916
    993917                                        car = Mobility.createNewCarCommunicatingWithInfrastucture(
     
    1060984        }
    1061985
    1062        
    1063 
    1064         long messagesSize = 0;
    1065         long carInfosSize = 0;
     986////////////////////////////////////////// playEvent ////////////////////////////////////////////////////////////////   
     987
     988        static long messagesSize = 0;
     989        static long carInfosSize = 0;
    1066990        /**
    1067991         * Execute the following event in the eventQueue
    1068992         *
    1069993         */
    1070         public void playEvent() {
     994        public static void playEvent() {
     995               
     996                //System.out.println(">> Thread:"+Thread.currentThread().getName());
     997               
    1071998                if (eventQueue.size() == 0) {
    1072999                        doneFlag = true;
     
    10781005                        e = eventQueue.remove(0);
    10791006                }
    1080                 // System.out.print(e.toString()+", ");
    1081                 // System.out.flush();
    1082                 //             
    1083                 if (e instanceof GPSEvent) {
     1007                //System.out.print(e.toString()+", ");
     1008                //System.out.flush();
     1009                               
     1010                if (e instanceof GPSEvent) {    //////////// eveniment GPS
     1011                       
    10841012                        Iterator<SimulatedCarInfo> it = cars.iterator();
    10851013                        while (it.hasNext()) {
     
    10901018                        schedEvent(newEvent);
    10911019                }
    1092                 if (e instanceof CleanupEvent) {
     1020                if (e instanceof CleanupEvent) {        //////////// eveniment CLEANUP
    10931021
    10941022                        long t1 = System.currentTimeMillis();
     
    10971025                        while (it.hasNext()) {
    10981026                                SimulatedCarInfo r = it.next();
    1099 //                              if (r.isPromiscuousMode() && r.pointIdx < 256 && r.pointIdx > 50){
    1100 //                                      r.getDirection();
    1101 //                              }
     1027
    11021028                                Iterator<CarInfo> j = r.trafficDB.iterator();
    11031029                                while (j.hasNext()) {
    11041030                                        CarInfo neighbor = j.next();
    1105                                         if ( (crtTime - neighbor.getTimestamp() > Globals.NEIGHBOR_EXPIRES
    1106                                                         && neighbor.state != 3) ||
     1031                                        if ( (crtTime - neighbor.getTimestamp() > Globals.NEIGHBOR_EXPIRES && neighbor.state != 3) ||
    11071032                                                        (neighbor.state == 3 && crtTime - neighbor.getTimestamp() > Globals.PROMISCUOUS_NEIGHBOR_EXPIRES)){
    11081033                                                j.remove();
    1109 //                                              deleted++;
    11101034                                        }
    11111035                                }
     
    11391063                                schedEvent(newCleanupEvent);
    11401064                        }
    1141 //                      if (deleted != 0)
    1142 //                              System.out.println(crtTime+")\n\ttotal cars - "+carInfosSize+"\n\ttotal cars deleted- "+deleted+"\n\ttotal bytes transfered - "+messagesSize);
    11431065                        messagesSize = 0;
    11441066                }
    1145                 if (e instanceof SendEvent) {
     1067               
     1068                if (e instanceof SendEvent) {   /////////////////////////////// eveniment SEND
     1069                       
     1070                        /**
     1071                         * cod mutat in metoda run a lui SendEventProcessingThread - intre timp m-am razgandit.. am pornit threaduri in metoda step
     1072                         */
     1073                       
     1074                        /*SendEventProcessingThread thread=new SendEventProcessingThread(e, crtTime, disableComm, messagesSize);
     1075                        synchronized (eventQueue) {
     1076                                if(!thread.isAlive()) {
     1077                                        thread.start();
     1078                                        System.out.println(".........................thread started");
     1079                                }
     1080                        }*/
     1081                       
     1082                       
    11461083                        SendEvent se = (SendEvent) e;
    11471084                        Communicator sender = se.getSender();
    1148 
     1085                       
    11491086                        long t1 = System.currentTimeMillis();   
    11501087                       
     1088                        // senderul e un SimulatedCarInfo
    11511089                       
    11521090                        if (se.getMessage() == null){
     
    11541092                                se.setMessage(message);
    11551093                                if (se.getMessage() == null){
    1156         //                              System.out.println("null message"+se.sender + " "+se.sender.getClass());
    11571094                                        if (sender.isPromiscuousMode() && sender.isPeriodicalMessage(se.getMessageType()) && !disableComm) {
    11581095                                                int eventPeriod = sender.getPeriod(se.getMessageType());
    11591096                                                if (eventPeriod != -1)
    1160                                                         schedEvent(new SendEvent(crtTime + eventPeriod, sender, se
    1161                                                                 .getMessageType()));
     1097                                                        schedEvent(new SendEvent(crtTime + eventPeriod, sender, se.getMessageType()));
    11621098                                        }
    11631099                                        return;
     
    11701106                                        int eventPeriod = sender.getPeriod(se.getMessageType());
    11711107                                        if (eventPeriod != -1)
    1172                                                 schedEvent(new SendEvent(crtTime + eventPeriod, sender, se
    1173                                                         .getMessageType()));
     1108                                                schedEvent(new SendEvent(crtTime + eventPeriod, sender, se.getMessageType()));
    11741109                                }
    11751110                        }
     
    11781113                        if(Engine.simulationProtocol==Globals.PROTOCOL_80211)
    11791114                        {
    1180                                 //                       TODO To be replaced with a real MAC layer
     1115                               
    11811116                                if (!sender.mediumAvailable(crtTime)) {
    11821117                                        e.setTime(crtTime + 1);
     
    12271162                                        simulateCommunication(se);
    12281163                                }
    1229                                
    1230                                
    1231                         }
    1232                        
    1233 
    1234                        
    1235                        
    1236                        
    1237                 }
    1238                 if (e instanceof ReceiveEvent) {
     1164                        }
     1165                }
     1166               
     1167                if (e instanceof ReceiveEvent) {        //////////////////////// eveniment RECEIVE
    12391168                        ReceiveEvent re = (ReceiveEvent) e;
    1240                        
    1241 //                      long tmp = 0;
    1242 //                      long t3 = System.currentTimeMillis();
    1243 //                      long t4;
    1244 //                      if (re.isUnicast()) {
    1245 //                              long t1 = System.currentTimeMillis();
    1246 //                              re.receiver.onReceive(re.getMessage(), re.sender);
    1247 //                              long t2 = System.currentTimeMillis();
    1248 //                              codeTime += t2 - t1;
    1249 //                      } else {
     1169
    12501170                                long t1 = System.currentTimeMillis();
     1171                               
    12511172                                //Petroaca - the DSRC impl
    1252                                 if(Engine.simulationProtocol==Globals.PROTOCOL_80211)
    1253                                 {
     1173                                if(Engine.simulationProtocol==Globals.PROTOCOL_80211){
    12541174                                        RadioDev rxradio = re.receiver.getRadio();
    12551175                                        ReceiveEvent goodSignal = rxradio.receive(re.signals);
    12561176                                        re.receiver.removeReceiveEventForTime(re.getTime());
    12571177                               
    1258 //                              for (ReceiveEvent goodSignal : re.signals){
    1259 //                                      Road r1 = (Road) Globals.map.roads.get(re.sender.getRoadIdx());
    1260 //                                      Point p1 = (Point) r1.points.get(re.sender.getPointIdx());
    1261 //                                      Road r2 = (Road) Globals.map.roads.get(re.receiver.getRoadIdx());
    1262 //                                      Point p2 = (Point) r2.points.get(re.receiver.getPointIdx());
    1263 //                                      double distance = GPSutil.distance(p1, p2);
    1264 //                                      if (distance <= WIRELESS_RANGE){
    1265                                                 if (goodSignal != null){
     1178                                        if (goodSignal != null){
    12661179                                                        re.receiver.onReceive(goodSignal.getMessage(), goodSignal.getMessageObject(), goodSignal.sender);
    12671180                                                }
    1268 //                                      }
    1269 //                              }
    1270                                
    12711181                                }
    12721182                                else
     
    12981208                                                                //appr.LaneChangeAssistance(best.getMessage(),((CarInfo)re.receiver));
    12991209                                                                re.receiver.onReceive(best.getMessage(), best.getMessageObject(), best.sender);
    1300                                                                
    13011210                                                        }
    1302                                                
    1303                                                        
    13041211                                                }
    1305                                                
    1306                                                
    13071212                                        }
    13081213                                        else
     
    13121217                                                re.receiver.removeReceiveEventForTime(re.getTime());
    13131218                                       
    1314 
    1315                                                         if (goodSignal != null){
     1219                                                if (goodSignal != null){
    13161220                                                                re.receiver.onReceive(goodSignal.getMessage(), goodSignal.getMessageObject(), goodSignal.sender);
    13171221                                                        }
    1318                                                
    1319 
    1320                                         }
    1321                                        
    1322                                        
     1222                                        }
    13231223                                }       
    13241224                               
    13251225                                long t2 = System.currentTimeMillis();
    13261226                                codeTime += t2 - t1;
    1327 /*                              if (!re.sender.mediumAvailable(crtTime)) {
    1328                                         re.setTime(crtTime + 1);
    1329                                         schedEvent(re);
    1330                                         return;
    1331                                 }
    1332 
    1333                                 Road r1 = null;
    1334                                 Point p1 = null;
    1335                                 if (re.sender instanceof SimulatedCarInfo){
    1336                                         SimulatedCarInfo sender = (SimulatedCarInfo)re.sender;
    1337                                         r1 = (Road) Globals.map.roads.get(sender.getRealPos()
    1338                                                         .getRoadIdx());
    1339                                         p1 = (Point) r1.points.get(sender.getRealPos().getPointIdx());
    1340                                 }else{
    1341                                         WirelessTrafficLight wtl = (WirelessTrafficLight)re.sender;
    1342                                         r1 = (Road) Globals.map.roads.get(wtl.segments.get(0).roadIndex);
    1343                                         p1 = (Point) r1.points.get(wtl.segments.get(0).pointIndex);
    1344                                 }
    1345 //                              recvEventsCnt++;
    1346 
    1347                                 long comp = 0;
    1348                                 // peanoKeys
    1349                                 int cnt2 = 0;
    1350                                 int cnt3 = 0;
    1351                                 int cnt4 = 0;
    1352                                 int pkcnt = 0;
    1353                                 PeanoKey pk = Globals.map.peanoKeys.get(p1.getPeanoKeyIdx());
    1354 
    1355                                 ListIterator<PeanoKey> pkit = Globals.map.peanoKeys
    1356                                                 .listIterator(p1.getPeanoKeyIdx());
    1357                                 PeanoKey maxpk = null;
    1358                                
    1359                                 double wifirange;
    1360                                 if (re.sender instanceof WirelessTrafficLight){
    1361                                         maxpk = GPSutil.getMaxSearchBoundPK(p1,Engine.EXTENDED_WIRELESS_RANGE);
    1362                                         wifirange = EXTENDED_WIRELESS_RANGE;
    1363                                 }else{
    1364                                         wifirange = WIRELESS_RANGE;
    1365                                         maxpk = pk.getMaxpk();
    1366                                 }
    1367                                 PeanoKey pkx = null;
    1368                                 for (pkx = pkit.next(); pkit.hasNext(); pkx = pkit.next()) {
    1369                                         pkcnt++;
    1370                                         // long tc1 = System.currentTimeMillis();
    1371                                         // PeanoKey pkx = Globals.map.peanoKeys.get(idx);
    1372                                         if (pkx.compareTo(maxpk) > 0)
    1373                                                 break;
    1374                                         // long tc2 = System.currentTimeMillis();
    1375                                         // comp += (tc2-tc1);
    1376 
    1377                                         if (pkx.getCars() != null) {
    1378                                                 Road r2 = (Road) Globals.map.roads.get(pkx
    1379                                                                 .getRoadIndex());
    1380                                                 Point p2 = (Point) r2.points.get(pkx.getPointIndex());
    1381                                                 if (GPSutil.distance(p1, p2) < wifirange) {
    1382                                                         cnt3 += pkx.getCars().size();
    1383                                                         Iterator<SimulatedCarInfo> it = pkx.getCars()
    1384                                                                         .iterator();
    1385                                                         while (it.hasNext()) {
    1386                                                                 SimulatedCarInfo r = it.next();
    1387                                                                 if (re.sender instanceof SimulatedCarInfo)
    1388                                                                         if (r.getVehicleId() == ((SimulatedCarInfo)re.sender)
    1389                                                                                 .getVehicleId())
    1390                                                                                 continue;
    1391                                                                 r.setLastMediumTransmition(crtTime);
    1392                                                                 t4 = System.currentTimeMillis();
    1393                                                                 tmp += t4 - t3;
    1394                                                                 long t1 = System.currentTimeMillis();
    1395                                                                 r.onReceive(re.getMessage(), re.sender);
    1396                                                                 long t2 = System.currentTimeMillis();
    1397                                                                 codeTime += t2 - t1;
    1398                                                                 cnt2++;
    1399                                                                 t3 = System.currentTimeMillis();
    1400                                                         }
    1401                                                 }
    1402                                         }
    1403                                 }
    1404                                 PeanoKey minpk = null;
    1405                                 if (re.sender instanceof WirelessTrafficLight)
    1406                                         minpk = GPSutil.getMaxSearchBoundPK(p1,-Engine.EXTENDED_WIRELESS_RANGE);
    1407                                 else
    1408                                         minpk = pk.getMinpk();
    1409                                
    1410                                 pkit = Globals.map.peanoKeys.listIterator(p1.getPeanoKeyIdx());
    1411 
    1412                                 if (pkit.hasPrevious()){
    1413                                         pkx = pkit.previous();
    1414                                 }
    1415                                 for (; pkit.hasPrevious(); pkx = pkit
    1416                                                 .previous()) {
    1417                                         pkcnt++;
    1418                                         // long tc1 = System.currentTimeMillis();
    1419                                         // PeanoKey pkx = Globals.map.peanoKeys.get(idx);
    1420                                         if (pkx.compareTo(minpk) < 0) {
    1421                                                 break;
    1422                                         }
    1423                                         // long tc2 = System.currentTimeMillis();
    1424                                         // comp += (tc2-tc1);
    1425 
    1426                                         if (pkx.getCars() != null) {
    1427                                                 Road r2 = (Road) Globals.map.roads.get(pkx
    1428                                                                 .getRoadIndex());
    1429                                                 Point p2 = (Point) r2.points.get(pkx.getPointIndex());
    1430                                                 if (GPSutil.distance(p1, p2) < wifirange) {
    1431                                                         Iterator<SimulatedCarInfo> it = pkx.getCars()
    1432                                                                         .iterator();
    1433                                                         cnt3 += pkx.getCars().size();
    1434                                                         while (it.hasNext()) {
    1435                                                                 SimulatedCarInfo r = it.next();
    1436                                                                 r.setLastMediumTransmition(crtTime);
    1437                                                                
    1438                                                                 if (re.sender instanceof SimulatedCarInfo)
    1439                                                                         if (r.getVehicleId() == ((SimulatedCarInfo)re.sender)
    1440                                                                                 .getVehicleId())
    1441                                                                                 continue;
    1442                                                                
    1443                                                                 t4 = System.currentTimeMillis();
    1444                                                                 tmp += t4 - t3;
    1445                                                                 long t1 = System.currentTimeMillis();
    1446                                                                 r.onReceive(re.getMessage(), re.sender);
    1447                                                                 long t2 = System.currentTimeMillis();
    1448                                                                 codeTime += t2 - t1;
    1449                                                                 cnt4++;
    1450                                                                 t3 = System.currentTimeMillis();
    1451                                                         }
    1452                                                 }
    1453                                         }
    1454                                 }
    1455                                
    1456                                 for (int j = 0; j < Globals.map.lightsIndices.size(); j++) {
    1457                                         WirelessTrafficLight wtl = (WirelessTrafficLight) Globals.map.allIntersections
    1458                                                         .get(Globals.map.lightsIndices.get(j));
    1459                                         long t1sem = System.currentTimeMillis();
    1460 
    1461                                         if (GPSutil.distance(p1, wtl.getMapPoint()) < WIRELESS_RANGE) {
    1462                                                 wtl.setLastMediumTransmition(crtTime);
    1463                                                 wtl.onReceive(re.getMessage(), re.sender);
    1464                                         }
    1465                                         long t2sem = System.currentTimeMillis();
    1466                                         semTime += (t2sem - t1sem);
    1467                                 }
    1468                                
    1469                                 t4 = System.currentTimeMillis();
    1470                                 tmp += t4 - t3;
    1471                                 netTime += tmp;
    1472                                 long t5 = System.currentTimeMillis();
    1473 */
    1474 //                              if (tmp > 0)
    1475 //                                      avgTime += (double) (100 * comp) / tmp;
    1476 //                              if (pkcnt > pkmax)
    1477 //                                      pkmax = pkcnt;
    1478 //                              avgi++;
    1479 //                              pkavg += cnt2;
    1480 
    1481                                 // long t5 = System.currentTimeMillis();
    1482                                 //                             
    1483                                 // if (cnt1 != cnt2 + cnt4){
    1484                                 // System.out.println("==== "+crtTime+" car: "+re.sender+ "
    1485                                 // ======\n"+
    1486                                 // "Count FAILED old:" + cnt1 +" - new: "+cnt2 +" +
    1487                                 // "+cnt4+"/"+pkcnt
    1488                                 // +" --- "+minpk+" - "+maxpk);
    1489                                 // }
    1490                                 // if (t5 - t4 > tmp){
    1491                                 // System.out.println("==== "+crtTime+" car: "+re.sender+ "
    1492                                 // ======\n"+
    1493                                 // "Time FAILED old:" + tmp+"/"+cnt1 +" - new: "+
    1494                                 // (t5-t4)+"/"+cnt2 +"/"+ cnt3+" / "+pkcnt +" - "+comp);
    1495                                 // }
    1496 
    1497                         }
    1498 
    1499                         // if (Globals.demo.mv.currentCar != null &&
    1500                         // Globals.demo.mv.currentCar == re.getReceiver().car)
    1501                         // System.out.println(i+" cars nearby");
    1502 
    1503 //              } // end if else isUnicast
    1504         }
    1505 
    1506 //      static int recvEventsCnt = 0;
    1507 //
    1508 //      static int pkmax;
    1509 //
    1510 //      static long pkavg = 0;
    1511 //
    1512 //      static double avgTime = 0;
    1513 //
    1514 //      static int avgi = 0;
    1515 //
     1227                        }
     1228        }
     1229
     1230
    15161231        public void playEventEmergency()
    15171232        {
     
    15291244                        SendEvent se = (SendEvent) e;
    15301245                        Communicator sender = se.getSender();
    1531 
     1246                       
    15321247                        long t1 = System.currentTimeMillis();   
    15331248                       
     
    15411256                                                int eventPeriod = sender.getPeriod(se.getMessageType());
    15421257                                                if (eventPeriod != -1)
    1543                                                         schedEventEmergency(new SendEvent(crtTime + eventPeriod, sender, se
    1544                                                                 .getMessageType()));
     1258                                                        schedEventEmergency(new SendEvent(crtTime + eventPeriod, sender, se.getMessageType()));
    15451259                                        }
    15461260                                        return;
     
    15531267                                        int eventPeriod = sender.getPeriod(se.getMessageType());
    15541268                                        if (eventPeriod != -1)
    1555                                                 schedEventEmergency(new SendEvent(crtTime + eventPeriod, sender, se
    1556                                                         .getMessageType()));
     1269                                                schedEventEmergency(new SendEvent(crtTime + eventPeriod, sender, se.getMessageType()));
    15571270                                }
    15581271                        }
     
    15911304                                        return;
    15921305                                }
    1593                                
    1594                                
    1595                                
    1596                                
    1597                         }
    1598                        
    1599                        
    1600                
     1306                        }
     1307                       
    16011308                if (e instanceof ReceiveEvent) {
    16021309                        ReceiveEvent re = (ReceiveEvent) e;
    16031310                       
    1604 //                      long tmp = 0;
    1605 //                      long t3 = System.currentTimeMillis();
    1606 //                      long t4;
    1607 //                      if (re.isUnicast()) {
    1608 //                              long t1 = System.currentTimeMillis();
    1609 //                              re.receiver.onReceive(re.getMessage(), re.sender);
    1610 //                              long t2 = System.currentTimeMillis();
    1611 //                              codeTime += t2 - t1;
    1612 //                      } else {
    1613                                 long t1 = System.currentTimeMillis();
    1614                                 //Petroaca - the DSRC impl
     1311                        long t1 = System.currentTimeMillis();
     1312                       
     1313                        //Petroaca - the DSRC impl
    16151314                               
    16161315                                        if(re.receiver instanceof CarRunningDSRC)
     
    16401339                                                                //appr.LaneChangeAssistance(best.getMessage(),((CarInfo)re.receiver));
    16411340                                                                re.receiver.onReceive(best.getMessage(), best.getMessageObject(), best.sender);
    1642                                                                
    16431341                                                        }
    1644                                                
    1645                                                        
    16461342                                                }
    1647                                                
    1648                                                
    16491343                                        }
    16501344                                        long t2 = System.currentTimeMillis();
    16511345                                        codeTime += t2 - t1;
    1652                                        
    16531346                                }       
    1654                                
    1655                                
    16561347        }
    16571348       
     
    16621353         * @param e Event to schedule
    16631354         */
    1664         public void schedEvent(Event e) {
     1355        public static void schedEvent(Event e) {
    16651356
    16661357                long t1 = System.currentTimeMillis();
     
    17281419         *
    17291420         */
    1730         public void simulateCommunication(SendEvent e) {
     1421        public static void simulateCommunication(SendEvent e) {
     1422               
     1423                Road r1 = null;
     1424                Point p1 = null;
     1425                r1 = (Road) Globals.map.roads.get(e.sender.getRoadIdx());
     1426                p1 = (Point) r1.points.get(e.sender.getPointIdx());
     1427               
     1428                if (e instanceof UnicastSendEvent) {
     1429                        long t1 = System.currentTimeMillis();
     1430                        Iterator<SimulatedCarInfo> it = cars.iterator();
     1431                        ReceiveEvent re = null;
     1432                        while (it.hasNext()) {
     1433                                SimulatedCarInfo r = it.next();
     1434                                if (r.vehicleId == ((UnicastSendEvent) e).getReceiverId()) {
     1435                                        Road r2 = (Road) Globals.map.roads.get(r.getRealPos().getRoadIdx());
     1436                                        Point p2 = (Point) r2.points.get(r.getRealPos().getPointIdx());
     1437
     1438                                        // MODIFIED BY CRISTI!!!
     1439                                        // ReceiveEvent er = new ReceiveEvent(e.getTime() + 1, r, e.getMessage());
     1440
     1441                                        re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
     1442                                        re.setUnicast(true);
     1443
     1444                                        schedEvent(re);
     1445                                        if (GPSutil.distance(p1, p2) < WIRELESS_RANGE) {
     1446                                        } else {
     1447                                                System.out.println("EROARE! DISTANCE="+ GPSutil.distance(p1, p2));
     1448                                        }
     1449                                        // END MODIFIED!!!
     1450                                        return;
     1451                                }
     1452                        }
     1453                       
     1454                       
     1455                        re.setSender(e.getSender());
     1456                       
     1457                        schedEvent(re);
     1458
     1459                        long t2 = System.currentTimeMillis();
     1460                        netTime += t2 - t1;
     1461
     1462                } else {
     1463                       
     1464                        long tmp = 0;
     1465                        long t3 = System.currentTimeMillis();
     1466                        long t4;
     1467
     1468//                      re = new ReceiveEvent(e.getTime() + 1, e.getSender(), e.getMessage());
     1469                       
     1470
     1471                        int cnt3 = 0;
     1472                        int pkcnt = 0;
     1473                        PeanoKey pk = Globals.map.peanoKeys.get(p1.getPeanoKeyIdx());
     1474
     1475                        ListIterator<PeanoKey> pkit = Globals.map.peanoKeys.listIterator(p1.getPeanoKeyIdx());
     1476                        PeanoKey maxpk = null;
     1477                       
     1478                        double wifirange;
     1479                        if (e.sender instanceof WirelessTrafficLight){
     1480                                maxpk = GPSutil.getMaxSearchBoundPK(p1,Engine.EXTENDED_WIRELESS_RANGE);
     1481                                wifirange = EXTENDED_WIRELESS_RANGE;
     1482                        }else{
     1483                                wifirange = WIRELESS_RANGE;
     1484                                maxpk = pk.getMaxpk();
     1485                        }
     1486                       
     1487                        PeanoKey pkx = null;
     1488                        for (pkx = pkit.next(); pkit.hasNext(); pkx = pkit.next()) {
     1489                                pkcnt++;
     1490                                // long tc1 = System.currentTimeMillis();
     1491                                if (pkx.compareTo(maxpk) > 0)
     1492                                        break;
     1493                                // long tc2 = System.currentTimeMillis();
     1494                                // comp += (tc2-tc1);
     1495
     1496                                if (pkx.getCars() != null) {
     1497                                        Road r2 = (Road) Globals.map.roads.get(pkx.getRoadIndex());
     1498                                        Point p2 = (Point) r2.points.get(pkx.getPointIndex());
     1499                                        if (GPSutil.distance(p1, p2) < 5 * wifirange) {
     1500                                                cnt3 += pkx.getCars().size();
     1501                                                Iterator<SimulatedCarInfo> it = pkx.getCars().iterator();
     1502                                                while (it.hasNext()) {
     1503                                                        SimulatedCarInfo r = it.next();
     1504                                                        if (e.sender instanceof SimulatedCarInfo)
     1505                                                                if (r.getVehicleId() == ((SimulatedCarInfo)e.sender).getVehicleId())
     1506                                                                        continue;
     1507                                                        r.setLastMediumTransmition(crtTime);
     1508                                                       
     1509                                                        ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
     1510                                                        re.setSender(e.getSender());
     1511                                                        schedEvent(re);
     1512                                                }
     1513                                        }
     1514                                }
     1515                        }
     1516                        PeanoKey minpk = null;
     1517                        if (e.sender instanceof WirelessTrafficLight)
     1518                                minpk = GPSutil.getMaxSearchBoundPK(p1,-Engine.EXTENDED_WIRELESS_RANGE);
     1519                        else
     1520                                minpk = pk.getMinpk();
     1521                       
     1522                        pkit = Globals.map.peanoKeys.listIterator(p1.getPeanoKeyIdx());
     1523
     1524                        if (pkit.hasPrevious()){
     1525                                pkx = pkit.previous();
     1526                        }
     1527                        for (; pkit.hasPrevious(); pkx = pkit.previous()) {
     1528                                pkcnt++;
     1529                                // long tc1 = System.currentTimeMillis();
     1530                                if (pkx.compareTo(minpk) < 0) {
     1531                                        break;
     1532                                }
     1533                                // long tc2 = System.currentTimeMillis();
     1534                                // comp += (tc2-tc1);
     1535
     1536                                if (pkx.getCars() != null) {
     1537                                        Road r2 = (Road) Globals.map.roads.get(pkx.getRoadIndex());
     1538                                        Point p2 = (Point) r2.points.get(pkx.getPointIndex());
     1539                                        double distance = GPSutil.distance(p1, p2);
     1540                                        if (distance < 5 * wifirange) {
     1541                                                Iterator<SimulatedCarInfo> it = pkx.getCars().iterator();
     1542                                                cnt3 += pkx.getCars().size();
     1543                                                while (it.hasNext()) {
     1544                                                        SimulatedCarInfo r = it.next();
     1545                                                       
     1546                                                        r.setLastMediumTransmition(crtTime);
     1547                                               
     1548                                                        if (e.sender instanceof SimulatedCarInfo)
     1549                                                                if (r.getVehicleId() == ((SimulatedCarInfo)e.sender).getVehicleId())
     1550                                                                        continue;
     1551                                                        ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
     1552                                                        re.setSender(e.getSender());
     1553                                                        schedEvent(re);
     1554                                                }
     1555                                        }
     1556                                }
     1557                        }
     1558                       
     1559                        for (int j = 0; j < Globals.map.lightsIndices.size(); j++) {
     1560                                WirelessTrafficLight wtl = (WirelessTrafficLight) Globals.map.allIntersections
     1561                                                .get(Globals.map.lightsIndices.get(j));
     1562                                long t1sem = System.currentTimeMillis();
     1563
     1564                                if (GPSutil.distance(p1, wtl.getMapPoint()) < 5 * WIRELESS_RANGE) {
     1565                                        wtl.setLastMediumTransmition(crtTime);
     1566                                        ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, wtl, e.getMessage(), e.getMessageObject(), e.getMessageType());
     1567                                        re.setSender(e.getSender());
     1568                                        schedEvent(re);
     1569                                }
     1570                                long t2sem = System.currentTimeMillis();
     1571                                semTime += (t2sem - t1sem);
     1572                        }
     1573                       
     1574                        t4 = System.currentTimeMillis();
     1575                        tmp += t4 - t3;
     1576                        netTime += tmp;
     1577                }
     1578        }
     1579
     1580        //Petroaca - the communication simulation for the emergency channel
     1581        public void simulateCommunicationEmergency(SendEvent e) {
    17311582
    17321583                Road r1 = null;
     
    17541605                                        re.setUnicast(true);
    17551606
    1756                                         schedEvent(re);
    1757                                         if (GPSutil.distance(p1, p2) < WIRELESS_RANGE) {
    1758                                         } else {
    1759                                                 System.out.println("EROARE! DISTANCE="
    1760                                                                 + GPSutil.distance(p1, p2));
    1761                                         }
    1762                                         // END MODIFIED!!!
    1763                                         return;
    1764                                 }
    1765                         }
    1766                        
    1767                         re.setSender(e.getSender());
    1768                         schedEvent(re);
    1769 
    1770                         long t2 = System.currentTimeMillis();
    1771                         netTime += t2 - t1;
    1772 
    1773                 } else {
    1774                        
    1775                         long tmp = 0;
    1776                         long t3 = System.currentTimeMillis();
    1777                         long t4;
    1778 
    1779 //                      re = new ReceiveEvent(e.getTime() + 1, e.getSender(), e
    1780 //                                      .getMessage());
    1781                        
    1782 
    1783                         long comp = 0;
    1784                         // peanoKeys
    1785                         int cnt2 = 0;
    1786                         int cnt3 = 0;
    1787                         int cnt4 = 0;
    1788                         int pkcnt = 0;
    1789                         PeanoKey pk = Globals.map.peanoKeys.get(p1.getPeanoKeyIdx());
    1790 
    1791                         ListIterator<PeanoKey> pkit = Globals.map.peanoKeys
    1792                                         .listIterator(p1.getPeanoKeyIdx());
    1793                         PeanoKey maxpk = null;
    1794                        
    1795                         double wifirange;
    1796                         if (e.sender instanceof WirelessTrafficLight){
    1797                                 maxpk = GPSutil.getMaxSearchBoundPK(p1,Engine.EXTENDED_WIRELESS_RANGE);
    1798                                 wifirange = EXTENDED_WIRELESS_RANGE;
    1799                         }else{
    1800                                 wifirange = WIRELESS_RANGE;
    1801                                 maxpk = pk.getMaxpk();
    1802                         }
    1803                         PeanoKey pkx = null;
    1804                         for (pkx = pkit.next(); pkit.hasNext(); pkx = pkit.next()) {
    1805                                 pkcnt++;
    1806                                 // long tc1 = System.currentTimeMillis();
    1807                                 if (pkx.compareTo(maxpk) > 0)
    1808                                         break;
    1809                                 // long tc2 = System.currentTimeMillis();
    1810                                 // comp += (tc2-tc1);
    1811 
    1812                                 if (pkx.getCars() != null) {
    1813                                         Road r2 = (Road) Globals.map.roads.get(pkx
    1814                                                         .getRoadIndex());
    1815                                         Point p2 = (Point) r2.points.get(pkx.getPointIndex());
    1816                                         if (GPSutil.distance(p1, p2) < 5 * wifirange) {
    1817                                                 cnt3 += pkx.getCars().size();
    1818                                                 Iterator<SimulatedCarInfo> it = pkx.getCars()
    1819                                                                 .iterator();
    1820                                                 while (it.hasNext()) {
    1821                                                         SimulatedCarInfo r = it.next();
    1822                                                         if (e.sender instanceof SimulatedCarInfo)
    1823                                                                 if (r.getVehicleId() == ((SimulatedCarInfo)e.sender)
    1824                                                                         .getVehicleId())
    1825                                                                         continue;
    1826                                                         r.setLastMediumTransmition(crtTime);
    1827                                                        
    1828                                                         ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
    1829                                                         re.setSender(e.getSender());
    1830                                                         schedEvent(re);
    1831                                                 }
    1832                                         }
    1833                                 }
    1834                         }
    1835                         PeanoKey minpk = null;
    1836                         if (e.sender instanceof WirelessTrafficLight)
    1837                                 minpk = GPSutil.getMaxSearchBoundPK(p1,-Engine.EXTENDED_WIRELESS_RANGE);
    1838                         else
    1839                                 minpk = pk.getMinpk();
    1840                        
    1841                         pkit = Globals.map.peanoKeys.listIterator(p1.getPeanoKeyIdx());
    1842 
    1843                         if (pkit.hasPrevious()){
    1844                                 pkx = pkit.previous();
    1845                         }
    1846                         for (; pkit.hasPrevious(); pkx = pkit
    1847                                         .previous()) {
    1848                                 pkcnt++;
    1849                                 // long tc1 = System.currentTimeMillis();
    1850                                 if (pkx.compareTo(minpk) < 0) {
    1851                                         break;
    1852                                 }
    1853                                 // long tc2 = System.currentTimeMillis();
    1854                                 // comp += (tc2-tc1);
    1855 
    1856                                 if (pkx.getCars() != null) {
    1857                                         Road r2 = (Road) Globals.map.roads.get(pkx
    1858                                                         .getRoadIndex());
    1859                                         Point p2 = (Point) r2.points.get(pkx.getPointIndex());
    1860                                         double distance = GPSutil.distance(p1, p2);
    1861                                         if (distance < 5 * wifirange) {
    1862                                                 Iterator<SimulatedCarInfo> it = pkx.getCars()
    1863                                                                 .iterator();
    1864                                                 cnt3 += pkx.getCars().size();
    1865                                                 while (it.hasNext()) {
    1866                                                         SimulatedCarInfo r = it.next();
    1867                                                         r.setLastMediumTransmition(crtTime);
    1868                                                
    1869                                                         if (e.sender instanceof SimulatedCarInfo)
    1870                                                                 if (r.getVehicleId() == ((SimulatedCarInfo)e.sender)
    1871                                                                         .getVehicleId())
    1872                                                                         continue;
    1873                                                         ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
    1874                                                         re.setSender(e.getSender());
    1875                                                         schedEvent(re);
    1876                                                 }
    1877                                         }
    1878                                 }
    1879                         }
    1880                        
    1881                         for (int j = 0; j < Globals.map.lightsIndices.size(); j++) {
    1882                                 WirelessTrafficLight wtl = (WirelessTrafficLight) Globals.map.allIntersections
    1883                                                 .get(Globals.map.lightsIndices.get(j));
    1884                                 long t1sem = System.currentTimeMillis();
    1885 
    1886                                 if (GPSutil.distance(p1, wtl.getMapPoint()) < 5 * WIRELESS_RANGE) {
    1887                                         wtl.setLastMediumTransmition(crtTime);
    1888                                         ReceiveEvent re = new ReceiveEvent(e.getTime() + 1, wtl, e.getMessage(), e.getMessageObject(), e.getMessageType());
    1889                                         re.setSender(e.getSender());
    1890                                         schedEvent(re);
    1891                                 }
    1892                                 long t2sem = System.currentTimeMillis();
    1893                                 semTime += (t2sem - t1sem);
    1894                         }
    1895                        
    1896                         t4 = System.currentTimeMillis();
    1897                         tmp += t4 - t3;
    1898                         netTime += tmp;
    1899                 }
    1900         }
    1901 
    1902         //Petroaca - the communication simulation for the emergency channel
    1903         public void simulateCommunicationEmergency(SendEvent e) {
    1904 
    1905                 Road r1 = null;
    1906                 Point p1 = null;
    1907                 r1 = (Road) Globals.map.roads.get(e.sender.getRoadIdx());
    1908                 p1 = (Point) r1.points.get(e.sender.getPointIdx());
    1909                
    1910                 if (e instanceof UnicastSendEvent) {
    1911                         long t1 = System.currentTimeMillis();
    1912                         Iterator<SimulatedCarInfo> it = cars.iterator();
    1913                         ReceiveEvent re = null;
    1914                         while (it.hasNext()) {
    1915                                 SimulatedCarInfo r = it.next();
    1916                                 if (r.vehicleId == ((UnicastSendEvent) e).getReceiverId()) {
    1917                                         Road r2 = (Road) Globals.map.roads.get(r.getRealPos()
    1918                                                         .getRoadIdx());
    1919                                         Point p2 = (Point) r2.points.get(r.getRealPos()
    1920                                                         .getPointIdx());
    1921 
    1922                                         // MODIFIED BY CRISTI!!!
    1923                                         // ReceiveEvent er = new ReceiveEvent(e.getTime() + 1, r,
    1924                                         // e.getMessage());
    1925 
    1926                                         re = new ReceiveEvent(e.getTime() + 1, r, e.getMessage(), e.getMessageObject(), e.getMessageType());
    1927                                         re.setUnicast(true);
    1928 
    19291607                                        schedEventEmergency(re);
    19301608                                        if (GPSutil.distance(p1, p2) < WIRELESS_RANGE) {
     
    19541632                       
    19551633
    1956                         long comp = 0;
    1957                         // peanoKeys
    1958                         int cnt2 = 0;
    19591634                        int cnt3 = 0;
    1960                         int cnt4 = 0;
    19611635                        int pkcnt = 0;
    19621636                        PeanoKey pk = Globals.map.peanoKeys.get(p1.getPeanoKeyIdx());
     
    21511825                                        dc.setRealPos(car);
    21521826                                        int t = 1 + random.nextInt(fps / 2 - 5);
    2153                                         schedEvent(new SendEvent(crtTime + t, dc,
    2154                                                         SimulatedCarInfo.STANDARD_MESSAGE_ID));
     1827                                        schedEvent(new SendEvent(crtTime + t, dc,SimulatedCarInfo.STANDARD_MESSAGE_ID));
    21551828                                        cars.add(dc);
    2156                                         dc.init();
     1829                                        dc.init();                                     
    21571830                                }
    21581831                                else
     
    22941967                        Random r;
    22951968                        int randId=0;
    2296                         if(this.simulationProtocol==Globals.PROTOCOL_DSRC)
     1969                        if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC)
    22971970                        {
    22981971                                r=new Random();
     
    23332006                                                car.move();
    23342007
    2335                                                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_SELF_ROUTE) {
     2008                                                if (Engine.simulationType == RoutingConstants.DYNAMIC_SELF_ROUTE) {
    23362009                                                        QueryGeneration.generateQueryForCar(car);
    23372010                                                }
    23382011
    2339                                                 if (this.simulationType == Globals.routePlanConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
     2012                                                if (Engine.simulationType == RoutingConstants.DYNAMIC_INFRASTRUCTURE_ROUTE) {
    23402013                                                        GuidanceRequest.generateRequestToInfrastructure(car);
    23412014                                                }
     
    23472020//                                              Petroaca - emergency messages schedule
    23482021                                               
    2349                                                 if(this.simulationProtocol==Globals.PROTOCOL_DSRC && car.ID==randId && crtTime%50==0)
     2022                                                if(Engine.simulationProtocol==Globals.PROTOCOL_DSRC && car.ID==randId && crtTime%50==0)
    23502023                                                {
    23512024                                                        EmergencyRequest.generateEmergencyMessage(car);
     
    23642037                                                        car.startMonitor = false;
    23652038                                                }
    2366                                                 // 2 hardcoded exits for manhatan
    2367 //                                              if (car.roadIdx == 2 && car.pointIdx < 7)
    2368 //                                                      car.finished = true;
    2369 //                                              if (car.roadIdx == 13 && car.pointIdx < 95)
    2370 //                                                      car.finished = true;
    2371 //                                              if (car.totalDistance > 10){
    2372 //                                                      System.out.println("Fuel: "+ car.em.fc / 1000);
    2373 //                                                      car.finished = true;
    2374 //                                              }
     2039
    23752040                                                car.updateCarToPointMapping();
    23762041                                                 
     
    23922057                                } else {
    23932058                                        // it's still on the same road
    2394                                         newVector
    2395                                                         .addCarInstance(Globals.map.roads.get(j).carsOnThisRoad
    2396                                                                         .get(k));
     2059                                        newVector.addCarInstance(Globals.map.roads.get(j).carsOnThisRoad.get(k));
    23972060                                }
    23982061                                NCARS++;
     
    24052068                        Globals.map.roads.get(j).carsOnThisRoad = newVector;
    24062069                }
    2407 
    2408 //              Iterator it2=cars.iterator();
    2409 //              int countt2=0;
    2410 //             
    2411 //              while(it2.hasNext()) {
    2412 //                      SimulatedCarInfo sci=(SimulatedCarInfo)it2.next();
    2413 //                     
    2414 //                      if(sci.pulseMessage)
    2415 //                              countt2++;
    2416 //              }
    2417 //              System.out.println(" -- "+countt2+" / "+cars.size());
    2418                
     2070       
    24192071               
    24202072                if (!outputToFile)
     
    25052157                                Engine e = Globals.engine = new Engine(false, true);
    25062158                                e.init();
    2507 //                              Thread t = new Thread ( new Runnable(){
    25082159//                                              public void run(){
    25092160//                                                      Globals.demo = new Display();
Note: See TracChangeset for help on using the changeset viewer.