1
0
Fork 0

[scheduler] Maintenance

This commit is contained in:
scttgs0 2023-05-14 17:49:40 -05:00
parent f98b5cd482
commit 3f7bb23b38
2 changed files with 201 additions and 229 deletions

View file

@ -1,9 +1,9 @@
#ifdef _MSC_VER
# include <windows.h>
# define sleep(x) Sleep(x*1000)
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#endif
#include <cstring>
//#//include <cstring>
#include <memory>
#include <simgear/debug/logstream.hxx>
@ -13,14 +13,15 @@
#include "parser.hxx"
#include "scheduler.hxx"
extern double gSnap;
SGLockedQueue<AirportInfo> global_workQueue;
std::ostream& operator<< (std::ostream &out, const AirportInfo &ai)
std::ostream& operator<<(std::ostream& out, const AirportInfo& ai)
{
char snap_string[32];
sprintf( snap_string, "%1.8lf", ai.snap );
sprintf(snap_string, "%1.8lf", ai.snap);
out << ai.icao;
out << ",";
@ -40,43 +41,42 @@ std::ostream& operator<< (std::ostream &out, const AirportInfo &ai)
out << ",";
out << ai.tessTime;
out << ",";
out << ai.parseTime+ai.buildTime+ai.cleanTime+ai.tessTime;
out << ai.parseTime + ai.buildTime + ai.cleanTime + ai.tessTime;
out << ",";
out << snap_string,
out << ",";
out << ",";
out << ai.errString;
return out; // MSVC
return out; // MSVC
}
void Scheduler::set_debug( const std::string& path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs )
void Scheduler::set_debug(const std::string& path,
std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs)
{
TG_LOG(SG_GENERAL, SG_ALERT, "Set debug Path " << path);
debug_path = path;
/* Find any ids for our tile */
for (unsigned int i=0; i< runway_defs.size(); i++) {
std::string dsd = runway_defs[i];
size_t d_pos = dsd.find(":");
for (std::string dsd : runway_defs) {
size_t d_pos = dsd.find(":");
std::string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
dsd.erase(0, d_pos+1);
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
shapes.push_back( std::numeric_limits<int>::max() );
if (dsd == "all") {
shapes.push_back(std::numeric_limits<int>::max());
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << idx << " for " << icao );
while (ss >> idx) {
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << idx << " for " << icao);
shapes.push_back(idx);
@ -84,27 +84,26 @@ void Scheduler::set_debug( const std::string& path, std::vector<std::string> run
ss.ignore();
}
}
debug_runways[icao] = shapes;
}
for (unsigned int i=0; i< pavement_defs.size(); i++) {
std::string dsd = pavement_defs[i];
size_t d_pos = dsd.find(":");
for (std::string dsd : pavement_defs) {
size_t d_pos = dsd.find(":");
std::string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
dsd.erase(0, d_pos+1);
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
shapes.push_back( std::numeric_limits<int>::max() );
if (dsd == "all") {
shapes.push_back(std::numeric_limits<int>::max());
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << idx << " for " << icao );
while (ss >> idx) {
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << idx << " for " << icao);
shapes.push_back(idx);
@ -112,27 +111,26 @@ void Scheduler::set_debug( const std::string& path, std::vector<std::string> run
ss.ignore();
}
}
debug_pavements[icao] = shapes;
}
for (unsigned int i=0; i< taxiway_defs.size(); i++) {
std::string dsd = taxiway_defs[i];
size_t d_pos = dsd.find(":");
for (std::string dsd : taxiway_defs) {
size_t d_pos = dsd.find(":");
std::string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
dsd.erase(0, d_pos+1);
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
shapes.push_back( std::numeric_limits<int>::max() );
if (dsd == "all") {
shapes.push_back(std::numeric_limits<int>::max());
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << idx << " for " << icao );
while (ss >> idx) {
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << idx << " for " << icao);
shapes.push_back(idx);
@ -140,27 +138,26 @@ void Scheduler::set_debug( const std::string& path, std::vector<std::string> run
ss.ignore();
}
}
debug_taxiways[icao] = shapes;
}
for (unsigned int i=0; i< feature_defs.size(); i++) {
std::string dsd = feature_defs[i];
size_t d_pos = dsd.find(":");
for (std::string dsd : feature_defs) {
size_t d_pos = dsd.find(":");
std::string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
dsd.erase(0, d_pos+1);
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
shapes.push_back( std::numeric_limits<int>::max() );
if (dsd == "all") {
shapes.push_back(std::numeric_limits<int>::max());
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << idx << " for " << icao );
while (ss >> idx) {
TG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << idx << " for " << icao);
shapes.push_back(idx);
@ -168,154 +165,138 @@ void Scheduler::set_debug( const std::string& path, std::vector<std::string> run
ss.ignore();
}
}
debug_features[icao] = shapes;
}
}
bool Scheduler::IsAirportDefinition( char* line, const std::string& icao )
bool Scheduler::IsAirportDefinition(char* line, const std::string& icao)
{
bool match = false;
// Get the number code
char* tok = strtok(line, " \t\r\n");
if (tok)
{
line += strlen(tok)+1;
if (tok) {
line += strlen(tok) + 1;
int code = atoi(tok);
switch(code)
{
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE:
{
Airport ap( code, line );
switch (code) {
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE: {
Airport ap(code, line);
if ( ap.GetIcao() == icao )
{
match = true;
}
}
break;
if (ap.GetIcao() == icao) {
match = true;
}
} break;
default:
break;
default:
break;
}
}
return match;
}
void Scheduler::AddAirport( std::string icao )
void Scheduler::AddAirport(std::string icao)
{
char line[2048];
bool found = false;
AirportInfo ai;
char line[2048];
bool found = false;
AirportInfo ai;
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
TG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
std::ifstream in(filename.c_str());
if (!in.is_open()) {
TG_LOG(SG_GENERAL, SG_ALERT, "Cannot open file: " << filename);
exit(-1);
}
TG_LOG( SG_GENERAL, SG_INFO, "Adding airport " << icao << " to parse list");
while ( !in.eof() && !found )
{
TG_LOG(SG_GENERAL, SG_INFO, "Adding airport " << icao << " to parse list");
while (!in.eof() && !found) {
// remember the position of this line
long cur_pos = in.tellg();
// get a line
in.getline(line, 2048);
in.getline(line, 2048);
// this is an airport definition - remember it
if ( IsAirportDefinition( line, icao ) )
{
TG_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << icao << " at " << cur_pos );
if (IsAirportDefinition(line, icao)) {
TG_LOG(SG_GENERAL, SG_DEBUG, "Found airport " << icao << " at " << cur_pos);
ai = AirportInfo( icao, cur_pos, gSnap );
global_workQueue.push( ai );
ai = AirportInfo(icao, cur_pos, gSnap);
global_workQueue.push(ai);
found = true;
}
}
}
long Scheduler::FindAirport( const std::string& icao )
long Scheduler::FindAirport(const std::string& icao)
{
char line[2048];
long cur_pos = 0;
bool found = false;
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
TG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
std::ifstream in(filename.c_str());
if (!in.is_open()) {
TG_LOG(SG_GENERAL, SG_ALERT, "Cannot open file: " << filename);
exit(-1);
}
TG_LOG( SG_GENERAL, SG_DEBUG, "Finding airport " << icao );
while ( !in.eof() && !found )
{
TG_LOG(SG_GENERAL, SG_DEBUG, "Finding airport " << icao);
while (!in.eof() && !found) {
// remember the position of this line
cur_pos = in.tellg();
// get a line
in.getline(line, 2048);
in.getline(line, 2048);
// this is and airport definition - remember it
if ( IsAirportDefinition( line, icao ) )
{
TG_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << line << " at " << cur_pos );
if (IsAirportDefinition(line, icao)) {
TG_LOG(SG_GENERAL, SG_DEBUG, "Found airport " << line << " at " << cur_pos);
found = true;
}
}
if (found)
{
return cur_pos;
}
else
{
return 0;
}
if (found) {
return cur_pos;
} else {
return 0;
}
}
void Scheduler::RetryAirport( AirportInfo* pai )
void Scheduler::RetryAirport(AirportInfo* pai)
{
// retryList.push_back( *pai );
}
bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
bool Scheduler::AddAirports(long start_pos, tgRectangle* boundingBox)
{
char line[2048];
long cur_apt_pos = 0;
std::string cur_apt_name;
int code;
bool match;
bool done;
char line[2048];
long cur_apt_pos = 0;
std::string cur_apt_name;
int code;
bool match;
bool done;
done = false;
done = false;
match = false;
// start from current position, and push all airports where a runway start or end
// lies within the given min/max coordinates
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
TG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
std::ifstream in(filename.c_str());
if (!in.is_open()) {
TG_LOG(SG_GENERAL, SG_ALERT, "Cannot open file: " << filename);
exit(-1);
}
if (start_pos)
{
if (start_pos) {
in.seekg(start_pos, std::ios::beg);
}
while (!done)
{
while (!done) {
// remember the position of this line
long cur_pos = in.tellg();
@ -326,115 +307,104 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
// Get the number code
char* tok = strtok(def, " \t\r\n");
if (tok)
{
def += strlen(tok)+1;
if (tok) {
def += strlen(tok) + 1;
code = atoi(tok);
switch(code)
{
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE:
{
auto airport = std::make_unique<Airport>( code, def );
if (match)
{
// Start off with given snap value
AirportInfo ai = AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
global_workQueue.push( ai );
}
// remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos;
cur_apt_name = airport->GetIcao();
switch (code) {
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE: {
auto airport = std::make_unique<Airport>(code, def);
if (match) {
// Start off with given snap value
AirportInfo ai = AirportInfo(cur_apt_name, cur_apt_pos, gSnap);
global_workQueue.push(ai);
}
// remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos;
cur_apt_name = airport->GetIcao();
match = false;
match = false;
} break;
case END_OF_FILE:
if (match) {
// Start off with given snap value
AirportInfo ai = AirportInfo(cur_apt_name, cur_apt_pos, gSnap);
global_workQueue.push(ai);
}
done = true;
break;
case LAND_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
auto runway = std::make_unique<Runway>(def);
if (boundingBox->isInside(runway->GetStart())) {
match = true;
} else if (boundingBox->isInside(runway->GetEnd())) {
match = true;
}
}
break;
case END_OF_FILE:
if (match)
{
// Start off with given snap value
AirportInfo ai = AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
global_workQueue.push( ai );
case WATER_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
auto runway = std::make_unique<WaterRunway>(def);
if (boundingBox->isInside(runway->GetStart())) {
match = true;
} else if (boundingBox->isInside(runway->GetEnd())) {
match = true;
}
done = true;
break;
}
break;
case LAND_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
auto runway = std::make_unique<Runway>(def);
if ( boundingBox->isInside(runway->GetStart()) ) {
match = true;
}
else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true;
}
case HELIPAD_CODE:
// if the heliport coords are within the rect, we have
// a winner
{
auto helipad = std::make_unique<Helipad>(def);
if (boundingBox->isInside(helipad->GetLoc())) {
match = true;
}
break;
}
break;
case WATER_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
auto runway = std::make_unique<WaterRunway>(def);
if ( boundingBox->isInside(runway->GetStart()) ) {
match = true;
}
else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true;
}
}
break;
case HELIPAD_CODE:
// if the heliport coords are within the rect, we have
// a winner
{
auto helipad = std::make_unique<Helipad>(def);
if ( boundingBox->isInside(helipad->GetLoc()) ) {
match = true;
}
}
break;
default:
break;
default:
break;
}
}
}
// did we add airports to the parse list?
if ( global_workQueue.size() ) {
if (global_workQueue.size())
return true;
} else {
return false;
}
return false;
}
Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src) :
filename(datafile),
elevation(elev_src),
work_dir(root)
Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src) : filename(datafile),
elevation(elev_src),
work_dir(root)
{
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
TG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
std::ifstream in(filename.c_str());
if (!in.is_open()) {
TG_LOG(SG_GENERAL, SG_ALERT, "Cannot open file: " << filename);
exit(-1);
}
}
void Scheduler::Schedule( int num_threads, std::string& summaryfile )
void Scheduler::Schedule(int num_threads, std::string& summaryfile)
{
std::vector<std::shared_ptr<Parser>> parsers;
for (int i=0; i<num_threads; i++) {
auto parser = std::make_shared<Parser>( filename, work_dir, elevation );
for (int i = 0; i < num_threads; i++) {
auto parser = std::make_shared<Parser>(filename, work_dir, elevation);
parser->start();
parsers.push_back( parser );
parsers.push_back(parser);
}
while (!global_workQueue.empty()) {
@ -442,7 +412,7 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile )
}
// Then wait until they are finished
for (unsigned int i=0; i<parsers.size(); i++) {
for (unsigned int i = 0; i < parsers.size(); i++) {
parsers[i]->join();
parsers[i] = nullptr;
}

View file

@ -1,15 +1,17 @@
#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
#include <simgear/compiler.h>
#include <simgear/math/sg_types.hxx>
#include <simgear/timing/timestamp.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGQueue.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/timing/timestamp.hxx>
#include <terragear/tg_rectangle.hxx>
#include "airport.hxx"
@ -21,10 +23,10 @@
#define P_STATE_DONE (8)
#define P_STATE_KILLED (9)
#define P_STATE_INIT_TIME (1*60)
#define P_STATE_PARSE_TIME (1*60)
#define P_STATE_INIT_TIME (60)
#define P_STATE_PARSE_TIME (60)
#define P_STATE_BUILD_TIME (30*60)
#define P_STATE_TRIANGULATE_TIME (1*60)
#define P_STATE_TRIANGULATE_TIME (60)
#define P_STATE_OUTPUT_TIME (10*60)
#define GENAPT_PORT (12397)
@ -56,21 +58,21 @@ public:
numTaxiways = -1;
}
std::string GetIcao(void) { return icao; }
long GetPos(void) { return pos; }
double GetSnap(void) { return snap; }
std::string GetIcao() const { return icao; }
long GetPos() const { return pos; }
double GetSnap() const { return snap; }
void SetRunways(int r) { numRunways = r; }
void SetPavements(int p) { numPavements = p; }
void SetFeats(int f) { numFeats = f; }
void SetTaxiways(int t) { numTaxiways = t; }
void SetParseTime(SGTimeStamp t) { parseTime = t; }
void SetBuildTime(SGTimeStamp t) { buildTime = t; }
void SetCleanTime(SGTimeStamp t) { cleanTime = t; }
void SetTessTime(SGTimeStamp t) { tessTime = t; }
void SetErrorString(char* e) { errString = e; }
void SetRunways(int r) { numRunways = r; }
void SetPavements(int p) { numPavements = p; }
void SetFeats(int f) { numFeats = f; }
void SetTaxiways(int t) { numTaxiways = t; }
void SetParseTime(SGTimeStamp t) { parseTime = t; }
void SetBuildTime(SGTimeStamp t) { buildTime = t; }
void SetCleanTime(SGTimeStamp t) { cleanTime = t; }
void SetTessTime(SGTimeStamp t) { tessTime = t; }
void SetErrorString(char* e) { errString = e; }
void IncreaseSnap(void) { snap *= 2.0f; }
void IncreaseSnap() { snap *= 2.0f; }
friend std::ostream& operator<<(std::ostream& output, const AirportInfo& ai);