MaDKit forum

Welcome All !
Please, use explicit topic names when creating new threads. Thanks.

You are not logged in.

#1 2014-03-01 01:29:51

keke
Member
Registered: 2014-03-01
Posts: 14

How to add/retrieve new property

Hi all,

I would like to modify the "madkit.properties" file for instance, by adding more pairs <file=abc.txt> .
But I don't know how to get that value in the class which extends madkit.kernal.Agent.

I see in the tutorial examples, in the main function, we can use some parameters to launch the program such as
String[] argss = { "--agentLogLevel", "INFO", "--launchAgents",
                LanceurAgents.class.getName() };
        Madkit.main(argss);

But we cannot read that parameters inside some function, e.g., activate() or live(),....
So could you please tell me how to read that pair?

Thank you

Offline

#2 2014-03-01 11:39:50

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

Hi,

Maybe that this could help : http://www.madkit.net/forum/viewtopic.p … 1275#p1275

By the way, it is possbile to add properties using an external xml file and the --configFile option (see the example in the docs dir)

Offline

#3 2014-03-01 19:21:30

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thank you so much.
By the way, I don't know how to use XML_config_file.xml file in the project, i.e., where we put it, and how to run the project with it.
I see in that file, I can modify madkit properties in the line <MadkitProperties test="yes" test2="good" desktop="true" />, is it right?
but I don't know how to run with that file.

Thanks

Offline

#4 2014-03-01 23:12:23

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

The xml file simply has to be in the working directory, that is where MaDKit is launched. In an Eclipse project, by default it is the project's dir.
So:
--configFile xml.xml
--configFile myConfig/xml.xml 
--configFile /pathToFile/xml.xml

are examples that should work

Offline

#5 2014-03-02 01:12:40

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thanks so much.

I have just tested your xml.xml file and get this error
[MadkitKernel-0] SEVERE : launchNode FAILED : Agent( GUI=false class=code.testLauncher logLevel=INFO nbOfInstances=1  )
** java.lang.NoSuchFieldException: aNbAsAnInteger
    at madkit.kernel.MadkitKernel$7.run(MadkitKernel.java:523)

The code XML is:
<Agent class="code.testLauncher" nbOfInstances="1" GUI="false" logLevel="INFO">
            <Attributes aNbAsAnInteger="3" aReal="5.5" aString="blabla" />
        </Agent>

The problem is I don't understand the tag <Attribute> of the <Agent>. What are the roles of that tag when we modify/add for that agent? Please tell me an example about this.

Offline

#6 2014-03-02 11:17:02

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

In fact, the attributes should match real class's fields of the agent. This is the reason why you get the   java.lang.NoSuchFieldException: aNbAsAnInteger : I assume your agent does not have a field called "aNbAsAnInteger", that is something like :

private int aNbAsAnInteger ;
or
private Integer aNbAsAnInteger ;

in its class.

And thus, considering the example,

private double aReal ;
private String aString ;

Offline

#7 2014-03-02 17:33:18

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thank you. I understand it now.

In addition, could you please tell me how to list a set of agents who are inside one group? For instance, user A is owner of group GA (by using createGroup()), and some other users  (like B) join in that group. So could A/B know the set of agents in group GA?

Offline

#8 2014-03-03 10:02:52

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

Just use :
public List<AgentAddress> getAgentsWithRole(String community, String group,String role) or
public List<AgentAddress> getAgentsWithRole(String community, String group, String role, boolean callerIncluded)

Offline

#9 2014-03-03 10:31:56

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thank you for your instruction.
I knew these functions in the docs, but the class AgentAddress cannot give the list of Agents (of AbstractAgent). I would like to take that list to send messages to all nodes who have some common role and group.
Do you know how to do that?
Thanks again

Offline

#10 2014-03-04 14:21:46

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

If it is about communication between agents, you should use the AgentAddress of the agents with the sendMessage primitives.
If you really need to access the object references of the agents, you will find what you are looking for in the simulation tutorial of the web site.
You can also then check the bees demo.

Offline

#11 2014-03-09 09:22:15

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

As I know that after activating with func activate(), agent will automatically run func live().
But now I want to postpone it by running some other functions before reaching to live().
Could you please tell me how to do like that?
Moreover, do you know how to get messages from users with role, e.g. function like getMessageWithRole(), as there is function sentMessageWithRole and i would like the receiver can get that message from senders with certain role.
Thank you.

Last edited by keke (2014-03-09 12:23:52)

Offline

#12 2014-03-10 08:54:34

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

keke wrote:

As I know that after activating with func activate(), agent will automatically run func live().
But now I want to postpone it by running some other functions before reaching to live().
Could you please tell me how to do like that?

Activate can stand as long as requred: It can contain an infinite loop or a blocking waitNextMessage for instance. Still the agent that laucnhes an agent which has a blocking activate method should launch it using 0 second as time out if it does not want to wait the end of the activate method of the launched agent

keke wrote:

Moreover, do you know how to get messages from users with role, e.g. function like getMessageWithRole(), as there is function sentMessageWithRole and i would like the receiver can get that message from senders with certain role.
Thank you.

There is no such methods for now. That is: You cannot select messages from the mailbox based on the sender's role although you can of course check it after on received messages.
But it is a nice suggestion and I will probably integrate it in a future version. I will keep you informed.

Offline

#13 2014-03-10 15:43:42

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thanks so much.
Please inform me your update version if it's available.
In addition, do you know how to check the queue of receiving messages? I mean when some msgs with id 1,2,3,4... come to inbox they will put into queue (is it right??), then we have to use func like nextMessage() or waitNextMessage(). However these functions with get the messages out of the queue and we cannot re-obtain it any more in queue. So, if i would like to get msg, e.g. msg id 3, from the queue, I have to use nextMessage three times? do you have any other solutions?

Offline

#14 2014-03-17 17:00:35

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

I have posted a new version today : 5.0.4. It includes a new interface madkit.message.MessageFilter so that you should be able to retrieve messages with any kind of filtering. See the new nextMessage(s) and waitNextMessage methods.
Some predefined filters have been included in the madkit.message package (for role selection and conversationID filtering).

Offline

#15 2014-03-28 10:39:33

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

Thanks for your new update.
I test my program with large number of nodes and receives the error "cannot assign requested address". Do you know what is really problem of this?
Thanks

Offline

#16 2014-03-29 11:18:16

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

Hello,

Well, as this error message is not part of MaDKit's outputs, I just cannot see what can be the problem without more information.

Offline

#17 2014-03-30 15:28:15

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

I am sorry, that's other error. Please abandon it.

I have a question, could I change the hashCode of (Abstract)Agent? I see in the code of these classes, we only assign the value in the constructors, but cannot change later.
I demand this since sometimes we need to change hashCode in the simulation model, we don't need to assign automatic hashcode value

Last edited by keke (2014-03-30 15:55:45)

Offline

#18 2014-03-31 15:48:35

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to add/retrieve new property

It is not possible to change the hashcode of an agent : it is an important value with respect to how MaDKit works.
Still, I do not understand why you want/need to change it. What's the use case exactly ?

Offline

#19 2014-04-01 10:48:42

keke
Member
Registered: 2014-03-01
Posts: 14

Re: How to add/retrieve new property

I want to change it since in my program the agent already has its own id, and I want that id is also hashcode (just for simulation, not real-world address), otherwise the consume other field for id (and in fact, there is a mapping id<-->hashcode).
Moreover, I would like to ask you an unrelated question. I have a problem with virtual memory when running in java (not RES memory in command "top" ubuntu): it increases much important. As I know that the necessary memory to run program is the RES memory (e.g., bee example has ~1G) not VIRT memory, but I get error with outofmemory with virtual memory. In your experience, could you please suggest any thing to decrease it? Thanks

Offline

Board footer