sbaldu / DynamicalSystemFramework

Framework for modelling dynamical complex systems

Home Page:https://sbaldu.github.io/DynamicalSystemFramework/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic setDelay not working

NotLudovico opened this issue · comments

 for (uint32_t i = 0; i < MAX_TIME; ++i) {
    if (i % 60 == 0) {
      if (i != 0) {
        ++it;
      }
      const int agentNumber = dynamics.agents().size();
      if (i % 300 == 0) {
        ofs << i << ";" << tlr_ptr->agentCounter() << ';' << '\n';
        previousAgentNumber = 0;
      }
      previousAgentNumber += agentNumber;
      dynamics.addAgents(0, *it, 0);
    }
    dynamics.evolve(false);
    if (i == 18000) {
      tl1.setDelay(std::make_pair(90, 10));
      tl2.setDelay(std::make_pair(90, 10));
      tl3.setDelay(std::make_pair(90, 10));
      tl4.setDelay(std::make_pair(90, 10));
    }
  }

The effect of the setDelay at 18000 seconds doesn't change the output of the simulation. It produces the same csv regardless of the presence of the if block.

This is not a bug. You are addressing a traffic light which is not in the graph. There are two possible solutions to this:

  • when you declare your traffic light you make it a pointer like auto tlr1_ptr = std::make_shared<TrafficLight>(tl1); , then you add it to the graph graph.addNode(tlr1_ptr); and then you modify it tlr1_ptr->setDelay(std::make_pair(90, 10));
  • you modify it by calling from graph.nodeSet().at(1)->setDelay(std::make_pair(90, 10));
    Otherwise you are just calling a traffic light which has been copied into the graph, not moved.
    Hope this is clear.

Now it works. Thanks!