/** * return an item of the list according its index * * @return an item of the list */ public TrustedTripletIdRoleGroup get(int id) { TrustedTripletIdRoleGroup triplet; ListIterator<TrustedTripletIdRoleGroup> iter = neighboorList.listIterator(); while (iter.hasNext()) { triplet = iter.next(); if (triplet.id == id) return triplet.clone(); } return null; }
/** * returns the identifier of a link agent which allows to communicate with a specific * representative agent * * @param representativeId identifier of the specific reprensentative agent * @return identifier of a link agent */ public int getLinkToRepresentant(int representativeId) { boolean trouve = false; TrustedTripletIdRoleGroup triplet = null; ListIterator<TrustedTripletIdRoleGroup> iter = neighboorList.listIterator(); while (!trouve && iter.hasNext()) { triplet = iter.next(); if (triplet.role == TrustedMWACAgent.roleLINK) trouve = triplet.inGroup(representativeId); } if (trouve) { // on le deplace pour qu'il ne soit pas utilisé en priorité au prochain coup iter.remove(); this.neighboorList.add(triplet); return triplet.id; } return UNDEFINED_ID; }
public boolean isKnowedGroups(int[] groups, int ignoredAgent) { int i; Vector<Integer> v = new Vector<Integer>(groups.length); for (i = 0; i < groups.length; i++) v.add(groups[i]); TrustedTripletIdRoleGroup t; ListIterator<TrustedTripletIdRoleGroup> iter = neighboorList.listIterator(); while ((!v.isEmpty()) && iter.hasNext()) { t = iter.next(); if (t.id != ignoredAgent) for (i = 0; i < v.size(); i++) if (t.inGroup(v.get(i))) { v.remove(i); i--; } } return v.isEmpty(); }
/** (Anca) Trust recovery algorithm (Algorithm 1 / p. 8 - PAAMS article) */ public void trustRecovery() { for (TrustedTripletIdRoleGroup triplet : neighboorList) { triplet.trust = (1 - TrustManager.LAMBDA) * triplet.trust + TrustManager.LAMBDA; } }