]> git.mxchange.org Git - flightgear.git/blob - src/Traffic/TrafficMgr.cxx
Move viewer-related sources to separate folder.
[flightgear.git] / src / Traffic / TrafficMgr.cxx
1 /******************************************************************************
2  * TrafficMGr.cxx
3  * Written by Durk Talsma, started May 5, 2004.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  *
19  *
20  **************************************************************************/
21
22 /* 
23  * Traffic manager parses airlines timetable-like data and uses this to 
24  * determine the approximate position of each AI aircraft in its database.
25  * When an AI aircraft is close to the user's position, a more detailed 
26  * AIModels based simulation is set up. 
27  * 
28  * I'm currently assuming the following simplifications:
29  * 1) The earth is a perfect sphere
30  * 2) Each aircraft flies a perfect great circle route.
31  * 3) Each aircraft flies at a constant speed (with infinite accelerations and
32  *    decelerations) 
33  * 4) Each aircraft leaves at exactly the departure time. 
34  * 5) Each aircraft arrives at exactly the specified arrival time. 
35  *
36  *
37  *****************************************************************************/
38
39 #ifdef HAVE_CONFIG_H
40 #  include "config.h"
41 #endif
42
43 #include <stdlib.h>
44 #include <time.h>
45 #include <cstring>
46 #include <iostream>
47 #include <fstream>
48
49
50 #include <string>
51 #include <vector>
52 #include <algorithm>
53 #include <boost/foreach.hpp>
54
55 #include <simgear/compiler.h>
56 #include <simgear/misc/sg_path.hxx>
57 #include <simgear/misc/sg_dir.hxx>
58 #include <simgear/props/props.hxx>
59 #include <simgear/route/waypoint.hxx>
60 #include <simgear/structure/subsystem_mgr.hxx>
61 #include <simgear/xml/easyxml.hxx>
62
63 #include <AIModel/AIAircraft.hxx>
64 #include <AIModel/AIFlightPlan.hxx>
65 #include <AIModel/AIBase.hxx>
66 #include <Airports/simple.hxx>
67 #include <Main/fg_init.hxx>
68
69
70
71 #include "TrafficMgr.hxx"
72
73 using std::sort;
74 using std::strcmp;
75
76 /******************************************************************************
77  * TrafficManager
78  *****************************************************************************/
79 FGTrafficManager::FGTrafficManager() :
80   inited(false),
81   doingInit(false),
82   enabled("/sim/traffic-manager/enabled"),
83   aiEnabled("/sim/ai/enabled"),
84   realWxEnabled("/environment/realwx/enabled"),
85   metarValid("/environment/metar/valid")
86 {
87     //score = 0;
88     //runCount = 0;
89     acCounter = 0;
90 }
91
92 FGTrafficManager::~FGTrafficManager()
93 {
94     // Save the heuristics data
95     bool saveData = false;
96     ofstream cachefile;
97     if (fgGetBool("/sim/traffic-manager/heuristics")) {
98         SGPath cacheData(fgGetString("/sim/fg-home"));
99         cacheData.append("ai");
100         string airport = fgGetString("/sim/presets/airport-id");
101
102         if ((airport) != "") {
103             char buffer[128];
104             ::snprintf(buffer, 128, "%c/%c/%c/",
105                        airport[0], airport[1], airport[2]);
106             cacheData.append(buffer);
107             if (!cacheData.exists()) {
108                 cacheData.create_dir(0777);
109             }
110             cacheData.append(airport + "-cache.txt");
111             //cerr << "Saving AI traffic heuristics" << endl;
112             saveData = true;
113             cachefile.open(cacheData.str().c_str());
114             cachefile << "[TrafficManagerCachedata:ref:2011:09:04]" << endl;
115         }
116     }
117     for (ScheduleVectorIterator sched = scheduledAircraft.begin();
118          sched != scheduledAircraft.end(); sched++) {
119         if (saveData) {
120             cachefile << (*sched)->getRegistration() << " "
121                 << (*sched)->getRunCount() << " "
122                 << (*sched)->getHits() << " "
123                 << (*sched)->getLastUsed() << endl;
124         }
125         delete(*sched);
126     }
127     if (saveData) {
128         cachefile.close();
129     }
130     scheduledAircraft.clear();
131     flights.clear();
132 }
133
134
135 void FGTrafficManager::init()
136 {
137     if (!enabled || !aiEnabled) {
138       return;
139     }
140
141     assert(!doingInit);
142     doingInit = true;
143     if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) {
144         simgear::Dir trafficDir(SGPath(globals->get_fg_root(), "AI/Traffic"));
145         simgear::PathList d = trafficDir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
146         
147         BOOST_FOREACH(SGPath p, d) {
148           simgear::Dir d2(p);
149           simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml");
150           schedulesToRead.insert(schedulesToRead.end(), trafficFiles.begin(), trafficFiles.end());
151         }
152     } else {
153         fgSetBool("/sim/traffic-manager/heuristics", false);
154         SGPath path = string(fgGetString("/sim/traffic-manager/datafile"));
155         string ext = path.extension();
156         if (path.extension() == "xml") {
157             if (path.exists()) {
158                 readXML(path.str(), *this);
159             }
160         } else if (path.extension() == "conf") {
161             if (path.exists()) {
162                 readTimeTableFromFile(path);
163             }
164         } else {
165              SG_LOG(SG_AI, SG_ALERT,
166                                "Unknown data format " << path.str()
167                                 << " for traffic");
168         }
169         //exit(1);
170     }
171 }
172
173 void FGTrafficManager::initStep()
174 {
175     assert(doingInit);
176     if (schedulesToRead.empty()) {
177         finishInit();
178         return;
179     }
180     
181     SGPath path = schedulesToRead.front();
182     schedulesToRead.erase(schedulesToRead.begin());
183     SG_LOG(SG_AI, SG_DEBUG, path << " for traffic");
184     readXML(path.str(), *this);
185 }
186
187 void FGTrafficManager::finishInit()
188 {
189     assert(doingInit);
190     SG_LOG(SG_AI, SG_INFO, "finishing AI-Traffic init");
191     loadHeuristics();
192     
193     // Do sorting and scoring separately, to take advantage of the "homeport| variable
194     for (currAircraft = scheduledAircraft.begin();
195          currAircraft != scheduledAircraft.end(); currAircraft++) {
196         (*currAircraft)->setScore();
197     }
198     
199     sort(scheduledAircraft.begin(), scheduledAircraft.end(),
200          compareSchedules);
201     currAircraft = scheduledAircraft.begin();
202     currAircraftClosest = scheduledAircraft.begin();
203     
204     doingInit = false;
205     inited = true;
206 }
207
208 void FGTrafficManager::loadHeuristics()
209 {
210     if (!fgGetBool("/sim/traffic-manager/heuristics")) {
211         return;
212     }
213   
214     HeuristicMap heurMap;
215     //cerr << "Processing Heuristics" << endl;
216     // Load the heuristics data
217     SGPath cacheData(fgGetString("/sim/fg-home"));
218     cacheData.append("ai");
219     string airport = fgGetString("/sim/presets/airport-id");
220     if ((airport) != "") {
221       char buffer[128];
222       ::snprintf(buffer, 128, "%c/%c/%c/",
223                  airport[0], airport[1], airport[2]);
224       cacheData.append(buffer);
225       cacheData.append(airport + "-cache.txt");
226       string revisionStr;
227       if (cacheData.exists()) {
228         ifstream data(cacheData.c_str());
229         data >> revisionStr;
230         if (revisionStr != "[TrafficManagerCachedata:ref:2011:09:04]") {
231           SG_LOG(SG_GENERAL, SG_ALERT,"Traffic Manager Warning: discarding outdated cachefile " << 
232                  cacheData.c_str() << " for Airport " << airport);
233         } else {
234           while (1) {
235             Heuristic h; // = new Heuristic;
236             data >> h.registration >> h.runCount >> h.hits >> h.lastRun;
237             if (data.eof())
238               break;
239             HeuristicMapIterator itr = heurMap.find(h.registration);
240             if (itr != heurMap.end()) {
241               SG_LOG(SG_GENERAL, SG_WARN,"Traffic Manager Warning: found duplicate tailnumber " << 
242                      h.registration << " for AI aircraft");
243             } else {
244               heurMap[h.registration] = h;
245             }
246           }
247         }
248       }
249     } 
250     
251   for(currAircraft = scheduledAircraft.begin(); currAircraft != scheduledAircraft.end(); ++currAircraft) {
252         string registration = (*currAircraft)->getRegistration();
253         HeuristicMapIterator itr = heurMap.find(registration);
254         if (itr != heurMap.end()) {
255             (*currAircraft)->setrunCount(itr->second.runCount);
256             (*currAircraft)->setHits(itr->second.hits);
257             (*currAircraft)->setLastUsed(itr->second.lastRun);
258         }
259     }
260 }
261
262 void FGTrafficManager::update(double /*dt */ )
263 {
264     if (!enabled || !aiEnabled || (realWxEnabled && !metarValid)) {
265         return;
266     }
267         
268     if (!inited) {
269         if (!doingInit) {
270             init();
271         }
272         
273         initStep();
274         if (!inited) {
275             return; // still more to do on next update() call
276         }
277     }
278         
279     time_t now = time(NULL) + fgGetLong("/sim/time/warp");
280     if (scheduledAircraft.size() == 0) {
281         return;
282     }
283
284     SGVec3d userCart = globals->get_aircraft_positon_cart();
285
286     if (currAircraft == scheduledAircraft.end()) {
287         currAircraft = scheduledAircraft.begin();
288     }
289     //cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
290     if (!((*currAircraft)->update(now, userCart))) {
291         (*currAircraft)->taint();
292     }
293     currAircraft++;
294 }
295
296 void FGTrafficManager::release(int id)
297 {
298     releaseList.push_back(id);
299 }
300
301 bool FGTrafficManager::isReleased(int id)
302 {
303     IdListIterator i = releaseList.begin();
304     while (i != releaseList.end()) {
305         if ((*i) == id) {
306             releaseList.erase(i);
307             return true;
308         }
309         i++;
310     }
311     return false;
312 }
313
314
315 void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
316 {
317     string model;
318     string livery;
319     string homePort;
320     string registration;
321     string flightReq;
322     bool   isHeavy;
323     string acType;
324     string airline;
325     string m_class;
326     string FlightType;
327     double radius;
328     double offset;
329
330     char buffer[256];
331     string buffString;
332     vector <string> tokens, depTime,arrTime;
333     vector <string>::iterator it;
334     ifstream infile(infileName.str().c_str());
335     while (1) {
336          infile.getline(buffer, 256);
337          if (infile.eof()) {
338              break;
339          }
340          //cerr << "Read line : " << buffer << endl;
341          buffString = string(buffer);
342          tokens.clear();
343          Tokenize(buffString, tokens, " \t");
344          //for (it = tokens.begin(); it != tokens.end(); it++) {
345          //    cerr << "Tokens: " << *(it) << endl;
346          //}
347          //cerr << endl;
348          if (!tokens.empty()) {
349              if (tokens[0] == string("AC")) {
350                  if (tokens.size() != 13) {
351                      SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
352                      exit(1);
353                  }
354                  model          = tokens[12];
355                  livery         = tokens[6];
356                  homePort       = tokens[1];
357                  registration   = tokens[2];
358                  if (tokens[11] == string("false")) {
359                      isHeavy = false;
360                  } else {
361                      isHeavy = true;
362                  }
363                  acType         = tokens[4];
364                  airline        = tokens[5];
365                  flightReq      = tokens[3] + tokens[5];
366                  m_class        = tokens[10];
367                  FlightType     = tokens[9];
368                  radius         = atof(tokens[8].c_str());
369                  offset         = atof(tokens[7].c_str());;
370                  SG_LOG(SG_GENERAL, SG_ALERT, "Adding Aircraft" << model << " " << livery << " " << homePort << " " 
371                                                                 << registration << " " << flightReq << " " << isHeavy 
372                                                                 << " " << acType << " " << airline << " " << m_class 
373                                                                 << " " << FlightType << " " << radius << " " << offset);
374                  scheduledAircraft.push_back(new FGAISchedule(model, 
375                                                               livery, 
376                                                               homePort,
377                                                               registration, 
378                                                               flightReq,
379                                                               isHeavy,
380                                                               acType, 
381                                                               airline, 
382                                                               m_class, 
383                                                               FlightType,
384                                                               radius,
385                                                               offset));
386              }
387              if (tokens[0] == string("FLIGHT")) {
388                  //cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl;
389                  if (tokens.size() != 10) {
390                      SG_LOG(SG_GENERAL, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
391                      exit(1);
392                  }
393                  string callsign = tokens[1];
394                  string fltrules = tokens[2];
395                  string weekdays = tokens[3];
396                  string departurePort = tokens[5];
397                  string arrivalPort   = tokens[7];
398                  int    cruiseAlt     = atoi(tokens[8].c_str());
399                  string depTimeGen    = tokens[4];
400                  string arrTimeGen    = tokens[6];
401                  string repeat        = "WEEK";
402                  string requiredAircraft = tokens[9];
403
404                  if (weekdays.size() != 7) {
405                      SG_LOG(SG_GENERAL, SG_ALERT, "Found misconfigured weekdays string" << weekdays);
406                      exit(1);
407                  }
408                  depTime.clear();
409                  arrTime.clear();
410                  Tokenize(depTimeGen, depTime, ":");
411                  Tokenize(arrTimeGen, arrTime, ":");
412                  double dep = atof(depTime[0].c_str()) + (atof(depTime[1].c_str()) / 60.0);
413                  double arr = atof(arrTime[0].c_str()) + (atof(arrTime[1].c_str()) / 60.0);
414                  //cerr << "Using " << dep << " " << arr << endl;
415                  bool arrivalWeekdayNeedsIncrement = false;
416                  if (arr < dep) {
417                        arrivalWeekdayNeedsIncrement = true;
418                  }
419                  for (int i = 0; i < 7; i++) {
420                      int j = i+1;
421                      if (weekdays[i] != '.') {
422                          char buffer[4];
423                          snprintf(buffer, 4, "%d/", j);
424                          string departureTime = string(buffer) + depTimeGen + string(":00");
425                          string arrivalTime;
426                          if (!arrivalWeekdayNeedsIncrement) {
427                              arrivalTime   = string(buffer) + arrTimeGen + string(":00");
428                          }
429                          if (arrivalWeekdayNeedsIncrement && i != 6 ) {
430                              snprintf(buffer, 4, "%d/", j+1);
431                              arrivalTime   = string(buffer) + arrTimeGen + string(":00");
432                          }
433                          if (arrivalWeekdayNeedsIncrement && i == 6 ) {
434                              snprintf(buffer, 4, "%d/", 0);
435                              arrivalTime   = string(buffer) + arrTimeGen  + string(":00");
436                          }
437                          SG_LOG(SG_GENERAL, SG_ALERT, "Adding flight " << callsign       << " "
438                                                       << fltrules       << " "
439                                                       <<  departurePort << " "
440                                                       <<  arrivalPort   << " "
441                                                       <<  cruiseAlt     << " "
442                                                       <<  departureTime << " "
443                                                       <<  arrivalTime   << " "
444                                                       << repeat        << " " 
445                                                       <<  requiredAircraft);
446
447                          flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
448                                                                  fltrules,
449                                                                  departurePort,
450                                                                  arrivalPort,
451                                                                  cruiseAlt,
452                                                                  departureTime,
453                                                                  arrivalTime,
454                                                                  repeat,
455                                                                  requiredAircraft));
456                     }
457                 }
458              }
459          }
460
461     }
462     //exit(1);
463 }
464
465
466 void FGTrafficManager::Tokenize(const string& str,
467                       vector<string>& tokens,
468                       const string& delimiters)
469 {
470     // Skip delimiters at beginning.
471     string::size_type lastPos = str.find_first_not_of(delimiters, 0);
472     // Find first "non-delimiter".
473     string::size_type pos     = str.find_first_of(delimiters, lastPos);
474
475     while (string::npos != pos || string::npos != lastPos)
476     {
477         // Found a token, add it to the vector.
478         tokens.push_back(str.substr(lastPos, pos - lastPos));
479         // Skip delimiters.  Note the "not_of"
480         lastPos = str.find_first_not_of(delimiters, pos);
481         // Find next "non-delimiter"
482         pos = str.find_first_of(delimiters, lastPos);
483     }
484 }
485
486
487 void FGTrafficManager::startXML()
488 {
489     //cout << "Start XML" << endl;
490     requiredAircraft = "";
491     homePort = "";
492 }
493
494 void FGTrafficManager::endXML()
495 {
496     //cout << "End XML" << endl;
497 }
498
499 void FGTrafficManager::startElement(const char *name,
500                                     const XMLAttributes & atts)
501 {
502     const char *attval;
503     //cout << "Start element " << name << endl;
504     //FGTrafficManager temp;
505     //for (int i = 0; i < atts.size(); i++)
506     //  if (string(atts.getName(i)) == string("include"))
507     attval = atts.getValue("include");
508     if (attval != 0) {
509         //cout << "including " << attval << endl;
510         SGPath path = globals->get_fg_root();
511         path.append("/Traffic/");
512         path.append(attval);
513         readXML(path.str(), *this);
514     }
515     elementValueStack.push_back("");
516     //  cout << "  " << atts.getName(i) << '=' << atts.getValue(i) << endl; 
517 }
518
519 void FGTrafficManager::endElement(const char *name)
520 {
521     //cout << "End element " << name << endl;
522     const string & value = elementValueStack.back();
523
524     if (!strcmp(name, "model"))
525         mdl = value;
526     else if (!strcmp(name, "livery"))
527         livery = value;
528     else if (!strcmp(name, "home-port"))
529         homePort = value;
530     else if (!strcmp(name, "registration"))
531         registration = value;
532     else if (!strcmp(name, "airline"))
533         airline = value;
534     else if (!strcmp(name, "actype"))
535         acType = value;
536     else if (!strcmp(name, "required-aircraft"))
537         requiredAircraft = value;
538     else if (!strcmp(name, "flighttype"))
539         flighttype = value;
540     else if (!strcmp(name, "radius"))
541         radius = atoi(value.c_str());
542     else if (!strcmp(name, "offset"))
543         offset = atoi(value.c_str());
544     else if (!strcmp(name, "performance-class"))
545         m_class = value;
546     else if (!strcmp(name, "heavy")) {
547         if (value == string("true"))
548             heavy = true;
549         else
550             heavy = false;
551     } else if (!strcmp(name, "callsign"))
552         callsign = value;
553     else if (!strcmp(name, "fltrules"))
554         fltrules = value;
555     else if (!strcmp(name, "port"))
556         port = value;
557     else if (!strcmp(name, "time"))
558         timeString = value;
559     else if (!strcmp(name, "departure")) {
560         departurePort = port;
561         departureTime = timeString;
562     } else if (!strcmp(name, "cruise-alt"))
563         cruiseAlt = atoi(value.c_str());
564     else if (!strcmp(name, "arrival")) {
565         arrivalPort = port;
566         arrivalTime = timeString;
567     } else if (!strcmp(name, "repeat"))
568         repeat = value;
569     else if (!strcmp(name, "flight")) {
570         // We have loaded and parsed all the information belonging to this flight
571         // so we temporarily store it. 
572         //cerr << "Pusing back flight " << callsign << endl;
573         //cerr << callsign  <<  " " << fltrules     << " "<< departurePort << " " <<  arrivalPort << " "
574         //   << cruiseAlt <<  " " << departureTime<< " "<< arrivalTime   << " " << repeat << endl;
575
576         //Prioritize aircraft 
577         string apt = fgGetString("/sim/presets/airport-id");
578         //cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl;
579         //if (departurePort == apt) score++;
580         //flights.push_back(new FGScheduledFlight(callsign,
581         //                                fltrules,
582         //                                departurePort,
583         //                                arrivalPort,
584         //                                cruiseAlt,
585         //                                departureTime,
586         //                                arrivalTime,
587         //                                repeat));
588         if (requiredAircraft == "") {
589             char buffer[16];
590             snprintf(buffer, 16, "%d", acCounter);
591             requiredAircraft = buffer;
592         }
593         SG_LOG(SG_GENERAL, SG_DEBUG, "Adding flight: " << callsign << " "
594                << fltrules << " "
595                << departurePort << " "
596                << arrivalPort << " "
597                << cruiseAlt << " "
598                << departureTime << " "
599                << arrivalTime << " " << repeat << " " << requiredAircraft);
600         // For database maintainance purposes, it may be convenient to
601         // 
602         if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
603              SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump FLIGHT," << callsign << ","
604                           << fltrules << ","
605                           << departurePort << ","
606                           << arrivalPort << ","
607                           << cruiseAlt << ","
608                           << departureTime << ","
609                           << arrivalTime << "," << repeat << "," << requiredAircraft);
610         }
611         flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
612                                                                   fltrules,
613                                                                   departurePort,
614                                                                   arrivalPort,
615                                                                   cruiseAlt,
616                                                                   departureTime,
617                                                                   arrivalTime,
618                                                                   repeat,
619                                                                   requiredAircraft));
620         requiredAircraft = "";
621     } else if (!strcmp(name, "aircraft")) {
622         string isHeavy;
623         if (heavy) {
624             isHeavy = "true";
625         } else {
626             isHeavy = "false"; 
627         }
628         /*
629         cerr << "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft 
630              << "," << acType << "," << livery << "," 
631              << airline << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl << endl;*/
632         int proportion =
633             (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
634         int randval = rand() & 100;
635         if (randval <= proportion) {
636             if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
637                 SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft 
638                  << "," << acType << "," << livery << "," 
639                  << airline << ","  << m_class << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl);
640             }
641             //scheduledAircraft.push_back(new FGAISchedule(mdl, 
642             //                                     livery, 
643             //                                     registration, 
644             //                                     heavy,
645             //                                     acType, 
646             //                                     airline, 
647             //                                     m_class, 
648             //                                     flighttype,
649             //                                     radius,
650             //                                     offset,
651             //                                     score,
652             //                                     flights));
653             if (requiredAircraft == "") {
654                 char buffer[16];
655                 snprintf(buffer, 16, "%d", acCounter);
656                 requiredAircraft = buffer;
657             }
658             if (homePort == "") {
659                 homePort = departurePort;
660             }
661             scheduledAircraft.push_back(new FGAISchedule(mdl,
662                                                          livery,
663                                                          homePort,
664                                                          registration,
665                                                          requiredAircraft,
666                                                          heavy,
667                                                          acType,
668                                                          airline,
669                                                          m_class,
670                                                          flighttype,
671                                                          radius, offset));
672
673             //  while(flights.begin() != flights.end()) {
674 //      flights.pop_back();
675 //       }
676         } else {
677             cerr << "Skipping : " << randval;
678         }
679         acCounter++;
680         requiredAircraft = "";
681         homePort = "";
682         //for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
683         //  {
684         //    delete (*flt);
685         //  }
686         //flights.clear();
687         SG_LOG(SG_GENERAL, SG_BULK, "Reading aircraft : "
688                << registration << " with prioritization score " << score);
689         score = 0;
690     }
691     elementValueStack.pop_back();
692 }
693
694 void FGTrafficManager::data(const char *s, int len)
695 {
696     string token = string(s, len);
697     //cout << "Character data " << string(s,len) << endl;
698     elementValueStack.back() += token;
699 }
700
701 void FGTrafficManager::pi(const char *target, const char *data)
702 {
703     //cout << "Processing instruction " << target << ' ' << data << endl;
704 }
705
706 void FGTrafficManager::warning(const char *message, int line, int column)
707 {
708     SG_LOG(SG_IO, SG_WARN,
709            "Warning: " << message << " (" << line << ',' << column << ')');
710 }
711
712 void FGTrafficManager::error(const char *message, int line, int column)
713 {
714     SG_LOG(SG_IO, SG_ALERT,
715            "Error: " << message << " (" << line << ',' << column << ')');
716 }