Parcourir la source

dtss: add observables and change time_step definition

Eric Ramat il y a 4 ans
Parent
commit
8cee3ffe62

+ 3 - 7
src/artis-star/kernel/dtss/Coordinator.hpp

@@ -37,12 +37,8 @@ namespace artis {
     namespace dtss {
 
         template<class Time>
-        class Parameters {
-        public:
-            Parameters(typename Time::type time_step)
-                    :_time_step(time_step) { }
-
-            typename Time::type _time_step;
+        struct Parameters {
+            typename Time::type time_step;
         };
 
         template<class Time, class Policy, class GraphManager,
@@ -61,7 +57,7 @@ namespace artis {
                     common::Model<Time>(name),
                     common::Coordinator<Time>(name),
                     _graph_manager(this, parameters, graph_parameters),
-                    _time_step(parameters._time_step) { }
+                    _time_step(parameters.time_step) { }
 
             virtual ~Coordinator() { }
 

+ 28 - 3
src/artis-star/kernel/dtss/Dynamics.hpp

@@ -42,6 +42,13 @@ namespace artis {
             typedef dtss::Simulator<Time, Dyn, Parameters> Simulator;
 
         public:
+            struct Observable {
+                unsigned int index;
+                std::string name;
+            };
+
+            typedef std::map<unsigned int, std::string> Observables;
+
             Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
                     :
                     _name(name), _simulator(context.simulator()) { }
@@ -49,12 +56,12 @@ namespace artis {
             virtual ~Dynamics() { }
 
             virtual void transition(const common::Bag<Time>& /* x */,
-                    typename Time::type /* t */) { }
+                    const typename Time::type& /* t */) { }
 
-            virtual void start(typename Time::type/* time */) { }
+            virtual void start(const typename Time::type& /* time */) { }
 
             virtual common::Bag<Time> lambda(
-                    typename Time::type /* time */) const { return common::Bag<Time>(); }
+                    const typename Time::type& /* time */) const { return common::Bag<Time>(); }
 
             virtual common::Value observe(const typename Time::type& /* t */,
                     unsigned int /* index */) const { return common::Value(); }
@@ -74,6 +81,20 @@ namespace artis {
                 }
             }
 
+            void observable(Observable observable)
+            {
+                _observables[observable.index] = observable.name;
+            }
+
+            void observables(std::initializer_list<Observable> list)
+            {
+                for (typename std::initializer_list<Observable>::iterator it = list.begin();
+                     it != list.end();
+                     ++it) {
+                    _observables[it->index] = it->name;
+                }
+            }
+
             void output_port(common::Port p)
             {
                 _simulator->add_out_port(p);
@@ -97,9 +118,13 @@ namespace artis {
                 common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
             }
 
+            const typename Time::type& time_step() const
+            { return _simulator->time_step(); }
+
         private:
             std::string _name;
             Simulator* _simulator;
+            Observables _observables;
         };
 
     }

+ 12 - 0
src/artis-star/kernel/dtss/GraphManager.hpp

@@ -127,6 +127,18 @@ namespace artis {
                 }
             }
 
+            virtual std::string to_string(int level) const
+            {
+                std::ostringstream ss;
+
+                ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
+                for (auto& child : common::GraphManager<Time>::_children) {
+                    ss << child->to_string(level + 1);
+                }
+                ss << _link_list.to_string(level);
+                return ss.str();
+            }
+
         private:
             void add_link(common::Model<Time>* src_model, unsigned int src_port_index,
                     common::Model<Time>* dst_model, unsigned int dst_port_index)

+ 4 - 1
src/artis-star/kernel/dtss/Simulator.hpp

@@ -72,7 +72,7 @@ namespace artis {
                     common::Model<Time>(name),
                     common::Simulator<Time>(name),
                     _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)),
-                    _time_step(parameters._time_step) { }
+                    _time_step(parameters.time_step) { }
 
             ~Simulator() { }
 
@@ -241,6 +241,9 @@ namespace artis {
                 return type::_tn;
             }
 
+            const typename Time::type& time_step() const
+            { return _time_step; }
+
         private :
             Dynamics _dynamics;
             typename Time::type _time_step;

+ 1 - 1
src/artis-star/kernel/pdevs/qss/Integrator.hpp

@@ -199,7 +199,7 @@ namespace artis {
                     _state = INIT;
                 }
 
-                virtual typename Time::type ta(const typename Time::type& t)
+                virtual typename Time::type ta(const typename Time::type& /* time */)
                 {
                     double current_derivative;