From 59d7ab5a324ee62996f093f353ea2a7f274a9721 Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Fri, 17 Mar 2023 10:12:02 +0100 Subject: [PATCH 001/103] first draft --- cpp/memilio/utils/history.h | 90 +++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 cpp/memilio/utils/history.h diff --git a/cpp/memilio/utils/history.h b/cpp/memilio/utils/history.h new file mode 100644 index 0000000000..7907c1bf9c --- /dev/null +++ b/cpp/memilio/utils/history.h @@ -0,0 +1,90 @@ +/* +* Copyright (C) 2020-2021 German Aerospace Center (DLR-SC) +* +* Authors: Daniel Abele, Elisabeth Kluth +* +* Contact: Martin J. Kuehn +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef MIO_ABM_HISTORY_H +#define MIO_ABM_HISTORY_H +namespace mio +{ +namespace abm +{ + +template +class Writer +{ + write(Types... args) + { + } + using Data = std::tuple; +}; + +template +class History +{ +public: + //TODO: maybe change this to arglist + template + void log(const T& t) + { + log_impl(t); + // write(Loggers::log(t)...); + } + + TimeSeries get_data() + { + return m_data; + } + +private: + Writer::Data m_data; + + template + std::enable_if_t> log_impl(const T& t) + { + Writer::write(Logger::log(t)); + log_impl(t); + } + + template + std::enable_if_t> log_impl(const T& t) + { + Writer::write(Logger::log(t)); + log_impl(t); + } + + template + log_impl(const T&) + { + // end of recursion + } +}; +struct LogOnce { +}; + +struct LogLocId : public LogOnce { + using Type = std::vector; + static Type log(const World& world) + { + [world.get_location().get_id()]; + } +}; + +} // namespace abm +} // namespace mio + +#endif \ No newline at end of file From 72f9c6052f18053ad52d25f58f4d1eb8528d091d Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Mon, 27 Mar 2023 17:00:37 +0200 Subject: [PATCH 002/103] add another logger Signed-off-by: Sascha Korf <51127093+xsaschako@users.noreply.github.com> --- cpp/memilio/utils/history.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpp/memilio/utils/history.h b/cpp/memilio/utils/history.h index 7907c1bf9c..ae64f5f02e 100644 --- a/cpp/memilio/utils/history.h +++ b/cpp/memilio/utils/history.h @@ -73,6 +73,7 @@ class History // end of recursion } }; + struct LogOnce { }; @@ -84,6 +85,17 @@ struct LogLocId : public LogOnce { } }; +struct LogAlways { +}; + +struct LogTime : public LogAlways { + using Type = std::vector; + static Type log(const World& world) + { + [world.get_time()]; + } +}; + } // namespace abm } // namespace mio From 6e977374485962547184417155c41d87001afea4 Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Mon, 27 Mar 2023 23:45:12 +0200 Subject: [PATCH 003/103] change some things Signed-off-by: Sascha Korf <51127093+xsaschako@users.noreply.github.com> --- cpp/memilio/utils/history.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/memilio/utils/history.h b/cpp/memilio/utils/history.h index ae64f5f02e..012d08dbb2 100644 --- a/cpp/memilio/utils/history.h +++ b/cpp/memilio/utils/history.h @@ -81,7 +81,7 @@ struct LogLocId : public LogOnce { using Type = std::vector; static Type log(const World& world) { - [world.get_location().get_id()]; + return [world.get_location().get_id()]; } }; From b49606f9903324fba687e701e6d179a7277ef9f0 Mon Sep 17 00:00:00 2001 From: Sascha Korf <51127093+xsaschako@users.noreply.github.com> Date: Mon, 27 Mar 2023 23:45:33 +0200 Subject: [PATCH 004/103] example for testing purposes Signed-off-by: Sascha Korf <51127093+xsaschako@users.noreply.github.com> --- cpp/memilio/utils/history_example.cpp | 97 +++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 cpp/memilio/utils/history_example.cpp diff --git a/cpp/memilio/utils/history_example.cpp b/cpp/memilio/utils/history_example.cpp new file mode 100644 index 0000000000..6d72e0efd1 --- /dev/null +++ b/cpp/memilio/utils/history_example.cpp @@ -0,0 +1,97 @@ +/* +* Copyright (C) 2020-2021 German Aerospace Center (DLR-SC) +* +* Authors: Daniel Abele, Elisabeth Kluth +* +* Contact: Martin J. Kuehn +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include +#include + +template +class Writer +{ + write(Types... args) + { + } + using Data = std::tuple; +}; + +template +class History +{ +public: + //TODO: maybe change this to arglist + template + void log(const T& t) + { + log_impl(t); + // write(Loggers::log(t)...); + } + + TimeSeries get_data() + { + return m_data; + } + +private: + Writer::Data m_data; + + template + std::enable_if_t> log_impl(const T& t) + { + Writer::write(Logger::log(t)); + log_impl(t); + } + + template + std::enable_if_t> log_impl(const T& t) + { + Writer::write(Logger::log(t)); + log_impl(t); + } + + template + log_impl(const T&) + { + // end of recursion + } +}; + +struct LogOnce { +}; + +struct LogLocId : public LogOnce { + using Type = std::vector; + static Type log(const double id) + { + return [world.get_location().get_id()]; + } +}; + +struct LogAlways { +}; + +struct LogTime : public LogAlways { + using Type = std::vector; + static Type log(const double time) + { + [world.get_time()]; + } +}; + +int main() +{ +} \ No newline at end of file From bf5099501a4cd5fd505301677082d2936ff7045a Mon Sep 17 00:00:00 2001 From: Sascha <51127093+xsaschako@users.noreply.github.com> Date: Thu, 30 Mar 2023 16:36:00 +0200 Subject: [PATCH 005/103] barebone implementation --- cpp/memilio/utils/history_example.cpp | 107 ++++++++++++++++---------- 1 file changed, 68 insertions(+), 39 deletions(-) diff --git a/cpp/memilio/utils/history_example.cpp b/cpp/memilio/utils/history_example.cpp index 6d72e0efd1..67a630477c 100644 --- a/cpp/memilio/utils/history_example.cpp +++ b/cpp/memilio/utils/history_example.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2020-2021 German Aerospace Center (DLR-SC) * -* Authors: Daniel Abele, Elisabeth Kluth +* Authors: Sascha Korf, Rene Schmieding * * Contact: Martin J. Kuehn * @@ -19,79 +19,108 @@ */ #include #include +#include -template -class Writer +class example { - write(Types... args) +public: + int a = 1; + int b = 2; +}; +struct LogOnce { +}; + +struct LogA : LogOnce { + using Type = int; + static Type log(const example& ex) + { + return ex.a; + } +}; + +struct LogAlways { +}; + +struct LogB : LogAlways { + using Type = int; + static Type log(const example& ex) { + return ex.b; } - using Data = std::tuple; }; -template +template +struct Writer { + using Data = std::tuple...>; + template + static void write(const typename Logger::Type& t, Data& data) + { + //std::get::value>(data).push_back(t); + std::cout << t << std::endl; + } +}; + +template