Class simulation_framework::evaluator::GtBaseEvaluator
Last update: 22.04.2026
Definition: autonomy/evaluator/gt_base_evaluator/gt_base_evaluator.h (line 133)
This is the implementation of IEvaluator interface and provides users ability to evaluate KPIs that are added by themselves. This class controls all KPIs centrally and fill/reset the KpiMessage accordingly based on each KPI's calculation result.
To join the simulation, the evaluator must be injected into an Activity and required KPIs need to be added using AddKpi(std::unique_ptr<core::kpi::IKpi<osi3::GroundTruth>> kpi).
Example of creating one customized KpiEvaluatorActivity containing 2 KPIs and publish the KpiMessage into KpiLoggerTopic to have the KPI results in output json
class MyFirstKpi : public core::kpi::IKpi<osi3::GroundTruth>
{
public:
MyFirstKpi(const std::string& kpi_name): kpi_name_(kpi_name) {}
void Init() override {}
void Reset() override {}
kpi::KpiContent CalculateKpi(const osi3::GroundTruth& ground_truth) override
{
kpi::KpiContent kpi;
return kpi;
}
kpi::Type GetKpiType() const override { return kpi::Type::kScalar; }
};
class MySecondKpi : public core:kpi::IKpi<osi3::GroundTruth> {
class MyKpiEvaluatorActivity : public BaseActivity
{
public:
MyKpiEvaluatorActivity(const std::string& name,
const Topics& topics,
evaluator::std::unique_ptr<kpi::IKpiMessageConverter> kpi_message_converter,
std::unique_ptr<core::IEvaluator<osi3::GroundTruth>> evaluator)
: BaseActivity(name, topics),
kpi_message_converter_(std::move(kpi_message_converter)),
evaluator_(std::move(evaluator))
{
evaluator_->Init();
}
~MyKpiEvaluatorActivity() = default;
void AddPublisherAndSubscriber() override
{
AddSubscriber<core::Topic<rtidds::GenericBytesMessage>>(
"SensorViewTopic", [&](const rtidds::GenericBytesMessage& sv_bytes_msg) {
if (!osi_proto_sv_.ParseFromArray(sv_bytes_msg.bytes_array.data(), sv_bytes_msg.size))
{
throw std::runtime_error(
"[MyKpiEvaluatorActivity]: Error parsing "
"osi proto msg from bytes array!");
}
});
AddPublisher<core::Topic<rtidds::KpiMessage>>("KpiLoggerTopic", [&]() {
const auto dds_kpi_message = kpi_message_converter_->ConvertToDds(kpi_message_);
return dds_kpi_message;
});
}
void ExecuteStep() override
{
evaluator_->SetInput(osi_proto_sv_.global_ground_truth());
evaluator_->Evaluate();
kpi_message_ = evaluator_->GetKpiMessage();
}
private:
evaluator::std::unique_ptr<kpi::IKpiMessageConverter> kpi_message_converter_;
std::unique_ptr<core::IEvaluator<osi3::GroundTruth>>evaluator_;
core::kpi::KpiMessage kpi_message_;
osi3::SensorView osi_proto_sv_{};
};
auto my_first_kpi = std::make_unique<MyFirstKpi>("kpi_1");
auto my_second_kpi = std::make_unique<MySecondKpi>("kpi_2");
auto evaluator = std::make_unique<simulation_framework::evaluator::BaseEvaluator>();
evaluator->AddKpi(std::move(my_first_kpi));
evaluator->AddKpi(std::move(my_second_kpi));
auto kpi_message_converter = std::make_unique<core::kpi::KpiMessageConverter>();
auto my_kpi_evaluator_activity = std::make_unique<MyKpiEvaluatorActivity>(
"MyKpiEvaluatorActivity",
Topics{autonomy::topic_registry::GetExistingTopicById("SensorViewTopic"),
autonomy::topic_registry::GetExistingTopicById("KpiLoggerTopic")},
std::move(kpi_message_converter),
std::move(evaluator));
Inherits from:
Members
- AddKpi
- AddKpi
- Evaluate
- GetKpiMessage
- GtBaseEvaluator
- Init
- Reset
- SetInput
- ~GtBaseEvaluator
- ~IEvaluator
Public functions
Function GtBaseEvaluator
simulation_framework::evaluator::GtBaseEvaluator::GtBaseEvaluator()
Return type:
Function ~GtBaseEvaluator
virtual simulation_framework::evaluator::GtBaseEvaluator::~GtBaseEvaluator()=default
Return type:
Function Init
void simulation_framework::evaluator::GtBaseEvaluator::Init()
Initial all KPIs (call all kpi->Init();) which are added in this evaluator
Return type: void
Reimplements: Init
Function Reset
void simulation_framework::evaluator::GtBaseEvaluator::Reset()
Clear KpiMessage and reset all KPIs (call all kpi->Reset();) which are added in this evaluator
Return type: void
Reimplements: Reset
Function Evaluate
void simulation_framework::evaluator::GtBaseEvaluator::Evaluate()
Calculate all KPIs (call all kpi->CalculateKpi(gt);) which are added in this evaluator and fill the KpiMessage
Return type: void
Reimplements: Evaluate
Function AddKpi
void simulation_framework::evaluator::GtBaseEvaluator::AddKpi(std::unique_ptr< core::kpi::IKpi< osi3::GroundTruth > > kpi) override
Add one KPI into this evaluator
Parameters:
- kpi: The iKpi interface
Parameters:
- std::unique_ptr< core::kpi::IKpi< osi3::GroundTruth > > kpi
Return type: void
Function GetKpiMessage
core::kpi::KpiMessage simulation_framework::evaluator::GtBaseEvaluator::GetKpiMessage() const
Get the filled KPI messages based on calculation of all KPIs
Returns:
A kpi::KpiMessage object, the vector of KpiContent represents of all added KPIs into this evaluator
Return type: core::kpi::KpiMessage
Reimplements: GetKpiMessage
Function SetInput
void simulation_framework::evaluator::GtBaseEvaluator::SetInput(const osi3::GroundTruth &ground_truth)
Set GroundTruth message for KPI calculations
Parameters:
- ground_truth: The osi groundtruth type in protobuf
Parameters:
- const osi3::GroundTruth & ground_truth
Return type: void
Reimplements: SetInput