Commit 08e2853c authored by Eduardo Varas's avatar Eduardo Varas
Browse files

Actialización de la obtención de datos de simulación

parent 71a79a0c
......@@ -31,6 +31,7 @@ xfire=60
yfire=50
sizefire=1
speedfire=1
#Segundos antes de que empieze el fuego durante la simulación
delayfire=100
#Valores de agentes:
......
......@@ -53,7 +53,7 @@ public class Ubik extends SimState {
* . luego el máximo de trabajadores por planta es relativo a estos valores
*/
private Configuration configuration;
private static final Logger LOG = Logger.getLogger(Ubik.class.getName());
public static final Logger LOG = Logger.getLogger(Ubik.class.getName());
private long seedFromFile;
private int cellSize;
......@@ -192,6 +192,7 @@ public class Ubik extends SimState {
public void setFireActivity(boolean activity) {
this.isFireActive=activity;
LOG.info("The fire has started "+ this.getUbik().getClock().getDate());
}
public int getDelayFire() {
......
......@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import sim.app.ubik.Ubik;
import sim.app.ubik.behaviors.PositionTools;
import sim.app.ubik.people.Person;
import sim.app.ubik.people.Teacher;
import sim.app.ubik.utils.GenericLogger;
import sim.engine.SimState;
......@@ -68,17 +69,16 @@ public class MonitorServiceImpl implements GenericLoggerService {
return;
}
double toLog[] = new double[people.size()];
boolean toLog[] = new boolean[people.size()];
System.out
.print(" --------------------------------------------------->");
for (int i = 0; i < people.size(); i++) {
LOG.info("REPLACE COMMENTS IN THIS CLASS WITH THE DATA TO BE LOGGED");
/**toLog[i] = ((TestPerson) people.get(i))
.getDistanceLeftToReachDestiny();
System.out.print(toLog[i] + " ");*/
toLog[i] = ((Teacher) people.get(i)).hasBeenCloseToFire();
System.out.print(toLog[i] + " ");
}
System.out.println();
genericLogger.addStep(toLog);
//genericLogger.addStep(toLog);
}
@Override
......
......@@ -108,6 +108,7 @@ public class AutomatonTestPerson extends Automaton {
if(!p.hasBeenCloseToFire()){
if (sim.getFire().tauchingFire(personImplementingAutomaton)){
p.setCloseToFire(true);
sim.getMonitorAgent().peopleCloseToFire++;
}
}
......
......@@ -47,7 +47,7 @@ import sim.engine.SimState;
public class EscapeMonitorAgent implements MonitorService {
/**This agent stops simulation in this step */
protected static long maxStepToStop=1000;
protected static long maxStepToStop=1500;
/**
* Data structure to log data and conduct statistical operations
......@@ -58,12 +58,18 @@ public class EscapeMonitorAgent implements MonitorService {
* Counter with people who have touch fire
*/
public int peopleCloseToFire=0;
public int exit1 = 0;
public int exit2 = 0;
public int exit3 = 0;
public int burnedexit1 = 0;
public int burnedexit2 = 0;
public int burnedexit3 = 0;
public EscapeMonitorAgent(Ubik u) {
this.ubik = u;
String logHeadings[]={"PeopleInBuilding","PeopleWhoReachFire"};
String logHeadings[]={"PeopleInBuilding","PeopleWhoReachFire", "EXIT1", "EXIT2", "EXIT3",
"burnedexit1", "burnedexit2", "burnedexit3" };
genericLogger = new GenericLogger(logHeadings);
register();
}
......@@ -97,7 +103,8 @@ public class EscapeMonitorAgent implements MonitorService {
*/
public void step(SimState ss) {
List<Person> people = ubik.getBuilding().getFloor(0).getPersonHandler().getPersons();
double[] toLogInStep ={ people.size(), peopleCloseToFire};
double[] toLogInStep ={ people.size(), peopleCloseToFire, exit1, exit2, exit3,
burnedexit1, burnedexit2, burnedexit3};
genericLogger.addStep(toLogInStep);
if(ubik.schedule.getSteps()>=maxStepToStop){//end simulation from agent monitor
......
......@@ -85,7 +85,9 @@ public class Fire implements Steppable, Stoppable {
ubik.setFireActivity(isActive);
}
else {
spreadFire();
if(ss.schedule.getSteps()%4 == 0)
spreadFire();
steps++;
}
......
......@@ -118,7 +118,7 @@ public class Pathfinder implements Steppable {
setGoalAndGeneratePath(goal);
}
} catch (Exception e) {
e.printStackTrace();
//e.printStackTrace();
}
}
......
......@@ -26,6 +26,7 @@ package sim.app.ubik.people;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import sim.app.ubik.Ubik;
import sim.app.ubik.behaviors.PositionTools;
......@@ -62,13 +63,15 @@ public class Teacher extends Person {
private String newGoal;
protected boolean hasBeenCloseToFire;
protected EscapeSim sim= (EscapeSim) this.getUbik();
private List<String[]> timeexit;
public Teacher(int floor, HomePieceOfFurniture person3DModel, Ubik ubik) {
super(floor, person3DModel, ubik);
}
public void step(SimState state) {
@SuppressWarnings("unused")
public void step(SimState state) {
super.step(state);
if (pf==null) {
pf = new PathfinderThread(this);
......@@ -115,10 +118,62 @@ public class Teacher extends Person {
this.stop();//stop agent and make it get out of the simulation
PositionTools.getOutOfSpace(this);
LOG.info(name + " has leave the building using " + localGoal);
if(this.hasBeenCloseToFire)
timeexit = sim.getTimeexit();
String id = this.getName();
int time = this.getUbik().getClock().getDate().getMinutes()*60 +
this.getUbik().getClock().getDate().getSeconds()-
this.getUbik().getDelayFire();
LOG.info(name + " has spent: " + time + " seconds after the "
+ "emergency before to come out");
String exit = null;
String quemado = "False";
switch (localGoal) {
case "Exit1":
sim.getMonitorAgent().exit1++;
exit= "Exit1";
if(this.hasBeenCloseToFire) {
sim.getMonitorAgent().burnedexit1++;
quemado = "True";
}
break;
case "Exit2":
sim.getMonitorAgent().exit2++;
exit= "Exit2";
if(this.hasBeenCloseToFire) {
sim.getMonitorAgent().burnedexit2++;
quemado = "True";
}
break;
case "Exit3":
sim.getMonitorAgent().exit3++;
exit= "Exit3";
if(this.hasBeenCloseToFire) {
sim.getMonitorAgent().burnedexit3++;
quemado = "True";
}
break;
}
StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(time);
String strtime = sb.toString();
String[]data = {id, quemado, strtime, exit};
timeexit = sim.getTimeexit();
timeexit.add(data);
sim. setTimeexit(timeexit);
if(this.hasBeenCloseToFire) {
LOG.info(name + " has touched the fire");
}
else
LOG.info(name + " has not touched the fire");
return;
}
else{
......@@ -392,4 +447,9 @@ public class Teacher extends Person {
public void setCloseToFire(boolean b) {
hasBeenCloseToFire=b;
}
public double getDistanceLeftToReachDestiny() {
// TODO Auto-generated method stub
return 0;
}
}
......@@ -73,8 +73,18 @@ public class EscapeSim extends Ubik {
*/
EscapeMonitorAgent ema ;
Fire fire;
static List<String[]> timeexit = new ArrayList<String[]>();
/**
public List<String[]> getTimeexit() {
return timeexit;
}
public void setTimeexit(List<String[]> timeexit) {
this.timeexit = timeexit;
}
/**
* Passing a random seed
* @param seed
*/
......@@ -138,24 +148,9 @@ public class EscapeSim extends Ubik {
}
Teacher teacher = (sim.app.ubik.people.Teacher) ph.createPerson(0, new HomePieceOfFurniture(model1), ubik);
ph.addPersons(this.population, true, teacher);
/*
//Creacin de nuevas personas en base al modelo anterior
Worker worker1 = (sim.app.ubik.people.Worker) ph.createPerson(0, new HomePieceOfFurniture(model1), ubik);
//Colocacin de la persona en la simulacin
worker.setPosition(50, 50);
ph.add(worker);
boolean aux = PositionTools.putInSpace(worker, worker.getPosition().x, worker.getPosition().y);
worker1.setPosition(80, 80);
ph.add(worker1);
boolean aux2 = PositionTools.putInSpace(worker, worker1.getPosition().x, worker1.getPosition().y);
//PositionTools.getOutOfSpace(worker1);
ph.addPersons(10, true, worker);
//ph.addPersonInRandomPosition(worker);
//Worker worker = Worker(0, ,super());
*/
//this.getBuilding().getFloor(0).getPersonHandler().addPersons(100, true, (HomePieceOfFurniture)null);
//change their name
ph.changeNameOfAgents("a");
......@@ -168,16 +163,19 @@ public class EscapeSim extends Ubik {
*/
public static void main(String []args) {
EscapeSim state = new EscapeSim(2);
EscapeSim state = new EscapeSim();
//EscapeSim state = new EscapeSim(System.currentTimeMillis());
state.start();
do{
if (!state.schedule.step(state)) break;
if (!state.schedule.step(state))
break;
}while(state.schedule.getSteps() < maxTimeForExecution);//
state.finish();
EscapeMonitorAgent ema = state.getMonitorAgent();
System.out.println(ema.getGenericLogger());
System.out.println(timeexit.size());
LOG.info("Se han quemado "+ state.getMonitorAgent().peopleCloseToFire);
}
/**
......
......@@ -40,6 +40,7 @@ package ubiksimdist;
import sim.app.ubik.Ubik;
import sim.app.ubik.UbikSimWithUI;
import sim.app.ubik.behaviors.escape.EscapeMonitorAgent;
import sim.display.Console;
......@@ -70,6 +71,8 @@ public class EscapeSimWithGUI extends UbikSimWithUI {
*/
@Override
public void finish() {
EscapeMonitorAgent ema = escapesim.getMonitorAgent();
System.out.println(ema.getGenericLogger());
LOG.info("Se han quemado"+ escapesim.getMonitorAgent().peopleCloseToFire);
super.finish();
//controller.unregisterFrame(myDisplay);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment