Commit 76ea8f6d authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

Activity times

parent dd2d937a
......@@ -46,8 +46,8 @@ namespace Loco
struct TimeSpec
{
unsigned hour = 1000; // intentionally invalid
unsigned minute = 1000; // intentionally invalid
unsigned hour{0};
unsigned minute{0};
TimeSpec() = default;
TimeSpec(unsigned h, unsigned m) : hour(h), minute(m) {}
......
......@@ -94,7 +94,11 @@ void
Loco::TrainRouteGraph::AddLeaveActivity()
{
mActList.emplace_back(mTrain->Ident() + "Leave", mLeavePlace, true);
mActList.back().mTransitionTime = global_cfg.model.transition_time;
auto &act = mActList.back();
act.mForced = true;
act.mMinDuration = 0;
act.mMaxDuration = Activity::kLeafMaxDuration;
act.mTransitionTime = global_cfg.model.transition_time;
}
void
......@@ -421,8 +425,17 @@ Loco::TrainRouteGraph::UpdateInitialActivity(const SectionCPtr &initial_section,
act.mUse = true;
act.mForced = true;
act.mMinStart = current_time;
act.mMaxEnd =
std::max(current_time + act.mScheduledMinDuration, act.mScheduledEnd);
if (act.mScheduled)
{
act.mMaxEnd =
std::max(current_time + act.mScheduledMinDuration, act.mScheduledEnd);
act.mMinDuration = act.mScheduledMinDuration;
act.mMaxDuration = act.mMaxEnd - act.mMinStart;
}
else
{
act.mMaxEnd = current_time + act.mMaxDuration;
}
return elem_id;
}
......@@ -481,29 +494,56 @@ Loco::TrainRouteGraph::UpdateSubgraphNode(const Element &el, unsigned node)
{
// Look at predecessors
auto &node_act = mActList[el.mSectActivities.at(node)];
for (unsigned pred : node_act.mPred)
if (node_act.mUse)
{
if (mActList[pred].mUse)
{
node_act.mUse = true;
break;
}
return;
}
UpdateActivityWithPred(node_act);
}
void
Loco::TrainRouteGraph::UpdateLastActivity()
Loco::TrainRouteGraph::UpdateActivityWithPred(Activity &act)
{
// look at predecessors
for (unsigned pred : mActList.back().mPred)
activity_time_type min_start = 0;
activity_time_type max_end = 0;
for (unsigned pred : act.mPred)
{
if (mActList[pred].mUse)
const auto &pred_act = mActList[pred];
if (pred_act.mUse)
{
mActList.back().mUse = true;
mActList.back().mForced = true;
break;
if (!act.mUse)
{
act.mUse = true;
min_start = pred_act.MinNextStart();
max_end = pred_act.mMaxEnd;
}
else
{
min_start = std::min(min_start, pred_act.MinNextStart());
max_end = std::max(max_end, pred_act.mMaxEnd);
}
}
}
if (act.mScheduled)
{
act.mMinStart = std::max(min_start, act.mScheduledStart);
act.mMaxEnd = std::max(act.mMinStart + act.mScheduledMinDuration,
act.mScheduledEnd);
act.mMinDuration = act.mScheduledMinDuration;
act.mMaxDuration = act.mMaxEnd - act.mMinStart;
}
else
{
act.mMinStart = min_start;
act.mMaxEnd = std::max(max_end, min_start + act.mMaxDuration);
}
}
void
Loco::TrainRouteGraph::UpdateLastActivity()
{
UpdateActivityWithPred(mActList.back());
mActList.back().mForced = true;
}
bool
......
......@@ -21,6 +21,7 @@ namespace Loco
struct Activity
{
static const activity_time_type kDefaultTransitionTime{10};
static const activity_time_type kLeafMaxDuration{10000};
std::string mName;
Place mPlace;
bool mForced{false};
......@@ -43,6 +44,13 @@ namespace Loco
: mName(std::move(name)), mPlace(std::move(place)), mForced(forced)
{
}
activity_time_type
MinNextStart() const
{
auto min_end = mMinStart + mMinDuration;
return min_end > mTransitionTime ? min_end - mTransitionTime : 0;
}
};
struct UsedPlaces
......@@ -113,6 +121,7 @@ namespace Loco
unsigned ElementWithSection(unsigned sect_id) const;
void UpdateElement(const Element &el);
void UpdateSubgraphNode(const Element &el, unsigned node);
void UpdateActivityWithPred(Activity &act);
unsigned UpdateInitialActivity(const SectionCPtr &initial_section,
activity_time_type current_time);
void UpdateLastActivity();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment