MaDKit forum

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

You are not logged in.

#1 Re: HowTo » ACLMessage content » 2017-03-12 15:42:28

In fact, using the ACL class, you should use getFieldValue(String key) with content as key to get what was set using setContent(), i.e. getFieldValue("content").

But, indeed there is an API problem here in the sense that the behavior of getContent is very misleading in the ACL class and should be overridden. I will fix that.
Still, the fact is that this class's code is very old and implement a lot of features which are now available in MDK, i.e. conversation/reply mechanisms of communication methods of agents.
If you do not use ACL semantics and are only interested in tagging conversation and using messages containing a map, maybe that you could consider this new class that I will add in a near future:

package madkit.message;

import java.util.HashMap;
import java.util.Map;

/**
 * This class could be used to build message conveying {@link Map} 
 * objects between MaDKit agents.
 * 
 * @author Fabien Michel
 * @since MaDKit 5.1.2
 * @version 0.9
 *
 */
public class MapMessage<K,V> extends ObjectMessage<Map<K,V>> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6301488493002636831L;

	/**
	 * Builds a <code>MapMessage</code> containing the specified map
	 * @param map the original map
	 */
	public MapMessage(final Map<K,V> map) {
		super(map);
	}

	/**
	/**
	 * Builds a <code>MapMessage</code> containing an empty  {@link HashMap}}
	 */
	public MapMessage() {
		this(new HashMap<>());
	}

	/**
	 * invoke {@link Map#put(K, V)} on the map contained in this message
	 * 
	 * @param key key with which the specified value is to be associated
	 * @param value value to be associated with the specified key
	 * @return the previous value associated with <tt>key</tt>, or
	 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
	 *         (A <tt>null</tt> return can also indicate that the map
	 *         previously associated <tt>null</tt> with <tt>key</tt>,
	 *         if the implementation supports <tt>null</tt> values.)
	 *         
	 * @see Map#put(K, V)  
	 */
	public V put(K key, V value){
		return getContent().put(key, value);
	}

	/**
	 * invoke {@link Map#get(K)} on the map contained in this message
	 * 
     * @param key key with which the specified value is to be associated
     * @param value value to be associated with the specified key
     * @return the previous value associated with <tt>key</tt>, or
     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
     *         (A <tt>null</tt> return can also indicate that the map
     *         previously associated <tt>null</tt> with <tt>key</tt>,
     *         if the implementation supports <tt>null</tt> values.)
 	 */
	public V get(K key){
		return getContent().get(key);
	}

}

#2 Re: HowTo » How to know message type » 2017-03-10 09:51:12

Hello,

Since an agent may send and receive any kind of messages, you have to test that the message is of a particular expected type. Example:

			Message m = waitNextMessage();
			if (m instanceof GUIMessage) {
				treat((GUIMessage) m);
			}
			else
				if (m instanceof KernelMessage) {
					treat((KernelMessage) m);
				}
				else
					if (logger != null)
						logger.warning("I received a message that I do not understand. Discarding "
								+ m);
		}

Therefore it is of course possible to use different types of messages at the same time.

#3 Re: HowTo » Send messages » 2017-02-05 18:36:30

Hello,

First, I advice you to check the last version; 5.0.0.10 is quite old now.

sendMessage methods return a ReturnCode that gives this kind of information (cf. the madkit.kernel.AbstractAgent.ReturnCode javadoc)

So, for instance:
ReturnCode r = sendMessage(m,target);
if(r != ReturnCode.SUCCESS){
  getLogger().info("there was a problem "+r);
}

But more simply, sendMessage methods are automatically  logged.
So, for debugging purposes :
setLogLevel(Level.FINEST);//somewhere before
sendMessage(m,target);

will print out what the result is

Even more simply, if you are just interested in printing the ReturnCode only if there was a problem, use

getLogger().setWarningLogLevel(Level.FINE);//which is equal to the default log level of agents, so that warnings will be displayed when methods do not return SUCCESS
sendMessage(m,target);

Moreover, if the target is running on the same kernel, a SUCCESS also means that the message was safely delivered in the target's mailbox.

#4 Re: Projets MaDKit » Projet n'a pas été créé » 2017-01-24 14:04:39

Bonjour,

Nous ne faisons plus de support pour la version 4.x
Je vous suggère de passer à la version 5. Après le téléchargement, ici une page pour démarrer : http://www.madkit.net/madkit/documents.php

#5 Re: TurtleKit questions (how to) » Run several simulations in parallel » 2016-06-29 09:21:55

Hello,

ximog wrote:

I do not know if it is possible to build several simulations in parallel and how to do it in MadKit/turtleKit.

It is, that is to say that you can, within a regular main method of a dedicated class, launch several instances of TurtleKit with different options (no overlap normally). Still it could be easier and probably as fast to launch them in sequentially.

ximog wrote:

Furthermore, how could I do to run one simulation after another without having to rerun again everytime the simulation finishes?

I personally use shell script (which could be easily adapted to windows). Here is one example:

rm $1
touch $1
date >> $1
echo "phero nb = $3 ..... Simulation duration = $2"
echo "envSize;totalTime;agentsComputationTime;envComputationTime;percentage;nbAgents" >> $1
for i in 30 70 100 120
do
	echo "" >> $1
	echo  "---------$i%" >> $1
	echo $i
	for size in 600 
	do 
		for nbIteration in $(seq 3)
		do
			java -Xmx12G -Xms4G -cp bin:lib/turtlekit-3.0.0.4.jar bench.phero.RandBenchTurtle $size $i --csv.file $1 $2
			sleep 4
		done
	echo "" >> $1
	done
done
date >> $1

$1 is the name of the current csv file.
This name is known at runtime using

String csvFile = getMadkitProperty("cvs.file");

Other $ are arguments which are passed to main method of a Turtle :

	
                public static void main(String[] args) {
		float percentage = Float.parseFloat(args[1])/100;
		int size = Integer.parseInt(args[0]);
		int nbAgents = (int) ((float) size * size * percentage);
		executeThisTurtle(nbAgents
				,Option.envDimension.toString(),args[0]+","+size
				,args[2]
				,"--cvs.file",args[4]
				,Option.startSimu.toString()
				,Option.endTime.toString(),args[5]
				,Option.scheduler.toString(),BenchScheduler.class.getName()
				,Option.viewers.toString(),"null"
				);

There are many other ways (using @Test series witgh Junit, using a Java program instead of a script, etc.).

Hope this help.

Fabien

#6 Re: HowTo » Suppress Viewer Windows » 2016-05-04 09:48:06

Hi,

Maybe that you could take a look at the tutorial on GUI that explains the three ways of making an agent's GUI : 1. default, 2 custom, 3 independent :  http://www.madkit.net/madkit/tutorials/ … index.html

Also, I guess that you are extending SwingViewer, which GUI is forced on start-up using createGUIOnStartUp() in its constructor, because there is no point in using the SwingViewer class otherwise as it extends the Watcher class for defining a default GUI for simulation (which does not mean that you cannot customize the SwingViewer'GUI as will, see the bees demo examples for instance).

So, my advice would be to either (1) create your own version of SwingViewer starting from its source code, (2) customize the SwingViewer frame like it is done in the bees demo or (3) start from scratch by extending Watcher and using the independent GUI method to use your own (which is probably what you want to do).

#7 Re: TurtleKit questions (how to) » How to launch » 2016-05-03 09:10:02

Hi,

A first answer is that TurtleKit 2 is a bit out-of-date compared to how TurtleKit 3 is now working (much more simpler despite the alpha tag). So a first answer could be that you should first try to use this version. For instance, one way (there are others) of running the termite simulation is just about executing the main method which is in the Termite class (from the demo zip file) once the TurtleKit jar file is in the class path of your IDE.
Do not hesitate to post again if you encounter any problem using it.

Best,
Fabien

#8 Re: HowTo » Launch nested/inner class » 2016-03-11 10:45:30

oxality wrote:

This worked, thanks. However now the panel for that AbstractAgent doesnt pop up. Any output set through logger just goes to my IDE terminal. Im just using the inherited setupFrame method if that matters

Well, it should just be because you have to use the version of the method that includes the boolean parameter so that the agent has a GUI or not, i.e. launchAgent(a,true). Does this solve your problem ?

#9 Re: HowTo » Launch nested/inner class » 2016-03-10 11:00:35

oxality wrote:

ah ok. is there a way to pass values to the new Agent when you launch it, similar to the way you can pass values when constructing an object? Ive noticed AbstractAgents ignore/dont require constructors

AbstractAgents  subclasses can have their own constructor and thus be parametrized when instantiated before being launched using the launchAgent(madkit.kernel.AbstractAgent) version. Is it what you are looking for or do you have another use case in mind ?

#10 Re: HowTo » Launch nested/inner class » 2016-03-09 10:52:23

oxality wrote:

This gives me an InstantiationError, i guess because it cant find the correct class name?

Not exactly. In fact, to instantiate an inner class you need to do it from an existing instance of the enclosing class, i.e. outerClass here, which cannot be the case when you only pass the name of the inner class to the kernel.

So, for doing this you can use the following :

public class InnerAgentClassTest {
	    public static void main(String[] args) {
	   	 InnerAgentClassTest test = new InnerAgentClassTest();
	         Madkit m = new Madkit("--launchAgents", ConsoleAgent.class.getName());
	         m.doAction(KernelAction.LAUNCH_AGENT, test.new InnerClass(),Boolean.TRUE);
	     }

	class InnerClass extends Scheduler
	{ 
		@Override
		protected void activate() {
			super.activate();
		}
	}
}

#11 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2016-03-07 20:50:23

oxality wrote:

So i have two entities, a console with a task list and a robot. The robot asks the console for a task (end step) the console responds with a task (end step) the robot then begins the process of moving to the work area, which i would like to span over multiple steps. In this case, the robot moves grid unit to grid unit, so preferably moving to an adjacent grid unit would take up one step.

OK, maybe that what you want could be done by using several activators in your scheduler (one per task). Did you try that ?

#12 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2016-03-04 12:25:57

oxality wrote:

Is there a way to launch into a certain method after checking the mailbox, but have that method span over multiple steps in the simulation?

Not sure about what you want to do here, could you describe a use case ?

oxality wrote:

Also, how does the scheduler interact/affect the regular Agents?

The scheduler can trigger an Agent's method regardless of its Thread. Therefore, in a such a case, having such a method synchronized could be a good idea for avoiding inconsistent states.

#13 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2016-02-28 19:20:09

Not sure that this will help but here is a first reply: You can work with AA and communicate by checking your mailbox each turn. Also, be aware that you can use a scheduler on agents from the Agent class. Finally, you can mix agents from any type.

#14 Re: HowTo » Random generation of events in the agent's environments » 2014-10-22 11:58:31

Hi,

Considering simulation ?
In this case, the simplest thing to do is to add a method in the environment and add an activator so that this method is called during the simulation process. Then in this method, yous can add random generation of events as will.

#15 Re: HowTo » Gérer la priorité entre des agents lancés en parallèle » 2014-05-08 11:30:05

Bonjour,

le temps de pause doit simplement être trop court

#16 Re: HowTo » An agent with a different behaviour » 2014-05-08 11:28:01

Hi,

I meant :

lanchAgent(new MyAgent(), true);//returns when its activate ends, no timeout
sendMessage(c,g,r, new Message());//here I am sure that the agent has ended its activate method, and thus that it should be reachable because it took its position in it s activate.

#17 Re: HowTo » Display the agent execution time » 2014-05-05 09:30:14

Hi,

Personnaly, I use something like (extracted from the javadoc)

" For example, to measure how long some code takes to execute:"

long startTime = System.nanoTime();
// ... the code being measured ...
long estimatedTime = System.nanoTime() - startTime;

#18 Re: HowTo » An agent with a different behaviour » 2014-05-04 23:09:48

Hi,

How are the agents launched ?
Because they are autonomous, if you want to be sure that one agent is in place (having a particular group/role) is either :
- check, and wait if necessary, that it is really in place (getAgentsWithRole)
- launch the agent from the agent that will reach it (by default launch returns when the activate method of the launched agent is done)

#19 Re: Projets TurtleKit » utiliser un projet existant » 2014-04-21 17:38:15

Bonjour,

Vous pouvez utilisez la méthode getCurrentBehaviorCount() qui renvoit le nombre de fois où le même comportement a été appelé.

donc

public String myMethod(){
if (getCurrentBehaviorCount() % 2) {
              doSome...
}
return "myMethod";
}

donne un comportement 2 fois plus lent que sans le "if"

Pour la distance, il y a une méthode distance(Turtle) qui devrait faire l'affaire

#20 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2014-04-11 16:01:55

Without more info (without seeing the code), it is hard to say what is the bottleneck. Especially, 10000 is not a so big number and you should not experience such problems imo.
Still, I have try to launch 10000 (threaded) Agents and it took only about one 1 Go on my PC, which is a relatively small amount of memory. So, if your agents mainly wait for messages before doing something, maybe that it is worth a try so that you could do your application without any scheduling.

#21 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2014-04-10 15:47:24

keke wrote:

The problem is that: I don't know in advance the 1st and 10000th node will take that role

I understood that, but the idea would be that you would do a first round on everybody using a particular activator that make some agents take the "working" roles. Then schedule the second activator (targeting the agents that have something to do) and so on. Could that be a solution ?

#22 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2014-04-10 13:56:37

Well, what I would do would be to use the group/role system to dynamically make the agents that have to be scheduled in another group : a "working group".
the 1st and the 10000th could take the role "worker" if they know they have to be scheduled for waiting a message (you need another activator on that group/role). Once done they could leave this group/role so that they would not be scheduled anymore for this particular work.
Summarizing, the idea is : structure your application using group/role. Entering and leaving group/role is easy and would allow you to only target the right agents.

#23 Re: HowTo » What is difference between Agent Type and AbstractAgent? » 2014-04-08 14:00:09

keke wrote:

Which type of data consume much memory? AbstractAgent or Agent?

Agent, because they require the creation of a thread.

keke wrote:

In addition, how can I modify the code such that the AbstractAgent could wait a message forever like function waitNextMessage() in the one of Agent?

You could do something like

Message m = nextMessage();
while(m == null){
Thread.sleep(1000);
m = nextMessage();
}

It is on purpose that such a method is not present in the AA class because the user should be aware of what he is doing : calling such a method causes the calling thread to be blocked and that is error proned because it could be another agent or a swing/GUI thread.

#24 Re: HowTo » How to add/retrieve new property » 2014-03-31 15:48:35

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 ?

#25 Re: Projets MaDKit » new MaDKit project : investment game » 2014-03-31 15:44:18

Hello Martin,

Many thanks for your positive feedback !

Nice project, good luck with it !
I will take a closer look at it when possible.

Best,
Fabien

Board footer