1   package examples.bookTrading;
2   
3   import jade.core.AID;
4   import jade.core.Agent;
5   import jade.domain.DFService;
6   import jade.domain.FIPAException;
7   import jade.domain.FIPAAgentManagement.DFAgentDescription;
8   import jade.domain.FIPAAgentManagement.ServiceDescription;
9   import jade.wrapper.AgentContainer;
10  import jade.wrapper.AgentController;
11  import jade.wrapper.StaleProxyException;
12  
13  import java.sql.Connection;
14  import java.sql.DriverManager;
15  import java.sql.PreparedStatement;
16  import java.sql.ResultSet;
17  import java.sql.SQLException;
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.ListIterator;
22  import java.util.Map;
23  import java.util.Map.Entry;
24  import java.util.Set;
25  import java.util.StringTokenizer;
26  import java.util.concurrent.ConcurrentHashMap;
27  
28  import de.uni_stuttgart.informatik.canu.mobisim.core.Position3D;
29  import de.uni_stuttgart.informatik.canu.mobisim.core.Universe;
30  import de.uni_stuttgart.informatik.canu.mobisim.notifications.RouteChoiceNotification;
31  import de.uni_stuttgart.informatik.canu.senv.core.Vertex;
32  import de.uni_stuttgart.informatik.canu.uomm.CommunicationsManager;
33  
34  /**
35   * This user-defined Java class is a helper class. It consists of helper methods
36   * to store preference details of the agents in a communication group, to
37   * evaluate cost of the route allocation and to maintain the status of agent
38   * communication operations.
39   * 
40   * @author prajakta
41   * 
42   */
43  public class QueueManager extends Thread {
44      private static ArrayList agentUsingRoad = new ArrayList<Agent>();
45      private static ConcurrentHashMap agentsInTheSystem = new ConcurrentHashMap();
46      private static ConcurrentHashMap agentPreferences = new ConcurrentHashMap();
47      private static ArrayList agentsWithPriority = new ArrayList();
48      private static DFAgentDescription dfd = new DFAgentDescription();
49      private static ServiceDescription sd = new ServiceDescription();
50      public static ConcurrentHashMap agentMap = new ConcurrentHashMap();
51      public static ConcurrentHashMap agentNameMap = new ConcurrentHashMap();
52      public static ConcurrentHashMap outOfPathAgents = new ConcurrentHashMap();
53      public static ConcurrentHashMap samePathAgents = new ConcurrentHashMap();
54      public static ConcurrentHashMap priorityPaths = new ConcurrentHashMap();
55      public static ConcurrentHashMap myPrefSentList = new ConcurrentHashMap();
56      public static ConcurrentHashMap savedPath = new ConcurrentHashMap();
57      public static ConcurrentHashMap communicatingVehMaps = new ConcurrentHashMap();
58      public static ConcurrentHashMap recordEvalInfo = new ConcurrentHashMap();
59      public static ConcurrentHashMap participatingNodes = new ConcurrentHashMap();
60  
61      public static ConcurrentHashMap recordSentRouteHash = new ConcurrentHashMap();
62      public static ConcurrentHashMap recordSentRouteCFP = new ConcurrentHashMap();
63      public static ConcurrentHashMap finalRouteAlloc = new ConcurrentHashMap();
64      public static ConcurrentHashMap finalCommAlloc = new ConcurrentHashMap();
65      private static Agent a;
66      private static Connection c = null;
67      private static CondVariable startUpLatch = new CondVariable();
68      private static CondVariable mssgQueue = new CondVariable();
69      private static ConcurrentHashMap<String, ArrayList> routeChoiceMap = new ConcurrentHashMap<String, ArrayList>();
70  
71      public static CondVariable getMssgQueue() {
72          return mssgQueue;
73      }
74  
75      public static void setMssgQueue(CondVariable mssgQueue) {
76          QueueManager.mssgQueue = mssgQueue;
77      }
78  
79      private static AgentInteractionModel interMod = new AgentInteractionModel();
80      private static ArrayList<AgentInteractionModel> agentInteractionModelList = new ArrayList<AgentInteractionModel>();
81      static Universe uni = Universe.getReference();
82  
83      private static ConcurrentHashMap agentRouteChoice = new ConcurrentHashMap();
84      public static ConcurrentHashMap routeChoiceMapFlag = new ConcurrentHashMap();
85      public static ArrayList otherPossibleRoutes = new ArrayList();
86  
87      public static ArrayList getOtherPossibleRoutes() {
88          return otherPossibleRoutes;
89      }
90  
91      public static void setOtherPossibleRoutes(ArrayList otherPossibleRoutes) {
92          QueueManager.otherPossibleRoutes = otherPossibleRoutes;
93      }
94  
95      public static int cfpMsgSaved = 0;
96      public static int routeChoiceMsgSaved = 0;
97  
98      private static boolean simNoticeFlag = false;
99      private static ArrayList obtainedList = null;
100 
101     public static synchronized boolean isSimNoticeFlag(
102            CommunicatingVehicles vehMaps) {
103         return vehMaps.isSimNoticeFlag();
104     }
105 
106     public static synchronized void setSimNoticeFlag(boolean simNoticeFlagval) {
107         simNoticeFlag = simNoticeFlagval;
108     }
109 
110     public static boolean shortestRouteFlag = false;
111 
112     public static ConcurrentHashMap myCheckList = new ConcurrentHashMap();
113 
114     public synchronized static boolean doneFinalAlloc(String agentID,
115             String congSeg) {
116         String rtStr = null;
117         if (finalRouteAlloc != null) {
118             Object congID = finalRouteAlloc.get(agentID);
119 
120             if (congID == null) {
121                 // System.out.println("Query status FALSE  CONGID NULL Final Alloc in QM: "+agentID+" for "+congSeg);
122                 return false;
123             } else {
124                 rtStr = congID.toString();
125                 if (rtStr != null && rtStr.equals(congSeg)) {
126                     // System.out.println("Query status TRUE Final Alloc in QM: "+agentID+" for "+congSeg);
127                     return true;
128                 } else if (congSeg != null && agentID != null) {
129                     // System.out.println("Query status FALSE ELSE IF Final Alloc in QM: "+agentID+" for "+congSeg);
130                     return false;
131                 } else {
132                     // System.out.println("Query status FALSE ELSE Final Alloc in QM: "+agentID+" for "+congSeg);
133                     return false;
134                 }
135             }
136 
137         }
138         System.out.println("Query status TRUE BY DEFAULT Final Alloc in QM: "
139                 + agentID + " for " + congSeg);
140         return true;
141     }
142 
143     /**
144      * This method is used to retrieve the communication status
145      * 
146      * @param commID
147      *            - communication ID
148      * @param congSeg
149      *            - congested segment
150      * @return true, if the final allocation is complete else returns false
151      */
152     public synchronized static boolean doneFinalCommAlloc(String commID,
153             String congSeg) {
154         String rtStr = null;
155         if (finalCommAlloc != null) {
156             Object congID = finalCommAlloc.get(commID);
157 
158             if (congID == null) {
159                 return false;
160             } else {
161                 rtStr = congID.toString();
162                 if (rtStr != null && rtStr.equals(congSeg)) {
163                     // System.out.println("Query status TRUE Final Alloc in QM: "+agentID+" for "+congSeg);
164                     return true;
165                 } else if (congSeg != null && commID != null) {
166                     // System.out.println("Query status FALSE ELSE IF Final Alloc in QM: "+agentID+" for "+congSeg);
167                     return false;
168                 } else {
169                     // System.out.println("Query status FALSE ELSE Final Alloc in QM: "+agentID+" for "+congSeg);
170                     return false;
171                 }
172             }
173         }
174         System.out.println("Query status TRUE BY DEFAULT Final Alloc in QM: "
175                 + commID + " for " + congSeg);
176         return true;
177     }
178 
179     public synchronized static void doFinalAlloc(String agentID, String congSeg) {
180         if (congSeg != null && agentID != null) {
181             System.out.println("Adding Alloc in QM: " + agentID + " for "
182                     + congSeg);
183             finalRouteAlloc.put(agentID, congSeg);
184         }
185     }
186 
187     /**
188      * This method is used to do final allocation for communication ID
189      * 
190      * @param commID
191      *            communication ID
192      * @param congSeg
193      *            congested segment ID
194      */
195     public synchronized static void doFinalAllocationfForCommunicationID(
196             String commID, String congSeg) {
197         if (congSeg != null && commID != null) {
198             System.out.println("Adding Alloc in QM: " + commID + " for "
199                     + congSeg);
200             finalCommAlloc.put(commID, congSeg);
201         }
202     }
203 
204     public synchronized static void addToMyCheckList(String name, int size,
205             String communicID, double utility, int agtCnt) {
206         if (size == Constants.VEHICLESEED) {
207             myCheckList.put(name, size);
208         }
209     }
210 
211     /**
212      * This method returns the status of the agents
213      * 
214      * @param communicID
215      *            communication ID
216      * @param agtCnt
217      * @return
218      */
219     public static boolean allAgentsRcd(String communicID, int agtCnt) {
220         int finalCnt = Constants.VEHICLESEED;
221         int myCnt = 0;
222         Object sizeObj = null;
223         for (int i = 0; i < finalCnt; i++) {
224             sizeObj = myCheckList.get("#" + i);
225             if (sizeObj != null) {
226                 myCnt = Integer.parseInt(sizeObj.toString());
227                 if (myCnt != finalCnt) {
228                     return false;
229                 }
230             } else {
231                 return false;
232             }
233         }
234         // System.out.println("Retruning true for "+finalCnt);
235         return true;
236     }
237 
238     /**
239      * This method is used to send the init preferences
240      * 
241      * @param myVehicleID
242      *            list of vehicle IDs
243      * @param sellerAgents
244      *            details of seller agents
245      * @return agent identifier details
246      */
247     public static synchronized AID[] sentInitPrefTo(String myVehicleID,
248             AID[] sellerAgents) {
249         ArrayList recList = new ArrayList();
250         if (myPrefSentList != null && sellerAgents != null) {
251             AID[] receivers = new AID[sellerAgents.length];
252 
253             Object myPref = myPrefSentList.get(myVehicleID);
254 
255             if (myPref != null) {
256                 String str = myPrefSentList.get(myVehicleID).toString();
257                 for (int i = 0; i < sellerAgents.length; i++) {
258                     if (str.indexOf(sellerAgents[i].getLocalName()) <= -1) {
259                         recList.add(sellerAgents[i]);
260                     } else {
261                         str.concat(sellerAgents[i].getLocalName());
262                         myPrefSentList.put(myVehicleID, str);
263                     }
264                 }
265             }
266         }
267         AID[] newArray = new AID[myPrefSentList.size()];
268 
269         return (AID[]) recList.toArray(newArray);
270 
271     }
272 
273     /**
274      * This method returns the processing status of the ommunicting and
275      * negotiating agents
276      * 
277      * @param sellerAgents
278      *            - agent IDs of the seller agents
279      * @param communicID
280      *            - communication ID
281      * @return processing status - true, if processing is to continue else false
282      */
283     public synchronized static boolean continueProcessing(AID[] sellerAgents,
284             String communicID) {
285         boolean routeChoiceMapFlagForID = false;
286         int cnt = 0;
287         if (routeChoiceMapFlag.get(communicID) != null
288                 && routeChoiceMapFlag.get("Count") != null) {
289             routeChoiceMapFlagForID = (Boolean) routeChoiceMapFlag
290                     .get(communicID);
291             cnt = (Integer) routeChoiceMapFlag.get("Count");
292         }
293         if (routeChoiceMapFlag != null && routeChoiceMapFlagForID) {
294             if (cnt == (sellerAgents.length) * 0.8)
295                 return false;
296             else
297                 return true;
298         } else if (shortestRouteFlag) {
299             return false;
300         } else
301             return true;
302     }
303 
304     public synchronized static boolean compareAgents(AID[] sellerAgents,
305             ConcurrentHashMap routeMap) {
306         boolean allAgentsProcessed = false;
307         for (int i = 0; i < sellerAgents.length; i++) {
308             if (routeMap.get(sellerAgents[i].getLocalName()) == null) {
309 
310                 allAgentsProcessed = true;
311                 break;
312             } else
313                 allAgentsProcessed = false;
314 
315         }
316         return allAgentsProcessed;
317     }
318 
319     /**
320      * This method returns the database connection details
321      * 
322      * @return db connection
323      */
324     public synchronized static Connection getConnection() {
325 
326         try {
327             if (c == null) {
328                 Class.forName("org.hsqldb.jdbcDriver");
329                 c = DriverManager.getConnection(
330                         "jdbc:hsqldb:hsql://localhost/xdb/", "sa", "");
331             }
332 
333         } catch (Exception e) {
334             System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
335             e.printStackTrace();
336         }
337 
338         return c;
339     }
340 
341     /**
342      * This method returns the agent interaction details
343      * 
344      * @param modelToAdd
345      */
346     public synchronized static void addToAgentInteractionList(
347             AgentInteractionModel modelToAdd) {
348         ArrayList<AgentInteractionModel> agentInteractionModelListCpy = new ArrayList<AgentInteractionModel>();
349         String agentKey;
350         AgentInteractionModel model;
351         ListIterator<AgentInteractionModel> iter = (ListIterator<AgentInteractionModel>) agentInteractionModelList
352                 .listIterator();
353         synchronized (iter) {
354 
355             if (agentInteractionModelList.size() == 0) {
356                 agentInteractionModelList.add(modelToAdd);
357             } else {
358 
359                 while (iter.hasNext()) {
360                     model = iter.next();
361                     if (model != null
362                             && modelToAdd != null
363                             && (model.getSenderAgent() != null && model
364                                     .getRecAgent() != null)) {
365 
366                         if (model.getSenderAgent().equals(
367                                 modelToAdd.getSenderAgent())
368                                 && model.getRecAgent().equals(
369                                         modelToAdd.getRecAgent())) {
370                             agentInteractionModelListCpy.remove(model);
371                             agentInteractionModelListCpy.add(modelToAdd);
372                         } else {
373                             agentInteractionModelListCpy.add(modelToAdd);
374                         }
375                     }
376                 }
377                 agentInteractionModelList = agentInteractionModelListCpy;
378             }
379         }
380         // agentInteractionModelList.add(modelToAdd);
381 
382     }
383 
384     public synchronized static AgentInteractionModel getAgentInteractionModel(
385             AID sender, AID rec) {
386         String agentKey;
387         AgentInteractionModel model = null;
388         ListIterator<AgentInteractionModel> iter = (ListIterator<AgentInteractionModel>) agentInteractionModelList
389                 .listIterator();
390         synchronized (agentInteractionModelList) {
391             if (agentInteractionModelList.size() == 0) {
392                 return model;
393             } else {
394                 while (iter.hasNext()) {
395                     model = iter.next();
396                     if (model != null) {
397                         if (model.getSenderAgent().equals(sender)) {
398                             return model;
399                         }
400                     }
401                 }
402             }
403         }
404 
405         return null;
406 
407     }
408 
409     public static ArrayList<AgentInteractionModel> getAgentList() {
410         return agentInteractionModelList;
411     }
412 
413     public static void setAgentList(ArrayList<AgentInteractionModel> agentList) {
414         agentInteractionModelList = agentList;
415     }
416 
417     public static CondVariable getStartUpLatch() {
418         return startUpLatch;
419     }
420 
421     public static void setStartUpLatch(CondVariable startUpLatch) {
422         startUpLatch = startUpLatch;
423     }
424 
425     public static Agent getA() {
426         return a;
427     }
428 
429     public static void setA(Agent ag) {
430         a = ag;
431     }
432 
433     private static CondVariable objLock = new CondVariable();
434     private static ConcurrentHashMap rcdRsponse = new ConcurrentHashMap();
435 
436     public static CondVariable getObjLock() {
437         return objLock;
438     }
439 
440     public static void setObjLock(CondVariable objectLock) {
441         objLock = objectLock;
442     }
443 
444     public synchronized static DFAgentDescription registerAgent(Agent thisAgent) {
445         dfd.setName(thisAgent.getAID());
446         ServiceDescription sd = new ServiceDescription();
447         sd.setType("traffic");
448         sd.setName("JADE-traffic-mngt");
449 
450         dfd.addServices(sd);
451         try {
452             DFService.register(thisAgent, dfd);
453         } catch (FIPAException fe) {
454             fe.printStackTrace();
455         }
456 
457         return dfd;
458     }
459 
460     /**
461      * This method is used to add agent to the system
462      * 
463      * @param r
464      */
465     public synchronized static void addAgent(Object r) {
466         // System.out.println("####adding agent : "+a.getLocalName());
467         agentUsingRoad.add(a);
468         synchronized (r) {
469             try {
470                 addUpdateAgentDetails(a.getLocalName(), 1000);
471                 
472                 sleep(6000);
473             } catch (InterruptedException e) {
474                 // TODO Auto-generated catch block
475                 e.printStackTrace();
476             }
477             removeAgent();
478         }
479 
480     }
481 
482     /**
483      * This method is used to remove the agent
484      */
485     public synchronized static void removeAgent() {
486         String agentKey;
487         int agentTime;
488         agentUsingRoad.remove(a);
489         System.out.println("AGENT  " + a.getLocalName()
490                 + " REACHED END OF THE ROAD ");
491         Set entries = agentsInTheSystem.entrySet();
492         if (entries != null && !entries.isEmpty()) {
493             for (Iterator it = entries.iterator(); it.hasNext();) {
494                 Map.Entry entry = (Entry) it.next();
495                 agentKey = (String) entry.getKey();
496                 agentTime = Integer.parseInt(entry.getValue().toString());
497 
498                 if (agentKey.equals(a)) {
499                     agentsInTheSystem.remove(agentKey);
500                 }
501             }
502         }
503         try {
504             DFService.deregister(a);
505         } catch (FIPAException e) {
506             // TODO Auto-generated catch block
507             e.printStackTrace();
508         }
509         a = null;
510 
511     }
512 
513     /**
514      * This method is used to update agent details
515      * 
516      * @param newAgent
517      * @param time
518      */
519     public synchronized static void addUpdateAgentDetails(String newAgent,
520             int time) {
521 
522         String agentKey;
523         int agentTime;
524         Set entries = agentsInTheSystem.entrySet();
525         synchronized (entries) {
526             if (entries != null && !entries.isEmpty()) {
527                 for (Iterator it = entries.iterator(); it.hasNext();) {
528                     synchronized (it) {
529                         Map.Entry entry = (Entry) it.next();
530                         agentKey = (String) entry.getKey();
531                         agentTime = Integer.parseInt(entry.getValue()
532                                 .toString());
533                         if (agentKey.equals(newAgent)) {
534                             agentsInTheSystem.put(agentKey, time);
535                             // updateDB(agentKey, time);
536                         } else {
537                             agentsInTheSystem.put(newAgent, time);
538                             // updateDB(newAgent, time);
539                         }
540                     }
541                 }
542             } else {
543                 agentsInTheSystem.put(newAgent, time);
544                 // updateDB(newAgent, time);
545             }
546         }
547     }
548 
549     /**
550      * This method is used to update the database details
551      * @param agentKey agent name
552      * @param time
553      */
554     private synchronized static void updateDB(String agentKey, int time) {
555         try {
556             Class.forName("org.hsqldb.jdbcDriver");
557         } catch (Exception e) {
558             System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
559             e.printStackTrace();
560             return;
561         }
562 
563         try {
564             Connection c = DriverManager.getConnection(
565                     "jdbc:hsqldb:hsql://localhost/xdb/", "sa", "");
566             PreparedStatement st = null;
567             String[] args = new String[] { agentKey,
568                     (new Integer(time).toString()) };
569             String sql = "INSERT INTO sample_table(str_col,num_col) VALUES(?, ?)";
570             st = c.prepareStatement("INSERT INTO sample_table(str_col,num_col) VALUES(?, ?)");
571             st.setString(1, agentKey);
572             st.setInt(2, time);
573             st.execute();
574             st.close();
575         } catch (SQLException e) {
576             // TODO Auto-generated catch block
577             e.printStackTrace();
578         }
579 
580     }
581 
582     /**
583      * This method is used to add/update agent preferences
584      * @param newAgentPref new agent preferences
585      * @param pref
586      */
587     public synchronized static void addUpdateAgentPreferences(
588             String newAgentPref, String pref) {
589 
590         String agentPrefKey;
591         String agentPrefTime;
592 
593         Set entries = agentPreferences.entrySet();
594         synchronized (entries) {
595             if (entries != null && !entries.isEmpty()) {
596 
597                 for (Iterator it = entries.iterator(); it.hasNext();) {
598                     synchronized (entries) {
599                         Map.Entry entry = (Entry) it.next();
600                         agentPrefKey = (String) entry.getKey();
601                         agentPrefTime = entry.getValue().toString();
602                         if (agentPrefKey.equals(newAgentPref)) {
603                             agentPreferences.remove(agentPrefKey);
604                         }
605                         agentPreferences.put(newAgentPref, pref);
606 
607                     }
608                 }
609             } else {
610                 agentPreferences.put(newAgentPref, pref);
611 
612             }
613         }
614     }
615 
616     
617     public synchronized static int getAgentPositions(String searchAgent) {
618         String agentKey;
619         int agentTime = 0;
620         Set entries = agentsInTheSystem.entrySet();
621 
622         if (!entries.isEmpty()) {
623             for (Iterator it = entries.iterator(); it.hasNext();) {
624                 Map.Entry entry = (Entry) it.next();
625                 agentKey = (String) entry.getKey();
626                 agentTime = Integer.parseInt(entry.getValue().toString());
627                 if (agentKey.equals(searchAgent)) {
628                     break;
629                 }
630 
631             }
632         }
633         return agentTime;
634     }
635 
636     public synchronized static String getAgentPreferences(String searchAgentPref) {
637         String agentKeyPref;
638         String agentPref = null;
639         Set entries = agentPreferences.entrySet();
640 
641         if (!entries.isEmpty()) {
642             for (Iterator it = entries.iterator(); it.hasNext();) {
643                 Map.Entry entry = (Entry) it.next();
644                 agentKeyPref = (String) entry.getKey();
645                 agentPref = (entry.getValue().toString());
646                 if (agentKeyPref.equals(searchAgentPref)) {
647                     break;
648                 }
649 
650             }
651         }
652         return agentPref;
653     }
654 
655     public synchronized static String agentPriorityMapOperations(
656             String agentKey, int operation) {
657 
658         // 0:GET
659         // 1:ADD
660         // 2:remove
661         String priKey;
662         Iterator iter = agentsWithPriority.iterator();
663         boolean flag = false;
664         while (iter != null && iter.hasNext()) {
665 
666             priKey = (String) iter.next();
667             if (priKey != null && priKey.equals(agentKey)) {
668 
669                 flag = true;
670 
671                 if (operation == 2) {
672                     agentsWithPriority.remove(agentKey);
673                     return null;
674                 } else if (operation == 0) {
675                     return agentKey;
676                 }
677 
678             }
679         }
680 
681         System.out.println("()()()()()()()()(ENTRIES ADDED FOR" + agentKey);
682         if (!flag) {
683             System.out.println("(C)(H)(E)(C)(K)(I)(N)(G)(fLAG" + flag);
684             agentsWithPriority.add(agentKey);
685         }
686 
687         return null;
688     }
689 
690     public synchronized static void addNegoAgentToMap(Agent agentt) {
691         // Register the vehicle agent service in the yellow pages
692         /*
693          * DFAgentDescription dfd = new DFAgentDescription();
694          * dfd.setName(agt.getAID()); ServiceDescription sd = new
695          * ServiceDescription(); sd.setType("traffic");
696          * sd.setName("JADE-traffic-mngt"); dfd.addServices(sd); try {
697          * DFService.register(agt, dfd); } catch (FIPAException fe) {
698          * fe.printStackTrace(); }
699          */
700         agentMap.put(agentt.getLocalName(), agentt);
701     }
702 
703     public static NegotiatingAgents getNegoAgent(String agtName) {
704         Set entries = agentMap.entrySet();
705         NegotiatingAgents ag = null;
706         if (entries != null && !entries.isEmpty()) {
707             for (Iterator it = entries.iterator(); it.hasNext();) {
708                 Map.Entry entry = (Entry) it.next();
709                 String agentName = (String) entry.getKey().toString();
710                 if (agentName != null && agentName.equals(agtName))
711 
712                 {
713                     ag = (NegotiatingAgents) (entry.getValue());
714                     break;
715                 }
716 
717             }
718         }
719         return ag;
720     }
721 
722     public synchronized static void addAgentToMap(Agent agentt) {
723         // Register the vehicle agent service in the yellow pages
724         /*
725          * DFAgentDescription dfd = new DFAgentDescription();
726          * dfd.setName(agt.getAID()); ServiceDescription sd = new
727          * ServiceDescription(); sd.setType("traffic");
728          * sd.setName("JADE-traffic-mngt"); dfd.addServices(sd); try {
729          * DFService.register(agt, dfd); } catch (FIPAException fe) {
730          * fe.printStackTrace(); }
731          */
732         agentMap.put(agentt.getLocalName(), agentt);
733     }
734 
735     /**
736      * This method is used to retieve the agent based on agent name
737      * @param agtName agent name
738      * @return NegotiatingVehicleAgent information
739      */
740     public static NegotiatingVehicleAgent getAgent(String agtName) {
741         Set entries = agentMap.entrySet();
742         NegotiatingVehicleAgent ag = null;
743         if (entries != null && !entries.isEmpty()) {
744             for (Iterator it = entries.iterator(); it.hasNext();) {
745                 Map.Entry entry = (Entry) it.next();
746                 String agentName = (String) entry.getKey().toString();
747                 if (agentName != null && agentName.equals(agtName))
748 
749                 {
750                     ag = (NegotiatingVehicleAgent) (entry.getValue());
751                     break;
752                 }
753 
754             }
755         }
756         return ag;
757     }
758 
759     public static int getAgentMapSize() {
760         if (agentMap != null)
761             return agentMap.size();
762         else
763             return 0;
764     }
765 
766     public synchronized static void registerRouteChoice(String agentName,
767             String pref) {
768         String agentPrefKey;
769         String agentPrefTime;
770         if (agentRouteChoice != null) {
771             Set entries = agentRouteChoice.entrySet();
772             boolean entryFound = true;
773             synchronized (entries) {
774                 if (entries != null && !entries.isEmpty()) {
775                     System.out.println("><><><><><><><><<ENTRIES NOT NULL FOR"
776                             + pref);
777                     for (Iterator it = entries.iterator(); it.hasNext();) {
778                         Map.Entry entry = (Entry) it.next();
779                         agentPrefKey = (String) entry.getKey();
780                         agentPrefTime = entry.getValue().toString();
781                         // System.out.println("agentKey: "+agentKey+"agentValue: "+agentTime);
782 
783                         if (agentPrefKey.equals(agentName)) {
784 
785                             agentRouteChoice.remove(agentName);
786                         }
787                         agentRouteChoice.put(agentName, pref);
788 
789                     }
790                 } else {
791 
792                     agentRouteChoice.put(agentName, pref);
793                 }
794             }
795 
796         }
797 
798     }
799 
800     public synchronized static void frameRouteChoice(String cmID, int cnt) {
801         String agentCommID;
802         int numberOfAgents = 0;
803         Set entries = agentRouteChoice.entrySet();
804         synchronized (entries) {
805 
806             for (Iterator it = entries.iterator(); it.hasNext();) {
807                 Map.Entry entry = (Entry) it.next();
808 
809                 agentCommID = entry.getValue().toString();
810                 // System.out.println("agentKey: "+agentKey+"agentValue: "+agentTime);
811 
812                 if (agentCommID != null && agentCommID.equals(cmID)) {
813                     numberOfAgents++;
814                 }
815             }
816             if (numberOfAgents == cnt) {
817                 if (uni != null) {
818                     // System.out.println("U%%%%%niv%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%erse found with "+cnt+
819                     // " agents !!");
820                     uni.sendNotification(new RouteChoiceNotification(
821                             "QueueManager", uni, false));
822                 } else {
823                     System.out.println("Universe not found!!");
824                 }
825             } else {
826                 // System.out.println("Waiting for remaining preferences");
827             }
828         }
829 
830     }
831 
832     /**
833      * This method creates new agents
834      * @param ac agent container
835      * @param agentName name of the agent
836      * @param className name of the class
837      * @param args init params to pass a new agent
838      * @return agent container
839      */
840     public synchronized static AgentController createNewAgent(
841             AgentContainer ac, String agentName, String className, Object[] args) {
842         AgentController agentController = null;
843         try {
844             String retAgent = getAgentName(agentName);
845             if (retAgent == null) {
846                 agentController = ac.createNewAgent(agentName, className, args);
847                 addAgentNameToMap(agentName);
848             }
849 
850             else
851                 return null;
852             // if(agentController!=null)
853 
854         } catch (StaleProxyException e) {
855             // TODO Auto-generated catch block
856             e.printStackTrace();
857 
858         }
859 
860         return agentController;
861     }
862 
863     public synchronized static void addAgentNameToMap(String agentt) {
864         // Register the vehicle agent service in the yellow pages
865         /*
866          * DFAgentDescription dfd = new DFAgentDescription();
867          * dfd.setName(agt.getAID()); ServiceDescription sd = new
868          * ServiceDescription(); sd.setType("traffic");
869          * sd.setName("JADE-traffic-mngt"); dfd.addServices(sd); try {
870          * DFService.register(agt, dfd); } catch (FIPAException fe) {
871          * fe.printStackTrace(); }
872          */
873         agentNameMap.put(agentt, agentt);
874     }
875 
876     public static String getAgentName(String agtName) {
877         Set entries = agentNameMap.entrySet();
878         String ag = null;
879         if (entries != null && !entries.isEmpty()) {
880             for (Iterator it = entries.iterator(); it.hasNext();) {
881                 Map.Entry entry = (Entry) it.next();
882                 String agentName = (String) entry.getKey().toString();
883                 if (agentName != null && agentName.equals(agtName))
884 
885                 {
886                     ag = (String) (entry.getValue());
887                     break;
888                 }
889 
890             }
891         }
892         return ag;
893     }
894 
895     public static boolean getRouteChoice(ConcurrentHashMap regVehicleInfo,
896             String communicID, int length) {
897         PreferenceUtilityIndex rcdMssg;
898         int numberOfAgents = 0;
899         Set entries = regVehicleInfo.entrySet();
900         String agentName = null;
901         synchronized (entries) {
902 
903             for (Iterator it = entries.iterator(); it.hasNext();) {
904                 Map.Entry entry = (Entry) it.next();
905                 rcdMssg = (PreferenceUtilityIndex) entry.getValue();
906                 agentName = (String) entry.getKey();
907                 if (rcdMssg != null && rcdMssg.getCommID().equals(communicID)) {
908                     numberOfAgents++;
909                     // System.out.println("Agent registered "+agentName+"is "+rcdMssg.getB1Val()+rcdMssg.getB2Val()+rcdMssg.getB3Val()+rcdMssg.getB4Val()+rcdMssg.getB5Val());
910                 }
911             }
912             numberOfAgents = numberOfAgents + outOfPathAgents.size();
913 
914             if (numberOfAgents == length + 1) {
915                 if (uni != null) {
916                     routeChoiceMapFlag.put(communicID, true);
917                     routeChoiceMapFlag.put("Count", numberOfAgents);
918                 } else {
919                     System.out.println("Universe not found!!");
920                 }
921 
922                 return true;
923             } else {
924                 routeChoiceMapFlag.put(communicID, false);
925                 // System.out.println("Waiting for remaining preferences");
926                 return false;
927             }
928         }
929 
930     }
931 
932     public static boolean getRouteChoiceNegAgent(String invokingAgent, ConcurrentHashMap regVehicleInfo, String communicID, int length) {
933         PreferenceUtilityIndex rcdMssg;
934         int numberOfAgents = 0;
935         Set entries = regVehicleInfo.entrySet();
936         String agentName = null;
937         synchronized (entries) {
938 
939             for (Iterator it = entries.iterator(); it.hasNext();) {
940                 Map.Entry entry = (Entry) it.next();
941                 rcdMssg = (PreferenceUtilityIndex) entry.getValue();
942                 agentName = (String) entry.getKey();
943                 if (rcdMssg != null && rcdMssg.getCommID().equals(communicID)) {
944                     numberOfAgents++;
945                     // System.out.println("Agent registered "+agentName+"is "+rcdMssg.getB1Val()+rcdMssg.getB2Val()+rcdMssg.getB3Val()+rcdMssg.getB4Val()+rcdMssg.getB5Val());
946                 }
947             }
948             numberOfAgents = numberOfAgents + outOfPathAgents.size();
949 
950             if (numberOfAgents == length + 1) {
951                 if (uni != null) {
952                     // System.out.println("U%%%%%niv%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%erse found with "+numberOfAgents+
953                     // " agents !!");
954                     // uni.sendNotification(new
955                     // RouteChoiceNotification("QueueManager",uni,true));
956                     // routeChoiceMapFlag = true;
957                     routeChoiceMapFlag.put(communicID, true);
958                     routeChoiceMapFlag.put("Count", numberOfAgents);
959                 } else {
960                     System.out.println("Universe not found!!");
961                 }
962                 // System.out.println("Returning true by "+invokingAgent);
963                 return true;
964             } else {
965                 routeChoiceMapFlag.put(communicID, false);
966                 // System.out.println("Waiting for remaining preferences");
967                 return false;
968             }
969         }
970 
971     }
972 
973     public static synchronized ConcurrentHashMap<String, ArrayList> getRouteChoiceMap() {
974         return routeChoiceMap;
975     }
976 
977     /**
978      * This method is used to set the route choice
979      * @param routeChoice map of route choices
980      * @param commString communication ID
981      * @param cvMaps map of vehicle information
982      */
983     public static synchronized void setRouteChoice(ConcurrentHashMap routeChoice, String commString,
984             CommunicatingVehicles cvMaps) {
985         String tempSegmentList = "";
986         ArrayList<Vertex> verticesList = new ArrayList<Vertex>();
987         Set routeEntries = routeChoice.entrySet();
988         double complianceDegree = 0.0;
989         int count = 1;
990         String congRt = null;
991 
992         // if not null routeChoiceMap
993         if (!shortestRouteFlag && routeChoice != null && routeChoice.size() > 0) {
994             System.out
995                     .println("Route choice is not null for the cogested segment : "
996                             + commString);
997             for (Iterator i = routeEntries.iterator(); i.hasNext();) {
998                 Map.Entry entry = (Entry) i.next();
999                 String agtName = (String) entry.getKey();
1000                String vPath = (String) entry.getValue();
1001
1002                System.out.println("Sending it to simulator.." + vPath
1003                        + " for " + agtName);
1004                if (vPath.equals("1")) {
1005                    tempSegmentList = "s1,s2,s4,s5,s6,s52,s7,s8,s9,s10,s11,s32,s17,s18,s19,s22";
1006                } else if (vPath.equals("2"))
1007                    tempSegmentList = "s1,s45,s3,s37,s46,s50,s51,s42,s27,s30,s31,s32,s17,s18,s19,s22";
1008                else if (vPath.equals("3"))
1009                    tempSegmentList = "s2,s23,s24,s25,s26,s27,s30,s31,s32,s17,s18,s19,s22";
1010                if (vPath.equals("4")) {
1011                    tempSegmentList = "s2,s4,s5,s6,s52,s7,s8,s9,s10,s11,s32,s17,s18,s19,s22";
1012                }
1013                if (vPath.equals("5")) {
1014                    tempSegmentList = "s24,s53,s52,s7,s8,s9,s10,s12,s13,s17,s18,s19,s22";
1015                }
1016                if (vPath.equals("6")) {
1017                    tempSegmentList = "s24,s25,s26,s27,s30,s31,s32,s17,s18,s19,s22";
1018                }
1019                if (vPath.equals("7")) {
1020                    tempSegmentList = "s37,s38,s39,s40,s43,s54,s55,s17,s18,s19,s22";
1021                }
1022                if (vPath.equals("8")) {
1023                    tempSegmentList = "s37,s46,s50,s51,s42,s27,s30,s31,s32,s17,s18,s19,s22";
1024                }
1025                if (vPath.equals("9")) {
1026                    tempSegmentList = "s40,s43,s54,s55,s17,s18,s19,s22";
1027                }
1028                if (vPath.equals("10")) {
1029                    tempSegmentList = "s40,s41,s42,s27,s30,s31,s32,s17,s18,s19,s22";
1030                }
1031                if (vPath.equals("11")) {
1032                    tempSegmentList = "s43,s44,s30,s31,s32,s17,s18,s19,s22";
1033                }
1034                if (vPath.equals("12")) {
1035                    tempSegmentList = "s43,s54,s55,s17,s18,s19,s22";
1036                }
1037                if (vPath.equals("13")) {
1038                    tempSegmentList = "s27,s30,s31,s32,s17,s18,s19,s22";
1039                }
1040                if (vPath.equals("14")) {
1041                    tempSegmentList = "s27,s28,s29,s8,s9,s10,s12,s13,s17,s18,s19,s22";
1042                }
1043                if (vPath.equals("15")) {
1044                    tempSegmentList = "s10,s12,s13,s17,s18,s19,s22";
1045                }
1046                if (vPath.equals("16")) {
1047                    tempSegmentList = "s10,s14,s15,s16,s13,s17,s18,s19,s22";
1048                }
1049                if (vPath.equals("17")) {
1050                    tempSegmentList = "s17,s18,s19,s22";
1051                }
1052                if (vPath.equals("18")) {
1053                    tempSegmentList = "s17,s18,s20,s21,s22";
1054                }
1055                if (vPath.equals("21")) {
1056                    tempSegmentList = "s2,s4,s5,s6,s52,s7,s8,s9,s10,s12,s13,s17,s18,s19,s22";
1057                }
1058                if (vPath.equals("22")) {
1059                    tempSegmentList = "s2,s23,s24,s25,s26,s27,s30,s31,s32,s17,s18,s19,s22";
1060                }
1061                if (vPath.equals("23")) {
1062                    tempSegmentList = "s2,s47,s48,s58,s57,s40,s43,s54,s55,s17,s18,s19,s22";
1063                }
1064                if (vPath.equals("24")) {
1065                    tempSegmentList = "s31,s11,s12,s13,s17,s18,s19,s22";
1066                }
1067                if (vPath.equals("25")) {
1068                    tempSegmentList = "s31,s32,s17,s18,s19,s22";
1069                }
1070                if (vPath.equals("26")) {
1071                    tempSegmentList = "s11,s12,s13,s17,s18,s19,s22";
1072                }
1073                if (vPath.equals("27")) {
1074                    tempSegmentList = "s11,s14,s15,s16,s13,s17,s18,s19,s22";
1075                }
1076                /*
1077                 * if(vPath.equals("19")){ tempSegmentList =
1078                 * "s81,s82,s83,s84,s35,s36,s37,s38";}
1079                 */
1080                verticesList = getPathVertex(tempSegmentList, agtName);
1081                System.out.println("ROUTE CHOICE MAP CONTAINS : " + agtName
1082                        + " " + vPath);
1083
1084                if (cvMaps != null) {
1085                    congRt = cvMaps.getPathID();
1086                    retrieveAndUpdateParticipatingNodes(congRt, agtName, "ADD");
1087                }
1088
1089                routeChoiceMap.put(agtName, verticesList);
1090
1091            }
1092        }// if not null routeChoiceMap
1093            // 31st
1094        /*
1095         * Set otherRouteEntries = outOfPathAgents.entrySet(); //
1096         * System.out.println
1097         * ("NNNNNNNNNNNNNNNNNNNumber of out of ph agents"+outOfPathAgents
1098         * .size()); if(otherRouteEntries!=null){ for(Iterator i=
1099         * otherRouteEntries.iterator();i.hasNext();){ Map.Entry entry =
1100         * (Entry)i.next(); String agtName = (String) entry.getKey();
1101         * verticesList = (ArrayList<Vertex>) entry.getValue();
1102         * routeChoiceMap.put(agtName, verticesList); } }
1103         */
1104        // 31st
1105        // TEMP
1106
1107        /********
1108         * preferential routes //familar route
1109         * s1,s45,s3,s37,s46,s50,s51,s42,s27,s30,s31,s32,s17,s18,s19,s22
1110         * 
1111         * 
1112         * //shortest time
1113         * s1,s2,s4,s5,s6,s52,s7,s8,s9,s10,s12,s13,s17,s18,s19,s22
1114         * 
1115         * 
1116         * //shortest distance
1117         * s1,s45,s3,s37,s46,s50,s51,s42,s27,s30,s31,s32,s17,s18,s19,s22
1118         *******/
1119        try {
1120
1121            Vertex vd3 = new Vertex("id", "dest1", "6.5", "15.0");
1122            Vertex vd5 = new Vertex("id", "dest1", "19.5", "22.5");
1123            Vertex vd9 = new Vertex("id", "dest1", "11.0", "47.0");
1124            Vertex vd14 = new Vertex("id", "dest1", "17.0", "55.0");
1125            Vertex vd16 = new Vertex("id", "dest1", "36.0", "55.0");
1126            Vertex vd17 = new Vertex("id", "dest1", "37.0", "52.0");
1127            Vertex vd18 = new Vertex("id", "dest1", "44.0", "51.0");
1128            Vertex vd21 = new Vertex("id", "dest1", "43.0", "84.5");
1129            Vertex vd29 = new Vertex("id", "dest1", "54.5", "133.0");
1130
1131            Vertex vd13 = new Vertex("id", "dest1", "9.0", "51.0");
1132            // Vertex vd14= new Vertex("id","dest1","54.5","133.0");
1133            Vertex vd15 = new Vertex("id", "dest1", "17.0", "59.5");
1134            Vertex vd22 = new Vertex("id", "dest1", "22.5", "90.0");
1135            Vertex vd42 = new Vertex("id", "dest1", "34.0", "183.0");
1136            Vertex vd32 = new Vertex("id", "dest1", "81.0", "177.0");
1137            Vertex vd33 = new Vertex("id", "dest1", "87.5", "219.0");
1138            Vertex vd34 = new Vertex("id", "dest1", "96.5", "232.0");
1139            Vertex vd36 = new Vertex("id", "dest1", "101.5", "272.0");
1140            Vertex vd37 = new Vertex("id", "dest1", "104.0", "288.0");
1141
1142            Vertex vd1 = new Vertex("id", "dest1", "0.0", "0.0");
1143            Vertex vd2 = new Vertex("id", "dest1", "12.0", "8.0");
1144            Vertex vd4 = new Vertex("id", "dest1", "24.5", "21.0");
1145            Vertex vd7 = new Vertex("id", "dest1", "36.5", "31");
1146            Vertex vd6 = new Vertex("id", "dest1", "62.5", "24");
1147            Vertex vd41 = new Vertex("id", "dest1", "70.0", "38.5");
1148            Vertex vd11 = new Vertex("id", "dest1", "72.0", "52.0");
1149            Vertex vd19 = new Vertex("id", "dest1", "75.5", "81.0");
1150            Vertex vd23 = new Vertex("id", "dest1", "77.5", "95");
1151            Vertex vd25 = new Vertex("id", "dest1", "80.0", "107.0");
1152            Vertex vd27 = new Vertex("id", "dest1", "83.0", "129.0");
1153            Vertex vd28 = new Vertex("id", "dest1", "71.0", "131.0");
1154            Vertex vd39 = new Vertex("id", "dest1", "15.0", "47.0");
1155
1156            Vertex vd31 = new Vertex("id", "dest1", "89.0", "176.0");
1157
1158            ArrayList list7 = new ArrayList();
1159            list7.add(1);
1160            list7.add(3);
1161            list7.add(5);
1162            list7.add(9);
1163            list7.add(13);
1164            list7.add(14);
1165            list7.add(15);
1166            list7.add(22);
1167            list7.add(42);
1168            list7.add(32);
1169            list7.add(33);
1170            list7.add(34);
1171            list7.add(36);
1172            list7.add(37);
1173
1174            ArrayList list4 = new ArrayList();
1175            list4.add(vd1);
1176            list4.add(vd2);
1177            list4.add(vd4);
1178            list4.add(vd7);
1179            list4.add(vd6);
1180            list4.add(vd41);
1181            list4.add(vd11);
1182            list4.add(vd19);
1183            list4.add(vd23);
1184            list4.add(vd25);
1185            list4.add(vd27);
1186            list4.add(vd28);
1187            list4.add(vd32);
1188            list4.add(vd33);
1189            list4.add(vd34);
1190            list4.add(vd36);
1191            list4.add(vd37);
1192
1193            // 1,2,3,5,9,14,16,17,18,21,29,28,32,33,34,36,37
1194            ArrayList list2 = new ArrayList();
1195            list2.add(vd1);
1196            list2.add(vd2);
1197            list2.add(vd3);
1198            list2.add(vd5);
1199            list2.add(vd9);
1200            list2.add(vd14);
1201            list2.add(vd16);
1202            list2.add(vd17);
1203            list2.add(vd18);
1204            list2.add(vd21);
1205            list2.add(vd29);
1206            list2.add(vd28);
1207            list2.add(vd32);
1208            list2.add(vd33);
1209            list2.add(vd34);
1210            list2.add(vd36);
1211            list2.add(vd37);
1212            // 1,2,3,5,9,14,16,17,18,21,29,28,32,33,34,36,37
1213
1214            // s1,s45,s3,s37,s46,s50,s51,s42,s27,s30,s31,s32,s17,s18,s19,s22
1215            ArrayList familiar = new ArrayList();
1216            familiar.add(vd1);
1217            familiar.add(vd2);
1218            familiar.add(vd3);
1219            familiar.add(vd5);
1220            familiar.add(vd9);
1221            familiar.add(vd39);
1222            familiar.add(vd16);
1223            familiar.add(vd17);
1224            familiar.add(vd18);
1225            familiar.add(vd21);
1226            familiar.add(vd29);
1227            familiar.add(vd28);
1228            familiar.add(vd32);
1229            familiar.add(vd33);
1230            familiar.add(vd34);
1231            familiar.add(vd36);
1232            familiar.add(vd37);
1233
1234            ArrayList st = new ArrayList();
1235            st.add(vd1);
1236            st.add(vd2);
1237            st.add(vd4);
1238            st.add(vd7);
1239            st.add(vd6);
1240            st.add(vd41);
1241            st.add(vd11);
1242            st.add(vd19);
1243            st.add(vd23);
1244            st.add(vd25);
1245            st.add(vd27);
1246            st.add(vd31);
1247            st.add(vd32);
1248            st.add(vd33);
1249            st.add(vd34);
1250            st.add(vd36);
1251            st.add(vd37);
1252
1253            ArrayList sd = new ArrayList();
1254            sd.add(vd1);
1255            sd.add(vd2);
1256            sd.add(vd3);
1257            sd.add(vd5);
1258            sd.add(vd9);
1259            sd.add(vd39);
1260            sd.add(vd16);
1261            sd.add(vd17);
1262            sd.add(vd18);
1263            sd.add(vd21);
1264            sd.add(vd29);
1265            sd.add(vd28);
1266            sd.add(vd32);
1267            sd.add(vd33);
1268            sd.add(vd34);
1269            sd.add(vd36);
1270            sd.add(vd37);
1271
1272            ArrayList sd1 = new ArrayList();
1273            sd1.add(vd1);
1274            sd1.add(vd2);
1275            sd1.add(vd3);
1276            sd1.add(vd5);
1277            sd1.add(vd9);
1278            sd1.add(vd13);
1279            sd1.add(vd14);
1280            sd1.add(vd15);
1281            sd1.add(vd22);
1282            sd1.add(vd42);
1283            sd1.add(vd32);
1284            sd1.add(vd33);
1285            sd1.add(vd34);
1286            sd1.add(vd36);
1287            sd1.add(vd37);
1288            // routeChoiceMap.clear();
1289
1290            // String nonEquipped =
1291            // "#0,#1,#2,#3,#4,#5,#6,#7,#15,#16,#17,#18,#19,#20,#21,#22,#23,#24";
1292
1293            /*
1294             * routeChoiceMap.put("#0", list4); routeChoiceMap.put("#1", list4);
1295             * routeChoiceMap.put("#2", list4); routeChoiceMap.put("#3", list4);
1296             * routeChoiceMap.put("#4", list4); routeChoiceMap.put("#5", list4);
1297             * routeChoiceMap.put("#6", list4); routeChoiceMap.put("#7", list4);
1298             * routeChoiceMap.put("#8", list4); routeChoiceMap.put("#9", list4);
1299             * 
1300             * 
1301             * routeChoiceMap.put("#10", list4); routeChoiceMap.put("#11",
1302             * list4); routeChoiceMap.put("#12", list4);
1303             * routeChoiceMap.put("#13", list4); routeChoiceMap.put("#14",
1304             * list4); routeChoiceMap.put("#15", list4);
1305             * routeChoiceMap.put("#16", list4); routeChoiceMap.put("#17",
1306             * list4); routeChoiceMap.put("#18", list4);
1307             * routeChoiceMap.put("#19", list4);
1308             * 
1309             * routeChoiceMap.put("#20", list4); routeChoiceMap.put("#21",
1310             * list4); routeChoiceMap.put("#22", list4);
1311             * routeChoiceMap.put("#23", list4); routeChoiceMap.put("#24",
1312             * list4); routeChoiceMap.put("#25", list4);
1313             * routeChoiceMap.put("#26", list4); routeChoiceMap.put("#27",
1314             * list4); routeChoiceMap.put("#28", list4);
1315             * routeChoiceMap.put("#29", list4);
1316             * 
1317             * routeChoiceMap.put("#30", list4); routeChoiceMap.put("#31",
1318             * list4); routeChoiceMap.put("#32", list4);
1319             * routeChoiceMap.put("#33", list4);
1320             * 
1321             * routeChoiceMap.put("#34", list4); routeChoiceMap.put("#35",
1322             * list4); routeChoiceMap.put("#36", list4);
1323             * routeChoiceMap.put("#37", list4);
1324             * 
1325             * routeChoiceMap.put("#38", list4); routeChoiceMap.put("#39",
1326             * list4);
1327             * 
1328             * /* routeChoiceMap.put("#40", list4); routeChoiceMap.put("#41",
1329             * list4); routeChoiceMap.put("#42", list4);
1330             * routeChoiceMap.put("#43", list4); routeChoiceMap.put("#44",
1331             * list4);
1332             * 
1333             * routeChoiceMap.put("#45", list4); routeChoiceMap.put("#46",
1334             * list4); routeChoiceMap.put("#47", list4);
1335             * routeChoiceMap.put("#48", list4); routeChoiceMap.put("#49",
1336             * list4);
1337             * 
1338             * routeChoiceMap.put("#50", list4); routeChoiceMap.put("#51",
1339             * list4); routeChoiceMap.put("#52", list4);
1340             * routeChoiceMap.put("#53", list4); routeChoiceMap.put("#54",
1341             * list4); routeChoiceMap.put("#55", list4);
1342             * routeChoiceMap.put("#56", list4); routeChoiceMap.put("#57",
1343             * list4); routeChoiceMap.put("#58", list4);
1344             * routeChoiceMap.put("#59", list4); routeChoiceMap.put("#60",
1345             * list4); routeChoiceMap.put("#61", list4);
1346             * routeChoiceMap.put("#62", list4); routeChoiceMap.put("#63",
1347             * list4); routeChoiceMap.put("#64", list4);
1348             * routeChoiceMap.put("#65", list4); routeChoiceMap.put("#66",
1349             * list4); routeChoiceMap.put("#67", list4);
1350             * routeChoiceMap.put("#68", list4); routeChoiceMap.put("#69",
1351             * list4); routeChoiceMap.put("#70", list4);
1352             * routeChoiceMap.put("#71", list4); routeChoiceMap.put("#72",
1353             * list4); routeChoiceMap.put("#73", list4);
1354             * 
1355             * 
1356             * 
1357             * /*routeChoiceMap.put("#0", list4); routeChoiceMap.put("#1",
1358             * list4); routeChoiceMap.put("#2", list4); routeChoiceMap.put("#3",
1359             * list4); routeChoiceMap.put("#4", list4); routeChoiceMap.put("#5",
1360             * list4); routeChoiceMap.put("#6", list4); routeChoiceMap.put("#7",
1361             * list4); routeChoiceMap.put("#8", list4); routeChoiceMap.put("#9",
1362             * st); routeChoiceMap.put("#10", st); routeChoiceMap.put("#11",
1363             * st); routeChoiceMap.put("#12", st); routeChoiceMap.put("#13",
1364             * st); routeChoiceMap.put("#14", st); routeChoiceMap.put("#15",
1365             * sd); routeChoiceMap.put("#16", sd); routeChoiceMap.put("#17",
1366             * sd); routeChoiceMap.put("#18", sd); routeChoiceMap.put("#19",
1367             * sd); routeChoiceMap.put("#20", sd); routeChoiceMap.put("#21",
1368             * sd); routeChoiceMap.put("#22", sd); routeChoiceMap.put("#23",
1369             * sd); /* routeChoiceMap.put("#24", sd); routeChoiceMap.put("#25",
1370             * sd); routeChoiceMap.put("#26", sd); routeChoiceMap.put("#27",
1371             * sd); routeChoiceMap.put("#28", sd); routeChoiceMap.put("#29",
1372             * familiar); routeChoiceMap.put("#30", familiar);
1373             * routeChoiceMap.put("#31", familiar); routeChoiceMap.put("#32",
1374             * familiar); routeChoiceMap.put("#33", familiar);
1375             * routeChoiceMap.put("#34", familiar); routeChoiceMap.put("#35",
1376             * familiar); routeChoiceMap.put("#36", familiar);
1377             * routeChoiceMap.put("#37", familiar); routeChoiceMap.put("#38",
1378             * familiar); routeChoiceMap.put("#39", familiar);
1379             * routeChoiceMap.put("#40", st); routeChoiceMap.put("#41", st);
1380             * routeChoiceMap.put("#42", st); routeChoiceMap.put("#43", st);
1381             * routeChoiceMap.put("#44", st); routeChoiceMap.put("#45", st);
1382             * routeChoiceMap.put("#46", st); routeChoiceMap.put("#47", st);
1383             * routeChoiceMap.put("#48", st); routeChoiceMap.put("#49", st);
1384             * routeChoiceMap.put("#50", st);
1385             * 
1386             * routeChoiceMap.put("#51", st); routeChoiceMap.put("#52", st);
1387             * routeChoiceMap.put("#53", st); routeChoiceMap.put("#54", st);
1388             * routeChoiceMap.put("#55", sd); routeChoiceMap.put("#56", sd);
1389             * routeChoiceMap.put("#57", sd); routeChoiceMap.put("#58", sd);
1390             * routeChoiceMap.put("#59", sd); routeChoiceMap.put("#60", sd);
1391             * routeChoiceMap.put("#61", sd); routeChoiceMap.put("#62", sd);
1392             * routeChoiceMap.put("#63", sd); routeChoiceMap.put("#64", sd);
1393             * routeChoiceMap.put("#65", sd); routeChoiceMap.put("#66", sd);
1394             * routeChoiceMap.put("#67", sd); routeChoiceMap.put("#68", sd);
1395             * routeChoiceMap.put("#69", familiar); routeChoiceMap.put("#70",
1396             * familiar);
1397             * 
1398             * routeChoiceMap.put("#71", familiar); routeChoiceMap.put("#72",
1399             * familiar); routeChoiceMap.put("#73", familiar);
1400             * routeChoiceMap.put("#74", familiar); routeChoiceMap.put("#75",
1401             * familiar); routeChoiceMap.put("#76", familiar);
1402             * routeChoiceMap.put("#77", familiar); routeChoiceMap.put("#78",
1403             * familiar); routeChoiceMap.put("#79", familiar);
1404             * routeChoiceMap.put("#80", st); routeChoiceMap.put("#81", st);
1405             * routeChoiceMap.put("#82", st); routeChoiceMap.put("#83", st);
1406             * routeChoiceMap.put("#84", sd); routeChoiceMap.put("#85", sd);
1407             * routeChoiceMap.put("#86", sd); routeChoiceMap.put("#87",
1408             * familiar); routeChoiceMap.put("#88", familiar);
1409             * routeChoiceMap.put("#89", familiar); /*routeChoiceMap.put("#20",
1410             * list4); routeChoiceMap.put("#21", list4);
1411             * routeChoiceMap.put("#22", list4); routeChoiceMap.put("#23",
1412             * list4); routeChoiceMap.put("#24", list4);
1413             * routeChoiceMap.put("#25", list4); routeChoiceMap.put("#26",
1414             * list4); routeChoiceMap.put("#27", list4);
1415             * routeChoiceMap.put("#28", list4); routeChoiceMap.put("#29",
1416             * list4);
1417             * 
1418             * routeChoiceMap.put("#40", list4); routeChoiceMap.put("#41",
1419             * list4); routeChoiceMap.put("#42", list4);
1420             * routeChoiceMap.put("#43", list4); routeChoiceMap.put("#44",
1421             * list4); routeChoiceMap.put("#45", list4);
1422             * routeChoiceMap.put("#46", list4); routeChoiceMap.put("#47",
1423             * list4); routeChoiceMap.put("#48", list4);
1424             * routeChoiceMap.put("#49", list4); routeChoiceMap.put("#50",
1425             * list4); routeChoiceMap.put("#51", list4);
1426             * routeChoiceMap.put("#52", list4); routeChoiceMap.put("#53",
1427             * list4); routeChoiceMap.put("#54", list4);
1428             * routeChoiceMap.put("#55", list4); routeChoiceMap.put("#56",
1429             * list4); routeChoiceMap.put("#57", list4);
1430             * routeChoiceMap.put("#58", list4); routeChoiceMap.put("#70",
1431             * list4); routeChoiceMap.put("#71", list4);
1432             * routeChoiceMap.put("#72", list4); routeChoiceMap.put("#73",
1433             * list4); routeChoiceMap.put("#74", list4);
1434             * routeChoiceMap.put("#75", list4); routeChoiceMap.put("#76",
1435             * list4); routeChoiceMap.put("#77", list4);
1436             * routeChoiceMap.put("#78", list4); routeChoiceMap.put("#79",
1437             * list4); routeChoiceMap.put("#80", list4);
1438             * routeChoiceMap.put("#81", list4); routeChoiceMap.put("#82",
1439             * list4); /* routeChoiceMap.put("#40", list4);
1440             * routeChoiceMap.put("#41", list4); routeChoiceMap.put("#42",
1441             * list4); routeChoiceMap.put("#43", list4);
1442             * routeChoiceMap.put("#44", list4); routeChoiceMap.put("#45",
1443             * list4); routeChoiceMap.put("#46", list4);
1444             * routeChoiceMap.put("#47", list4); routeChoiceMap.put("#48",
1445             * list4); routeChoiceMap.put("#49", list4);
1446             * routeChoiceMap.put("#50", list4); routeChoiceMap.put("#51",
1447             * list4); routeChoiceMap.put("#52", list4);
1448             * routeChoiceMap.put("#53", list4); routeChoiceMap.put("#54",
1449             * list4); routeChoiceMap.put("#55", list4);
1450             * routeChoiceMap.put("#56", list4); routeChoiceMap.put("#57",
1451             * list4); routeChoiceMap.put("#58", list4);
1452             * routeChoiceMap.put("#59", list4);
1453             * 
1454             * /*routeChoiceMap.put("#60", list4); routeChoiceMap.put("#61",
1455             * list4); routeChoiceMap.put("#62", list4);
1456             * routeChoiceMap.put("#63", list4); routeChoiceMap.put("#64",
1457             * list4);
1458             */
1459            // getUserPreferenceIndex("S12",routeChoiceMap);
1460            // getSystemOptimalIndex(routeChoiceMap, "S12");
1461        } catch (Exception e) {
1462            // TODO Auto-generated catch block
1463            e.printStackTrace();
1464        }
1465
1466        // TEMP*/
1467        // System.out.println("Routechoicemap..");
1468        // if(obtainedList!=null && maxAgentCntRecorded!=null){
1469        if (routeChoice != null && routeChoice.size() > 0) {// if(obtainedList!=null
1470                                                            // &&
1471                                                            // obtainedList.size()>=Integer.parseInt(maxAgentCntRecorded.get(commString).toString())){
1472            cvMaps.setSimNoticeFlag(true);
1473        }
1474
1475        ConcurrentHashMap sMap = uni.returnFlagMap();
1476        Set tempSet = routeChoice.entrySet();
1477        if (tempSet != null) {
1478            Iterator tempIter = tempSet.iterator();
1479            while (tempIter.hasNext()) {
1480                Map.Entry tempEntry = (Entry) tempIter.next();
1481                if (tempEntry != null) {
1482                    String tempKey = (String) tempEntry.getKey();
1483                    String tempVal = (String) tempEntry.getValue();
1484                    // if(tempKey.equals("#6") || tempKey.equals("#10") ||
1485                    // tempKey.equals("#15")){
1486                    // System.out.println("setting flaggg to TRUE for : "+
1487                    // tempKey+" and value of : "+tempVal);
1488                    // }
1489                    sMap.put(tempKey, true);
1490
1491                    System.out
1492                            .println("Setting final choice in Queue Manager.."
1493                                    + tempKey + " and val " + tempVal);
1494                }
1495            }
1496            uni.setReadyFlag(sMap);
1497
1498            Set valFlag = sMap.entrySet();
1499            if (valFlag != null) {
1500                Iterator valIter = valFlag.iterator();
1501                while (valIter != null && valIter.hasNext()) {
1502                    Map.Entry valEntry = (Entry) valIter.next();
1503                    if (valEntry != null) {
1504                        String tempKey = (String) valEntry.getKey();
1505                        Object tempVal = valEntry.getValue();
1506                        if (tempVal != null
1507                                && !Boolean.parseBoolean(tempVal.toString())) {
1508                            System.out
1509                                    .println("this vehicle has false flagg : "
1510                                            + tempKey);
1511                        }
1512
1513                    }
1514                }
1515            }
1516        }
1517        // }
1518        // }
1519        uni.sendNotification(new RouteChoiceNotification("QueueManager", uni,
1520                routeChoiceMap));
1521    }
1522
1523    public static boolean retrieveAndUpdateParticipatingNodes(String congRt,
1524            String agtName, String operation) {
1525        String agtList = null, nodeName = null;
1526        if (participatingNodes != null && congRt != null) {
1527            agtList = (String) participatingNodes.get(congRt);
1528            if (agtList != null && agtName != null) {
1529                StringTokenizer st = new StringTokenizer(agtList, ",");
1530                if (operation != null && operation.equals("GET")) {
1531                    {
1532                        while (st != null && st.hasMoreTokens()) {
1533                            nodeName = st.nextToken();
1534
1535                            if (nodeName != null && nodeName.equals(agtName)) {
1536                                if (congRt != null && congRt.equals("s37")) {
1537                                    // System.out.println("agtList : "+agtList+
1538                                    // " returning true");
1539                                    if (agtName != null && agtName.equals("#0")) {
1540                                        // System.out.println("1...returning true");
1541                                    }
1542                                }
1543                                return true;
1544                            }
1545                        }
1546                        if (agtName != null && agtName.equals("#0")) {
1547                            // System.out.println("1...returning false");
1548                        }
1549                        return false;
1550                    }
1551                }
1552
1553            }
1554
1555        }
1556
1557        if (operation != null && operation.equals("ADD")) {
1558            agtList = (String) participatingNodes.get(congRt);
1559            if (agtList != null) {
1560                if (agtList.length() == 0) {
1561                    agtList = new String(agtName);
1562                } else {
1563                    agtList += "," + agtName;
1564                }
1565            } else {
1566                agtList = new String(agtName);
1567            }
1568            participatingNodes.put(congRt, agtList);
1569        }// else if
1570        if (congRt != null && congRt.equals("s37") && operation.equals("GET")) {
1571            // System.out.println("agtList : "+agtList+ " returning false");
1572        }
1573
1574        return false;
1575    }
1576
1577    /**
1578     * This method is used to retrieve the path vertices
1579     * @param vPath path
1580     * @param vehicleID ID of the vehicle
1581     * @return list of vertices on the path
1582     */
1583    public static synchronized ArrayList<Vertex> getPathVertex(String vPath,
1584            String vehicleID) {
1585        StringTokenizer st = new StringTokenizer(vPath, ",");
1586        String segmentID = null;
1587        String selectVertices = null;
1588        PreparedStatement ps = null;
1589        ResultSet rs = null;
1590        String xCoord = null;
1591        String yCoord = null;
1592        String vertex = null;
1593        String temp = null;
1594        Vertex vd = null;
1595        ArrayList<Vertex> verticesList = new ArrayList<Vertex>();
1596
1597        while (st.hasMoreTokens()) {
1598
1599            segmentID = st.nextToken();
1600            selectVertices = "select sourcecoordinates from roadSegment where segmentID='"
1601                    + segmentID + "'";
1602            try {
1603                temp = null;
1604
1605                ps = getConnection().prepareStatement(selectVertices);
1606                rs = ps.executeQuery();
1607                while (rs != null && rs.next()) {
1608                    vertex = rs.getString(1);
1609                    StringTokenizer vSt = new StringTokenizer(vertex, ",");
1610                    while (vSt.hasMoreTokens()) {
1611                        if (temp == null)
1612                            xCoord = vSt.nextToken();
1613                        else
1614                            yCoord = vSt.nextToken();
1615                        temp = new String(xCoord);
1616                    }
1617
1618                    vd = new Vertex("dest1", "", temp, yCoord);
1619
1620                }
1621                // System.out.println("adding "+vd.getX()+"and "+vd.getY()+"for agent "+vehicleID);
1622                verticesList.add(vd);
1623                ps.clearParameters();
1624                ps.close();
1625            } catch (SQLException e) {
1626                e.printStackTrace();
1627            } catch (Exception e) {
1628                // TODO Auto-generated catch block
1629                e.printStackTrace();
1630            }
1631
1632        }
1633
1634        // add destination coordinates
1635        try {
1636
1637            Position3D destVer = CommunicationsManager
1638                    .retrieveDestPos(vehicleID);// new
1639                                                // Vertex("dest1","","500.0","300.0");
1640
1641            if (destVer == null) {
1642                System.out.println("destVer is null for " + vehicleID);
1643            } else {
1644
1645                vd = new Vertex("dest1", "", String.valueOf(destVer.getX()),
1646                        String.valueOf(destVer.getY()));
1647                verticesList.add(vd);
1648            }
1649        } catch (Exception e) {
1650            // TODO Auto-generated catch block
1651            e.printStackTrace();
1652        }
1653        return verticesList;
1654
1655    }
1656
1657    // 31st
1658    public static void addToRouteChoiceForOutOfPathAgents(String vehicleID) {
1659        String vPath = DataAccess.getVehiclePath(vehicleID);
1660        if (vPath != null) {
1661            ArrayList<Vertex> vertexList = getPathVertex(vPath, vehicleID);
1662            outOfPathAgents.put(vehicleID, vertexList);
1663
1664        }
1665    }
1666
1667    public static synchronized void saveAssignedRoute(String vehicleID, String path) {
1668        String addVehPath = "UPDATE VEHICLEAGENT SET ASSIGNEDROUTEID = '"
1669                + path + "' WHERE VEHICLEID = '" + vehicleID + "'";
1670
1671        try {
1672
1673            PreparedStatement st = null;
1674            st = getConnection().prepareStatement(addVehPath);
1675            st.executeUpdate();
1676
1677            st.close();
1678        } catch (SQLException e) {
1679            // TODO Auto-generated catch block
1680            e.printStackTrace();
1681        }
1682    }
1683
1684    /**
1685     * This method is used to update and retrieve the route choice
1686     * @param vehicleID Id of the vehicle
1687     * @param map 
1688     * @param cvMaps
1689     * @param congestedRt
1690     * @return the status of route choice updation
1691     */
1692    public static synchronized boolean updateAndGetAssignedRouteChoice(String vehicleID, ConcurrentHashMap map,
1693           CommunicatingVehicles cvMaps, String congestedRt) {
1694
1695        if (cvMaps != null) {
1696            ConcurrentHashMap<String, ConcurrentHashMap> savedPathObj = cvMaps
1697                    .getSavedPathMap();
1698
1699            if (savedPathObj != null) {
1700
1701                if (savedPathObj.size() == 12) {
1702                    if (map != null && map.size() == 14) {
1703                        System.out.println("checking...");
1704                    }
1705                }
1706
1707                Object getBoolean = savedPathObj.get(vehicleID);
1708                if (getBoolean != null) {
1709                    return false;
1710                } else {
1711                    savedPathObj.put(vehicleID, map);
1712                    cvMaps.setSavedPathMap(savedPathObj);
1713
1714                    return true;
1715                }
1716            }
1717            return false;
1718        } else {
1719            return false;
1720        }
1721
1722    }
1723
1724    public static synchronized boolean checkIfRoutesRecorded(String vehicleID,
1725            CommunicatingVehicles cvMaps) {
1726        if (cvMaps != null) {
1727            ConcurrentHashMap<String, ConcurrentHashMap> savedPathObj = cvMaps
1728                    .getSavedPathMap();
1729            if (savedPathObj != null) {
1730                Object getBoolean = savedPathObj.get(vehicleID);
1731                if (getBoolean != null) {
1732                    return true;
1733                } else {
1734
1735                    return false;
1736                }
1737            }
1738            return false;
1739        } else {
1740            return false;
1741        }
1742    }
1743
1744    public static synchronized ArrayList returnQueueList(CommunicatingVehicles cvMaps) {
1745        if (cvMaps != null) {
1746            ConcurrentHashMap savedPath = cvMaps.getSavedPathMap();
1747            Set mapSet = savedPath.entrySet();
1748            ConcurrentHashMap map = new ConcurrentHashMap();
1749            ConcurrentHashMap newMap = new ConcurrentHashMap();
1750            ArrayList listToReturn = new ArrayList();
1751            if (mapSet != null) {
1752                Iterator iter = mapSet.iterator();
1753                while (iter != null && iter.hasNext()) {
1754                    Map.Entry routeEntry = (Entry) iter.next();
1755
1756                    if (routeEntry != null) {
1757                        newMap = (ConcurrentHashMap) routeEntry.getValue();
1758                        listToReturn.add(newMap);
1759                    }
1760                }
1761            }
1762            // System.out.println("returning vehMaps for: "+cvMaps.getCommID()+" list size: "+listToReturn.size());
1763            return listToReturn;
1764        } else {
1765            return null;
1766        }
1767    }
1768
1769    
1770    /**
1771     * This method is used to retrieve deviation index for the route under consideration
1772     * @param routeUnderConsideration
1773     * @param agentName - name of the agent for which deviation inde is to be retrieved
1774     * @param fIndex - familiarity index
1775     * @return deviation index
1776     */
1777    public static synchronized double getDeviationIndex(String routeUnderConsideration, String agentName, double fIndex) {
1778
1779        int pathID = Integer.parseInt(routeUnderConsideration);
1780        String getcrd = "select srccrd,destcrd from route where pathid="
1781                + pathID;
1782        ResultSet rsSelectAltPath = null;
1783        String src = null, dest = null;
1784
1785        try {
1786            PreparedStatement st = null;
1787            st = QueueManager.getConnection().prepareStatement(getcrd);
1788            rsSelectAltPath = st.executeQuery();
1789
1790            while (rsSelectAltPath != null && rsSelectAltPath.next()) {
1791                src = rsSelectAltPath.getString(1);
1792                dest = rsSelectAltPath.getString(2);
1793            }
1794            st.close();
1795        } catch (SQLException e) {
1796            e.printStackTrace();
1797        }
1798
1799        String str = "select pathid from route where srccrd = '" + src + "'"
1800                + " and destcrd='" + dest + "' order by TT";
1801
1802        rsSelectAltPath = null;
1803        int vehPathID;
1804        String natureRoute = "";
1805        try {
1806            PreparedStatement st = null;
1807            st = QueueManager.getConnection().prepareStatement(str);
1808            rsSelectAltPath = st.executeQuery();
1809
1810            while (rsSelectAltPath != null && rsSelectAltPath.next()) {
1811                vehPathID = rsSelectAltPath.getInt(1);
1812                if (vehPathID == pathID) {
1813                    natureRoute = "ST";
1814                    break;
1815                } else {
1816                    otherPossibleRoutes.add(vehPathID);
1817                    break;
1818                }
1819
1820            }
1821            st.close();
1822
1823        } catch (SQLException e) {
1824            e.printStackTrace();
1825        }
1826        if (natureRoute.equals("")) {
1827            str = "select pathid from route where srccrd = '" + src + "'"
1828                    + " and destcrd='" + dest + "' order by TD";
1829            rsSelectAltPath = null;
1830
1831            try {
1832                PreparedStatement st = null;
1833                st = QueueManager.getConnection().prepareStatement(str);
1834                rsSelectAltPath = st.executeQuery();
1835
1836                while (rsSelectAltPath != null && rsSelectAltPath.next()) {
1837                    vehPathID = rsSelectAltPath.getInt(1);
1838                    if (vehPathID == pathID) {
1839                        natureRoute = "SD";
1840                        break;
1841                    } else {
1842                        otherPossibleRoutes.add(vehPathID);
1843                        break;
1844                    }
1845                }
1846                st.close();
1847
1848            } catch (SQLException e) {
1849                e.printStackTrace();
1850            }
1851        }
1852        if (agentName != null && natureRoute.equals("")) {
1853            String selPath = "select path from route where pathID in (select pathID from fdevindx where vehicleID='"
1854                    + agentName
1855                    + "'"
1856                    + "order by findx DESC) and destcrd='"
1857                    + dest + "'";
1858            rsSelectAltPath = null;
1859
1860            try {
1861                PreparedStatement st = null;
1862                st = QueueManager.getConnection().prepareStatement(str);
1863                rsSelectAltPath = st.executeQuery();
1864
1865                while (rsSelectAltPath != null && rsSelectAltPath.next()) {
1866                    vehPathID = rsSelectAltPath.getInt(1);
1867                    if (vehPathID == pathID) {
1868                        natureRoute = "F";
1869                    }
1870
1871                    otherPossibleRoutes.add(vehPathID);
1872                }
1873                st.close();
1874
1875            } catch (SQLException e) {
1876                e.printStackTrace();
1877            }
1878        }
1879
1880        // System.out.println("RoadType"+roadType);
1881
1882        // String priPref = DataAccess.getPrimaryPreference(agentName);
1883
1884        // System.out.println("AgentName  : "+agentName+
1885        // " prefers the route : "+natureRoute);
1886
1887        ArrayList<DeviationIndex> DIBeans = DataAccess
1888                .getDeviationIndices(agentName);
1889        String priPref, secPref, familiarRoutList = "2,4,6";
1890        double DIByPref;
1891        if (natureRoute == null)
1892            return 1;
1893        if (DIBeans != null) {
1894            Iterator iter = DIBeans.iterator();
1895            if (iter != null) {
1896                while (iter.hasNext()) {
1897                    DeviationIndex index = (DeviationIndex) iter.next();
1898                    if (index != null) {
1899                        priPref = index.getPriPref();
1900                        secPref = index.getSecPref();
1901                        DIByPref = index.getVal();
1902
1903                        if (priPref != null && priPref.equals(natureRoute)) {
1904                            return 1;
1905                        }/*
1906                         * else if(priPref!=null && priPref.equals("F") &&
1907                         * fIndex!=0.0){ return 1; }
1908                         */else if (secPref != null) {
1909
1910                            if (secPref.equals(natureRoute)) {
1911                                if (secPref.equals("F")) {
1912                                    if (familiarRoutList != null
1913                                            && familiarRoutList
1914                                                    .indexOf(routeUnderConsideration) > -1) {
1915                                        return DIByPref;
1916                                    } else {
1917                                        return 0;
1918                                    }
1919                                } else {
1920                                    return (1 - DIByPref);
1921                                }
1922
1923                            }
1924                        }
1925                    }
1926                }
1927            }
1928        }
1929        return 0;
1930    }
1931
1932    
1933    // 31st
1934/**
1935 * This method is used to retieve the segment coordinates
1936 * @param src src coordinates
1937 * @param dest destination coordinates
1938 * @return route based on segment coordinates
1939 */
1940    public static synchronized String getRouteSegmentFromCoordinates(Vertex src, Vertex dest) {
1941        String getSegment = "select segmentID from roadsegment where sourcecoordinates=? and destcoordinates=?";
1942        String seg = null;
1943        try {
1944
1945            PreparedStatement st = null;
1946            String srcC = src.getX() + "," + src.getY();
1947            String destC = dest.getX() + "," + dest.getY();
1948            st = getConnection().prepareStatement(getSegment);
1949            // System.out.println("PARAM "+src.getX()+dest.getX());
1950
1951            st.setString(1, srcC);
1952            st.setString(2, destC);
1953            // System.out.println("Query string: "+getSegment+" and source "+srcC+" and dest "+destC);
1954            ResultSet rs = st.executeQuery();
1955            while (rs != null && rs.next()) {
1956                // System.out.println("got the result");
1957                seg = rs.getString(1);
1958            }
1959            st.close();
1960
1961            return seg;
1962        } catch (SQLException e) {
1963            // TODO Auto-generated catch block
1964            e.printStackTrace();
1965        }
1966        return seg;
1967    }
1968
1969    /**
1970     * This methos is used to evaluate the cost of route allocation
1971     * @param routeChoice map of routes and vehicles
1972     * @param vRouteID route ID
1973     * @return cost of allocation
1974     */
1975    public static double evaluateCost(ConcurrentHashMap routeChoice, String vRouteID) {
1976        double solutionCost = 0.0;
1977        String roadSegments = null;
1978        int matchingCnt = 0;
1979        int occCap = 0;
1980        double congSpeed = 0.0f;
1981
1982        if (routeChoice == null) {
1983            System.out.println("rt choice is null");
1984        } else {
1985
1986            ArrayList<RoadSegment> segList = DataAccess
1987                    .selectRoadSegmentParams(routeChoice);
1988            Iterator listIter = segList.iterator();
1989            if (vRouteID != null) {
1990                roadSegments = DataAccess.selectPathFromRouteID(vRouteID);
1991
1992            }
1993            if (vRouteID != null) {
1994                if (!checkIfRouteInOptions(routeChoice, vRouteID)) {
1995                    return 0;
1996                }
1997            }
1998            double speed = 0.0;
1999            double time = 0.0;
2000
2001            if (segList == null) {
2002                System.out.println("segList is null");
2003            }
2004
2005            /*
2006             * if(routeChoice!=null && routeChoice.size()==20) {
2007             * System.out.println("allocation"); }
2008             */
2009            if (listIter != null) {
2010                while (listIter.hasNext()) {
2011
2012                    RoadSegment road = (RoadSegment) listIter.next();
2013
2014                    if (road != null) {
2015                        if (road.getSegmentID().equals("s6")
2016                                || road.getSegmentID().equals("s17")
2017                                || road.getSegmentID().equals("s32")) {
2018                            occCap = 25;
2019                            congSpeed = 0.001f;
2020                        } else {
2021                            occCap = road.getOccupiedCapacity();
2022                            congSpeed = road.getSegmentFreeFlowSpeed();
2023                        }
2024                        if (vRouteID != null) {
2025                            
2026                            if (roadSegments != null
2027                                    && IsRoadSegmentIndexOf(roadSegments,
2028                                            road.getSegmentID())) {
2029                                // System.out.println("SolutionCost of "+road.getSegmentID()+" is- "+solutionCost);
2030                                matchingCnt++;
2031                                if (occCap > road.getSegmentCapacity()) {
2032
2033                                    // road.getSegmentID()+ " " +
2034                                    // "  - "+road.getOccupiedCapacity());
2035                                    // if(road.getSegmentLength()<450.0 ||
2036                                    // road.getSegmentID().equals("s4")||
2037                                    // road.getSegmentID().equals("s5")){
2038                                    double freeFlowTT = (road.getSegmentLength()) / congSpeed;
2039                                    time = freeFlowTT * (1 + 0.15 * Math.pow((occCap / road
2040                                                            .getThresholdCapacity()),
2041                                                            4));
2042                                    speed = road.getSegmentLength() / time;
2043                                    if (roadSegments != null
2044                                            && roadSegments.indexOf(road
2045                                                    .getSegmentID()) > -1) {
2046
2047                                        solutionCost = solutionCost
2048                                                + (occCap * time);
2049                                    } else if (roadSegments == null) {
2050                                        solutionCost = solutionCost
2051                                                + (occCap * time);
2052                                    }
2053
2054                                } else {
2055                                    if (occCap > road.getThresholdCapacity()) {
2056                                    
2057                                        double freeFlowTT = (road.getSegmentLength())/ congSpeed;
2058                                        time = freeFlowTT* (1 + 0.15 * Math.pow((occCap / road.getThresholdCapacity()),4));
2059                                        speed = road.getSegmentLength() / time;
2060
2061                                        if (roadSegments != null
2062                                                && roadSegments.indexOf(road.getSegmentID()) > -1) {
2063                                            solutionCost = solutionCost + (occCap * time);
2064                                        } else if (roadSegments == null) {
2065                                            solutionCost = solutionCost
2066                                                    + (occCap * time);
2067                                        }
2068
2069                                    } else {
2070                                    
2071                                        speed = road.getSegmentFreeFlowSpeed();
2072                                        time = road.getSegmentLength()/ congSpeed;
2073
2074                                        solutionCost = solutionCost + (occCap * time);
2075                                    }
2076
2077                                }
2078                                /*
2079                                 * if(road.getSegmentID().equals("s7") ||
2080                                 * road.getSegmentID().equals("s52") ||
2081                                 * road.getSegmentID().equals("s6") &&
2082                                 * road.getOccupiedCapacity()>4){
2083                                 * solutionCost+=8000000; }
2084                                 */
2085
2086                            }// if matching road segment
2087                        } else if (vRouteID == null) {
2088                            if (occCap > road.getSegmentCapacity()) {
2089                                // if(road.getSegmentLength()<450.0 ||
2090                                // road.getSegmentID().equals("s4")||
2091                                // road.getSegmentID().equals("s5")){
2092                                double freeFlowTT = (road.getSegmentLength())/ congSpeed;
2093                                time = freeFlowTT* (1 + 0.15 * Math.pow((occCap / road.getThresholdCapacity()), 4));
2094                                speed = road.getSegmentLength() / time;
2095                                if (roadSegments != null && roadSegments.indexOf(road.getSegmentID()) > -1) {
2096                                    solutionCost = solutionCost + (occCap * time);
2097                                } else if (roadSegments == null) {
2098                                    solutionCost = solutionCost + (occCap * time);
2099                                }
2100                                /*
2101                                 * }else{ return 0.0; }
2102                                 */
2103
2104                            } else {
2105                                if (occCap > road.getThresholdCapacity()&& occCap <= road.getSegmentCapacity()) {
2106                                    double freeFlowTT = (road.getSegmentLength()) / congSpeed;
2107                                    time = freeFlowTT* (1 + 0.15 * Math.pow((occCap / road.getThresholdCapacity()), 4));
2108                                    speed = road.getSegmentLength() / time;
2109                                    solutionCost = solutionCost + (occCap * time);
2110                                } else {
2111                                    speed = road.getSegmentFreeFlowSpeed();
2112                                    time = road.getSegmentLength() / congSpeed;
2113                                    solutionCost = solutionCost + (occCap * time);
2114                                    // System.out.println("else SolutionCost of "+road.getSegmentID()+" is : "+(road.getThresholdCapacity()*time)+
2115                                    // " solutionCost-"+solutionCost);
2116                                }
2117
2118                            }
2119                            
2120                        }
2121                    }
2122
2123                }
2124
2125            }
2126
2127            if (vRouteID != null && matchingCnt < 4) {
2128                return 0;
2129            }
2130        }
2131
2132        return solutionCost;
2133
2134    }
2135
2136    private static boolean checkIfRouteInOptions(ConcurrentHashMap routeChoice,
2137            String vRouteID) {
2138        if (routeChoice != null && vRouteID != null) {
2139            Set thisSet = routeChoice.entrySet();
2140            Iterator iter = thisSet.iterator();
2141            while (iter != null && iter.hasNext()) {
2142
2143                Map.Entry entry = (Entry) iter.next();
2144                String key = (String) entry.getKey();
2145                String val = (String) entry.getValue();
2146                if (val != null && val.equals(vRouteID)) {
2147                    return true;
2148                }
2149            }
2150            return false;
2151        }
2152        return false;
2153    }
2154
2155    private static boolean IsRoadSegmentIndexOf(String roadSegments,
2156            String segmentID) {
2157        String token = null;
2158        if (roadSegments != null && segmentID != null) {
2159            StringTokenizer st = new StringTokenizer(roadSegments, ",");
2160            while (st != null && st.hasMoreTokens()) {
2161                token = st.nextToken();
2162                if (token != null) {
2163                    if (token.equals(segmentID)) {
2164                        return true;
2165                    }
2166                }
2167            }
2168        }
2169        return false;
2170    }
2171
2172    public static synchronized boolean checkRcdResponse(String localName,
2173            int size) {
2174        boolean retResponse = true;
2175        if (rcdRsponse != null && rcdRsponse.size() > 0) {
2176            Object obj = rcdRsponse.get(localName);
2177
2178            if (obj != null && Integer.parseInt(obj.toString()) == size) {
2179                /*
2180                 * if(localName.equals("#2")){ System.out.println("It's me!!");
2181                 * }
2182                 */
2183                return true;
2184            } else {
2185                rcdRsponse.put(localName, size);
2186            }
2187
2188        } else {
2189            rcdRsponse.put(localName, size);
2190        }
2191        return false;
2192    }
2193
2194    public static ConcurrentHashMap evaluateCostMap(
2195            ConcurrentHashMap routeChoice) {
2196        ConcurrentHashMap costMap = new ConcurrentHashMap();
2197        double solutionCost = 0.0;
2198        String roadSegments = null;
2199        ArrayList<RoadSegment> segList = DataAccess
2200                .selectRoadSegmentParams(routeChoice);
2201        double speed = 0.0;
2202        double time = 0.0;
2203        if (routeChoice != null) {
2204            Set routeSet = routeChoice.entrySet();
2205            if (routeSet != null) {
2206                Iterator routeIter = routeSet.iterator();
2207                if (routeIter != null) {
2208                    while (routeIter.hasNext()) {
2209                        Map.Entry entry = (Entry) routeIter.next();
2210                        String key = (String) entry.getKey();
2211                        String val = (String) entry.getValue();
2212                        if (val != null) {
2213                            roadSegments = DataAccess
2214                                    .selectPathFromRouteID(val);
2215                        }
2216                        Iterator listIter = segList.iterator();
2217                        if (listIter != null) {
2218                            while (listIter.hasNext()) {
2219                                RoadSegment road = (RoadSegment) listIter
2220                                        .next();
2221
2222                                if (road != null) {
2223                                    if (road.getOccupiedCapacity() > road
2224                                            .getSegmentCapacity()) {
2225                                        if (road.getSegmentLength() < 450.0
2226                                                || road.getSegmentID().equals(
2227                                                        "s4")
2228                                                || road.getSegmentID().equals(
2229                                                        "s5")) {
2230                                            double freeFlowTT = (road
2231                                                    .getSegmentLength())
2232                                                    / road.getSegmentFreeFlowSpeed();
2233                                            time = freeFlowTT
2234                                                    * (1 + 0.15 * Math
2235                                                            .pow((road
2236                                                                    .getOccupiedCapacity() / road
2237                                                                    .getThresholdCapacity()),
2238                                                                    4));
2239                                            speed = road.getSegmentLength()
2240                                                    / time;
2241                                            if (roadSegments != null
2242                                                    && roadSegments
2243                                                            .indexOf(road
2244                                                                    .getSegmentID()) > -1) {
2245                                                solutionCost = solutionCost
2246                                                        + (road.getOccupiedCapacity() * time);
2247                                            } else if (roadSegments == null) {
2248                                                solutionCost = solutionCost
2249                                                        + (road.getOccupiedCapacity() * time);
2250                                            }
2251                                        } else {
2252                                            costMap.put(road.getSegmentID(),
2253                                                    0.0);
2254                                        }
2255
2256                                        /*
2257                                         * if(road.getSegmentLength()>450.0){
2258                                         * costMap.put(road.getSegmentID(),
2259                                         * 0.0); }else{ double freeFlowTT =
2260                                         * (road.getSegmentLength())/road.
2261                                         * getSegmentFreeFlowSpeed(); time =
2262                                         * freeFlowTT*(1+0.15*Math.pow((road.
2263                                         * getThresholdCapacity
2264                                         * ()+1/road.getThresholdCapacity
2265                                         * ()),4)); solutionCost =
2266                                         * solutionCost+time; }
2267                                         */
2268                                    } else {
2269                                        if (road.getOccupiedCapacity() > road
2270                                                .getThresholdCapacity()
2271                                                && road.getOccupiedCapacity() <= road
2272                                                        .getSegmentCapacity()) {
2273                                            double freeFlowTT = (road
2274                                                    .getSegmentLength())
2275                                                    / road.getSegmentFreeFlowSpeed();
2276                                            time = freeFlowTT
2277                                                    * (1 + 0.15 * Math
2278                                                            .pow((road
2279                                                                    .getThresholdCapacity() + 1 / road
2280                                                                    .getThresholdCapacity()),
2281                                                                    4));
2282                                            speed = road.getSegmentLength()
2283                                                    / time;
2284                                        } else {
2285                                            speed = road
2286                                                    .getSegmentFreeFlowSpeed();
2287                                            time = road.getSegmentLength()
2288                                                    / speed;
2289                                        }
2290                                        if (roadSegments != null
2291                                                && roadSegments.indexOf(road
2292                                                        .getSegmentID()) > -1) {
2293                                            solutionCost = solutionCost + time;
2294
2295                                        }
2296
2297                                    }
2298                                }
2299                            }
2300                        }
2301                        costMap.put(val, solutionCost);
2302                    }
2303                }
2304            }
2305        }
2306        return costMap;
2307    }
2308
2309    private static ConcurrentHashMap maxAgentCntRecorded = new ConcurrentHashMap();
2310
2311    public static synchronized int getMaxAgentCntRecorded(String commID) {
2312        Object val = maxAgentCntRecorded.get(commID);
2313        if (val != null) {
2314            return Integer.parseInt(val.toString());
2315        }
2316        return 0;
2317
2318    }
2319
2320    public static synchronized void setMaxAgentCntRecorded(int maxCntRecorded,
2321            String commID) {
2322        maxAgentCntRecorded.put(commID, maxCntRecorded);
2323    }
2324
2325    public static synchronized void setList(ArrayList rcdReqRouteList) {
2326        // TODO Auto-generated method stub
2327        obtainedList = rcdReqRouteList;
2328        // System.out.println("size of obtained list : "+obtainedList.size());
2329    }
2330
2331    public static synchronized CommunicatingVehicles getCVMaps(String communicID) {
2332        CommunicatingVehicles cVehicles = (CommunicatingVehicles) communicatingVehMaps
2333                .get(communicID);
2334        return cVehicles;
2335    }
2336
2337    public static synchronized void setCVMaps(String communicID,
2338           CommunicatingVehicles cv) {
2339        if (communicatingVehMaps != null) {
2340            // System.out.println("Putting data into cvMAPS for "+communicID+
2341            // " size: "+communicatingVehMaps.size());
2342            communicatingVehMaps.put(communicID, cv);
2343        }
2344    }
2345
2346    public static ConcurrentHashMap returnSentMessage() {
2347        return recordSentRouteHash;
2348    }
2349
2350    /**
2351     * This method is used to check if message is already sent
2352     * @param sendRouteHash 
2353     * @param localName name of the agent
2354     * @param recAgent receiver agent
2355     * @param onCongestedRoute congested route
2356     * @param agentCount number of agents
2357     * @param sellerAgents list of seller agents
2358     * @return tru if message already sent, else return false
2359     */
2360    public static boolean checkIfMessageAlreadySent(ConcurrentHashMap sendRouteHash, String localName, String recAgent,
2361            String onCongestedRoute, int agentCount, AID[] sellerAgents) {
2362        String strOfKeys = "";
2363        String array = "";
2364        ConcurrentHashMap tempHolder = new ConcurrentHashMap();
2365        if (recordSentRouteHash != null) {
2366           SentMessageInfo sentMsgg = (SentMessageInfo) recordSentRouteHash
2367                    .get(localName);
2368            if (sentMsgg != null) {
2369
2370                if (sentMsgg.getCongestedSegmentID().equals(onCongestedRoute)) {
2371                    if (sendRouteHash != null
2372                            && sentMsgg.getAgentsRouteHash() != null) {
2373                        if (sendRouteHash.equals(sentMsgg.getAgentsRouteHash())) {
2374                            if (sentMsgg.getReceiverIDs() != null) {
2375                                array = sentMsgg.getReceiverIDs();
2376                                if (array != null
2377                                        && array.indexOf(recAgent) <= -1) {
2378                                    // message not sent ot this recieiver
2379                                    return false;
2380                                } else {
2381                                    // add it to the list
2382                                    array = array.concat(",");
2383                                    array = array.concat(recAgent);
2384                                    return true;
2385                                }
2386                            }
2387
2388                        } else {
2389                            return false;
2390                        }
2391                    } else {
2392                        return false;
2393                    }
2394
2395                } else {
2396                    if (array != null && array.length() > 0) {
2397                        array = array.concat(",");
2398                        array = array.concat(recAgent);
2399                    } else {
2400                        array = array.concat(recAgent);
2401                    }
2402                    sentMsgg = new SentMessageInfo(localName);
2403                    sentMsgg.setCongestedSegmentID(onCongestedRoute);
2404                    sentMsgg.setReceiverIDs(array);
2405                    sentMsgg.setAgentsRouteHash(sendRouteHash);
2406                    recordSentRouteHash.put(localName, sentMsgg);
2407                    return false;
2408                }
2409
2410            } else {
2411                if (array != null && array.length() > 0) {
2412                    array = array.concat(",");
2413                    array = array.concat(recAgent);
2414                } else {
2415                    array = array.concat(recAgent);
2416                }
2417                sentMsgg = new SentMessageInfo(localName);
2418                sentMsgg.setCongestedSegmentID(onCongestedRoute);
2419                sentMsgg.setReceiverIDs(array);
2420
2421                sentMsgg.setAgentsRouteHash(sendRouteHash);
2422                recordSentRouteHash.put(localName, sentMsgg);
2423                return false;
2424            }
2425        }
2426        return false;
2427    }
2428
2429    /**
2430     * This method will record all the agents to which the proposals have been
2431     * sent and then if it sent the CFP will not be repeated otherwise it will
2432     * be added to the master concurrent map
2433     * @param prefIndex preference utillity index
2434     * @param localName name of the agent
2435     * @param recName receiver agent
2436     * @param onCongestedRoute congested route
2437     * @param sellerAgents seller agents
2438     * @return true, if CFP already sent else return false
2439     */
2440    public static boolean checkIfCFPAlreadySent(PreferenceUtilityIndex prefIndex, String localName, String recName,
2441            String onCongestedRoute, jade.core.AID[] sellerAgents) {
2442        String strOfKeys = "";
2443        if (recordSentRouteCFP != null) {
2444           SentMessageInfo sentMsgg = (SentMessageInfo) recordSentRouteCFP
2445                    .get(localName);
2446            if (sentMsgg != null) {
2447
2448                if (sentMsgg.getCongSegIDcfp().equals(onCongestedRoute)) {
2449                    if (prefIndex != null
2450                            && sentMsgg.getPrefUtilitycfp() != null) {
2451                        if (sentMsgg.getPrefUtilitycfp().equals(prefIndex)) {
2452                            if (sentMsgg.getReceiverIDcfp() != null) {
2453                                AID[] array = sentMsgg.getReceiverIDcfp();
2454                                for (int i = 0; i < array.length; i++) {
2455                                    if (array[i].getLocalName().equals(recName)) {
2456                                        System.out
2457                                                .println("saved one CFP exchange"
2458                                                        + cfpMsgSaved);
2459                                        cfpMsgSaved++;
2460                                        return true;
2461                                    }
2462                                }
2463                            }
2464
2465                        } else {
2466                            return false;
2467                        }
2468                    } else {
2469                        return false;
2470                    }
2471
2472                } else {
2473                    sentMsgg = new SentMessageInfo(localName);
2474                    sentMsgg.setCongSegIDcfp(onCongestedRoute);
2475                    sentMsgg.setReceiverIDcfp(sellerAgents);
2476                    sentMsgg.setPrefUtilitycfp(prefIndex);
2477                    recordSentRouteCFP.put(localName, sentMsgg);
2478                    return false;
2479                }
2480
2481            } else {
2482                sentMsgg = new SentMessageInfo(localName);
2483                sentMsgg.setCongSegIDcfp(onCongestedRoute);
2484                sentMsgg.setReceiverIDcfp(sellerAgents);
2485                sentMsgg.setPrefUtilitycfp(prefIndex);
2486                recordSentRouteCFP.put(localName, sentMsgg);
2487                return false;
2488            }
2489        }
2490        return false;
2491    }
2492
2493    
2494      
2495    /**
2496     * This method will record all the agents to which the proposals have been
2497     * sent and then if it sent the CFP will not be repeated otherwise it will
2498     * be added to the master concurrent map
2499     * @param localName agent name
2500     * @param onCongestedRoute congested route
2501     * @param routeChoiceParam map of route choices
2502     * @param cvmaps map of communicating vehicle agents
2503     * @return true if route info is valid else return false
2504     */
2505     public static boolean checkIfEvalRouteInfoIsValid(String localName,
2506            String onCongestedRoute, ConcurrentHashMap routeChoiceParam,2507           CommunicatingVehicles cvmaps) {
2508        String strOfKeys = "";
2509        ConcurrentHashMap oldMap = new ConcurrentHashMap();
2510       EvaluateRouteInfo evalInf = (EvaluateRouteInfo) recordEvalInfo
2511                .get(localName);
2512        /*
2513         * if(localName.equals("#3") && routeChoiceParam!=null){
2514         * System.out.println
2515         * ("Rt chc size ..in checkIfEvalRouteInfoIsValid"+routeChoiceParam
2516         * .size()+ " onCongested- "+onCongestedRoute); }
2517         */
2518
2519        if (recordEvalInfo != null && routeChoiceParam != null) {
2520            if (evalInf != null && cvmaps != null) {
2521                oldMap = evalInf.getAgentsRouteChoice();
2522                if (oldMap != null
2523                        && evalInf.getCongestedSegmentID().equals(
2524                                onCongestedRoute)) {
2525                    if (oldMap != null
2526                            && oldMap.size() == routeChoiceParam.size()) {
2527                        // if(localName.equals("#3"))
2528                        // System.out.println("Returning true... "+routeChoiceParam.size()+"  agent name : "+localName+" onCongestedRoute - "+onCongestedRoute);
2529                        return true;
2530                    } else {
2531                        // if(localName.equals("#3"))
2532                        // System.out.println("In else 1 Returning true... "+routeChoiceParam.size()+"  agent name : "+localName+" onCongestedRoute - "+onCongestedRoute);
2533                        evalInf.setOwnerID(localName);
2534                        evalInf.setCongestedSegmentID(onCongestedRoute);
2535                        evalInf.setRouteEvalFlag(true);
2536                        evalInf.setAgentsRouteChoice(routeChoiceParam);
2537                        recordEvalInfo.put(localName, evalInf);
2538                        return false;
2539                    }
2540                } else {
2541                    // if(localName.equals("#3"))
2542                    // System.out.println("In else 2 Returning true... "+routeChoiceParam.size()+"  agent name : "+localName+" onCongestedRoute - "+onCongestedRoute+
2543                    // " evalInf.getCongestedSegmentID()-"+evalInf.getCongestedSegmentID());
2544                    evalInf.setOwnerID(localName);
2545                    evalInf.setCongestedSegmentID(onCongestedRoute);
2546                    evalInf.setRouteEvalFlag(false);
2547                    evalInf.setAgentsRouteChoice(routeChoiceParam);
2548                    recordEvalInfo.put(localName, evalInf);
2549                    return false;
2550                }
2551            } else {
2552                // if(localName.equals("#3"))
2553                // System.out.println("in else 3 Returning true... "+routeChoiceParam.size()+"  agent name : "+localName+" onCongestedRoute - "+onCongestedRoute);
2554                evalInf = new EvaluateRouteInfo(localName);
2555                evalInf.setOwnerID(localName);
2556                evalInf.setCongestedSegmentID(onCongestedRoute);
2557                evalInf.setRouteEvalFlag(false);
2558                evalInf.setAgentsRouteChoice(routeChoiceParam);
2559                recordEvalInfo.put(localName, evalInf);
2560                return false;
2561            }
2562        } else {
2563            // if(localName.equals("#3"))
2564            // System.out.println("In else 4 Returning true...  agent name : "+localName+" onCongestedRoute - "+onCongestedRoute);
2565            evalInf = new EvaluateRouteInfo(localName);
2566            evalInf.setOwnerID(localName);
2567            evalInf.setCongestedSegmentID(onCongestedRoute);
2568            evalInf.setRouteEvalFlag(false);
2569            evalInf.setAgentsRouteChoice(routeChoiceParam);
2570            recordEvalInfo.put(localName, evalInf);
2571            return false;
2572        }
2573
2574    }
2575
2576    public static int recordSize() {
2577        if (recordEvalInfo != null) {
2578            return recordEvalInfo.size();
2579        } else {
2580            return 0;
2581        }
2582    }
2583
2584}// end of main classs