Steps 1 and 3 are probably a bad idea.
Implement a model class with a "tick" or "timestep" variable. Set the
value to 0. Instances of the model class are shadow facts. Have a
setTick(int t) method:
public void setTick(double t) {
double oldTick = tick;
tick = t;
pcs.firePropertyChange("tick", oldTick, tick);
}
And a scheduling method such as:
private void runSimulation(){
for (int t = 0; t < runLength; t++) {
setTick(t);
System.out.println("Starting tick " + tick);
long start = System.currentTimeMillis();
try {
//put modules on stack: they become current in reverse
order
engine.setFocus("CLEANUP");
engine.setFocus("SIM");
engine.run();
}catch(JessException je){
System.err.println("An error occurred at line "
+ je.getLineNumber());
System.err.println("caused by " + je.getCause());
System.err.println("Message: " + je.getDetail());
je.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("Time to run: " + (end -
start)/1000.0 + "
seconds");
displayInstance.updateDisplay();
}
});
}
Define the model shadowfact in Jess in the usual way and then in your
rules you have the lhs clause:
(model (tick ?t))
and then you timestamp every clause that could change with time. My
deftemplates look like this:
(deftemplate
(slot x)
(slot y)
(slot tickStamp))
for such clauses/facts. You can retract facts from previous timesteps
that are no longer wanted by defining a cleanup module to fire first (or
last) as in the example above.
I use RePast and its scheduler because it contains a lot of
functionality useful for agent based modelling. But if you don't need
that functionality and the substantial overheads, I think something
along the lines described here should do what you want.
hope this helps.
On Wed, 2007-05-09 at 17:40 -0400, Nicolas wrote:
> Hello,
>
> I want to create a Java simulation program that is using Jess.
>
> The simulation has i = [1..n] steps. I have in mind the following
> pseudo-code:
>
> The program defines some rules, fact templates, and asserts shadow facts.
>
> The program excecutes the engine until halt.
>
> For each step i the program does these operations:
> (1) It asserts a fact that contains the current step value (i). This
> assertion fires a sequence of rules that are modifying the shadow facts.
>
> (2) Once there is no more activation, it updates the gui by reading some
> shadow facts properties values.
>
> (3) Then it retracts the fact with the current step value (i), it increments
> i (i++) and it resumes the first operation (1).
>
> Because the gui can change quickly (2), I am thinking to use a
> javax.swing.Timer, to allow the user to see what is happening. So the timer
> will control the simulation pace. For example, the user could assign a
> simulation pace of 5 seconds between each step (i).
>
> The fact that contains the current step value (i) would be asserted in the
> timer's event listener. However, before to assert it, all the rules
> activated during the previous step (i -1) must have been fired. How can I do
> that? Should I check if there is no element in activationLists(), before
> asserting the new step value?
>
> I have found in JIA a small example with gui (chapter 13), but I am still
> wondering if I can use it.
>
> Any hint that can help me to solve my problem would be appreciated.
>
> Thanks in advance.
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
>
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------