    

 ## On this page

  

 

 # simulation\_framework::evaluator::BaseEvaluator Class Reference

 Last update: 16.07.2025 

This is the implementation of [IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml "class 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...](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#details)

`#include <<a class="el" href="base__evaluator_8h_source.xhtml">base_evaluator.h</a>>`

Inheritance diagram for simulation_framework::evaluator::BaseEvaluator:

![Inheritance graph](/sites/default/files/migrate-content/avxcelerate_simulation_framework_2024_r1/classsimulation__framework_1_1evaluator_1_1BaseEvaluator__inherit__graph.png)

\[[legend](graph_legend.xhtml)\]

Collaboration diagram for simulation_framework::evaluator::BaseEvaluator:

![Collaboration graph](/sites/default/files/migrate-content/avxcelerate_simulation_framework_2024_r1/classsimulation__framework_1_1evaluator_1_1BaseEvaluator__coll__graph.png)

\[[legend](graph_legend.xhtml)\]

## <a id="pub-methods" name="pub-methods"></a>Public Member Functions

void [Init](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a2c79b6267cc4da10eabdc7f87a648e48) () void [Reset](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a688d826f7112e8f8f6561e6ebaeb6a09) () void [Evaluate](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a6fb2ef47d7255c49aee0c8a469b8fd1a) () void [AddKpi](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#ab4b009e8c649215e9efa0538a26e5434) (kpi::IKpiPtr kpi) kpi::KpiMessage [GetKpiMessage](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a71c2d66129809f394b74069a92649b7d) () const void [SetGroundTruth](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a042e972003ab591146f202d580c73b21) (const avx\_osi3::GroundTruth &amp;ground\_truth) <a id="details" name="details"></a>## Detailed Description

This is the implementation of [IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml "class 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)](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#ab4b009e8c649215e9efa0538a26e5434).

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&amp; kpi_name): kpi_name_(kpi_name) {}

 void [Init](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a2c79b6267cc4da10eabdc7f87a648e48)() override {}

 void [Reset](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a688d826f7112e8f8f6561e6ebaeb6a09)() override {}

 kpi::KpiContent CalculateKpi(const avx_osi3::GroundTruth&amp; ground_truth) override

 {

 kpi::KpiContent [kpi](namespacekpi.xhtml);

 return [kpi](namespacekpi.xhtml);

 }

 kpi::Type GetKpiType() const override { return kpi::Type::kScalar; }

};

class MySecondKpi : public kpi::IKpi { 

 

class MyKpiEvaluatorActivity : public BaseActivity

{

 public:

 MyKpiEvaluatorActivity(const std::string&amp; name,

 const Topics&amp; topics,

 evaluator::kpi::IKpiMessageConverterPtr kpi_message_converter,

 evaluator::IEvaluatorPtr [evaluator](namespaceevaluator.xhtml))

 : BaseActivity(name, topics),

 kpi_message_converter_(std::move(kpi_message_converter)),

 evaluator_(std::move([evaluator](namespaceevaluator.xhtml)))

 {

 evaluator_-&gt;Init();

 }

 

 ~MyKpiEvaluatorActivity() = default;

 

 void AddPublisherAndSubscriber() override

 {

 AddSubscriber&lt;core::Topic&lt;rtidds::GenericBytesMessage&gt;&gt;(

 "SensorViewTopic", [&amp;](const rtidds::GenericBytesMessage&amp; 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&lt;core::Topic&lt;rtidds::KpiMessage&gt;&gt;("KpiLoggerTopic", [&amp;]() {

 const auto dds_kpi_message = kpi_message_converter_-&gt;ConvertToDds(kpi_message_);

 return dds_kpi_message;

 });

 }

 

 void ExecuteStep() override

 {

 evaluator_-&gt;SetGroundTruth(osi_proto_sv_.global_ground_truth());

 evaluator_-&gt;Evaluate();

 kpi_message_ = evaluator_-&gt;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&lt;MyFirstKpi&gt;("kpi\_1");

 auto my_second_kpi = std::make_unique&lt;MySecondKpi&gt;("kpi\_2");

 

 auto [evaluator](namespaceevaluator.xhtml) = std::make_unique&lt;simulation_framework::evaluator::BaseEvaluator&gt;();

 [evaluator](namespaceevaluator.xhtml)-&gt;AddKpi(std::move(my_first_kpi));

 [evaluator](namespaceevaluator.xhtml)-&gt;AddKpi(std::move(my_second_kpi));

 

 auto kpi_message_converter = std::make_unique&lt;evaluator::kpi::KpiMessageConverter&gt;();

 

 auto my_kpi_evaluator_activity = std::make_unique&lt;MyKpiEvaluatorActivity&gt;(

 "MyKpiEvaluatorActivity",

 Topics{topic_registry::GetExistingTopicById("SensorViewTopic"),

 topic_registry::GetExistingTopicById("KpiLoggerTopic")},

 std::move(kpi_message_converter),

 std::move([evaluator](namespaceevaluator.xhtml)));





## Member Function Documentation

<a id="ab4b009e8c649215e9efa0538a26e5434"></a>## [◆ ](#ab4b009e8c649215e9efa0538a26e5434)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](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#a0ce6030014428862f9045b23646a979a).





<a id="a6fb2ef47d7255c49aee0c8a469b8fd1a"></a>## [◆ ](#a6fb2ef47d7255c49aee0c8a469b8fd1a)Evaluate()

 void simulation\_framework::evaluator::BaseEvaluator::Evaluate  ( )   virtual 

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

Implements [simulation\_framework::evaluator::IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#ad57b87c746be02f976f6446355adba0f).





<a id="a71c2d66129809f394b74069a92649b7d"></a>## [◆ ](#a71c2d66129809f394b74069a92649b7d)GetKpiMessage()

 kpi::KpiMessage simulation\_framework::evaluator::BaseEvaluator::GetKpiMessage  ( )  const  virtual 

Get the filled KPI messages based on calculation of all KPIs

ReturnsA kpi::KpiMessage object, the vector of KpiContent represents of all added KPIs into this evaluator Implements [simulation\_framework::evaluator::IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#ab0f3c91ae7570b0316536ad935347f29).





<a id="a2c79b6267cc4da10eabdc7f87a648e48"></a>## [◆ ](#a2c79b6267cc4da10eabdc7f87a648e48)Init()

 void simulation\_framework::evaluator::BaseEvaluator::Init  ( )   virtual 

Initial all KPIs (call all kpi-&gt;[Init()](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a2c79b6267cc4da10eabdc7f87a648e48);) which are added in this evaluator

Implements [simulation\_framework::evaluator::IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#afda42274ea5a6cbf100dd37c75c18ad1).





<a id="a688d826f7112e8f8f6561e6ebaeb6a09"></a>## [◆ ](#a688d826f7112e8f8f6561e6ebaeb6a09)Reset()

 void simulation\_framework::evaluator::BaseEvaluator::Reset  ( )   virtual 

Clear KpiMessage and reset all KPIs (call all kpi-&gt;[Reset()](classsimulation__framework_1_1evaluator_1_1BaseEvaluator.xhtml#a688d826f7112e8f8f6561e6ebaeb6a09);) which are added in this evaluator

Implements [simulation\_framework::evaluator::IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#a7de1d24ee59889bdde8a3920db7b9a8e).





<a id="a042e972003ab591146f202d580c73b21"></a>## [◆ ](#a042e972003ab591146f202d580c73b21)SetGroundTruth()

 void simulation\_framework::evaluator::BaseEvaluator::SetGroundTruth  ( const avx\_osi3::GroundTruth &amp;  *ground\_truth*)   virtual 

Set GroundTruth message for KPI calculations

Parameters ground\_truthThe osi groundtruth type in protobuf Implements [simulation\_framework::evaluator::IEvaluator](classsimulation__framework_1_1evaluator_1_1IEvaluator.xhtml#a7c9ad6bc77c910ee07a46575d92c95fa).





---

The documentation for this class was generated from the following file:- [base\_evaluator.h](base__evaluator_8h_source.xhtml)