how to get the object of an agent from the database table in anylogic 8
how to get the object of an agent from the database table in anylogic 8
In my anylogic project I have created a population of agent named DATA. This population contains 4 values that are being fetched from the database table. This means that there are 4 agents in this population. The table contains two columns i.e. data_id and data_state. Ultimately these become the parameters of this agent Data. Table sample is shown below:
data_id | data_state
d1 | delivered
d2 | delivered
d3 | undelivered
d4 | delivered
I am applying any condition in an event named "retransmit", based on which the object of undelivered data is to be fetched and then later on called. This event is in some other agent named SENDER. Once I have obtained the value "d3" by sql, how can I get the object of DATA with data_id 'd3' from SENDER?
What should I write?
main.datas.get(??)
I dont want to hard code this like: main.datas.get(2);
Does anybody know any method or a built-in function by which I can achieve this?
1 Answer
1
assuming that there is only one DATA with data_id=d3
Data theData=findFirst(main.datas,d->d.data_id==d3);
If there are many
List <Data> theDatas=findAll(main.datas,d->d.data_id==d3);
you are right :D
– Felipe
Jun 30 at 12:02
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
That's exactly what I wanted!.. Thanks alot :) .. Above code needs just a little correction, it should be like this: List<Data> theDatas=findAll(main.datas, d->d.data_id==d3);
– Murk
Jun 30 at 10:43