Skip to content

Commit

Permalink
introduce the OrganizationSnapshot class as an alias for the
Browse files Browse the repository at this point in the history
Organization data structure
  • Loading branch information
fab committed Feb 17, 2020
1 parent 69d32da commit a9e6639
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 31 deletions.
9 changes: 5 additions & 4 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="bench"/>
<classpathentry kind="src" path="sandbox"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="bench"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/usr/lib/jvm/java-8-jdk/jre/lib/javaws.jar"/>
<classpathentry kind="lib" path="/usr/lib/jvm/java-8-jdk/jre/lib/deploy.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar"/>
<classpathentry kind="lib" path="/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
9 changes: 9 additions & 0 deletions resource/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ It also contains generic MAS simulation authoring tools.
----------------------------------------------------------------------------------


----------------------------------------------------------------------------------
------------------------------- MaDKit 5.3.1 -------------------------------------
----------------------------------------------------------------------------------

Changes:
+ Adding an event-based scheduling :
+ madkit.simulation.activator.DateBasedDiscreteEventActivator<A>
+ madkit.simulation.scheduler.DateBasedDiscreteEventScheduler

----------------------------------------------------------------------------------
------------------------------- MaDKit 5.3 ---------------------------------------
----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions resource/madkitKernelBuild.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ web.codebase=${madkit.web}/${madkit.ftp.dir}/${javaws.ftp.dir}
github.url=https://github.com/fmichel/MaDKit

#build resources
sun.api.url=http://docs.oracle.com/javase/7/docs/api/
jnlp.api.url=http://docs.oracle.com/javase/7/docs/jre/api/javaws/jnlp/
sun.api.url=https://docs.oracle.com/javase/8/docs/api/
jnlp.api.url=https://docs.oracle.com/javase/8/docs/jre/api/javaws/jnlp/

#files ref
jar.file=${release.dir}/${madkit.jar.name}
Expand Down
55 changes: 55 additions & 0 deletions src/madkit/agr/OrganizationSnapshot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright or © or Copr. Fabien Michel, Olivier Gutknecht, Jacques Ferber (1997)
fmichel@lirmm.fr
olg@no-distance.net
ferber@lirmm.fr
This software is a computer program whose purpose is to
provide a lightweight Java library for designing and simulating Multi-Agent Systems (MAS).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
*/
package madkit.agr;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import madkit.kernel.AgentAddress;


/**
* This class is just an alias for using the underlying data structure
*
* @author Fabien Michel
* @since MaDKit 5.3.1
* @version 5.0
*/
public class OrganizationSnapshot extends TreeMap<String, Map<String, Map<String, Set<AgentAddress>>>> {

}
6 changes: 4 additions & 2 deletions src/madkit/kernel/AbstractAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -84,6 +83,7 @@
import madkit.agr.LocalCommunity;
import madkit.agr.LocalCommunity.Groups;
import madkit.agr.NetworkCommunity;
import madkit.agr.OrganizationSnapshot;
import madkit.gui.AgentFrame;
import madkit.gui.AgentStatusPanel;
import madkit.gui.OutputPanel;
Expand Down Expand Up @@ -919,6 +919,7 @@ public void setName(final String name) {// TODO trigger gui changes and so on ne
* @see #logger
* @deprecated as of MaDKit 5.2, {@link AgentLogger#setLevel(Level)} should now be used through {@link #getLogger()}
*/
@Deprecated
public void setLogLevel(final Level newLevel) {
getLogger().setLevel(newLevel);
// setKernel(kernel.getLoggedKernel());//TODO
Expand Down Expand Up @@ -1831,7 +1832,7 @@ public void setupFrame(final AgentFrame frame) {
* if <code>true</code> this takes into account agents coming from other connected kernels
* @return a data containing all the organization structure
*/
public Map<String, Map<String, Map<String, Set<AgentAddress>>>> getOrganizationSnapShot(boolean global) {
public OrganizationSnapshot getOrganizationSnapShot(boolean global) {
return getKernel().getOrganizationSnapShot(global);
}

Expand Down Expand Up @@ -2827,6 +2828,7 @@ public enum ReturnCode {
// static ResourceBundle messages =
// I18nUtilities.getResourceBundle(ReturnCode.class);

@Override
public String toString() {
return messages.getString(name());
}
Expand Down
4 changes: 3 additions & 1 deletion src/madkit/kernel/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Activator(String community, String group, String role) {
}

/**
* The priority of this activator when {@link #getNextActivationDate()} is conflicting with another Activator. A
* The priority of this activator when conflicting with another Activator. A
* lesser priority means that the activator will be triggered first.
* When the activator's priority is not set, a default priority is defined using the order in which the
* activators are added to the simulation engine using {@link Scheduler#addActivator(Activator)}, that is
Expand Down Expand Up @@ -182,6 +182,7 @@ protected void multicoreExecute(final Object... args) {
final int index = i;
workers.add(new Callable<Void>() {

@Override
public Void call() throws Exception {
int firstIndex = nbOfAgentsPerTask * index;// TODO check that using junit
execute(list.subList(firstIndex, firstIndex + nbOfAgentsPerTask), args);
Expand All @@ -191,6 +192,7 @@ public Void call() throws Exception {
}
workers.add(new Callable<Void>() {

@Override
public Void call() throws Exception {
execute(list.subList(nbOfAgentsPerTask * cpuCoreNb, list.size()), args);
return null;
Expand Down
10 changes: 5 additions & 5 deletions src/madkit/kernel/KernelConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

import madkit.agr.OrganizationSnapshot;

/**
* @author Fabien Michel
* @version 0.9
Expand Down Expand Up @@ -100,8 +100,8 @@ public KernelConnection(NetworkAgent netAgent, Socket kernelClient) throws IOExc
* @throws IOException
*/
@SuppressWarnings("unchecked")
Map<String, Map<String, Map<String, Set<AgentAddress>>>> waitForDistantOrg() throws IOException, ClassNotFoundException {
return (Map<String, Map<String, Map<String, Set<AgentAddress>>>>) ois.readObject();
OrganizationSnapshot waitForDistantOrg() throws IOException, ClassNotFoundException {
return (OrganizationSnapshot) ois.readObject();
}

/**
Expand All @@ -119,7 +119,7 @@ KernelAddress waitForDistantKernelAddress() throws IOException, ClassNotFoundExc
* @param map
* @throws IOException
*/
void sendConnectionInfo(KernelAddress myKA, Map<String, Map<String, Map<String, Set<AgentAddress>>>> map) throws IOException {
void sendConnectionInfo(KernelAddress myKA, OrganizationSnapshot map) throws IOException {
oos.writeObject(myKA);
oos.writeObject(map);
}
Expand Down
18 changes: 14 additions & 4 deletions src/madkit/kernel/MadkitKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.TimerTask;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
Expand All @@ -96,6 +95,7 @@
import madkit.agr.LocalCommunity;
import madkit.agr.LocalCommunity.Groups;
import madkit.agr.LocalCommunity.Roles;
import madkit.agr.OrganizationSnapshot;
import madkit.gui.ConsoleAgent;
import madkit.gui.MASModel;
import madkit.i18n.ErrorMessages;
Expand Down Expand Up @@ -123,6 +123,7 @@ class MadkitKernel extends Agent {

private static final ThreadGroup SYSTEM = new ThreadGroup("MK_SYSTEM") {

@Override
public void uncaughtException(Thread t, Throwable e) {
System.err.println("\n------------uncaught exception on " + t);
}
Expand All @@ -132,6 +133,7 @@ public void uncaughtException(Thread t, Throwable e) {
// Runtime.getRuntime().availableProcessors() + 1,
2, Integer.MAX_VALUE, 2L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {

@Override
public Thread newThread(Runnable r) {
final Thread t = new Thread(SYSTEM, r);
t.setPriority(Thread.MAX_PRIORITY);
Expand Down Expand Up @@ -219,6 +221,7 @@ AgentThreadFactory getNormalAgentThreadFactory() {
daemonAgentThreadFactory = new AgentThreadFactory(kernelAddress, true);
lifeExecutor = new ThreadPoolExecutor(2, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {

@Override
public Thread newThread(Runnable r) {
final Thread t = new Thread(normalAgentThreadFactory.getThreadGroup(), r);
// t.setPriority(Thread.MIN_PRIORITY);
Expand Down Expand Up @@ -485,6 +488,7 @@ private void launchConfigAgents() {
for (int i = 0; i < number; i++) {
lifeExecutor.execute(new Runnable() {

@Override
public void run() {
if (!shuttedDown) {
try {
Expand Down Expand Up @@ -1126,6 +1130,7 @@ final List<AbstractAgent> createBucket(final String agentClass, int bucketSize,
for (int i = 0; i < cpuCoreNb; i++) {
ecs.submit(new Callable<List<AbstractAgent>>() {

@Override
public List<AbstractAgent> call() throws InvocationTargetException, InstantiationException, IllegalAccessException {
final List<AbstractAgent> list = new ArrayList<>(nbOfAgentsPerTask);
for (int j = nbOfAgentsPerTask; j > 0; j--) {
Expand Down Expand Up @@ -1173,6 +1178,7 @@ ReturnCode launchAgent(final AbstractAgent requester, final AbstractAgent agent,
// holds for Integer.MAX_VALUE
final ReturnCode returnCode = lifeExecutor.submit(new Callable<ReturnCode>() {

@Override
public ReturnCode call() {
return launchingAgent(agent, defaultGUI);
}
Expand Down Expand Up @@ -1217,6 +1223,7 @@ private ReturnCode launchingAgent(final AbstractAgent agent, boolean defaultGUI)
ReturnCode r = AGENT_CRASH;
final Future<ReturnCode> activationAttempt = lifeExecutor.submit(new Callable<ReturnCode>() {

@Override
public ReturnCode call() {
return agent.activation();
}
Expand Down Expand Up @@ -1275,6 +1282,7 @@ ReturnCode killAgent(final AbstractAgent requester, final AbstractAgent target,
}
final Future<ReturnCode> killAttempt = serviceExecutor.submit(new Callable<ReturnCode>() {

@Override
public ReturnCode call() {
return killingAgent(target, timeOutSeconds);
}
Expand Down Expand Up @@ -1365,6 +1373,7 @@ final ReturnCode startEndBehavior(final AbstractAgent target, int timeOutSeconds
if (timeOutSeconds != 0) {
final Future<Boolean> endAttempt = executor.submit(new Callable<Boolean>() {

@Override
public Boolean call() {
return target.ending();
}
Expand Down Expand Up @@ -1603,6 +1612,7 @@ public MadkitProperties getMadkitConfig() {
return platform.getConfigOption();
}

@Override
MadkitKernel getMadkitKernel() {
return this;
}
Expand Down Expand Up @@ -1659,7 +1669,7 @@ boolean isRole(@SuppressWarnings("unused") final AbstractAgent requester, final
}
}

final void importDistantOrg(final Map<String, Map<String, Map<String, Set<AgentAddress>>>> distantOrg) {
final void importDistantOrg(final OrganizationSnapshot distantOrg) {
if (logger != null)
logger.finer(() -> "Importing org..." + distantOrg);
synchronized (organizations) {
Expand All @@ -1675,8 +1685,8 @@ final void importDistantOrg(final Map<String, Map<String, Map<String, Set<AgentA
}

@Override
public final Map<String, Map<String, Map<String, Set<AgentAddress>>>> getOrganizationSnapShot(boolean global) {
Map<String, Map<String, Map<String, Set<AgentAddress>>>> export = new TreeMap<>();
public final OrganizationSnapshot getOrganizationSnapShot(boolean global) {
OrganizationSnapshot export = new OrganizationSnapshot();
synchronized (organizations) {
for (Map.Entry<String, Organization> org : organizations.entrySet()) {
Map<String, Map<String, Set<AgentAddress>>> currentOrg = org.getValue().getOrgMap(global);
Expand Down
7 changes: 4 additions & 3 deletions src/madkit/kernel/NetworkAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import madkit.agr.LocalCommunity.Groups;
import madkit.agr.LocalCommunity.Roles;
import madkit.agr.NetworkCommunity;
import madkit.agr.OrganizationSnapshot;
import madkit.gui.AgentStatusPanel;
import madkit.kernel.Madkit.LevelOption;
import madkit.message.EnumMessage;
Expand Down Expand Up @@ -414,8 +415,8 @@ private boolean sendingConnectionInfo(final KernelConnection kc) {
return true;
}

private Map<String, Map<String, Map<String, Set<AgentAddress>>>> cleanUp(Map<String, Map<String, Map<String, Set<AgentAddress>>>> organizationSnapShot, KernelAddress from) {
for (Iterator<Entry<String, Map<String, Map<String, Set<AgentAddress>>>>> iterator = organizationSnapShot.entrySet().iterator(); iterator.hasNext();) {
private OrganizationSnapshot cleanUp(OrganizationSnapshot organizationSnapshot, KernelAddress from) {
for (Iterator<Entry<String, Map<String, Map<String, Set<AgentAddress>>>>> iterator = organizationSnapshot.entrySet().iterator(); iterator.hasNext();) {
Entry<String, Map<String, Map<String, Set<AgentAddress>>>> org = iterator.next();
for (Iterator<Entry<String, Map<String, Set<AgentAddress>>>> iterator2 = org.getValue().entrySet().iterator(); iterator2.hasNext();) {
Entry<String, Map<String, Set<AgentAddress>>> group = iterator2.next();
Expand All @@ -438,7 +439,7 @@ private Map<String, Map<String, Map<String, Set<AgentAddress>>>> cleanUp(Map<Str
iterator.remove();
}
}
return organizationSnapShot;
return organizationSnapshot;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/madkit/kernel/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import madkit.kernel.AbstractAgent.ReturnCode;

/**
* /** Reifying the notion of Role in AGR
* Reifying the notion of Role in AGR
*
* @author Fabien Michel
* @since MaDKit 3.0
Expand Down
2 changes: 1 addition & 1 deletion src/madkit/kernel/madkit.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#MaDKit version info
madkit.version=5.3.2
madkit.version=5.3.1
build.id=${build.id}
madkit.jar.name=madkit-${madkit.version}.jar
madkit.main.class=madkit.kernel.Madkit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import madkit.simulation.scheduler.DateBasedDiscreteEventScheduler;

/**
* A behavior activator that is designed to work with an {@link DateBasedDiscreteEventScheduler},
* A behavior activator that is designed to work with a {@link DateBasedDiscreteEventScheduler},
* that is following a discrete-event simulation scheme.
* This activator activates all the agents of the corresponding CGR for each specific date for
* which it is activated.
Expand Down

0 comments on commit a9e6639

Please sign in to comment.