diff --git a/simulator/config/dasprotocol.cfg b/simulator/config/dasprotocol.cfg index 83c4670b..36fbc665 100644 --- a/simulator/config/dasprotocol.cfg +++ b/simulator/config/dasprotocol.cfg @@ -5,13 +5,13 @@ # ::::: GLOBAL :::::: # Network size -SIZE 5000 +SIZE 100 # Random seed K 5 -MINDELAY 10 -MAXDELAY 200 +MINDELAY 100 +MAXDELAY 100 #Simulation time in ms SIM_TIME 1000*60*9 @@ -88,7 +88,7 @@ control.0traffic.dasprotocol 4dasprotocol control.0traffic.step TRAFFIC_STEP control.0traffic.mapping_fn 2 control.0traffic.sample_copy_per_node 2 -control.0traffic.block_dim_size 512 +control.0traffic.block_dim_size 100 # turbulence #control.2turbolenceAdd peersim.kademlia.Turbulence diff --git a/simulator/src/main/java/peersim/kademlia/das/Block.java b/simulator/src/main/java/peersim/kademlia/das/Block.java index e7ae6bf8..44fdad35 100644 --- a/simulator/src/main/java/peersim/kademlia/das/Block.java +++ b/simulator/src/main/java/peersim/kademlia/das/Block.java @@ -133,7 +133,7 @@ public BigInteger computeRegionRadius(int numberOfCopiesPerSample) { MAX_KEY .divide(BigInteger.valueOf(Network.size())) .multiply(BigInteger.valueOf(numberOfCopiesPerSample)); - radius = radius.shiftRight(1); + // radius = radius.shiftRight(1); return radius; } diff --git a/simulator/src/main/java/peersim/kademlia/das/DASProtocol.java b/simulator/src/main/java/peersim/kademlia/das/DASProtocol.java index adbb6b28..4254a8f5 100644 --- a/simulator/src/main/java/peersim/kademlia/das/DASProtocol.java +++ b/simulator/src/main/java/peersim/kademlia/das/DASProtocol.java @@ -37,7 +37,7 @@ import peersim.kademlia.operations.Operation; import peersim.transport.UnreliableTransport; -public class DASProtocol implements Cloneable, EDProtocol, KademliaEvents, MissingNode { +public class DASProtocol implements EDProtocol, KademliaEvents, MissingNode { private static final String PAR_TRANSPORT = "transport"; // private static final String PAR_DASPROTOCOL = "dasprotocol"; @@ -46,9 +46,9 @@ public class DASProtocol implements Cloneable, EDProtocol, KademliaEvents, Missi private static String prefix = null; private UnreliableTransport transport; private int tid; - private int kademliaId; + protected int kademliaId; - private KademliaProtocol kadProtocol; + protected KademliaProtocol kadProtocol; /** allow to call the service initializer only once */ private static boolean _ALREADY_INSTALLED = false; @@ -60,25 +60,25 @@ public class DASProtocol implements Cloneable, EDProtocol, KademliaEvents, Missi private boolean isValidator; - private KeyValueStore kv; + protected KeyValueStore kv; - private Block currentBlock; + protected Block currentBlock; - private LinkedHashMap samplingOp; + protected LinkedHashMap samplingOp; - private LinkedHashMap kadOps; + protected LinkedHashMap kadOps; - private boolean samplingStarted; + protected boolean samplingStarted; - private SearchTable searchTable; + protected SearchTable searchTable; - private int[] row, column; + protected int[] row, column; - private int samplesRequested; + protected int samplesRequested; - private BigInteger[] validatorsList; + protected BigInteger[] validatorsList; - private HashSet queried; + protected HashSet queried; protected int dasID; @@ -408,31 +408,32 @@ protected void handleGetSampleResponse(Message m, int myPid) { row[s.getRow()]++; } - SamplingOperation op = (SamplingOperation) samplingOp.get(m.operationId); + SamplingOperation sop = (SamplingOperation) samplingOp.get(m.operationId); // We continue an existing operation - if (op != null) { + if (sop != null) { // keeping track of received samples - op.elaborateResponse(samples); + sop.elaborateResponse(samples); logger.warning( "Continue operation " - + op.getId() + + sop.getId() + " " - + op.getAvailableRequests() + + sop.getAvailableRequests() + " " - + op.nrHops + + sop.nrHops + " " + searchTable.nodesIndexed().size() + " " - + ((SamplingOperation) op).samplesCount()); + + ((SamplingOperation) sop).samplesCount()); - if (!op.completed() && op.nrHops < KademliaCommonConfigDas.MAX_HOPS) { - BigInteger[] nextNodes = op.doSampling(); + if (!sop.completed() && sop.nrHops < KademliaCommonConfigDas.MAX_HOPS) { + BigInteger[] missingSamples = sop.getMissingSamples(); + BigInteger[] nodesToAsk = searchTable.getNodesForSamples(missingSamples, sop.getRadius()); - for (BigInteger nextNode : nextNodes) { + for (BigInteger nextNode : nodesToAsk) { logger.warning("sending to node " + nextNode); - BigInteger[] reqSamples = op.getSamples(); - Message msg = generateGetSampleMessage(reqSamples); - msg.operationId = op.getId(); + + Message msg = generateGetSampleMessage(missingSamples); + msg.operationId = sop.getId(); msg.src = this.kadProtocol.getKademliaNode(); msg.dst = kadProtocol.nodeIdtoNode(nextNode).getKademliaProtocol().getKademliaNode(); @@ -440,37 +441,39 @@ protected void handleGetSampleResponse(Message m, int myPid) { logger.warning("Error sending to builder or 0 samples assigned"); continue; }*/ - op.AddMessage(msg.id); + sop.AddMessage(msg.id); sendMessage(msg, nextNode, myPid); - op.nrHops++; + sop.nrHops++; } - if (nextNodes.length == 0) { + if (nodesToAsk.length == 0) { logger.warning( "No left nodes to ask " - + op.getAvailableRequests() + + sop.getAvailableRequests() + " " + kadOps.size() + " " - + op.getSamples().length); - if (op.getAvailableRequests() == KademliaCommonConfigDas.ALPHA) { - for (BigInteger sample : op.getSamples()) logger.warning("Missing sample " + sample); - while (!doSampling(op)) { - op.increaseRadius(2); - logger.warning("Increasing radius " + op.getId()); + + sop.getMissingSamples().length); + if (sop.getAvailableRequests() == KademliaCommonConfigDas.ALPHA) { + for (BigInteger sample : sop.getMissingSamples()) + logger.warning("Missing sample " + sample); + while (!doSampling(sop)) { + if (sop.increaseRadius(2)) { + samplingOp.remove(m.operationId); + logger.warning("Sampling operation finished"); + KademliaObserver.reportOperation(sop); + break; + } + logger.warning("Increasing radius " + sop.getId()); } - /*samplingOp.remove(m.operationId); - logger.warning("Sampling operation finished"); - KademliaObserver.reportOperation(op);*/ - } } } else { logger.warning("Operation completed"); samplingOp.remove(m.operationId); - if (op instanceof ValidatorSamplingOperation) - logger.warning("Sampling operation finished validator completed " + op.getId()); - else logger.warning("Sampling operation finished random completed " + op.getId()); - KademliaObserver.reportOperation(op); + if (sop instanceof ValidatorSamplingOperation) + logger.warning("Sampling operation finished validator completed " + sop.getId()); + else logger.warning("Sampling operation finished random completed " + sop.getId()); + KademliaObserver.reportOperation(sop); } // We start a new operation // we start the actual sampling when the last sample from the builder is received @@ -497,7 +500,7 @@ protected void handleGetSampleResponse(Message m, int myPid) { * @param destId the Id of the destination node * @param myPid the sender Pid */ - private void sendMessage(Message m, BigInteger destId, int myPid) { + protected void sendMessage(Message m, BigInteger destId, int myPid) { // int destpid; assert m.src != null; @@ -526,7 +529,7 @@ private void sendMessage(Message m, BigInteger destId, int myPid) { * * @return Message */ - private Message generateGetSampleMessage(BigInteger[] sampleId) { + protected Message generateGetSampleMessage(BigInteger[] sampleId) { Message m = new Message(Message.MSG_GET_SAMPLE, sampleId); m.timestamp = CommonState.getTime(); @@ -569,7 +572,7 @@ public void addKnownValidator(BigInteger[] ids) { * @param m initial message * @param myPid protocol pid */ - private void startRandomSampling(Message m, int myPid) { + protected void startRandomSampling(Message m, int myPid) { logger.warning("Starting random sampling"); RandomSamplingOperation op = @@ -594,7 +597,7 @@ private void startRandomSampling(Message m, int myPid) { * @param m initial message * @param myPid protocol pid */ - private void startRowsandColumnsSampling(Message m, int myPid) { + protected void startRowsandColumnsSampling(Message m, int myPid) { logger.warning( "Starting rows and columns fetch " + rowWithHighestNumSamples() @@ -615,7 +618,7 @@ private void startRowsandColumnsSampling(Message m, int myPid) { 0, CommonState.r.nextInt(KademliaCommonConfigDas.BLOCK_DIM_SIZE) + 1, m.timestamp); } - private boolean doSampling(SamplingOperation sop) { + protected boolean doSampling(SamplingOperation sop) { if (sop.completed()) { samplingOp.remove(sop.getId()); @@ -625,38 +628,38 @@ private boolean doSampling(SamplingOperation sop) { logger.warning("Sampling operation finished validator dosampling " + sop.getId()); else logger.warning("Sampling operation finished random dosampling " + sop.getId()); return true; - } else { - boolean success = false; - logger.warning("Dosampling " + sop.getAvailableRequests()); - BigInteger[] nextNodes = sop.doSampling(); - for (BigInteger nextNode : nextNodes) { - BigInteger[] reqSamples = sop.getSamples(); - logger.warning( - "sending to node " - + nextNode - + " " - + reqSamples.length - + " " - + sop.getAvailableRequests() - + " " - + sop.getId()); - - Message msg = generateGetSampleMessage(reqSamples); - msg.operationId = sop.getId(); - msg.src = this.kadProtocol.getKademliaNode(); - success = true; - msg.dst = kadProtocol.nodeIdtoNode(nextNode).getKademliaProtocol().getKademliaNode(); - /*if (nextNode.compareTo(builderAddress) == 0) { - logger.warning("Error sending to builder or 0 samples assigned"); - continue; - }*/ - sop.AddMessage(msg.id); - // logger.warning("Send message " + dasID + " " + this); - sendMessage(msg, nextNode, dasID); - sop.nrHops++; - } - return success; } + BigInteger[] missingSamples = sop.getMissingSamples(); + BigInteger[] nodesToAsk = searchTable.getNodesForSamples(missingSamples, sop.getRadius()); + + boolean success = false; + logger.warning("Dosampling " + sop.getAvailableRequests()); + for (BigInteger nextNode : nodesToAsk) { + logger.warning( + "sending to node " + + nextNode + + " " + + missingSamples.length + + " " + + sop.getAvailableRequests() + + " " + + sop.getId()); + + Message msg = generateGetSampleMessage(missingSamples); + msg.operationId = sop.getId(); + msg.src = this.kadProtocol.getKademliaNode(); + success = true; + msg.dst = kadProtocol.nodeIdtoNode(nextNode).getKademliaProtocol().getKademliaNode(); + /*if (nextNode.compareTo(builderAddress) == 0) { + logger.warning("Error sending to builder or 0 samples assigned"); + continue; + }*/ + sop.AddMessage(msg.id); + // logger.warning("Send message " + dasID + " " + this); + sendMessage(msg, nextNode, dasID); + sop.nrHops++; + } + return success; } private void createValidatorSamplingOperation(int row, int column, long timestamp) { @@ -676,7 +679,7 @@ private void createValidatorSamplingOperation(int row, int column, long timestam op.elaborateResponse(kv.getAll().toArray(new Sample[0])); op.setAvailableRequests(KademliaCommonConfigDas.ALPHA); while (!doSampling(op)) { - op.increaseRadius(2); + if (op.increaseRadius(2)) break; } } diff --git a/simulator/src/main/java/peersim/kademlia/das/Sample.java b/simulator/src/main/java/peersim/kademlia/das/Sample.java index a4ff4baf..dfa0eb46 100644 --- a/simulator/src/main/java/peersim/kademlia/das/Sample.java +++ b/simulator/src/main/java/peersim/kademlia/das/Sample.java @@ -4,6 +4,7 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import peersim.kademlia.Util; public class Sample { @@ -95,22 +96,24 @@ public boolean isInRegion(BigInteger peerID, BigInteger radius) { /** Given the peerID of a node, determine if this sample falls within the region of the node. */ public boolean isInRegionByColumn(BigInteger peerID, BigInteger radius) { - /** (peerID - radius) < this.id < (peerID + radius) */ - if ((this.idByColumn.compareTo(peerID.subtract(radius)) == 1) - && (this.idByColumn.compareTo(peerID.add(radius)) == -1)) { + // if radius is larger or equal than the distance between the node and the sample ID, the peerID + // is in the region + if (radius.compareTo(Util.xorDistance(this.idByColumn, peerID)) > -1) { return true; - } else { + } + { return false; } } /** Given the peerID of a node, determine if this sample falls within the region of the node. */ public boolean isInRegionByRow(BigInteger peerID, BigInteger radius) { - /** (peerID - radius) < this.id < (peerID + radius) */ - if ((this.idByRow.compareTo(peerID.subtract(radius)) == 1) - && (this.idByRow.compareTo(peerID.add(radius)) == -1)) { + // if radius is larger or equal than the distance between the node and the sample ID, the peerID + // is in the region + if (radius.compareTo(Util.xorDistance(this.idByRow, peerID)) > -1) { return true; - } else { + } + { return false; } } diff --git a/simulator/src/main/java/peersim/kademlia/das/SearchTable.java b/simulator/src/main/java/peersim/kademlia/das/SearchTable.java index 8b3d4e3a..79742475 100644 --- a/simulator/src/main/java/peersim/kademlia/das/SearchTable.java +++ b/simulator/src/main/java/peersim/kademlia/das/SearchTable.java @@ -2,12 +2,10 @@ import java.math.BigInteger; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.TreeSet; +import peersim.kademlia.Util; public class SearchTable { @@ -31,7 +29,7 @@ public void setBlock(Block currentBlock) { this.currentBlock = currentBlock; } - public BigInteger[] getSamples(BigInteger peerId) { + /*public BigInteger[] getSamples(BigInteger peerId) { List result = new ArrayList<>(); Collections.addAll( @@ -46,7 +44,7 @@ public BigInteger[] getSamples(BigInteger peerId) { currentBlock.computeRegionRadius(KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER))); return result.toArray(new BigInteger[0]); - } + }*/ public void addNodes(BigInteger[] nodes) { @@ -68,28 +66,26 @@ public TreeSet nodesIndexed() { return samplesIndexed; }*/ - public List getNodesbySample(BigInteger sampleId, BigInteger radius) { - - BigInteger bottom = sampleId.subtract(radius); - if (radius.compareTo(sampleId) == 1) bottom = BigInteger.ZERO; - - BigInteger top = sampleId.add(radius); - - Collection subSet = nodesIndexed.subSet(bottom, true, top, true); - return new ArrayList(subSet); - - // return sampleMap.get(sampleId); - + // Return nodes that should have the indicate sample + public List getNodesForSample(BigInteger sampleId, BigInteger radius) { + ArrayList result = new ArrayList(); + // TODO we should make it more efficient (now it's O(n)) + for (BigInteger nodeId : nodesIndexed) { + // if radius is larger than the distance between the node and the sample ID, then add the node + // to the result + if (radius.compareTo(Util.xorDistance(nodeId, sampleId)) == 1) result.add(nodeId); + } + return result; } - public List getNodesbySample(Set samples, BigInteger radius) { + BigInteger[] getNodesForSamples(BigInteger[] samples, BigInteger radius) { List result = new ArrayList<>(); for (BigInteger sample : samples) { // if (sampleMap.get(sample) != null) result.addAll(sampleMap.get(sample)); - result.addAll(getNodesbySample(sample, radius)); + result.addAll(getNodesForSample(sample, radius)); } - return result; + return result.toArray(new BigInteger[0]); } } diff --git a/simulator/src/main/java/peersim/kademlia/das/TrafficGeneratorSample.java b/simulator/src/main/java/peersim/kademlia/das/TrafficGeneratorSample.java index b7d3d993..278cee7e 100755 --- a/simulator/src/main/java/peersim/kademlia/das/TrafficGeneratorSample.java +++ b/simulator/src/main/java/peersim/kademlia/das/TrafficGeneratorSample.java @@ -206,22 +206,23 @@ public boolean execute() { int samplesWithinRegion = 0; // samples that are within at least one node's region int totalSamples = 0; + // make nodes request their initial samples directly from the builder while (b.hasNext()) { Sample s = b.next(); boolean inRegion = false; BigInteger radius = b.computeRegionRadius(KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER); - System.out.println( - "New sample " - + s.getRow() - + " " - + s.getColumn() - + " " - + s.getIdByRow() - + " " - + s.getIdByColumn() - + " " - + radius); + /*System.out.println( + "New sample " + + s.getRow() + + " " + + s.getColumn() + + " " + + s.getIdByRow() + + " " + + s.getIdByColumn() + + " " + + radius);*/ while (!inRegion) { for (int i = 0; i < Network.size(); i++) { @@ -243,6 +244,7 @@ public boolean execute() { } } if (!inRegion) { + System.out.println("Increasing radius!!"); radius = radius.multiply(BigInteger.valueOf(2)); } } diff --git a/simulator/src/main/java/peersim/kademlia/das/operations/RandomSamplingOperation.java b/simulator/src/main/java/peersim/kademlia/das/operations/RandomSamplingOperation.java index 82febe4a..ee0048f9 100755 --- a/simulator/src/main/java/peersim/kademlia/das/operations/RandomSamplingOperation.java +++ b/simulator/src/main/java/peersim/kademlia/das/operations/RandomSamplingOperation.java @@ -2,7 +2,6 @@ import java.math.BigInteger; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,22 +48,6 @@ public RandomSamplingOperation( } } - public BigInteger[] getSamples(BigInteger peerId) { - - List list = new ArrayList<>(); - Collections.addAll( - list, - currentBlock.getSamplesByRadiusByRow( - peerId, - currentBlock.computeRegionRadius(KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER))); - Collections.addAll( - list, - currentBlock.getSamplesByRadiusByColumn( - peerId, - currentBlock.computeRegionRadius(KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER))); - return list.toArray(new BigInteger[0]); - } - public boolean completed() { boolean completed = true; diff --git a/simulator/src/main/java/peersim/kademlia/das/operations/SamplingOperation.java b/simulator/src/main/java/peersim/kademlia/das/operations/SamplingOperation.java index e26a8065..2c3000ff 100644 --- a/simulator/src/main/java/peersim/kademlia/das/operations/SamplingOperation.java +++ b/simulator/src/main/java/peersim/kademlia/das/operations/SamplingOperation.java @@ -2,7 +2,6 @@ import java.math.BigInteger; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import peersim.kademlia.das.Block; @@ -14,6 +13,7 @@ public abstract class SamplingOperation extends FindOperation { + // maps sampleID into status (alrady fetched or not) protected HashMap samples; protected SearchTable searchTable; protected int samplesCount = 0; @@ -58,9 +58,7 @@ public SamplingOperation( public abstract boolean completed(); - public abstract BigInteger[] getSamples(BigInteger peerId); - - public BigInteger[] getSamples() { + public BigInteger[] getMissingSamples() { List result = new ArrayList<>(); for (BigInteger sample : samples.keySet()) { @@ -69,8 +67,7 @@ public BigInteger[] getSamples() { return result.toArray(new BigInteger[0]); } - // public abstract BigInteger[] startSampling(); - + /* public BigInteger[] doSampling() { List nextNodes = new ArrayList<>(); @@ -110,9 +107,12 @@ public BigInteger getNeighbour() { return res; } + */ - public void increaseRadius(int multiplier) { + public boolean increaseRadius(int multiplier) { radius = radius.multiply(BigInteger.valueOf(multiplier)); + if (radius.compareTo(Block.MAX_KEY) == 1) return true; + else return false; } public abstract void elaborateResponse(Sample[] sam); @@ -120,4 +120,9 @@ public void increaseRadius(int multiplier) { public int samplesCount() { return samplesCount; } + + public BigInteger getRadius() { + return radius; + } + } diff --git a/simulator/src/main/java/peersim/kademlia/das/operations/ValidatorSamplingOperation.java b/simulator/src/main/java/peersim/kademlia/das/operations/ValidatorSamplingOperation.java index d276a0b8..c98ec1e3 100644 --- a/simulator/src/main/java/peersim/kademlia/das/operations/ValidatorSamplingOperation.java +++ b/simulator/src/main/java/peersim/kademlia/das/operations/ValidatorSamplingOperation.java @@ -2,7 +2,6 @@ import java.math.BigInteger; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -85,35 +84,6 @@ public void elaborateResponse(Sample[] sam) { if (samplesCount >= samples.size() / 2) completed = true; } - public BigInteger[] getSamples(BigInteger peerId) { - - List list = new ArrayList<>(); - if (row > 0) { - Collections.addAll( - list, - currentBlock.getSamplesByRadiusByRow( - peerId, - currentBlock.computeRegionRadius( - KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER))); - } else if (column > 0) { - Collections.addAll( - list, - currentBlock.getSamplesByRadiusByColumn( - peerId, - currentBlock.computeRegionRadius( - KademliaCommonConfigDas.NUM_SAMPLE_COPIES_PER_PEER))); - } - - List result = new ArrayList<>(); - - for (BigInteger s : samples.keySet()) { - if (samples.get(s) != null) { - if (!samples.get(s) && list.contains(s)) result.add(s); - } - } - return result.toArray(new BigInteger[0]); - } - public boolean completed() { return completed; diff --git a/simulator/src/test/java/peersim/kademlia/das/SampleTest.java b/simulator/src/test/java/peersim/kademlia/das/SampleTest.java new file mode 100644 index 00000000..2662ddef --- /dev/null +++ b/simulator/src/test/java/peersim/kademlia/das/SampleTest.java @@ -0,0 +1,75 @@ +package peersim.kademlia.das; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigInteger; +import java.util.HashMap; +import org.junit.jupiter.api.Test; +import peersim.config.Configuration; +import peersim.config.ParsedProperties; +import peersim.core.CommonState; +import peersim.kademlia.KademliaCommonConfig; +import peersim.kademlia.UniformRandomGenerator; + +public class SampleTest { + + protected static void setUpBeforeClass() { + String[] array = new String[] {"config/dasprotocol.cfg"}; + Configuration.setConfig(new ParsedProperties(array)); + CommonState.setEndTime(Long.parseLong("100")); + CommonState.setTime(Long.parseLong("0")); + } + + @Test + public void nodeAssigment() { + + int n = 100; + int redundancy = 2; + int mSize = 100; + int idSize = 256; + KademliaCommonConfig.BITS = idSize; + // BigInteger[] nodes = new BigInteger[n]; + UniformRandomGenerator urg = new UniformRandomGenerator(idSize, 1); + HashMap nodeMap = new HashMap<>(); + BigInteger rad = urg.getMaxID().divide(BigInteger.valueOf(n)); + // System.out.println("Max id:" + urg.getMaxID() + " " + rad); + for (int i = 0; i < n; i++) { + nodeMap.put(rad.multiply(BigInteger.valueOf(i)), 0); + // nodeMap.put(urg.generate(), 0); + } + + Block b = new Block(mSize, 0); + int samplesWithinRegion = 0; // samples that are within at least one node's region + int totalSamples = 0; + + BigInteger MAX_KEY = + BigInteger.ONE.shiftLeft(KademliaCommonConfig.BITS).subtract(BigInteger.ONE); + + BigInteger radius = + MAX_KEY.divide(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(redundancy)); + + while (b.hasNext()) { + Sample s = b.next(); + boolean assigned = false; + for (BigInteger id : nodeMap.keySet()) { + Integer i = nodeMap.get(id); + + if (s.isInRegionByRow(id, radius)) { + + i++; + totalSamples++; + assigned = true; + nodeMap.put(id, i); + } + } + if (assigned) samplesWithinRegion++; + else System.out.println("Not assigned !"); + totalSamples++; + } + + assertEquals(samplesWithinRegion, mSize * mSize); + System.out.println("Samples assgined:" + totalSamples + " " + samplesWithinRegion); + + // assertEquals(1, 2); + } +}