-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpreading_innoculation.java
131 lines (127 loc) · 3.21 KB
/
Spreading_innoculation.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
import java.io.*;
import java.util.*;
public class Spreading_innoculation{
public static void main(String args[]){
ArrayList<Integer> source=new ArrayList<Integer>();
ArrayList<Integer> mid=new ArrayList<Integer>();
ArrayList<Integer> intm=new ArrayList<Integer>();
int no_of_nodes=Integer.parseInt(args[0]);
int min=0;
int max=no_of_nodes;
double prob = 0.2;
int msg_size=Integer.parseInt(args[1]);
int status[]=new int[msg_size+1];
Node_com nod[]=new Node_com[no_of_nodes];
for(int i=0;i<no_of_nodes;i++){
nod[i]=new Node_com();
nod[i].msg=new int[msg_size];
nod[i].id=i;
}
int iteration=0;
double s_t_b=0.0;
double s_t_1=0.0;
int round;
while(iteration<100){
round=0;
int flg=0;
int node_rem=0;
Random re=new Random();
int start=re.nextInt(max);
nod[start].src=1;
for(int i=0;i<msg_size;i++)
nod[start].msg[i]=1;
source.add(start);
int t_1=0;
//nod[start].k_stat=msg_size;
System.out.println("Initial node selected");
while(true){
for(int i=0;i<source.size();i++){
int s=source.get(i);
max=no_of_nodes;
min=0;
//System.out.println("first element of the list: "+n_list.get(0));
int t=re.nextInt(max);
while(t==s){
t=re.nextInt(max);
}
if(intm.contains(s))
continue;
if(intm.contains(t)){
intm.add(s);
continue;
}
//System.out.println("element selected");
for(int k=0;k<msg_size;k++){
if((nod[s].msg[k]==1)&&(nod[t].msg[k]==0)){
nod[t].msg[k]=1;
//System.out.println("size of the n_list: "+n_list.size());
//nod[t].k_stat++;
if(k==msg_size-1)
mid.add(t);
intm.add(t);
break;
}
}
//System.out.println("Message transmission complete");
}
round++;
for(int i=0;i<mid.size();i++)
source.add(mid.get(i));
//for(int i=0;i<no_of_nodes;i++)
// status[nod[i].k_stat]++;
//String str1=Integer.toString(round)+"\t";
//for(int i=0;i<msg_size+1;i++)
// str1+=Integer.toString(status[i])+"\t";
//System.out.println(str1);
//for(int i=0;i<msg_size+1;i++)
// status[i]=0;
mid.clear();
intm.clear();
if((source.size()==2)&&(flg==0)){
System.out.println("T1: "+round);
t_1=round;
s_t_1+=round;
flg=1;
}
if(round==200){
for(int i=0;i<no_of_nodes;i++){
if(i==start)
continue;
if(Math.random() < prob){
int j=0;
for(;j<msg_size;j++){
if(nod[i].msg[j]==0)
break;
}
if(j==0)
continue;
else{
if(j==msg_size-1)
source.remove(new Integer(i));
nod[i].msg[j-1]=0;
}
}
}
}
//System.out.println(round+"\t"+source.size());
//System.out.println("-----------------------------------------");
//if(round==Math.round(2.5*t_1))
// break;
if(source.size()==no_of_nodes)
break;
}
iteration++;
s_t_b+=source.size()+node_rem;
source.clear();
//System.out.println("Time: "+round);
for(int i=0;i<no_of_nodes;i++){
for(int k=0;k<msg_size;k++)
nod[i].msg[k]=0;
}
System.out.println(s_t_1);
}
s_t_1/=iteration;
s_t_b/=iteration;
System.out.println(no_of_nodes+"\t"+s_t_1);
}
}