Skip to content

Commit 37fed47

Browse files
committed
Wave Algotithm tested and working
1 parent dd384dc commit 37fed47

File tree

3 files changed

+14
-34
lines changed

3 files changed

+14
-34
lines changed

WaveAlgorithm/bin/WaveMain.class

38 Bytes
Binary file not shown.

WaveAlgorithm/src/WaveMain.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class WaveMain {
1212
public static void main(String args[])
1313
{
1414
treenodes = new ArrayList<ProcessNode>();
15+
boolean diffuse = true;
1516
ProcessNode n0=new ProcessNode(0);
1617
ProcessNode n1=new ProcessNode(1);
1718
ProcessNode n2=new ProcessNode(2);
@@ -44,44 +45,17 @@ public static void main(String args[])
4445
Iterator<ProcessNode> nodeItr = treenodes.iterator();
4546
while(nodeItr.hasNext())
4647
{
47-
nodeItr.next().init(true);
48+
nodeItr.next().init(diffuse);
4849
}
4950

5051
Random randomGenerator = new Random();
51-
52-
for(int i=0;i<treenodes.size()*100;i++ )
52+
int i;
53+
for(i=0;i<treenodes.size()*100;i++ )
5354
{
5455
int j = randomGenerator.nextInt(treenodes.size());
5556
treenodes.get(j).doStep();
5657
}
57-
58-
59-
60-
// n0.doStep();
61-
// n1.doStep();
62-
// n2.doStep();
63-
// n4.doStep();
64-
// n5.doStep();
65-
// n6.doStep();
66-
// n2.doStep();
67-
// n1.doStep();
68-
// n3.doStep();
69-
// n7.doStep();
70-
// n6.doStep();
71-
// n6.doStep();
72-
// n3.doStep();
73-
// n1.doStep();
74-
// n0.doStep();
75-
// n1.doStep();
76-
// n7.doStep();
77-
// n2.doStep();
78-
// n4.doStep();
79-
// n5.doStep();
80-
// n6.doStep();
81-
82-
83-
84-
58+
8559

8660
}
8761

WaveAlgorithm/src/com/technipun/dc/algorithm/ProcessNode.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ public void deffuse() {
143143
}
144144
}
145145

146-
public void doStep() {
147-
//System.out.println("Process Node["+nodeID+"] executing");
146+
public boolean doStep() {
147+
if (status==Status.DECIDED)
148+
{
149+
return false;
150+
}
151+
System.out.println("[---------Process Node["+nodeID+"]------------]");
148152
while (!messageQueue.isEmpty() && getNonRecCount() > 1) {
149153
this.status = Status.WAITING;
150154
receiveToken();
151155
}
152-
153156
this.silentNeigh = findSilentNeighbour();
154157
if (this.silentNeigh != null && this.status != Status.TOKEN_SENT) {
155158
send(this.silentNeigh, MessageType.TOKEN);
@@ -159,10 +162,13 @@ public void doStep() {
159162
ProcessNode sender = receiveToken();
160163
if (sender != null && sender == silentNeigh) {
161164
decide();
165+
return true;
162166
}
163167
}
168+
return false;
164169

165170
}
171+
166172
public void decide() {
167173
this.status = Status.DECIDED;
168174
System.out.println("Process Node[" + this.nodeID + "] Decides");

0 commit comments

Comments
 (0)