Skip to main content

AVxcelerate Simulation Framework 2024 R2 SP02

simulation_framework::evaluator::GtBaseEvaluator Class Reference

Last update: 16.07.2025

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. More...

#include <gt_base_evaluator.h>

Inheritance diagram for simulation_framework::evaluator::GtBaseEvaluator:
Collaboration diagram for simulation_framework::evaluator::GtBaseEvaluator:

Public Member Functions

void Init ()
 
void Reset ()
 
void Evaluate ()
 
void AddKpi (std::unique_ptr< core::kpi::IKpi< avx_osi3::GroundTruth >> kpi) override
 
core::kpi::KpiMessage GetKpiMessage () const
 
void SetInput (const avx_osi3::GroundTruth &ground_truth)
 
- Public Member Functions inherited from simulation_framework::core::evaluator::IEvaluator< avx_osi3::GroundTruth >
virtual void AddKpi (std::unique_ptr< kpi::IKpi< avx_osi3::GroundTruth >> kpi)=0
 
virtual core::kpi::KpiMessage GetKpiMessage () const=0
 

Detailed Description

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<avx_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<avx_osi3::GroundTruth>
{
public:
MyFirstKpi(const std::string& kpi_name): kpi_name_(kpi_name) {}
void Init() override {}
void Reset() override {}
kpi::KpiContent CalculateKpi(const avx_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<avx_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::evaluator::IEvaluator<avx_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::evaluator::IEvaluator<avx_osi3::GroundTruth>>evaluator_;
core::kpi::KpiMessage kpi_message_;
avx_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{topic_registry::GetExistingTopicById("SensorViewTopic"),
topic_registry::GetExistingTopicById("KpiLoggerTopic")},
std::move(kpi_message_converter),
std::move(evaluator));

Member Function Documentation

◆ AddKpi()

void simulation_framework::evaluator::GtBaseEvaluator::AddKpi ( std::unique_ptr< core::kpi::IKpi< avx_osi3::GroundTruth >>  kpi)
override

Add one KPI into this evaluator

Parameters
kpiThe iKpi interface

◆ Evaluate()

void simulation_framework::evaluator::GtBaseEvaluator::Evaluate ( )
virtual

Calculate all KPIs (call all kpi->CalculateKpi(gt);) which are added in this evaluator and fill the KpiMessage

Implements simulation_framework::core::evaluator::IEvaluator< avx_osi3::GroundTruth >.

◆ 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

◆ Init()

void simulation_framework::evaluator::GtBaseEvaluator::Init ( )
virtual

Initial all KPIs (call all kpi->Init();) which are added in this evaluator

Implements simulation_framework::core::evaluator::IEvaluator< avx_osi3::GroundTruth >.

◆ Reset()

void simulation_framework::evaluator::GtBaseEvaluator::Reset ( )
virtual

Clear KpiMessage and reset all KPIs (call all kpi->Reset();) which are added in this evaluator

Implements simulation_framework::core::evaluator::IEvaluator< avx_osi3::GroundTruth >.

◆ SetInput()

void simulation_framework::evaluator::GtBaseEvaluator::SetInput ( const avx_osi3::GroundTruth &  ground_truth)
virtual

Set GroundTruth message for KPI calculations

Parameters
ground_truthThe osi groundtruth type in protobuf

Implements simulation_framework::core::evaluator::IEvaluator< avx_osi3::GroundTruth >.


The documentation for this class was generated from the following file:

Connect with Ansys