SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Emilio Serrano, Ph.d.
Polytechnic University of Madrid
Madrid, Spain
eserrano@gsi.dit.upm.es
1
Developing social simulations with
UbikSim
Introduction
2
ď‚— UbikSim is a framework to develop social simulation which emphasizes:
ď‚— The construction of realistic indoor environments
ď‚— The modeling of realistic person behaviors
ď‚— The evaluation of Ubiquitous Computing and Ambient Intelligence systems
ď‚— UbikSim is written in Java
ď‚— and employs a number of third-party libraries such us SweetHome3D and MASON.
ď‚— UbikSim has a GPL license
 So its code is not only free (“libre”), but yours has to be it likewise.
ď‚— Website: http://ants.dif.um.es/staff/emilioserra/ubiksim/
ď‚— GitHub reposository: https://github.com/emilioserra/UbikSim
ď‚— Authors:
ď‚— Juan A. BotĂ­a , juanbot@um.es, Pablo Campillo, pablocampillo@um.es, Francisco
Campuzano, fjcampuzano@um.es, Emilio Serrano, emilioserra@um.es
ď‚— Software necessary for UbikSim:
ď‚— Java and Java3D
ď‚— Make sure you install Java3D correctly!
ď‚— NetBeans
ď‚— (recommended IDE, but not mandatory)
ď‚— The project: claseABSS
ď‚— (it uses UbikSimIDE.jar, available in GitHub)
Creating an environment
3
ď‚— Open NetBeans and the project UbikSimIDEclass.
ď‚— Execute the class StartUbikEditor
ď‚— Create a new environment model as follows:
Creating an environment 2
4
ď‚— Some clues:
ď‚— Add the walls for a big square
room
ď‚— Split it with another wall
 Add the floor with “create room”
ď‚— Add an open door
ď‚— Add aTestPerson
ď‚— Add a couple of NodeGraphs
ď‚— Why?
ď‚— Double click in the rooms and in
the agent to put them a name
ď‚— Why?
ď‚— Can you do something a little more
complicated?
Creating an environment 3
5
ď‚— The environment can be saved and used
 The “config.pros” file tells UbikSim the environment to use
 Now, it says “./environments/hotel.ubiksim”
ď‚— Open this environment that will be used in this class
ď‚— Explore the environment
 Clue: use the virtual visit in the 3D view menu which introduces an “observer
agent”
Running a simulation with GUI
6
ď‚— Run the class EscapeSimWithGUI
ď‚— It is the main class of the NetBeans project
ď‚— Run the simulation just like any other
simulation in MASON
ď‚— Explore the console menu
 “Pause” generates the scenario and displays
ď‚— Check the displays UbikSim3D and UbikSim
2D
ď‚— Execute just one step with play
ď‚— What happened?
ď‚— Keep executing pressing pause again
ď‚— Repeat step by step (stop, pause, button play
repeatedly)
ď‚— What problems do you see in this evacuation?
Running a simulation with GUI 2
7
ď‚— Simulations with GUI have to extend UbikSimWithUI
ď‚— The method start is called after pressing pause when the
environment and its variables are instantiated
ď‚— It can be used, among others, to register new displays
ď‚— (any Jframe that you could find useful to monitor/change the simulation
behavior)
ď‚— It should have a main method to start it
public static void main(String []args) {
escapesim = new EscapeSim(System.currentTimeMillis());
EscapeSimWithGUI vid = new EscapeSimWithGUI(escapesim);
Console c = new Console(vid);
c.setIncrementSeedOnStop(false);
c.setVisible(true);
}
Running a simulation without GUI
8
ď‚— Run the class EscapeSim
ď‚— What is the difference?
ď‚— Displays are very important to debug
ď‚— But they disappear in experimentation
ď‚— Simulations without GUI extends Ubik
ď‚— And are called by simulations with GUI (see previous slide).
ď‚— They have several methods to create the simulation
ď‚— The random seed is very important
ď‚— It ensures replicability
ď‚— It can be loaded from file, fixed, or depending on the current time.
public EscapeSim(long seed) {
super(seed);
}
public EscapeSim() {
super();
setSeed(getSeedFromFile());
}
Running a simulation without GUI 2
9
ď‚— The final condition must be defined
ď‚— In the main method, maxTimeForExecution steps are performed
ď‚— If EscapeSim(long seed,int timeForSim) is used, an agent finishes the simulation
public EscapeSim(long seed, int timeForSim) {
super(seed);
EscapeMonitorAgent.setStepToStop(timeForSim);
}
public static void main(String []args) {
EscapeSim state = new EscapeSim(System.currentTimeMillis());
state.start();
do{
if (!state.schedule.step(state)) break;
}while(state.schedule.getSteps() < maxTimeForExecution);//
state.finish();
}
Running a simulation without GUI 3
10
ď‚— Usually, some treatment is needed after setting up the environment
and before executing the simulation
ď‚— Again, method start is used
ď‚— Some examples are: adding a logger/analyzer/monitor agent, creating
more agents in the environment, changing agents’ name, etcetera
ď‚— Since simulations with GUI call the ones without GUI, this method is
executed in all of them.
public void start() {
super.start();
ema= new EscapeMonitorAgent(this);
Automaton.setEcho(false);
//add more people
PersonHandler ph= getBuilding().getFloor(0).getPersonHandler();
//ph.addPersons(20, true, ph.getPersons().get(0));
//change their name
ph.changeNameOfAgents("a");
}
Running batch experiments
11
ď‚— Run the class EscapeSimBatch
ď‚— Explore the files which have been created in the project folder
ď‚— What conclusions can you reach?
ď‚— An isolated simulation cannot determine anything
ď‚— Explore the class
ď‚— How many experiments are conducted?
ď‚— How long does it take each?
ď‚— What object is filling the generic logger?
ď‚— Next section treats the log of events
Running batch experiments 2
12
ď‚— A batch class must
ď‚— Iterate over the different parameters of the simulation experimentsForDifferentParameters()
ď‚— Execute a batch of experiments for those parameters batchOfExperiments()
ď‚— Execute one experiment for each element of the batch oneExperiment(int seed)
ď‚— The series of seeds must be repeated for each different combination of parameters
ď‚— Perform statistical operations on results and print them in files
ď‚— The example assumes 2 operations (in 2 files): mean and standard deviation
ď‚— It can be extended easily extended for more operations
ď‚— Can you add a third file with an interesting operation?
private static ArrayList<GenericLogger> batchOfExperiments() {
…
r.add(GenericLogger.getMean(listOfResults));
r.add(GenericLogger.getStandardDeviation(listOfResults));
}
private static void printInFile(ArrayList<GenericLogger> r) throws IOException {
PrintWriter w1 = new PrintWriter(new BufferedWriter(new FileWriter(fileName
+ " mean.txt", false)));
PrintWriter w2 = new PrintWriter(new BufferedWriter(new FileWriter(fileName
+ " sd.txt", false)));
…
if (i % 2 == 0) {//mean in pair positions
…
}
Logging interesting data
13
ď‚— As seen, batch experiments deals with genericLogger objects which are filled by an
EscapeMonitorAgent
ď‚— As seen, this agent is created in the start method of the simulation without GUI
ď‚— So it is also present in batches and experiments with GUIs
ď‚— It is a very simple MASON agent which extends from MonitorService, requiring to
define
ď‚— register():To be included in the schedule
ď‚— step(SimState ss):To perform actions which basically are:
ď‚— Fill a generic logger (or your favorite data structure)
ď‚— Check if the simulation has to finish to kill it
ď‚— Can you find another interesting metric and log it?
public void register() {ubik.schedule.scheduleRepeating(this, 1);}
…
public void step(SimState ss) {
…
double[] toLogInStep ={ people.size(), peopleCloseToFire};
genericLogger.addStep(toLogInStep);
…
if(ubik.schedule.getSteps()>=maxStepToStop){
ubik.kill();
}
…
Another simple agent, the fire
14
ď‚— The fire, as the EscapeMonitorAgent, has a method step and is registered in the
schedule when created
ď‚— It has a simple method to know if people is close to fire
ď‚— But here, we are interested in the method insertInDisplay()
ď‚— It paints a fire in the displays
ď‚— It is called by the simulation with GUI, why?
ď‚— It allow developers to insert any object
ď‚— It is important to have the 3D files in the same folder of the class that uses them
ď‚— Explore the folder UbikSimClaseABSSsrcsimappubikbehaviorsescape
 It has a .obj or .dae with the 3D object and .jpg or .png with the “texture”
o The files position matters!
ď‚— Can you make the flame spread?
public boolean tauchingFire(Person p) {
return PositionTools.isNeighboring(p.getPosition().x, p.getPosition().y,
initialPosition.x, initialPosition.y, steps);
}
Where can an agent be?
15
ď‚— In the display
ď‚— It is shown in the 3D and 2D display of the building
 It uses “3D coordinates” (see PositionTools)
ď‚— In the schedule
ď‚— Its method step is called each step
 In the “space” (SparseGrid2 of the class ElementHandler).
 It uses “MASON coordinates” (see PositionTools)
 It can be considered “an obstacle” (method isObstacle in OfficeFloor)
ď‚— Can you think a case where something is in the schedule but not in the
display?
ď‚— Methods PositionTools.getOutOfSpace,PositionTools.putInSpace
public void add(Person p) {
persons.add(p);
grid.setObjectLocation(p, p.getPosition().getX(), p.getPosition()
.getY());
}
public void register() {
ubik.schedule.scheduleRepeating(this, 1);
}
Modeling people
16
ď‚— We have seen a couple of simple agents
ď‚— MASON only gives you the step()
method
ď‚— UbikSim proposes a top-down
approach for complex agents
ď‚— This involves the breaking down of a
human behavior to gain insight into its
compositional sub-behaviors
ď‚— The class Automaton implements it
ď‚— Automaton is a hierarchical automaton of
behaviors (HAB)
ď‚— Each state is another automaton (with sub
states which also are automata).
ď‚— There is a main automaton, father
automata and subordinate automata
ď‚— Maybe you see it better as a tree of behaviors
ď‚— Where is the transition function?
Modeling people 2
17
ď‚— The transitions in the automaton are made automatically by an interpreter
ď‚— You can check the nextState method of the Automaton class
Modeling people 3
18
ď‚— So,TestPerson delegates in anAutomaton calledTestAutomaton
ď‚— AutomatonTestPerson extendsAutomaton, so 4 methods have
to be implemented
ď‚— (1)The constructor
ď‚— If the person delegates directly in this automaton, only the person is passed
ď‚— Otherwise, more information is needed (priority, duration, name of state, etc)
public void step(SimState state) {
…
if(automaton==null) {
automaton = new sim.app.ubik.behaviors.escape.AutomatonTestPerson(this);
}
automaton.nextState(state);
}
public AutomatonTestPerson(Person personImplementingAutomaton) {
super(personImplementingAutomaton);
}
public Move(Person personImplementingAutomaton, int priority, int duration, String
name, Room room) {
super(personImplementingAutomaton,priority,duration,name);
…
}
Modeling people 4
19
ď‚— (2) createNewTransitions
ď‚— It is called in each step
ď‚— Besides generating transitions, any extra action/instruction can be included and it will be executed while the
Automaton has the control
ď‚— It generates and returns a list with the states that Automaton can take from the current state
ď‚— Look out!, they are not taken, just planned; the interpreter will do it.
ď‚— isTransitionPlanned can be used to make sure that some transition are already planned
public class AutomatonTestPerson extends Automaton {
…
public ArrayList<Automaton> createNewTransitions(SimState simState) {
ArrayList<Automaton> r=null;
if(!this.isTransitionPlanned("goToExit")){
r=new ArrayList<Automaton>();
Room exit= PositionTools.closestRoom(p, STAIRS);
r.add(new Move(p,10,-1,"goToExit",exit));
r.add(new Disappear(p, " escaped ", p.getName() + " escaped using " +
exit.getName()));
}
if(!p.hasBeenCloseToFire()){
if (sim.getFire().tauchingFire(personImplementingAutomaton)){
p.setCloseToFire(true);
sim.getMonitorAgent().peopleCloseToFire++;
}
}
return r;
}
Modeling people 5
20
ď‚— (3) getDefaultState
ď‚— The main automaton (level 0), the highest in the hierarchy, never ends if a cyclic behavior
wants to be modeled (and therefore a default state must be given)
 Otherwise, it usually returns null to return control to the “automaton father” if no more
transitions are planned
public boolean isFinished(SimState state){
return destinyAchieved(state);
return super.isFinished(state);
}
ď‚— (4) isFinished
ď‚— As said, the main automaton usually does not have to finish
ď‚— Besides, If there are no transitions planned and no default state is given the automaton
ends and the control is given to the father automatically
ď‚— It also ends automatically if the time given in the constructor ends
ď‚— But, this method may be necessary for extra finalization , like in Move Automaton
public Automaton getDefaultState(SimState simState) {
return new DoNothing(p,0,1,"doNothing");
}
Modeling people 6
21
ď‚— MoveToClosestExit is an example of subordinate automaton
ď‚— What is the difference between using Move or MoveToClosestExist in
this code?
ď‚— The moment of calculating the closest exit!
ď‚— With move it is calculated before going to the hall
ď‚— With MoveToClosestExit it is calculated when the agent has already visited the hall
public class AutomatonTestPerson extends Automaton {
…
public ArrayList<Automaton> createNewTransitions(SimState simState) {
…
Room exit= PositionTools.closestRoom(p, STAIRS);
r.add(new Move(p,10,-1,”checkHall",hall));
r.add(new Move(p,10,-1,"goToExit",exit));
//r.add(new MoveToClosestExit(p,10,-1,"goToExit"));
…
}
Modeling people 7
22
ď‚— This seems complicated, but in the end, there are very simple
states that Automaton delegates to.
ď‚— Automaton allows developers to divide the complexity of human
behaviors
ď‚— The simple states extends SimpleState and only has to define
nextState
public class Disappear extends SimpleState {
…
public void nextState(SimState state) {
if(!personImplementingAutomaton.isStopped()) {
if(message!=null) System.out.println(message);
personImplementingAutomaton.stop();
}
}
…
The final question
23
ď‚— Can you improve AutomatonTestPerson to implement a
better evacuation?
ď‚— Examples:
ď‚— if Fire is too close to an exit, it should not be used
ď‚— if there are too many people using an exit and others are free, they could
be used
ď‚— Clue: study the PositionTools class
Testing and debugging in UbikSim
24
ď‚— Debugging any multi-agent system is challenging, here some advice
ď‚— MASON tools can be used: inspectors an charts
ď‚— Make it as automatic as possible
ď‚— If the display is not needed, do not use it
ď‚— 2D displays are way faster and clearer than 3D display
ď‚— Try to generate the conflictive situation at the beginning of the simulation
ď‚— Use the same random seed to reproduce always the same situation while testing
ď‚— Deal with just one agent or a few before trying the final environment
ď‚— An extra .ubiksim file can be generated for tests
ď‚— System.out in an agent will be executed withALLAGENTS
ď‚— The monitor agent is called once per step, so it is a good place to put messages
ď‚— To study an agent you can change its name and color from the code
ď‚— WithAutomaton.setEcho(true), the output of the interpreter is shown
Testing and debugging in UbikSim 2
25
ď‚— Output with Automaton.setEcho(true),
a1, MAINAUTOMATON pending transitions extended [goToExit, escaped ]
a1, MAINAUTOMATON automaton changes to state goToExit
a1, goToExit pending transitions extended [SimpleMove, simple move to (698,157) [editor
format: 3490,785], SimpleMove, simple move to (727,102) [editor format: 3635,510],
SimpleMove, simple move to (731,99) [editor format: 3655,495], SimpleMove, simple move to
(744,63) [editor format: 3720,315], SimpleMove, simple move to (744,63) [editor format:
3720,315]]
a1, goToExit automaton changes to state SimpleMove, simple move to (698,157) [editor format:
3490,785]
a1, goToExit automaton finished SimpleMove, simple move to (698,157) [editor format:
3490,785]
a1, goToExit automaton changes to state SimpleMove, simple move to (727,102) [editor format:
3635,510]
. . .
a1, MAINAUTOMATON automaton finished goToExit
a1, MAINAUTOMATON automaton changes to state escaped
26
Thank you very much for your attention

Weitere ähnliche Inhalte

Andere mochten auch

IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)
IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)
IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)Emilio Serrano
 
Infrastructure for forensic analysis of multi-agent systems
Infrastructure for forensic analysis  of multi-agent systems Infrastructure for forensic analysis  of multi-agent systems
Infrastructure for forensic analysis of multi-agent systems Emilio Serrano
 
Casos de sistemas inteligentes (only in Spanish)
Casos de sistemas inteligentes (only in Spanish)Casos de sistemas inteligentes (only in Spanish)
Casos de sistemas inteligentes (only in Spanish)Emilio Serrano
 
An Explanation-Based Alert Management Tool for Basic AAL Systems
An Explanation-Based Alert Management Tool for Basic AAL SystemsAn Explanation-Based Alert Management Tool for Basic AAL Systems
An Explanation-Based Alert Management Tool for Basic AAL SystemsEmilio Serrano
 
A qualitative reputation system for multiagent systems with protocol-based co...
A qualitative reputation system for multiagent systems with protocol-based co...A qualitative reputation system for multiagent systems with protocol-based co...
A qualitative reputation system for multiagent systems with protocol-based co...Emilio Serrano
 
Articial societies immersed in an Ambient Intelligence Environment
Articial societies immersed in an Ambient Intelligence EnvironmentArticial societies immersed in an Ambient Intelligence Environment
Articial societies immersed in an Ambient Intelligence EnvironmentEmilio Serrano
 
Un prototipo para el modelado de un sistema de metaheurĂ­sticas cooperativa...
Un prototipo para el modelado de un  sistema  de metaheurĂ­sticas  cooperativa...Un prototipo para el modelado de un  sistema  de metaheurĂ­sticas  cooperativa...
Un prototipo para el modelado de un sistema de metaheurĂ­sticas cooperativa...Emilio Serrano
 
TOWARDS SOCIO-CHRONOBIOLOGICAL COMPUTATIONAL HUMAN MODELS
TOWARDS SOCIO-CHRONOBIOLOGICAL  COMPUTATIONAL HUMAN MODELS   TOWARDS SOCIO-CHRONOBIOLOGICAL  COMPUTATIONAL HUMAN MODELS
TOWARDS SOCIO-CHRONOBIOLOGICAL COMPUTATIONAL HUMAN MODELS Emilio Serrano
 
An Approach for the Qualitative Analysis of Open Agent Conversations
An Approach for the Qualitative Analysis of Open Agent ConversationsAn Approach for the Qualitative Analysis of Open Agent Conversations
An Approach for the Qualitative Analysis of Open Agent ConversationsEmilio Serrano
 
Creating and validating emergency management services by social simulation a...
Creating and validating emergency management services  by social simulation a...Creating and validating emergency management services  by social simulation a...
Creating and validating emergency management services by social simulation a...Emilio Serrano
 
Desarrollo y evaluaciĂłn de sistemas de inteligencia ambiental con UbikSim
Desarrollo y evaluaciĂłn de sistemas de  inteligencia ambiental con UbikSimDesarrollo y evaluaciĂłn de sistemas de  inteligencia ambiental con UbikSim
Desarrollo y evaluaciĂłn de sistemas de inteligencia ambiental con UbikSimEmilio Serrano
 
Study and development of methods and tools for testing, validation and verif...
 Study and development of methods and tools for testing, validation and verif... Study and development of methods and tools for testing, validation and verif...
Study and development of methods and tools for testing, validation and verif...Emilio Serrano
 
Investigaciones y análisis de redes sociales (only in Spanish)
Investigaciones y análisis de redes sociales (only in Spanish)Investigaciones y análisis de redes sociales (only in Spanish)
Investigaciones y análisis de redes sociales (only in Spanish)Emilio Serrano
 

Andere mochten auch (13)

IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)
IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)
IntroducciĂłn a la simulaciĂłn social basada en agentes (only in Spanish)
 
Infrastructure for forensic analysis of multi-agent systems
Infrastructure for forensic analysis  of multi-agent systems Infrastructure for forensic analysis  of multi-agent systems
Infrastructure for forensic analysis of multi-agent systems
 
Casos de sistemas inteligentes (only in Spanish)
Casos de sistemas inteligentes (only in Spanish)Casos de sistemas inteligentes (only in Spanish)
Casos de sistemas inteligentes (only in Spanish)
 
An Explanation-Based Alert Management Tool for Basic AAL Systems
An Explanation-Based Alert Management Tool for Basic AAL SystemsAn Explanation-Based Alert Management Tool for Basic AAL Systems
An Explanation-Based Alert Management Tool for Basic AAL Systems
 
A qualitative reputation system for multiagent systems with protocol-based co...
A qualitative reputation system for multiagent systems with protocol-based co...A qualitative reputation system for multiagent systems with protocol-based co...
A qualitative reputation system for multiagent systems with protocol-based co...
 
Articial societies immersed in an Ambient Intelligence Environment
Articial societies immersed in an Ambient Intelligence EnvironmentArticial societies immersed in an Ambient Intelligence Environment
Articial societies immersed in an Ambient Intelligence Environment
 
Un prototipo para el modelado de un sistema de metaheurĂ­sticas cooperativa...
Un prototipo para el modelado de un  sistema  de metaheurĂ­sticas  cooperativa...Un prototipo para el modelado de un  sistema  de metaheurĂ­sticas  cooperativa...
Un prototipo para el modelado de un sistema de metaheurĂ­sticas cooperativa...
 
TOWARDS SOCIO-CHRONOBIOLOGICAL COMPUTATIONAL HUMAN MODELS
TOWARDS SOCIO-CHRONOBIOLOGICAL  COMPUTATIONAL HUMAN MODELS   TOWARDS SOCIO-CHRONOBIOLOGICAL  COMPUTATIONAL HUMAN MODELS
TOWARDS SOCIO-CHRONOBIOLOGICAL COMPUTATIONAL HUMAN MODELS
 
An Approach for the Qualitative Analysis of Open Agent Conversations
An Approach for the Qualitative Analysis of Open Agent ConversationsAn Approach for the Qualitative Analysis of Open Agent Conversations
An Approach for the Qualitative Analysis of Open Agent Conversations
 
Creating and validating emergency management services by social simulation a...
Creating and validating emergency management services  by social simulation a...Creating and validating emergency management services  by social simulation a...
Creating and validating emergency management services by social simulation a...
 
Desarrollo y evaluaciĂłn de sistemas de inteligencia ambiental con UbikSim
Desarrollo y evaluaciĂłn de sistemas de  inteligencia ambiental con UbikSimDesarrollo y evaluaciĂłn de sistemas de  inteligencia ambiental con UbikSim
Desarrollo y evaluaciĂłn de sistemas de inteligencia ambiental con UbikSim
 
Study and development of methods and tools for testing, validation and verif...
 Study and development of methods and tools for testing, validation and verif... Study and development of methods and tools for testing, validation and verif...
Study and development of methods and tools for testing, validation and verif...
 
Investigaciones y análisis de redes sociales (only in Spanish)
Investigaciones y análisis de redes sociales (only in Spanish)Investigaciones y análisis de redes sociales (only in Spanish)
Investigaciones y análisis de redes sociales (only in Spanish)
 

Ă„hnlich wie Developing social simulations with UbikSim

JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfMarlouFelixIIICunana
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...DroidConTLV
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)Fafadia Tech
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabScilab
 
Lhy tutorial gui(1)
Lhy tutorial gui(1)Lhy tutorial gui(1)
Lhy tutorial gui(1)Brijesh Naik
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesSamsung Developers
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Lifeparticle
 
YUI for control freaks - a presentation at The Ajax Experience
YUI for control freaks - a presentation at The Ajax ExperienceYUI for control freaks - a presentation at The Ajax Experience
YUI for control freaks - a presentation at The Ajax ExperienceChristian Heilmann
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8Utkarsh Mankad
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)TECOS
 
Activity
ActivityActivity
ActivityNikithaNag
 
Activity
ActivityActivity
ActivityNikithaNag
 
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHack
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHackAn inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHack
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHackSoya Aoyama
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorialsumitjoshi01
 

Ă„hnlich wie Developing social simulations with UbikSim (20)

JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in Scilab
 
Lhy tutorial gui(1)
Lhy tutorial gui(1)Lhy tutorial gui(1)
Lhy tutorial gui(1)
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
 
Event handling63
Event handling63Event handling63
Event handling63
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)Tech Talk: App Functionality (Android)
Tech Talk: App Functionality (Android)
 
YUI for control freaks - a presentation at The Ajax Experience
YUI for control freaks - a presentation at The Ajax ExperienceYUI for control freaks - a presentation at The Ajax Experience
YUI for control freaks - a presentation at The Ajax Experience
 
2.5 gui
2.5 gui2.5 gui
2.5 gui
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
 
Android 3
Android 3Android 3
Android 3
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHack
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHackAn inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHack
An inconvenient truth: Evading the Ransomware Protection in windows 10 @ LeHack
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 

KĂĽrzlich hochgeladen

Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In DubaiDubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubaikojalkojal131
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxmalonesandreagweneth
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024innovationoecd
 
Carbon Dioxide Capture and Storage (CSS)
Carbon Dioxide Capture and Storage (CSS)Carbon Dioxide Capture and Storage (CSS)
Carbon Dioxide Capture and Storage (CSS)Tamer Koksalan, PhD
 
User Guide: Capricorn FLX™ Weather Station
User Guide: Capricorn FLX™ Weather StationUser Guide: Capricorn FLX™ Weather Station
User Guide: Capricorn FLX™ Weather StationColumbia Weather Systems
 
User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)Columbia Weather Systems
 
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTX
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTXALL ABOUT MIXTURES IN GRADE 7 CLASS PPTX
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTXDole Philippines School
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPirithiRaju
 
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)User Guide: Pulsar™ Weather Station (Columbia Weather Systems)
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)Columbia Weather Systems
 
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuine
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 GenuineCall Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuine
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuinethapagita
 
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptx
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptxSTOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptx
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptxMurugaveni B
 
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)riyaescorts54
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024AyushiRastogi48
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxJorenAcuavera1
 
Bioteknologi kelas 10 kumer smapsa .pptx
Bioteknologi kelas 10 kumer smapsa .pptxBioteknologi kelas 10 kumer smapsa .pptx
Bioteknologi kelas 10 kumer smapsa .pptx023NiWayanAnggiSriWa
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxmaryFF1
 
preservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxpreservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxnoordubaliya2003
 
GenBio2 - Lesson 1 - Introduction to Genetics.pptx
GenBio2 - Lesson 1 - Introduction to Genetics.pptxGenBio2 - Lesson 1 - Introduction to Genetics.pptx
GenBio2 - Lesson 1 - Introduction to Genetics.pptxBerniceCayabyab1
 

KĂĽrzlich hochgeladen (20)

Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In DubaiDubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024
 
Carbon Dioxide Capture and Storage (CSS)
Carbon Dioxide Capture and Storage (CSS)Carbon Dioxide Capture and Storage (CSS)
Carbon Dioxide Capture and Storage (CSS)
 
User Guide: Capricorn FLX™ Weather Station
User Guide: Capricorn FLX™ Weather StationUser Guide: Capricorn FLX™ Weather Station
User Guide: Capricorn FLX™ Weather Station
 
User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)User Guide: Orion™ Weather Station (Columbia Weather Systems)
User Guide: Orion™ Weather Station (Columbia Weather Systems)
 
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTX
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTXALL ABOUT MIXTURES IN GRADE 7 CLASS PPTX
ALL ABOUT MIXTURES IN GRADE 7 CLASS PPTX
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdf
 
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)User Guide: Pulsar™ Weather Station (Columbia Weather Systems)
User Guide: Pulsar™ Weather Station (Columbia Weather Systems)
 
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuine
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 GenuineCall Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuine
Call Girls in Majnu Ka Tilla Delhi 🔝9711014705🔝 Genuine
 
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptx
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptxSTOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptx
STOPPED FLOW METHOD & APPLICATION MURUGAVENI B.pptx
 
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)
(9818099198) Call Girls In Noida Sector 14 (NOIDA ESCORTS)
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptx
 
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort ServiceHot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
 
Bioteknologi kelas 10 kumer smapsa .pptx
Bioteknologi kelas 10 kumer smapsa .pptxBioteknologi kelas 10 kumer smapsa .pptx
Bioteknologi kelas 10 kumer smapsa .pptx
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
 
preservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptxpreservation, maintanence and improvement of industrial organism.pptx
preservation, maintanence and improvement of industrial organism.pptx
 
GenBio2 - Lesson 1 - Introduction to Genetics.pptx
GenBio2 - Lesson 1 - Introduction to Genetics.pptxGenBio2 - Lesson 1 - Introduction to Genetics.pptx
GenBio2 - Lesson 1 - Introduction to Genetics.pptx
 

Developing social simulations with UbikSim

  • 1. Emilio Serrano, Ph.d. Polytechnic University of Madrid Madrid, Spain eserrano@gsi.dit.upm.es 1 Developing social simulations with UbikSim
  • 2. Introduction 2 ď‚— UbikSim is a framework to develop social simulation which emphasizes: ď‚— The construction of realistic indoor environments ď‚— The modeling of realistic person behaviors ď‚— The evaluation of Ubiquitous Computing and Ambient Intelligence systems ď‚— UbikSim is written in Java ď‚— and employs a number of third-party libraries such us SweetHome3D and MASON. ď‚— UbikSim has a GPL license ď‚— So its code is not only free (“libre”), but yours has to be it likewise. ď‚— Website: http://ants.dif.um.es/staff/emilioserra/ubiksim/ ď‚— GitHub reposository: https://github.com/emilioserra/UbikSim ď‚— Authors: ď‚— Juan A. BotĂ­a , juanbot@um.es, Pablo Campillo, pablocampillo@um.es, Francisco Campuzano, fjcampuzano@um.es, Emilio Serrano, emilioserra@um.es ď‚— Software necessary for UbikSim: ď‚— Java and Java3D ď‚— Make sure you install Java3D correctly! ď‚— NetBeans ď‚— (recommended IDE, but not mandatory) ď‚— The project: claseABSS ď‚— (it uses UbikSimIDE.jar, available in GitHub)
  • 3. Creating an environment 3 ď‚— Open NetBeans and the project UbikSimIDEclass. ď‚— Execute the class StartUbikEditor ď‚— Create a new environment model as follows:
  • 4. Creating an environment 2 4 ď‚— Some clues: ď‚— Add the walls for a big square room ď‚— Split it with another wall ď‚— Add the floor with “create room” ď‚— Add an open door ď‚— Add aTestPerson ď‚— Add a couple of NodeGraphs ď‚— Why? ď‚— Double click in the rooms and in the agent to put them a name ď‚— Why? ď‚— Can you do something a little more complicated?
  • 5. Creating an environment 3 5 ď‚— The environment can be saved and used ď‚— The “config.pros” file tells UbikSim the environment to use ď‚— Now, it says “./environments/hotel.ubiksim” ď‚— Open this environment that will be used in this class ď‚— Explore the environment ď‚— Clue: use the virtual visit in the 3D view menu which introduces an “observer agent”
  • 6. Running a simulation with GUI 6 ď‚— Run the class EscapeSimWithGUI ď‚— It is the main class of the NetBeans project ď‚— Run the simulation just like any other simulation in MASON ď‚— Explore the console menu ď‚— “Pause” generates the scenario and displays ď‚— Check the displays UbikSim3D and UbikSim 2D ď‚— Execute just one step with play ď‚— What happened? ď‚— Keep executing pressing pause again ď‚— Repeat step by step (stop, pause, button play repeatedly) ď‚— What problems do you see in this evacuation?
  • 7. Running a simulation with GUI 2 7 ď‚— Simulations with GUI have to extend UbikSimWithUI ď‚— The method start is called after pressing pause when the environment and its variables are instantiated ď‚— It can be used, among others, to register new displays ď‚— (any Jframe that you could find useful to monitor/change the simulation behavior) ď‚— It should have a main method to start it public static void main(String []args) { escapesim = new EscapeSim(System.currentTimeMillis()); EscapeSimWithGUI vid = new EscapeSimWithGUI(escapesim); Console c = new Console(vid); c.setIncrementSeedOnStop(false); c.setVisible(true); }
  • 8. Running a simulation without GUI 8 ď‚— Run the class EscapeSim ď‚— What is the difference? ď‚— Displays are very important to debug ď‚— But they disappear in experimentation ď‚— Simulations without GUI extends Ubik ď‚— And are called by simulations with GUI (see previous slide). ď‚— They have several methods to create the simulation ď‚— The random seed is very important ď‚— It ensures replicability ď‚— It can be loaded from file, fixed, or depending on the current time. public EscapeSim(long seed) { super(seed); } public EscapeSim() { super(); setSeed(getSeedFromFile()); }
  • 9. Running a simulation without GUI 2 9 ď‚— The final condition must be defined ď‚— In the main method, maxTimeForExecution steps are performed ď‚— If EscapeSim(long seed,int timeForSim) is used, an agent finishes the simulation public EscapeSim(long seed, int timeForSim) { super(seed); EscapeMonitorAgent.setStepToStop(timeForSim); } public static void main(String []args) { EscapeSim state = new EscapeSim(System.currentTimeMillis()); state.start(); do{ if (!state.schedule.step(state)) break; }while(state.schedule.getSteps() < maxTimeForExecution);// state.finish(); }
  • 10. Running a simulation without GUI 3 10 ď‚— Usually, some treatment is needed after setting up the environment and before executing the simulation ď‚— Again, method start is used ď‚— Some examples are: adding a logger/analyzer/monitor agent, creating more agents in the environment, changing agents’ name, etcetera ď‚— Since simulations with GUI call the ones without GUI, this method is executed in all of them. public void start() { super.start(); ema= new EscapeMonitorAgent(this); Automaton.setEcho(false); //add more people PersonHandler ph= getBuilding().getFloor(0).getPersonHandler(); //ph.addPersons(20, true, ph.getPersons().get(0)); //change their name ph.changeNameOfAgents("a"); }
  • 11. Running batch experiments 11 ď‚— Run the class EscapeSimBatch ď‚— Explore the files which have been created in the project folder ď‚— What conclusions can you reach? ď‚— An isolated simulation cannot determine anything ď‚— Explore the class ď‚— How many experiments are conducted? ď‚— How long does it take each? ď‚— What object is filling the generic logger? ď‚— Next section treats the log of events
  • 12. Running batch experiments 2 12 ď‚— A batch class must ď‚— Iterate over the different parameters of the simulation experimentsForDifferentParameters() ď‚— Execute a batch of experiments for those parameters batchOfExperiments() ď‚— Execute one experiment for each element of the batch oneExperiment(int seed) ď‚— The series of seeds must be repeated for each different combination of parameters ď‚— Perform statistical operations on results and print them in files ď‚— The example assumes 2 operations (in 2 files): mean and standard deviation ď‚— It can be extended easily extended for more operations ď‚— Can you add a third file with an interesting operation? private static ArrayList<GenericLogger> batchOfExperiments() { … r.add(GenericLogger.getMean(listOfResults)); r.add(GenericLogger.getStandardDeviation(listOfResults)); } private static void printInFile(ArrayList<GenericLogger> r) throws IOException { PrintWriter w1 = new PrintWriter(new BufferedWriter(new FileWriter(fileName + " mean.txt", false))); PrintWriter w2 = new PrintWriter(new BufferedWriter(new FileWriter(fileName + " sd.txt", false))); … if (i % 2 == 0) {//mean in pair positions … }
  • 13. Logging interesting data 13 ď‚— As seen, batch experiments deals with genericLogger objects which are filled by an EscapeMonitorAgent ď‚— As seen, this agent is created in the start method of the simulation without GUI ď‚— So it is also present in batches and experiments with GUIs ď‚— It is a very simple MASON agent which extends from MonitorService, requiring to define ď‚— register():To be included in the schedule ď‚— step(SimState ss):To perform actions which basically are: ď‚— Fill a generic logger (or your favorite data structure) ď‚— Check if the simulation has to finish to kill it ď‚— Can you find another interesting metric and log it? public void register() {ubik.schedule.scheduleRepeating(this, 1);} … public void step(SimState ss) { … double[] toLogInStep ={ people.size(), peopleCloseToFire}; genericLogger.addStep(toLogInStep); … if(ubik.schedule.getSteps()>=maxStepToStop){ ubik.kill(); } …
  • 14. Another simple agent, the fire 14 ď‚— The fire, as the EscapeMonitorAgent, has a method step and is registered in the schedule when created ď‚— It has a simple method to know if people is close to fire ď‚— But here, we are interested in the method insertInDisplay() ď‚— It paints a fire in the displays ď‚— It is called by the simulation with GUI, why? ď‚— It allow developers to insert any object ď‚— It is important to have the 3D files in the same folder of the class that uses them ď‚— Explore the folder UbikSimClaseABSSsrcsimappubikbehaviorsescape ď‚— It has a .obj or .dae with the 3D object and .jpg or .png with the “texture” o The files position matters! ď‚— Can you make the flame spread? public boolean tauchingFire(Person p) { return PositionTools.isNeighboring(p.getPosition().x, p.getPosition().y, initialPosition.x, initialPosition.y, steps); }
  • 15. Where can an agent be? 15 ď‚— In the display ď‚— It is shown in the 3D and 2D display of the building ď‚— It uses “3D coordinates” (see PositionTools) ď‚— In the schedule ď‚— Its method step is called each step ď‚— In the “space” (SparseGrid2 of the class ElementHandler). ď‚— It uses “MASON coordinates” (see PositionTools) ď‚— It can be considered “an obstacle” (method isObstacle in OfficeFloor) ď‚— Can you think a case where something is in the schedule but not in the display? ď‚— Methods PositionTools.getOutOfSpace,PositionTools.putInSpace public void add(Person p) { persons.add(p); grid.setObjectLocation(p, p.getPosition().getX(), p.getPosition() .getY()); } public void register() { ubik.schedule.scheduleRepeating(this, 1); }
  • 16. Modeling people 16 ď‚— We have seen a couple of simple agents ď‚— MASON only gives you the step() method ď‚— UbikSim proposes a top-down approach for complex agents ď‚— This involves the breaking down of a human behavior to gain insight into its compositional sub-behaviors ď‚— The class Automaton implements it ď‚— Automaton is a hierarchical automaton of behaviors (HAB) ď‚— Each state is another automaton (with sub states which also are automata). ď‚— There is a main automaton, father automata and subordinate automata ď‚— Maybe you see it better as a tree of behaviors ď‚— Where is the transition function?
  • 17. Modeling people 2 17 ď‚— The transitions in the automaton are made automatically by an interpreter ď‚— You can check the nextState method of the Automaton class
  • 18. Modeling people 3 18 ď‚— So,TestPerson delegates in anAutomaton calledTestAutomaton ď‚— AutomatonTestPerson extendsAutomaton, so 4 methods have to be implemented ď‚— (1)The constructor ď‚— If the person delegates directly in this automaton, only the person is passed ď‚— Otherwise, more information is needed (priority, duration, name of state, etc) public void step(SimState state) { … if(automaton==null) { automaton = new sim.app.ubik.behaviors.escape.AutomatonTestPerson(this); } automaton.nextState(state); } public AutomatonTestPerson(Person personImplementingAutomaton) { super(personImplementingAutomaton); } public Move(Person personImplementingAutomaton, int priority, int duration, String name, Room room) { super(personImplementingAutomaton,priority,duration,name); … }
  • 19. Modeling people 4 19 ď‚— (2) createNewTransitions ď‚— It is called in each step ď‚— Besides generating transitions, any extra action/instruction can be included and it will be executed while the Automaton has the control ď‚— It generates and returns a list with the states that Automaton can take from the current state ď‚— Look out!, they are not taken, just planned; the interpreter will do it. ď‚— isTransitionPlanned can be used to make sure that some transition are already planned public class AutomatonTestPerson extends Automaton { … public ArrayList<Automaton> createNewTransitions(SimState simState) { ArrayList<Automaton> r=null; if(!this.isTransitionPlanned("goToExit")){ r=new ArrayList<Automaton>(); Room exit= PositionTools.closestRoom(p, STAIRS); r.add(new Move(p,10,-1,"goToExit",exit)); r.add(new Disappear(p, " escaped ", p.getName() + " escaped using " + exit.getName())); } if(!p.hasBeenCloseToFire()){ if (sim.getFire().tauchingFire(personImplementingAutomaton)){ p.setCloseToFire(true); sim.getMonitorAgent().peopleCloseToFire++; } } return r; }
  • 20. Modeling people 5 20 ď‚— (3) getDefaultState ď‚— The main automaton (level 0), the highest in the hierarchy, never ends if a cyclic behavior wants to be modeled (and therefore a default state must be given) ď‚— Otherwise, it usually returns null to return control to the “automaton father” if no more transitions are planned public boolean isFinished(SimState state){ return destinyAchieved(state); return super.isFinished(state); } ď‚— (4) isFinished ď‚— As said, the main automaton usually does not have to finish ď‚— Besides, If there are no transitions planned and no default state is given the automaton ends and the control is given to the father automatically ď‚— It also ends automatically if the time given in the constructor ends ď‚— But, this method may be necessary for extra finalization , like in Move Automaton public Automaton getDefaultState(SimState simState) { return new DoNothing(p,0,1,"doNothing"); }
  • 21. Modeling people 6 21 ď‚— MoveToClosestExit is an example of subordinate automaton ď‚— What is the difference between using Move or MoveToClosestExist in this code? ď‚— The moment of calculating the closest exit! ď‚— With move it is calculated before going to the hall ď‚— With MoveToClosestExit it is calculated when the agent has already visited the hall public class AutomatonTestPerson extends Automaton { … public ArrayList<Automaton> createNewTransitions(SimState simState) { … Room exit= PositionTools.closestRoom(p, STAIRS); r.add(new Move(p,10,-1,”checkHall",hall)); r.add(new Move(p,10,-1,"goToExit",exit)); //r.add(new MoveToClosestExit(p,10,-1,"goToExit")); … }
  • 22. Modeling people 7 22 ď‚— This seems complicated, but in the end, there are very simple states that Automaton delegates to. ď‚— Automaton allows developers to divide the complexity of human behaviors ď‚— The simple states extends SimpleState and only has to define nextState public class Disappear extends SimpleState { … public void nextState(SimState state) { if(!personImplementingAutomaton.isStopped()) { if(message!=null) System.out.println(message); personImplementingAutomaton.stop(); } } …
  • 23. The final question 23 ď‚— Can you improve AutomatonTestPerson to implement a better evacuation? ď‚— Examples: ď‚— if Fire is too close to an exit, it should not be used ď‚— if there are too many people using an exit and others are free, they could be used ď‚— Clue: study the PositionTools class
  • 24. Testing and debugging in UbikSim 24 ď‚— Debugging any multi-agent system is challenging, here some advice ď‚— MASON tools can be used: inspectors an charts ď‚— Make it as automatic as possible ď‚— If the display is not needed, do not use it ď‚— 2D displays are way faster and clearer than 3D display ď‚— Try to generate the conflictive situation at the beginning of the simulation ď‚— Use the same random seed to reproduce always the same situation while testing ď‚— Deal with just one agent or a few before trying the final environment ď‚— An extra .ubiksim file can be generated for tests ď‚— System.out in an agent will be executed withALLAGENTS ď‚— The monitor agent is called once per step, so it is a good place to put messages ď‚— To study an agent you can change its name and color from the code ď‚— WithAutomaton.setEcho(true), the output of the interpreter is shown
  • 25. Testing and debugging in UbikSim 2 25 ď‚— Output with Automaton.setEcho(true), a1, MAINAUTOMATON pending transitions extended [goToExit, escaped ] a1, MAINAUTOMATON automaton changes to state goToExit a1, goToExit pending transitions extended [SimpleMove, simple move to (698,157) [editor format: 3490,785], SimpleMove, simple move to (727,102) [editor format: 3635,510], SimpleMove, simple move to (731,99) [editor format: 3655,495], SimpleMove, simple move to (744,63) [editor format: 3720,315], SimpleMove, simple move to (744,63) [editor format: 3720,315]] a1, goToExit automaton changes to state SimpleMove, simple move to (698,157) [editor format: 3490,785] a1, goToExit automaton finished SimpleMove, simple move to (698,157) [editor format: 3490,785] a1, goToExit automaton changes to state SimpleMove, simple move to (727,102) [editor format: 3635,510] . . . a1, MAINAUTOMATON automaton finished goToExit a1, MAINAUTOMATON automaton changes to state escaped
  • 26. 26 Thank you very much for your attention