0

I would like to change the number of the entities in my simulation based on the simulation time. I found this solution (found here: How to change a parameter value over time?):

Network.numberOfEntities = simTime() < 30s ? 50 : 250

I use this parameter for initializing submodules in the ned file like this:

submodules:
        entities[numberOfEntities]: Entity;

However, this does not work here, the number does not change. Any idea how I can change the number of network entities at runtime? The only alternative I can think of is to create 250 entities and only make 50 active at the beginning and change this by a parameter over time instead of creating new entities.

mapf
  • 496
  • 1
  • 5
  • 21

1 Answers1

1

Changing of numberOfEntities does not affect the number of entities in the network because submodules are created only during starting of a simulation (i.e. when t=0).
However, in OMNeT++ API there is a possibility of deleting and creating modules in every moment - look at Simulation Manual, 4.13 Dynamic Module Creation.

Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
  • Thanks for your answer. Do I understand correctly, that I need to have some module which checks each tick if the number of existing entities and the parameter are not the same anymore for creating the missing entities as described in the linked part of the manual? – mapf Jul 25 '18 at 07:42
  • 1
    Yes, you need an additional module which will delete and create modules during experiment. However, instead of permanent checking the value of `numberOfEntities` I suggest adding new parameters. For example: `numberOfEntities1`, `numberOfEntities2, ..., `changeTime1`, `changeTime2` etc. Then schedule a self-message for `changeTime1`. When it will fire, start deleting/creating modules to achieve the number of modules equal to `numberOfEntities2`, etc. – Jerzy D. Jul 25 '18 at 08:18
  • Okay this seems to work, however what is missing now: How can I add a created Entity to the array of entities which is specified in the network file? – mapf Jul 25 '18 at 13:06
  • It is not possible to use the fast way of initialization mentioned in the manual. I had to go for the manual creation using the create method. In the API I found out, that Omnet offers a create method explicitly for vectors looking like this: cModuleType::create(const char * name, cModule * parentmod, int vectorsize, int index). Now it works, thanks! – mapf Jul 25 '18 at 13:40