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); }