-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersoana.java
155 lines (114 loc) · 3.1 KB
/
Persoana.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.google.gwt.bacterialresistance.server;
import java.util.*;
public class Persoana {
private LinkedList<Legatura> edges = new LinkedList<Legatura>();
private int nodeNum;
private float edgeWeights = Math.round(100.0f) / 100.0f;
private BacterialResistance br;
private String condition;
private int time;
private static Random r = new Random();
public Persoana(int nodeNum, int numberOfAntibiotics){
this.nodeNum = nodeNum;
br = new BacterialResistance(numberOfAntibiotics);
}
public void setCondition(String condition){
this.condition = condition;
}
private float computeEdgeWeight(){
float u = Math.round(r.nextFloat() * 100.0f) / 100.0f;
return u;
}
public void addTime(int time){
this.time = time;
}
public void decrementTime(int decrValue){
time = (decrValue > time) ? 0 : (time - decrValue);
}
public void addEdgeWeight(){
float edgeW;
int pos = 0;
int dim = edges.size() - 1;
for(Legatura l : edges){
do
{
edgeW = computeEdgeWeight();
}
while((edgeW > edgeWeights) && (pos != dim));
if(pos != dim){
edgeWeights -= edgeW;
pos++;
}
else
edgeW = edgeWeights;
l.addWeight(edgeW);
}
}
public void addEdge(Persoana y){
Legatura l = new Legatura(this,y);
edges.add(l);
}
public void removeEdge(Persoana y){
for(Legatura l : edges){
if(l.getY().equals(y)){
edges.remove(y);
break;
}
}
}
public boolean hasEdge(Persoana p){
for(Legatura l : edges){
if(l.isVertex(p))
return true;
}
return false;
}
public Persoana getEdge(float chance){
for(Legatura l : edges){
if((l.getWeight() > chance) && (l.getY().time == 0) && l.getY().condition.equals("susceptible"))
return l.getY();
}
return null;
}
public int getNodeNum(){
return nodeNum;
}
public int getDegree(){
return edges.size();
}
public int getTime(){
return time;
}
/*public void adjustResistance(float tau, float gamma, float[] resistanceFreq){
float val;
for(int i = 0; i<resistanceFreq.length; i++){
if(br.getIndexOfResist() != i){
val = tau * resistanceFreq[i] - gamma;
if(val < 0.0f) val = 0.0f;
br.addResistance(i, val);
}
}
}
public void adjustResistance(float tau, float gamma, int index){
float val = tau - gamma;
if(val < 0.0f) val = 0.0f;
br.addResistance(index, val);
}*/
public void adjustResistance(float val, int index, boolean addResistance){
if(addResistance == false) val = val*(-1);
br.addResistance(index, val);
}
public boolean isResistant(){
return (br.maximumResistance() > 0.6f);
}
public boolean equals(Object o){
return (o instanceof Persoana) && (((Persoana)o).nodeNum == this.nodeNum);
}
public String toString(){
String s = "Node " + nodeNum + " time " + time + " numberOfAntibiotics " + br.getNumberOfAntibiotics() + "\n";
/*for(Legatura l : edges)
s += l.toString() + "\n";*/
s += br.toString() + "\n";
return s;
}
}