*/
ConsoleAppender ca = new ConsoleAppender();
ca.setThreshold(Priority.WARN);
BasicConfigurator.configure(ca);
SumoTraciConnection conn = new SumoTraciConnection(
"test/sumo_maps/box1l/test.sumo.cfg", // config file
12345 // random seed
);
/*
* Sets the TCP_NODELAY property on the socket connection to SUMO based
* on the OS we are executing in.
*/
String os = System.getProperty("os.name");
if(os.matches("Linux"))
{
conn.enableTcpNoDelay();
}
else
{
conn.disableTcpNoDelay();
}
/*
* Just some simple checking code.
*/
boolean check = conn.isTcpNoDelayActive();
System.out.println();
System.out.printf("Setting TcpNoDelay to [%b] as we are in %s\n", check, os);
/*
* For calculating mean execution times.
*/
ArrayList<Long> val = new ArrayList<Long>();
try
{
/*
* If we did not want to depend on the OS, we can simply override the
* TCP_NODELAY setting by doing conn.setTcpNoDelay(false) here.
*/
// conn.setTcpNoDelay(false);
conn.runServer();
System.out.println();
System.out.println("Map bounds are: " + conn.queryBounds());
System.out.println();
int i;
for (i = 0; i < 20; i++)
{
int time = conn.getCurrentSimStep();
long bgn;
long end;
long dif;
bgn = System.currentTimeMillis();
conn.nextSimStep();
end = System.currentTimeMillis();
dif = end - bgn;
System.out.println();
System.out.printf("Begin Time: %s ms\n", bgn);
System.out.printf("End Time : %s ms\n", end);
System.out.printf("Tick %03d : %d ms\n", time, dif);
val.add(dif);
}
double sum = 0;
for(Long l : val)
{
sum += l;
}
double avg = sum / (double)val.size();
System.out.println();
System.out.printf("Average: %.2f ms for %d ticks, with tcpnodelay=%b\n", avg, i, conn.isTcpNoDelayActive());
conn.close();
}
catch(Exception e) {
e.printStackTrace();
}
}