public List<RangeDimensionRange> partition( List<RangeDimensionRange> ranges, int num, Collection<Rule> rules, Aggregator aggregator) { int rangePerOutputRange = (int) (Math.ceil(1.0 * ranges.size() / num)); List<RangeDimensionRange> outputRanges = new ArrayList<RangeDimensionRange>(num); for (int i = 0; i < ranges.size(); i += rangePerOutputRange) { RangeDimensionRange dimensionRange = ranges.get(i); outputRanges.add( new RangeDimensionRange( dimensionRange.getStart(), ranges.get(Math.min(i + rangePerOutputRange, ranges.size()) - 1).getEnd(), dimensionRange.getInfo())); } return outputRanges; }
protected List<Long> findSortedSrcEdges(Collection<Rule> rules) { final Set<Long> srcIPs = new HashSet<Long>(rules.size() * 2 + 1, 1); int srcIPIndex = Util.getDimensionInfoIndex(Util.SRC_IP_INFO); for (Rule rule : rules) { RangeDimensionRange property = rule.getProperty(srcIPIndex); srcIPs.add(property.getStart()); srcIPs.add(property.getEnd()); } List<Long> ipsSorted = new ArrayList<Long>(srcIPs); for (Long srcIP : srcIPs) { ipsSorted.add(srcIP); } Collections.sort(ipsSorted); return ipsSorted; }
@Override public Collection<Long> getIps(Collection<Rule> rules, Random random, int numberOfIPs) { Set<Long> output = new HashSet<Long>(); while (output.size() < numberOfIPs) { // output.add(Util.SRC_IP_INFO.getDimensionRange().getRandomNumber(random)); RangeDimensionRange dimensionRange = Util.SRC_IP_INFO.getDimensionRange(); double randomNum; do { randomNum = random.nextGaussian() * std + mean; } while (randomNum < 0 || randomNum >= 1); output.add(dimensionRange.getStart() + (long) (dimensionRange.getSize() * randomNum)); // output.add(dimensionRange.getRandomNumber(random)); } return output; }