HSRAvatar{{ private Config config; /* Constructor to be called during registration where you supply config*/ public HSRAvatar(Config cfg){ config = cfg; } /**proposing random unique claims which are not in the forbidden list**/ public List propose(List forbiddenClaims){ List claims = List.create(); SCGConfig scg_cfg = config.getScgCfg(); int maxProposals = scg_cfg.getMaxProposals() -1; for(int i =0; i< maxProposals;i++){ Claim claim = generateRandomClaim(); while(forbiddenClaims.contains(claim) || claims.contains(claim)){ claim = generateRandomClaim(); } claims = claims.append(claim); } return claims; } /**Random oppose method - randomly agrees, refutes or strengthens by a factor of 1 **/ public List oppose(List claimsToBeOpposed){ return claimsToBeOpposed.map(new List.Map() { public OpposeAction map(Claim claim){ Random rand = new Random(); int randOppose = rand.nextInt(3); if(randOppose == 0) return new Agreement(); else if(randOppose == 1){ HSRInstanceSet is = (HSRInstanceSet)claim.getInstanceSet(); int n = is.getSingleton().getN(); int q = (int)Math.ceil(claim.getQuality() * n); SCGConfig scg_cfg = config.getScgCfg(); if (claim.getProtocol() instanceof ForAllExists){ if(q>1) return new Strengthening(claim.getQuality() - scg_cfg.getMinStrengthening()); else return new Refuting(); }else{ if(q hsr_cfg.getMaxN()){ randN = 2+ rand.nextInt(hsr_cfg.getMaxN() - 2); } int randK = 1 + rand.nextInt(randN - 1); int randQ = 1+ rand.nextInt(randN - 1); HSRInstance singleton = new HSRInstance(randN, randK); // get the maximum allowed n from config HSRInstanceSet instanceSet = new HSRInstanceSet(singleton ); // To Change: The protocol instance must be one of the // allowed protocols mentioned in SCGConfig Cons protocolsAllowed = config.getScgCfg().getProtocols(); ProtocolI protocol = generateRandomAllowedProtocol(protocolsAllowed ); return new Claim(instanceSet, protocol,((double)randQ)/randN,((double)randQ)/randN); } /** generates a random protocol instance from the given protocolsAllowed */ private ProtocolI generateRandomAllowedProtocol(Cons protocolsAllowed){ Random rand = new Random(); FullyQualifiedClassName randProtocol = protocolsAllowed.lookup(rand.nextInt(protocolsAllowed.length())); ProtocolI protocol = null; try{ Class protocolClass = Class.forName(randProtocol.print().trim()); Method instance = protocolClass.getMethod("parse", String.class); protocol = (ProtocolI) instance.invoke(null, randProtocol.print().trim()); }catch(Exception ex){ ex.printStackTrace(); } return protocol; } }}