📄 timetable.cpp
字号:
oflog << "Found the begin time: " << *ttit << endl; TTab.push_back(*ttit); beg = ttit->end; TTS.erase(ttit); break; } } if(beg == endcount) { // one segment covers it all - done! oflog << "One segment covers it all!" << endl; end = endcount; } else { // find the end point for(ttit=TTS.begin(); ttit != TTS.end(); ttit++) { if(ttit->end == endcount) { oflog << "Found the end time: " << *ttit << endl; TTab.push_back(*ttit); end = ttit->start; TTS.erase(ttit); break; } } if(TTab.size() != 2) { // error, we didn't find the beg and end -- throw? return -2; } } // start list of segs with the ones that contain endpoints ttit = TTab.begin(); Segs.push_back(make_pair(ttit->start,ttit->end)); ttit++; if(ttit != TTab.end()) Segs.push_back(make_pair(ttit->start,ttit->end)); if(beg >= end) { // two segments cover it all if(Segs.size() > 1) { // TD unsure if the logic is wrong here... ljt = lit = Segs.begin(); ljt++; lit->second = ljt->second; if(CI.Debug) oflog << "Two segments cover it all: erase seg (" << ljt->first << "-" << ljt->second << ")" << endl; Segs.erase(ljt); } } else { // 2. // start with // |======1st Seg======| gap |=====last Seg======| // // in general, new segs can be added, so Segs looks like this: // |===1st Seg===| gap |===2nd Seg===| gap |===last Seg===| // // consider 8 cases of new segments from TTS: // 1. |--------------| covers end of seg // 2. |-------| lies entirely w/in gap // 3. |--------| covers beg of seg // 4. |--------------------| covers entire gap // 5. |----------------------| covers entire seg // 6. covers seg and gap |-------------------------------------| // 7. |-------------------------------------| covers gap and seg // 8. |-----| lies entirely w/in seg // // Here is the algorithm: // for each new segment extending from b to e // for each i in list of segments in list (extending bi to ei) { // if(b > ei) skip to the next i // if(e > ei) { // b <= ei and e > ei // mod seg i so that ei -> e // case 1,4,7 // if(b < bi) mod seg i so that bi -> b // case 5,6 // while (e >= bj) where j > i, // merge segments i and j and delete j // case 4,6,7 // keep this segment // } // else { // b <= ei and e <= ei // if(e >= bi) { // if(b < bi) { // mod segment i so bi -> b // case 3 // keep this segment // } // //else { ignore this segment } // case 8 // } // else { // make a new segment (b,e), // and insert it before segment i // case 2 // keep this segment // } // } // } // end of loop over segments i // if(keep) add this segment to the time table // // loop over all segments, in decreasing order of metric() for(i=1,ttit=TTS.begin(); ttit != TTS.end(); i++,ttit++) { // i temp if(CI.Debug) { // temp oflog << "Here is the current time table (" << TTab.size() << ")" << endl; for(ttjt=TTab.begin(); ttjt != TTab.end(); ttjt++) oflog << " " << *ttjt << endl; } if(CI.Debug) { oflog << "and here is the seg list"; for(lit=Segs.begin(); lit != Segs.end(); lit++) oflog << " (" << lit->first << "-" << lit->second << ")"; oflog << endl; } // done if one segment covers all lit = Segs.begin(); if(Segs.size() == 1 && lit->first == begcount && lit->second == endcount) break; // keep this? you don't want metric to become very small -> failure if(ttit->metric() <= 100.0) break; // TD input param beg = ttit->start; end = ttit->end; if(CI.Debug) oflog << "consider new segment (" << beg << "-" << end << ")" << endl; // loop over the segs keep = false; lit = Segs.begin(); while(lit != Segs.end()) { if(beg > lit->second) { if(CI.Debug) oflog << " skip seg (" << lit->first << "-" << lit->second << ")" << endl; lit++; continue; } if(end > lit->second) { if(CI.Debug) oflog << " mod 1 seg (" << lit->first << "-" << lit->second << ")"; lit->second = end; if(beg < lit->first) lit->first=beg; if(CI.Debug) oflog << " to (" << lit->first << "-" << lit->second << ")" << endl; ljt = lit; while(++ljt != Segs.end() && end >= ljt->first) { // merge i and j if(CI.Debug) oflog << " merge segs (" << lit->first << "-" << lit->second << ") and (" << ljt->first << "-" << ljt->second << ")"; lit->second = ljt->second; if(CI.Debug) oflog << " and erase seg (" << ljt->first << "-" << ljt->second << ")" << endl; Segs.erase(ljt); ljt = lit; } keep = true; } else { if(end >= lit->first) { if(beg < lit->first) { if(CI.Debug) oflog << " mod 2 seg (" << lit->first << "-" << lit->second << ")"; lit->first = beg; keep = true; if(CI.Debug) oflog << " to (" << lit->first << "-" << lit->second << ")" << endl; } //else { keep=false; ignore -- this seg has nothing new } } else { seg newseg(beg,end); if(CI.Debug) oflog << " add seg (" << newseg.first << "-" << newseg.second << ")" << endl; Segs.insert(lit,newseg); keep = true; } } break; } // end while loop over segs if(keep) { TTab.push_back(*ttit); TTab.sort(startSort); // temp } if(CI.Debug) if(i > 100) break; // temp } // end for loop over segments TTS } // end if(initial gap is non-zero) // 3. are there gaps? if(Segs.size() != 1) { oflog << "There are real gaps in the data; segments with data:" << endl; for(lit=Segs.begin(); lit != Segs.end(); lit++) oflog << " (" << lit->first << "-" << lit->second << ")"; oflog << endl; } else oflog << "There are no gaps in the data" << endl; // sort the timetable TTab.sort(startSort); // TD 4. edit TTab, removing segments that do not create gaps // decide on actual transition times for(ttit=TTab.begin(); ttit != TTab.end(); ttit++) { if(CI.Verbose) oflog << " " << *ttit << endl; // compute the count at which to switch if(ttit == TTab.begin()) { ttit->first = ttit->start; // first = start for first segment ttjt = ttit; // initialize ttjt } else { // switch at the mid-point of overlap ttit->first = (ttjt->end + ttit->start)/2; } ttit->last = ttit->end; // change later, except for last segment if(ttit != TTab.begin()) { ttjt->last = ttit->first; // count at the switch point ttjt++; // ttjt lags behind ttit by 1 } } return 0;}catch(Exception& e) { GPSTK_RETHROW(e); }catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }}//------------------------------------------------------------------------------------void TTSegment::findElev(void){ int i,k; double elevi; RawData& rd=Stations[site1].RawDataBuffers[sat]; minelev = 99.0; maxelev = -1.0; k = index(rd.count,start); if(k == -1) return; for(i=k; i<k+length; i++) { elevi = RotatedAntennaElevation(rd.elev.at(i),rd.az.at(i)); if(elevi > maxelev) maxelev = elevi; if(elevi < minelev) minelev = elevi; }}//------------------------------------------------------------------------------------// friends of TTSegment, defined therebool startSort(const TTSegment& left, const TTSegment& right){ return (left.start < right.start); }bool increasingMetricSort(const TTSegment& left, const TTSegment& right){ return (left.metric() < right.metric()); }bool decreasingMetricSort(const TTSegment& left, const TTSegment& right){ return (left.metric() > right.metric()); }//------------------------------------------------------------------------------------ostream& operator<<(ostream& os, const TTSegment& t){try { os << " " << t.site1 << " " << t.site2 << " " << t.sat << " " << setw(5) << t.length << " " << setw(5) << t.start << " - " << setw(5) << t.end //<< " (" << t.first << "-" << t.last << ")" << " " << fixed << setw(4) << setprecision(1) << t.minelev << " - " << fixed << setw(4) << setprecision(1) << t.maxelev << " " << setw(7) << setprecision(2) << t.metric(); return os;}catch(Exception& e) { GPSTK_RETHROW(e); }catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }}//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -