private void changeTable(Know node) { for (int i = 1; i <= node.Max(); i++) { if ((node.NeighbourNode(i)) != -1) { Integer nodeI = new Integer(i); this.putProperty( nodeI.toString(), new String((new Integer(node.NeighbourNode(i))).toString())); } } }
private void sendKnowledge(Know node, int synchro) { Vector<Integer> vec = new Vector<Integer>(2); for (int i = 1; i <= node.Max(); i++) { if ((node.NeighbourNode(i)) != -1) { vec.add(new Integer(i)); vec.add(new Integer(node.NeighbourNode(i))); this.sendTo(synchro, new VectorMessage((Vector) vec.clone(), Mazurkiewicz_Election.labels)); vec.clear(); Mazurkiewicz_Election.messagesNumber++; } } vec.add(new Integer(-1)); vec.add(new Integer(-1)); this.sendTo(synchro, new VectorMessage((Vector) vec.clone(), Mazurkiewicz_Election.labels)); }
private void sendToAllKnowledge(Know node) { int arity = this.getArity(); Vector<Integer> vec = new Vector<Integer>(2); for (int i = 1; i <= node.Max(); i++) { if ((node.NeighbourNode(i)) != -1) { vec.add(new Integer(i)); vec.add(new Integer(node.NeighbourNode(i))); this.sendAll(new VectorMessage((Vector) vec.clone(), Mazurkiewicz_Election.labels)); vec.clear(); Mazurkiewicz_Election.messagesNumber = Mazurkiewicz_Election.messagesNumber + arity; /* * System.out.println("3-centre envois :"+ i +"=" + * node.NeighbourNode(i)); */ } } vec.add(new Integer(-1)); vec.add(new Integer(-1)); this.sendAll(new VectorMessage((Vector) vec.clone(), Mazurkiewicz_Election.labels)); /* System.out.println( "4-centre envoit -1"); */ }
private void receiveKnowledge(Know node, int door) { VectorMessage vm = (VectorMessage) this.receiveFrom(door); Vector data = vm.data(); /* * System.out.println("1-centre recoit de "+door+":" + * ((Integer)data.elementAt(0)).intValue()); */ while (((Integer) data.elementAt(0)).intValue() != -1) { node.ChangeKnowledge( ((Integer) data.elementAt(0)).intValue(), ((Integer) data.elementAt(1)).intValue()); vm = (VectorMessage) this.receiveFrom(door); data = vm.data(); /* * System.out.println("1-centre recoit de "+door+":" + * ((Integer)data.elementAt(0)).intValue()); */ } }
public void init() { int graphS = this.getNetSize(); /* la taille du graphe */ int synchro; boolean run = true; /* booleen de fin de l'algorithme */ boolean finishedNode[]; int arity = this.getArity(); Know node = new Know(); finishedNode = new boolean[this.getArity()]; for (int i = 0; i < this.getArity(); i++) { finishedNode[i] = false; } this.putProperty("label", new String("0")); node.Initial(graphS); while (run) { synchro = this.starSynchro(finishedNode); if (synchro == this.starCenter) { for (int door = 0; door < arity; door++) { if (!finishedNode[door]) { this.receiveKnowledge(node, door); } } if ((node.MyName() == 0) || (node.Neighbour() < node.NeighbourNode(node.MyName()))) { node.ChangeName(node.Max() + 1); } this.sendAll(new IntegerMessage(node.MyName(), Mazurkiewicz_Election.labels)); this.putProperty("label", new String((new Integer(node.MyName())).toString())); node.ChangeKnowledge(node.MyName(), node.Neighbour()); Mazurkiewicz_Election.messagesNumber = Mazurkiewicz_Election.messagesNumber + arity; this.sendToAllKnowledge(node); if (node.Max() == graphS) { run = false; } this.changeTable(node); this.breakSynchro(); } else { if (synchro != this.notInTheStar) { this.sendKnowledge(node, synchro); Message newName = this.receiveFrom(synchro); node.ChangeKnowledge(0, ((IntegerMessage) newName).value()); this.putProperty("My Neighbour", new String((new Integer(node.Neighbour())).toString())); this.receiveKnowledge(node, synchro); this.changeTable(node); } } } this.sendAll(new IntegerMessage(new Integer(-1), Mazurkiewicz_Election.synchronization)); System.out.println( "Nombre de starSynchro = " + Mazurkiewicz_Election.synchroNumber + " Nombre de messages = " + Mazurkiewicz_Election.messagesNumber); }