SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PreyPred.java
1package tutorial;
2
3import umontreal.ssj.simevents.*;
4
5public class PreyPred {
6 double r = 0.005, c = 0.00001, s = 0.01, d = 0.000005, h = 5.0;
7 double x0 = 2000.0, z0 = 150.0;
8 double horizon = 501.0;
9 Simulator sim = new Simulator();
10 Continuous x;
11 Continuous z;
12
13 public static void main(String[] args) {
14 new PreyPred();
15 }
16
17 public PreyPred() {
18 x = new Preys(sim);
19 z = new Preds(sim);
20 sim.init();
21 new EndOfSim(sim).schedule(horizon);
22 new PrintPoint(sim).schedule(h);
23 (sim.continuousState()).selectRungeKutta4(h);
24 x.startInteg(x0);
25 z.startInteg(z0);
26 sim.start();
27 }
28
29 public class Preys extends Continuous {
30 public Preys(Simulator sim) {
31 super(sim);
32 }
33
34 public double derivative(double t) {
35 return (r * value() - c * value() * z.value());
36 }
37 }
38
39 public class Preds extends Continuous {
40 public Preds(Simulator sim) {
41 super(sim);
42 }
43
44 public double derivative(double t) {
45 return (-s * value() + d * x.value() * value());
46 }
47 }
48
49 class PrintPoint extends Event {
50 public PrintPoint(Simulator sim) {
51 super(sim);
52 }
53
54 public void actions() {
55 System.out.println(sim.time() + " " + x.value() + " " + z.value());
56 this.schedule(h);
57 }
58 }
59
60 class EndOfSim extends Event {
61 public EndOfSim(Simulator sim) {
62 super(sim);
63 }
64
65 public void actions() {
66 sim.stop();
67 }
68 }
69}
void actions()
This is the method that is executed when this event occurs.
Definition PreyPred.java:65
double derivative(double t)
This method should return the derivative of this variable with respect to time, at time .
Definition PreyPred.java:44
double derivative(double t)
This method should return the derivative of this variable with respect to time, at time .
Definition PreyPred.java:34
void actions()
This is the method that is executed when this event occurs.
Definition PreyPred.java:54
Represents a variable in a continuous-time simulation.
Continuous()
Constructs a new continuous-time variable linked to the default simulator, without initializing it.
double value()
Returns the current value of this continuous-time variable.
Event()
Constructs a new event instance, which can be placed afterwards into the event list of the default si...
Definition Event.java:126
void schedule(double delay)
Schedules this event to happen in delay time units, i.e., at time sim.time() + delay,...
Definition Event.java:153
Represents the executive of a discrete-event simulator.