Skip to main content

AVxcelerate Simulation Framework 2024 R1

simulation_framework::evaluator::BaseEvaluator 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 <base_evaluator.h>

Inheritance diagram for simulation_framework::evaluator::BaseEvaluator:
Collaboration diagram for simulation_framework::evaluator::BaseEvaluator:

Public Member Functions

void Init ()
 
void Reset ()
 
void Evaluate ()
 
void AddKpi (kpi::IKpiPtr kpi)
 
kpi::KpiMessage GetKpiMessage () const
 
void SetGroundTruth (const avx_osi3::GroundTruth &ground_truth)
 

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(kpi::IKpiPtr 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 kpi::IKpi
{
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 kpi::IKpi {
class MyKpiEvaluatorActivity : public BaseActivity
{
public:
MyKpiEvaluatorActivity(const std::string& name,
const Topics& topics,
evaluator::kpi::IKpiMessageConverterPtr kpi_message_converter,
evaluator::IEvaluatorPtr 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_->SetGroundTruth(osi_proto_sv_.global_ground_truth());
evaluator_->Evaluate();
kpi_message_ = evaluator_->GetKpiMessage();
}
private:
evaluator::kpi::IKpiMessageConverterPtr kpi_message_converter_;
evaluator::IEvaluatorPtr evaluator_;
evaluator::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<evaluator::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::BaseEvaluator::AddKpi ( kpi::IKpiPtr  kpi)
virtual

Add one KPI into this evaluator

Parameters
kpiThe iKpi interface

Implements simulation_framework::evaluator::IEvaluator.

◆ Evaluate()

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

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

Implements simulation_framework::evaluator::IEvaluator.

◆ GetKpiMessage()

kpi::KpiMessage simulation_framework::evaluator::BaseEvaluator::GetKpiMessage ( ) const
virtual

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

Implements simulation_framework::evaluator::IEvaluator.

◆ Init()

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

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

Implements simulation_framework::evaluator::IEvaluator.

◆ Reset()

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

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

Implements simulation_framework::evaluator::IEvaluator.

◆ SetGroundTruth()

void simulation_framework::evaluator::BaseEvaluator::SetGroundTruth ( const avx_osi3::GroundTruth &  ground_truth)
virtual

Set GroundTruth message for KPI calculations

Parameters
ground_truthThe osi groundtruth type in protobuf

Implements simulation_framework::evaluator::IEvaluator.


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

Connect with Ansys