Commit 0596ce67 authored by Simon Tenbusch's avatar Simon Tenbusch

[sequencechart]

- further work on REAL TIME timeline mode
- fixed bug in critical path computation (see wiki)
parent bcffd494
......@@ -756,6 +756,11 @@ public class SequenceChart
public void setTimelineMode(TimelineMode timelineMode) {
org.omnetpp.common.engine.BigDecimal[] leftRightSimulationTimes = null;
if(timelineMode==TimelineMode.REAL_TIME) {
//Trigger initialization of earliest starting times
sequenceChartFacade.isOnCriticalPath(null);
}
if (!eventLog.isEmpty())
leftRightSimulationTimes = getViewportSimulationTimeRange();
......@@ -2763,6 +2768,12 @@ public class SequenceChart
return (int) (getViewportCoordinateForTimelineCoordinate(starttime+duration) - getViewportCoordinateForTimelineCoordinate(starttime));
}
/**
* Returns the relative pixellength of an event depending on its complexity.
*/
private int getEventComplexityLength(IEvent event) {
return (int) (getViewportCoordinateForTimelineCoordinate(event.getEarliestProcessingTime()/1000000.0) - getViewportCoordinateForTimelineCoordinate(event.getEarliestStartTime() / 1000000.0));
}
/**
* Returns the relative pixellength of an event depending on its duration.
*/
......@@ -2860,7 +2871,12 @@ public class SequenceChart
return Math.max(5,getEventDurationLength(sequenceChartFacade.IEvent_getEvent(eventPtr)));
case COMPLEXITY:
//TODO: Find good relative length
return Math.max(5,(int)(getComplexityPercentage(sequenceChartFacade.IEvent_getEvent(eventPtr).getComplexity()) * 100));
if (getTimelineMode() == TimelineMode.REAL_TIME) {
return Math.max(5,getEventComplexityLength(sequenceChartFacade.IEvent_getEvent(eventPtr)));
} else {
return Math.max(5,(int)(getComplexityPercentage(sequenceChartFacade.IEvent_getEvent(eventPtr).getComplexity()) * 100));
}
case NONE:
default:
return 5;
......
......@@ -23,6 +23,7 @@ IEvent::IEvent()
{
nextEvent = NULL;
previousEvent = NULL;
criticalPredecessor = NULL;
cachedTimelineCoordinate = -1;
cachedTimelineCoordinateSystemVersion = -1;
}
......
......@@ -30,6 +30,8 @@ class EVENTLOG_API IEvent
IEvent *previousEvent;
IEvent *nextEvent;
IEvent* criticalPredecessor;
public:
// gui state for SequenceChart
double cachedTimelineCoordinate;
......@@ -148,6 +150,14 @@ class EVENTLOG_API IEvent
virtual long getEarliestProcessingTime() = 0;
virtual long getEarliestStartTime() = 0;
IEvent* getCriticalPredecessor() {
return criticalPredecessor;
}
void setCriticalPredecessor(IEvent* e) {
criticalPredecessor = e;
}
};
NAMESPACE_END
......
......@@ -110,7 +110,7 @@ void SequenceChartFacade::relocateTimelineCoordinateSystem(IEvent *event)
timelineCoordinateSystemVersion++;
timelineCoordinateOriginEventNumber = timelineCoordinateRangeStartEventNumber = timelineCoordinateRangeEndEventNumber = event->getEventNumber();
timelineCoordinateOriginSimulationTime = event->getSimulationTime();
timelineCoordinateOriginRealTime = event->getEarliestStartTime();
timelineCoordinateOriginRealTime = event->getEarliestStartTime() / 1000000.0;
event->cachedTimelineCoordinate = 0;
event->cachedTimelineCoordinateSystemVersion = timelineCoordinateSystemVersion;
}
......@@ -169,7 +169,7 @@ double SequenceChartFacade::getTimelineCoordinate(IEvent *event, double lowerTim
switch (timelineMode) {
case REAL_TIME:
timelineCoordinate = ((event->getEarliestStartTime() - timelineCoordinateOriginRealTime));
timelineCoordinate = ((event->getEarliestStartTime()/1000000.0 - timelineCoordinateOriginRealTime));
break;
case SIMULATION_TIME:
timelineCoordinate = (event->getSimulationTime() - timelineCoordinateOriginSimulationTime).dbl();
......@@ -247,7 +247,7 @@ double SequenceChartFacade::getTimelineEventEndCoordinate(IEvent *event, double
double timelineEventEndCoordinate;
switch (timelineMode) {
case REAL_TIME:
timelineEventEndCoordinate = (event->getEarliestProcessingTime() - timelineCoordinateOriginRealTime);
timelineEventEndCoordinate = (event->getEarliestProcessingTime()/ 1000000.0 - timelineCoordinateOriginRealTime) ;
break;
case SIMULATION_TIME:
timelineEventEndCoordinate = (event->getSimulationTime()+event->getEventEntry()->duration - timelineCoordinateOriginSimulationTime).dbl();
......@@ -315,7 +315,7 @@ IEvent *SequenceChartFacade::getLastEventNotAfterTimelineCoordinate(double timel
//TODO MAKE THIS MORE EFFICIENT (i.e. sorted data structure)!
IEvent* res = eventLog->getFirstEvent();
for (IEvent *current = eventLog->getFirstEvent(); current; current = current->getNextEvent()) {
if ((double) current->getEarliestStartTime() < timelineCoordinate) {
if ((double) current->getEarliestStartTime() / 1000000.0 < timelineCoordinate) {
if (current->getEarliestStartTime() > res->getEarliestStartTime()) {
res = current;
}
......@@ -360,7 +360,7 @@ IEvent *SequenceChartFacade::getFirstEventNotBeforeTimelineCoordinate(double tim
//TODO MAKE THIS MORE EFFICIENT (i.e. sorted data structure)!
IEvent* res = eventLog->getLastEvent();
for (IEvent *current = eventLog->getFirstEvent(); current; current = current->getNextEvent()) {
if ((double) current->getEarliestStartTime() > timelineCoordinate) {
if ((double) current->getEarliestStartTime() / 1000000.0 > timelineCoordinate) {
if (current->getEarliestStartTime() < res->getEarliestStartTime()) {
res = current;
}
......@@ -400,11 +400,13 @@ void SequenceChartFacade::extractSimulationTimesAndTimelineCoordinates(
simtime_t &nextEventSimulationTime, double &nextEventTimelineCoordinate,
simtime_t &simulationTimeDelta, double &timelineCoordinateDelta)
{
//TODO: REAL_TIME
// if before the first event
if (event) {
eventSimulationTime = event->getSimulationTime();
if (timelineMode==REAL_TIME) {
eventSimulationTime = event->getEarliestStartTime() / 1000000.0;
} else {
eventSimulationTime = event->getSimulationTime();
}
eventTimelineCoordinate = getTimelineCoordinate(event);
}
else {
......@@ -414,6 +416,8 @@ void SequenceChartFacade::extractSimulationTimesAndTimelineCoordinates(
if (timelineMode == EVENT_NUMBER)
eventTimelineCoordinate -= 1;
else if (timelineMode == REAL_TIME)
eventTimelineCoordinate -= getTimelineCoordinateDelta(0);
else
eventTimelineCoordinate -= getTimelineCoordinateDelta(firstEvent->getSimulationTime().dbl());
}
......@@ -422,7 +426,12 @@ void SequenceChartFacade::extractSimulationTimesAndTimelineCoordinates(
nextEvent = event ? event->getNextEvent() : eventLog->getFirstEvent();
if (nextEvent) {
nextEventSimulationTime = nextEvent->getSimulationTime();
if(timelineMode==REAL_TIME) {
nextEventSimulationTime = nextEvent->getEarliestStartTime() / 1000000.0;
} else {
nextEventSimulationTime = nextEvent->getSimulationTime();
}
nextEventTimelineCoordinate = getTimelineCoordinate(nextEvent);
simulationTimeDelta = nextEventSimulationTime - eventSimulationTime;
......@@ -443,11 +452,11 @@ simtime_t SequenceChartFacade::getSimulationTimeForTimelineCoordinate(double tim
{
case REAL_TIME:
{
simtime_t lastEventSimulationTime = (eventLog->getLastEvent()->getEarliestStartTime()/1000000.0); //TODO: Change this to getEarliestStartTime();
simtime_t lastEventSimulationTime = (eventLog->getLastEvent()->getEarliestStartTime())/1000000.0;
//NOTE: This sometimes crashes the Sequencechart because the returned value might be too big
simulationTime = max(BigDecimal::Zero, min(lastEventSimulationTime, (timelineCoordinate + timelineCoordinateOriginRealTime)/1000000.0));
simulationTime = max(BigDecimal::Zero, min(lastEventSimulationTime, (timelineCoordinate + timelineCoordinateOriginRealTime)));
}
//Fall back to SIMULATION_TIME (TODO)
break;
case SIMULATION_TIME:
{
simtime_t lastEventSimulationTime = eventLog->getLastEvent()->getSimulationTime();
......@@ -492,7 +501,8 @@ simtime_t SequenceChartFacade::getSimulationTimeForTimelineCoordinate(double tim
Assert(!simulationTime.isNaN());
Assert(simulationTime >= BigDecimal::Zero);
Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
if (timelineMode != REAL_TIME)
Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
return simulationTime;
}
......@@ -505,14 +515,18 @@ double SequenceChartFacade::getTimelineCoordinateForSimulationTime(simtime_t sim
return 0;
Assert(simulationTime >= BigDecimal::Zero);
Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
if (timelineMode != REAL_TIME)
Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
double timelineCoordinate;
switch (timelineMode)
{
case REAL_TIME:
//Fall back to SIMULATION_TIME (TODO)
//treat simulationTime as real time:
timelineCoordinate = simulationTime.dbl() - timelineCoordinateOriginRealTime;
break;
case SIMULATION_TIME:
timelineCoordinate = (simulationTime - timelineCoordinateOriginSimulationTime).dbl();
break;
......@@ -939,6 +953,9 @@ void SequenceChartFacade::calculateCriticalPath() {
if(current->getEventEndEntry()) {
current->_earliestProcessingTime = current->getComplexity();
}
current->setCriticalPredecessor(eventLog->getFirstEvent());
for (IEvent *antecessor = eventLog->getFirstEvent(); antecessor; antecessor = antecessor->getNextEvent()) {
if(antecessor==current) {
break; //We have to consider earlier events only
......@@ -948,6 +965,7 @@ void SequenceChartFacade::calculateCriticalPath() {
}
if(antecessor->_earliestProcessingTime+current->getComplexity() > current->_earliestProcessingTime) {
current->_earliestProcessingTime = antecessor->_earliestProcessingTime+current->getComplexity();
current->setCriticalPredecessor(antecessor);
}
}
// Memorize max event
......@@ -956,9 +974,9 @@ void SequenceChartFacade::calculateCriticalPath() {
maxEarliestProcessingTimeEvent = current;
}
}
//Now produce the convex hull of predecessors:
//Now produce the convex hull of critical antecessors/predecessors:
cachedCriticalPath.clear();
for (IEvent *predecessor = maxEarliestProcessingTimeEvent; predecessor ; predecessor = predecessor->getCauseEvent()) {
for (IEvent *predecessor = maxEarliestProcessingTimeEvent; predecessor ; predecessor = predecessor->getCriticalPredecessor()) {
cachedCriticalPath.insert((ptr_t)predecessor);
if(predecessor->getEventNumber() == 0) {
break;
......
......@@ -39,7 +39,7 @@ class EVENTLOG_API SequenceChartFacade : public EventLogFacade
long timelineCoordinateSystemVersion;
eventnumber_t timelineCoordinateOriginEventNumber;
simtime_t timelineCoordinateOriginSimulationTime;
long timelineCoordinateOriginRealTime;
double timelineCoordinateOriginRealTime;
eventnumber_t timelineCoordinateRangeStartEventNumber;
eventnumber_t timelineCoordinateRangeEndEventNumber;
TimelineMode timelineMode;
......
Markdown is supported
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