0

I'm new in anylogic and I have faced with a problem while creating new agents using add_agent(). I am simulating an online shop having consumers, vendors and products as agents. Each product belongs to a vendor and consumers buy them during the time. when the number of products in each vendor is lower than a predefined threshold or consumer demand is more than available products I try to add new products using add_Product () (from Main agent). the problem is that in each vendor, the assigned indexes to products are repetitive (root.Products[5],root.Products[5]) and sometimes even an index -1 is produced (root.Products[-1]). consequently when I want to remove products (to model selling products) the products with -1 index are not removed. do you know where is my fault?

1 Answers1

0

Avoid relying on automatic indices to refer to agents in a population. Better add a parameter of type integer to your agent type and assign it a value that you can later "recognize" when you want to delete it.

If you add a param "myIndex" to Product, you can create a new Product using add_Product(6) where 6 is your index that you can later find that product by.

Check the help on parameters, agent creation, etc. to learn more

Benjamin
  • 10,603
  • 3
  • 16
  • 28