-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrobe.java
More file actions
executable file
·95 lines (69 loc) · 1.54 KB
/
Microbe.java
File metadata and controls
executable file
·95 lines (69 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.lang.Math;
import java.util.Random;
import java.util.*;
import java.lang.Double;
public abstract class Microbe implements AgentInterface, Comparable<Microbe>,
Comparator<Microbe> {
protected static int numMicrobes = 0;
int id;
Environment world;
int[] position;
int[] surroundings;
Random random;
int BACTERIUM_PRESENT = 1;
int MACROPHAGE_PRESENT = 3;
public Microbe(Environment _world) {
world = _world;
id = ++numMicrobes;
random = new Random();
position = new int[] {-1, -1};
surroundings = new int[9];
}
public int getID() {
return id;
}
public int[] getPosition()
{
return position;
}
public int getRow()
{
return position[0];
}
public int getCol()
{
return position[1];
}
public void setRowCol(int row, int col)
{
position[0] = row;
position[1] = col;
}
public AgentType getType()
{
if (this instanceof Macrophage) {
return AgentType.MACROPHAGE;
} else {
return AgentType.BACTERIUM;
}
}
public int compareTo(Microbe other) {
double t = this.getNextEventTime() - other.getNextEventTime();
if (t > 0) return 1;
if (t == 0) return 0;
return -1;
}
public int compare(Microbe one, Microbe two) {
double t = one.getNextEventTime() - two.getNextEventTime();
if (t > 0) return 1;
if (t == 0) return 0;
return -1;
}
// Return the time of the next event
public abstract double getNextEventTime();
public abstract void executeNextEvent();
public double nextExp(double mean)
{
return Math.log(1-random.nextDouble())/(-(1/mean));
}
}