@@ -67,6 +67,26 @@ void Environment::optimize() {
6767 optimized_graph_ = graph_;
6868}
6969
70+ void recursive_construct (Reactor* container) {
71+ container->construct ();
72+ for (auto * reactor : container->reactors ()) {
73+ recursive_construct (reactor);
74+ }
75+ }
76+
77+ void Environment::construct () {
78+ // phase_ = Phase::Assembly;
79+
80+ log::Info () << " Start Contruction of reactors" ;
81+ for (auto * reactor : top_level_reactors_) {
82+ recursive_construct (reactor);
83+ }
84+
85+ for (auto * env : contained_environments_) {
86+ env->construct ();
87+ }
88+ }
89+
7090void recursive_assemble (Reactor* container) {
7191 container->assemble ();
7292 for (auto * reactor : container->reactors ()) {
@@ -80,7 +100,7 @@ void Environment::assemble() { // NOLINT(readability-function-cognitive-complexi
80100 // constructing all the reactors
81101 // this mainly tell the reactors that they should connect their ports and actions not ports and ports
82102
83- log::Debug () << " start assembly of reactors" ;
103+ log::Info () << " start assembly of reactors" ;
84104 for (auto * reactor : top_level_reactors_) {
85105 recursive_assemble (reactor);
86106 }
@@ -112,6 +132,8 @@ void Environment::assemble() { // NOLINT(readability-function-cognitive-complexi
112132 source_port->add_outward_binding (destination_port);
113133 log::Debug () << " from: " << source_port->fqn () << " (" << source_port << " )"
114134 << " --> to: " << destination_port->fqn () << " (" << destination_port << " )" ;
135+ reactor::validate (source_port != destination_port,
136+ " Self wiring detected; from " + source_port->fqn () + " --> " + destination_port->fqn ());
115137 }
116138 } else {
117139 if (properties.type_ == ConnectionType::Enclaved || properties.type_ == ConnectionType::PhysicalEnclaved ||
@@ -221,6 +243,8 @@ void Environment::export_dependency_graph(const std::string& path) {
221243 std::ofstream dot;
222244 dot.open (path);
223245
246+ dependency_graph_and_indexes ();
247+
224248 // sort all reactions_ by their index
225249 std::map<unsigned int , std::vector<Reaction*>> reactions_by_index;
226250 for (auto * reaction : reactions_) {
@@ -317,7 +341,7 @@ auto Environment::startup() -> std::thread {
317341 return startup (get_physical_time ());
318342}
319343
320- auto Environment::startup ( const TimePoint& start_time) -> std::thread {
344+ void Environment::dependency_graph_and_indexes () {
321345 validate (this ->phase () == Phase::Assembly, " startup() may only be called during assembly phase!" );
322346
323347 log::Debug () << " Building the Dependency-Graph" ;
@@ -327,7 +351,17 @@ auto Environment::startup(const TimePoint& start_time) -> std::thread {
327351
328352 calculate_indexes ();
329353
330- log_.debug () << " Starting the execution" ;
354+ phase_ = Phase::Indexing;
355+ }
356+
357+ auto Environment::startup (const TimePoint& start_time) -> std::thread {
358+ if (phase_ == Phase::Assembly) {
359+ dependency_graph_and_indexes ();
360+ }
361+
362+ validate (this ->phase () == Phase::Indexing, " startup() may only be called during Indexing phase!" );
363+
364+ log_.info () << " Starting the execution" ;
331365 phase_ = Phase::Startup;
332366
333367 this ->start_tag_ = Tag::from_physical_time (start_time);
0 commit comments