[fix] fixed bug in sim that passed the wrong truth to child groups
- also checks and warns if a sensor parent has another sensor parent
This commit is contained in:
@@ -49,7 +49,7 @@ class Simulation(config: Configuration) {
|
|||||||
sharedMemory.publish(time)
|
sharedMemory.publish(time)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def simGroups(time: Time, cell: Cell, groups: Map[Group, List[(Group, Sensor, Option[GroundTruth])]], configTruths: Option[Map[Group, Truth]], PrevTruths: Map[Group, Truth], resultTruths: Map[Group, Truth], resultSensors: Map[Group, Vector[SensorResult]]): Unit = {
|
private def simGroups(time: Time, cell: Cell, groups: Map[Group, List[(Group, Sensor, Option[GroundTruth])]], configTruths: Option[Map[Group, Truth]], prevTruths: Map[Group, Truth], resultTruths: Map[Group, Truth], resultSensors: Map[Group, Vector[SensorResult]]): Unit = {
|
||||||
// TODO: possible optimisation (see text below)
|
// TODO: possible optimisation (see text below)
|
||||||
// this can be further optimised as a child is only dependent on its parents ground truth and could run
|
// this can be further optimised as a child is only dependent on its parents ground truth and could run
|
||||||
// at the same time as the parent in a different thread. This would allow the child to start running as soon
|
// at the same time as the parent in a different thread. This would allow the child to start running as soon
|
||||||
@@ -63,15 +63,36 @@ class Simulation(config: Configuration) {
|
|||||||
val group = input._1
|
val group = input._1
|
||||||
val truthGroup = group.getParentOrGroup // make sure the correct ground truth gets passed
|
val truthGroup = group.getParentOrGroup // make sure the correct ground truth gets passed
|
||||||
val groupList = input._2
|
val groupList = input._2
|
||||||
// overwrite truth with value from configuration if set for a non child group at this time (children just get results of their parent)
|
|
||||||
val prevTruth = if(group.parent.isEmpty && !configTruths.isEmpty && configTruths.get.contains(group)) configTruths.get(group) else PrevTruths(truthGroup)
|
|
||||||
groupList.foreach(element => {
|
groupList.foreach(element => {
|
||||||
val subGroup = element._1
|
val subGroup = element._1
|
||||||
debugf(DebugType.DEBUG, "simGroups: Time: %s | Cell: %s | Group: %s | Groupelement: %s", time.toString, cell.toString, group.toString, element._1.name)
|
val subGroupParent = sharedMemory.groups(subGroup.parent.getOrElse(group.name))
|
||||||
|
// overwrite truth with value from configuration if this is the root group
|
||||||
|
val prevTruth = if(subGroup.parent.isEmpty && !configTruths.isEmpty && configTruths.get.contains(subGroup)) {
|
||||||
|
configTruths.get(subGroup)
|
||||||
|
// make sure parent actually calculates a ground truth
|
||||||
|
} else if(prevTruths.contains(subGroupParent) && subGroupParent.sensorParent.isEmpty) {
|
||||||
|
prevTruths(subGroupParent)
|
||||||
|
} else {
|
||||||
|
// this can happen if sensor parent has another sensor parent
|
||||||
|
// TODO: A sensor with parent should not have children (warn in parser)
|
||||||
|
debugf(DebugType.WARNING, "Group [%s] parent does not have a ground truth, using default Root Group [%s]", subGroup.toString, group.toString())
|
||||||
|
prevTruths(group)
|
||||||
|
}
|
||||||
// pass either subGroup truth, if truth is available for subGroup, or the sensor parents truth
|
// pass either subGroup truth, if truth is available for subGroup, or the sensor parents truth
|
||||||
val resTruth = if(subGroup.sensorParent.isEmpty) resultTruths(subGroup) else resultTruths(sharedMemory.groups(subGroup.parent.getOrElse(subGroup.name)))
|
val resTruth = if(subGroup.sensorParent.isEmpty) {
|
||||||
|
resultTruths(subGroup)
|
||||||
|
} else if(resultTruths.contains(subGroupParent) && subGroupParent.sensorParent.isEmpty) {
|
||||||
|
resultTruths(subGroupParent)
|
||||||
|
} else {
|
||||||
|
// this can happen if sensor parent has another sensor parent
|
||||||
|
// TODO: A sensor with parent should not have children (warn in parser)
|
||||||
|
debugf(DebugType.WARNING, "Group [%s] parent does not have a ground truth, using Root Group [%s]", subGroup.toString, group.toString())
|
||||||
|
resultTruths(group)
|
||||||
|
}
|
||||||
|
|
||||||
// construct dummy result for sensors with count 0
|
// construct dummy result for sensors with count 0
|
||||||
val restSens = if(resultSensors.contains(subGroup)) resultSensors(subGroup) else Vector(SensorResult())
|
val restSens = if(resultSensors.contains(subGroup)) resultSensors(subGroup) else Vector(SensorResult())
|
||||||
|
debugf(DebugType.DEBUG, "simGroups: Time: %s | Cell: %s | Root: %s | Groupelement: %s | prevTruth: %s | resTruth: %s", time.toString, cell.toString, group.toString, element._1.name, prevTruth.peak(), resTruth.peak())
|
||||||
simulate(time, cell, prevTruth, resTruth, restSens, element)
|
simulate(time, cell, prevTruth, resTruth, restSens, element)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user