[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Time steps
From: |
Andre Costa |
Subject: |
Re: Time steps |
Date: |
Tue, 31 Jul 2001 23:44:04 +0930 (CST) |
On Tue, 31 Jul 2001, Jacek Gomoluch wrote:
> 1) I want to implement a simulation model of a distributed computer system.
> In the model I use arbitrary, floating-point messaging delays and processing
> delays (e.g. 0.132323 s). As far as I know, Swarm uses discrete time steps.
> Is there still a way of implementing the delays of my model?
I came across this issue last year, and I found the example code
"DoubleSchedule"
in the mailing list archives, which I have included below. It is a
self-contained piece of Java code which shows one way of implementing a
floating-point time schedule.
> Alternatively, I could "discretise" my model in a way that one milliecond
> corresponds to one timestep (with large gaps in the simulation time where
> nothing is happening). Will the performance of the tool be degraded then ?
This will also work, but I do believe that there would be some
performance loss if there are large gaps with "nothing happening" in a
simple time-stepping model (c.f. HeatBugs)
compared with an event-driven approach such as the one given in
"DoubleSchedule" (c.f. MouseTrap).
cheers,
Andre.
---------------------------------------------------------------------
Andre Costa
Research Student
Teletraffic Research Centre Telephone: (08) 8303 3237
Department of Applied Mathematics Fax: (08) 8303 4395
University of Adelaide Email:address@hidden
South Australia 5005
----------------------------------------------------------------------
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.ScheduleC;
import swarm.activity.ScheduleCImpl;
import swarm.activity.ConcurrentScheduleCImpl;
import swarm.activity.ConcurrentSchedule;
import swarm.activity.Activity;
import swarm.activity.ScheduleActivity;
import swarm.Selector;
import java.text.DecimalFormat;
import java.util.Arrays;
public class DoubleSchedule extends SwarmImpl {
Schedule schedule;
ScheduleActivity scheduleActivity;
Schedule stopSchedule;
DecimalFormat formatter;
final int precision = 10000;
final int digits = (int) Math.rint (Math.log ((double) precision) /
Math.log (10));
DoubleSchedule (Zone aZone) {
super (aZone);
ConcurrentScheduleCImpl typeProto = new ConcurrentScheduleCImpl ();
Object concGroupType;
ScheduleC scheduleProto;
typeProto.customizeBegin (aZone);
typeProto.setAutoDrop (true);
concGroupType = typeProto.customizeEnd ();
scheduleProto = new ScheduleCImpl (new ScheduleImpl ());
scheduleProto.createBegin (aZone);
scheduleProto.setAutoDrop (true);
scheduleProto.setConcurrentGroupType (concGroupType);
schedule = (Schedule) scheduleProto.createEnd ();
formatter = (DecimalFormat) DecimalFormat.getInstance ();
char ary[] = new char[digits];
Arrays.fill (ary, '0');
formatter.applyPattern (new String (ary));
}
public Object step () {
int subtval = (Globals.env.getCurrentTime () + 5) / 10;
System.out.println (formatter.format (scheduleActivity.getCurrentTime ())+
"." + formatter.format (subtval));
return this;
}
void at (double val, Selector sel) {
((ConcurrentSchedule) schedule.insertGroup ((int)
val)).at$createActionTo$message((int) ((val - Math.floor (val)) *
precision * 10), this, sel);
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
scheduleActivity = (ScheduleActivity) schedule.activateIn (this);
return getActivity ();
}
void go () {
activateIn (null).run ();
}
static void main (String args[]) {
Globals.env.initSwarm ("DoubleSchedule","0.0","address@hidden",args);
DoubleSchedule modelSwarm = new DoubleSchedule (Globals.env.globalZone);
try {
Selector sel = new Selector (modelSwarm.getClass (), "step", false);
modelSwarm.at (1.999, sel);
modelSwarm.at (2500.0051, sel);
modelSwarm.at (2000.11, sel);
} catch (Exception e) {
e.printStackTrace ();
}
modelSwarm.go ();
}
}
==================================
Swarm-Modelling is for discussion of Simulation and Modelling techniques
esp. using Swarm. For list administration needs (esp. [un]subscribing),
please send a message to <address@hidden> with "help" in the
body of the message.
==================================