Closed yakra closed 1 year ago
Almost used this for production, but simplifying HighwaySegment::add_concurrency
outweighed the extra iteration & comparisons in concurrency_detection.cpp
.
void HighwaySegment::add_concurrency(std::ofstream& concurrencyfile, Waypoint* w)
{ HighwaySegment& other = w->route->segments[w - w->route->points.data];
switch (bool(concurrent) + bool(other.concurrent))
{ case 0:
concurrent = new std::list<HighwaySegment*>;
// deleted by ~HighwaySegment
other.concurrent = concurrent;
concurrent->push_back(this);
concurrent->push_back(&other);
concurrencyfile << "New concurrency [" << str() << "][" << other.str() << "] (2)\n";
return;
case 1:
if (concurrent)
{ other.concurrent = concurrent;
concurrent->push_back(&other);
}
else { concurrent = other.concurrent;
other.concurrent->push_back(this);
}
concurrencyfile << "Extended concurrency ";
for (HighwaySegment *x : *concurrent)
concurrencyfile << '[' << x->str() << ']';
concurrencyfile << " (" << concurrent->size() << ")\n";
}
}
if (w1->route == w2->route)
{ s.add_concurrency(concurrencyfile, w1);
break;
}
}
else if (w2 == w1-1 && w1->route == w2->route)
{ s.add_concurrency(concurrencyfile, w2);
break;
}
conc
branch03a58d9
Route::find_segment_by_waypoints
{ return (std::abs(w2 - w1) == 1)
? (w1<w2 ? w1 : w2) - points.data + segments.data
: 0;
996be3b
nix concurrency detection extraneous condition
Remove && (w1 != s.waypoint2 || w2 != s.waypoint1)
dd9fc3d
don't iterate w2 if w1 == s.waypoint1
{ if (w1 == s.waypoint1) continue;
between w1
& w2
iteration, + a matching closing }
dd23dfe
get other segment inline
if (w1->route == w2->route && w2 != s.waypoint2)
-> if (std::abs(w2 - w1) == 1 && w1->route == w2->route)
HighwaySegment *other = w1->route->find_segment_by_waypoints(w1,w2)
-> (w1<w2 ? w1 : w2) - w1->route->points.data + w1->route->segments.data
;
Remove if (other)
Indent the following if
& else
blocks 1 less.
Delete Route::find_segment_by_waypoints
f8b18b4
switch & break
adapted from 32a129f
concurrency detection speedup in the TMARebase2 branch
switch (bool(s.concurrent) + bool(other->concurrent))
{ case 0:
s.concurrent = new list<HighwaySegment*>;
// deleted by ~HighwaySegment
other->concurrent = s.concurrent;
s.concurrent->push_back(&s);
s.concurrent->push_back(other);
concurrencyfile << "New concurrency [" << s.str() << "][" << other->str() << "] (2)\n";
break;
case 1:
if (s.concurrent)
{ other->concurrent = s.concurrent;
s.concurrent->push_back(other);
} else
{ s.concurrent = other->concurrent;
other->concurrent->push_back(&s);
}
concurrencyfile << "Extended concurrency ";
for (HighwaySegment *x : *(s.concurrent))
concurrencyfile << '[' << x->str() << ']';
concurrencyfile << " (" << s.concurrent->size() << ")\n";
}
break;
Just leaving this here to save some experimental code from dead branches for future reference.