MaDKit forum

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

You are not logged in.

#1 Re: HowTo » How to create a distributed society? » 2018-02-06 11:04:41

Hello Benjamin,

Sorry, I was very busy these last days.

--connnectToIp is indeed clearly missing from the options one can pass to the command line and I will add it in the next release.

Anyway, I see that you found your way in the Javadoc, which is great !
And your solution is very good as it works !

You may also try this in your agent, which may be more direct/reusable (same process under the hood) :

        javax.swing.Action connect;
	try {
	    connect = KernelAction.CONNECT_TO_IP.getActionFor(this, InetAddress.getByName("10.122.10.74"));
	}
	catch(UnknownHostException e) {
	    e.printStackTrace();
	}
	connect.actionPerformed(null);

Not tested recently but it should work.

Fabien

#2 Re: HowTo » How to create a distributed society? » 2018-01-30 10:44:42

bgateau wrote:

I use MaDKit 5 indeed, but I meant that in the window of the MaDKit desktop, I saw 3 menu items: "launch network", "stop network" and "connect to IP" !

Of course, my mistake.

bgateau wrote:

And I think that I will need to use the "connect to IP" command to make an agent of HOST1 (my laptop) able to communicate with agent of HOST2 (my desktop computer).

"launch network" starts the "network agent" and put the kernel online and thus make it available for receiving connections. It should also automatically connect to other kernels which are on the same LAN. "Connect to IP" is more about reaching hosts located on the WAN, but could also indeed be used to connect to any host thanks to its IP.

Fabien

#3 Re: HowTo » How to create a distributed society? » 2018-01-24 16:35:37

Hello,

bgateau wrote:

Thanks for your answer. Just before checking your message, I saw in the Desktop instance of MaDKit 3 menu items dealing with network. Than I read your message.

MaDKit 3 ? You meant 5, right ?

bgateau wrote:

Unfortunately, I didn't success to execute your example. As you said, I launched two instances of MaDKit desktop, launched network on both instances and started a PingPong agent on each ... and nothing happened. They didn't communicate.

If everything is OK, and without launching any agent at all, small "network icons" should first appear on the top right of the window.

bgateau wrote:

Besides, is there another way to launch network and connect two kernels (on the same host or not) without using an instance of the desktop. My goal is to launch an agent on a computer linked to the network and make it communicate with others agents on others hosts.

There are several ways possible indeed. the desktop is just about quickly having a menu to launch some agents but is not required at all. The network could be activated at startup or during the execution, even by the agents by sending a message to the kernel agent

bgateau wrote:

I will continue to investigate by firstly studying tutorials.

Great, it will be then indeed easier for you to understand how MaDKit works.

Regards,

#4 Re: HowTo » How to create a distributed society? » 2018-01-24 11:03:00

Hello,

bgateau wrote:

I would like to know if it is possible to create a distributed society. I mean a society with agents on different hosts. And how to send message between those distributed agents?
Regards

Yes it is possible. To try it out quickly on a single host, you can use the desktop mode and just launch one instance of, for the example, "PingPong". Then start the network mode (in the menu or icon). Then just redo this with another instance of the desktop : The two MDK kernels should automatically connect and the PingPong agents should see each other right after that.

In fact, agents do not have to care about where the other agents are when sending messages : groups and roles are the only things that matter for message passing. Of course it is possible to know that another agent is on the same host or not but it is not something crucial here.

So, MaDKit kernels automatically connect to one another on a LAN, and you should be able to repeat this on different hosts easily.  A distant host on a WAN can be added using the dialog box).

To enable the network mode by default when launching MaDKit, you should use the --network option.

Notice that you may encounter an issue if you have a virtual network interface installed on the host (such as the one which is installed by docker or similar softs)

Best regards,

#5 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);
	}

}

#6 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.

#7 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.

#8 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

#9 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

#10 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).

#11 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

#12 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 ?

#13 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 ?

#14 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();
		}
	}
}

#15 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 ?

#16 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.

#17 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.

#18 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.

#19 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

#20 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.

#21 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;

#22 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)

#23 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

#24 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.

#25 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 ?

Board footer