3 #ifndef GRAIL_DEBUG_INFO_H
4 #define GRAIL_DEBUG_INFO_H
6 #include "GrailStateSnapshot.h"
7 #include "PlannerSnapshots.h"
8 #include "SimulatedGamesSnapshots.h"
9 #include "UtilityReasonerSnapshot.h"
10 #include "../DataSerializationVersions.h"
11 #include "Flatbuffers/GrailDebugInfo_generated.h"
22 int version = data_serialization_versions::DEBUG_SERIALIZATION_VERSION;
23 float startTime = 0.0f;
25 std::vector<GrailStateSnapshot> grailStateSnapshots{};
26 std::map<size_t, std::vector<SimulatedGameReasonerSnapshot>> simGameReasonerSnapshotsPerEntityId{};
27 std::map<size_t, std::vector<UtilityReasonerSnapshot>> utilityReasonerSnapshotsPerEntityId{};
28 std::map<size_t, std::vector<PlannerReasonerSnapshot>> plannerReasonerSnapshotsPerEntityId{};
31 inline flatbuffers::Offset<generated::GrailDebugInfo> Pack(flatbuffers::FlatBufferBuilder& builder,
34 std::vector<flatbuffers::Offset<generated::GrailStateSnapshot>> packedGrailStates{};
35 packedGrailStates.reserve(snapshot.grailStateSnapshots.size());
36 std::vector<flatbuffers::Offset<generated::SimulatedGameReasonerSnapshot>> packedSimGames{};
37 packedSimGames.reserve(snapshot.simGameReasonerSnapshotsPerEntityId.size());
38 std::vector<flatbuffers::Offset<generated::UtilityReasonerSnapshot>> packedUtility{};
39 packedUtility.reserve(snapshot.utilityReasonerSnapshotsPerEntityId.size());
40 std::vector<flatbuffers::Offset<generated::PlannerReasonerSnapshot>> packedPlanners{};
41 packedPlanners.reserve(snapshot.plannerReasonerSnapshotsPerEntityId.size());
43 std::for_each(snapshot.grailStateSnapshots.begin(), snapshot.grailStateSnapshots.end(),
44 [&packedGrailStates, &builder](
const auto& state)
46 packedGrailStates.push_back(Pack(builder, state));
48 std::for_each(snapshot.simGameReasonerSnapshotsPerEntityId.begin(), snapshot.simGameReasonerSnapshotsPerEntityId.end(),
49 [&packedSimGames, &builder] (
const auto& reasonerSnapshots)
51 std::for_each(reasonerSnapshots.second.begin(), reasonerSnapshots.second.end(),
52 [&packedSimGames, &builder](const auto reasonerSnapshot)
54 packedSimGames.push_back(Pack(builder, reasonerSnapshot));
57 std::for_each(snapshot.utilityReasonerSnapshotsPerEntityId.begin(), snapshot.utilityReasonerSnapshotsPerEntityId.end(),
58 [&packedUtility, &builder] (
const auto& reasonerSnapshots)
60 std::for_each(reasonerSnapshots.second.begin(), reasonerSnapshots.second.end(),
61 [&packedUtility, &builder](const auto reasonerSnapshot)
63 packedUtility.push_back(Pack(builder, reasonerSnapshot));
66 std::for_each(snapshot.plannerReasonerSnapshotsPerEntityId.begin(), snapshot.plannerReasonerSnapshotsPerEntityId.end(),
67 [&packedPlanners, &builder] (
const auto& reasonerSnapshots)
69 std::for_each(reasonerSnapshots.second.begin(), reasonerSnapshots.second.end(),
70 [&packedPlanners, &builder](const auto reasonerSnapshot)
72 packedPlanners.push_back(Pack(builder, reasonerSnapshot));
76 return generated::CreateGrailDebugInfo(builder,
80 builder.CreateVector(packedGrailStates),
81 builder.CreateVector(packedSimGames),
82 builder.CreateVector(packedUtility),
83 builder.CreateVector(packedPlanners));
86 inline GrailDebugInfo Unpack(
const generated::GrailDebugInfo& snapshot)
88 GrailDebugInfo deserializedData{};
89 deserializedData.version = snapshot.version();
90 deserializedData.startTime = snapshot.startTime();
91 deserializedData.endTime = snapshot.endTime();
93 deserializedData.grailStateSnapshots.reserve(snapshot.grailStateSnapshots()->size());
94 for(
const auto& grailState : *snapshot.grailStateSnapshots())
96 deserializedData.grailStateSnapshots.emplace_back(Unpack(*grailState));
98 for(
const auto& simGame : *snapshot.simGameReasonerSnapshots())
100 deserializedData.simGameReasonerSnapshotsPerEntityId[simGame->entityId()].emplace_back(Unpack(*simGame));
102 for(
const auto& utility : *snapshot.utilityReasonerSnapshots())
104 deserializedData.utilityReasonerSnapshotsPerEntityId[utility->entityId()].emplace_back(Unpack(*utility));
106 for(
const auto& planner : *snapshot.plannerReasonerSnapshots())
108 deserializedData.plannerReasonerSnapshotsPerEntityId[planner->entityId()].emplace_back(Unpack(*planner));
111 return deserializedData;