List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.karusmc.commandwork.reference.help.HelpParser.java
public int getTotalPages(int listSize, int pageSize) { if (listSize != 0) { return (int) Math.max(1, Math.ceil((double) listSize / pageSize)); } else {//from w ww.j a v a 2 s .c o m return 0; } }
From source file:mase.spec.BasicHybridExchangerDunn.java
@Override protected Pair<MetaPopulation, MetaPopulation> findNextMerge(double[][] distanceMatrix, EvolutionState state) { List<BehaviourResult>[] mpBehavs = new List[metaPops.size()]; for (int i = 0; i < metaPops.size(); i++) { MetaPopulation mp = metaPops.get(i); Individual[] inds = getElitePortion(mp.inds, (int) Math.ceil(elitePortion * popSize)); mpBehavs[i] = new ArrayList<BehaviourResult>(mp.agents.size() * inds.length); for (Individual ind : inds) { for (Integer a : mp.agents) { mpBehavs[i].add(getAgentBR(ind, a)); }/* w w w.j av a 2 s . c o m*/ } } double currentDunn = dunnIndex(distanceMatrix); System.out.println("Current dunn: " + currentDunn); Pair<MetaPopulation, MetaPopulation> next = null; for (int i = 0; i < metaPops.size(); i++) { for (int j = 0; j < metaPops.size(); j++) { MetaPopulation mpi = metaPops.get(i); MetaPopulation mpj = metaPops.get(j); if (i != j && mpi.age > stabilityTime && mpj.age > stabilityTime) { List<BehaviourResult>[] hypothesis = new List[metaPops.size() - 1]; List<BehaviourResult> merged = new ArrayList<BehaviourResult>(); merged.addAll(mpBehavs[i]); merged.addAll(mpBehavs[j]); int index = 0; hypothesis[index++] = merged; for (int k = 0; k < mpBehavs.length; k++) { if (k != i && k != j) { hypothesis[index++] = mpBehavs[k]; } } double[][] dists = distanceMatrix(hypothesis, state); double dunn = dunnIndex(dists); System.out.println("Hypothesis merge " + mpi + " with " + mpj + ": " + dunn); if (dunn > currentDunn) { currentDunn = dunn; next = Pair.of(mpi, mpj); } } } } return next; }
From source file:com.simpsonwil.strongquests.util.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body);//ww w.j av a2 s . c o m JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.cnaude.mutemanager.UUIDFetcher.java
@Override public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body);/* w ww . j ava 2 s. c o m*/ JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:BucketizedHashtable.java
/** * Constructs a new, empty BucketizedHashtable with the specified bucket * size, initial capacity and load factor. * @param bucketSize the number of buckets used for hashing * @param initialCapacity the initial capacity of BucketizedHashtable * @param loadFactor the load factor of hashtable */// w w w .ja v a 2 s. c o m public BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor) { if (bucketSize <= 0 || initialCapacity < 0) { throw new IllegalArgumentException(); } this.bucketSize = bucketSize; hashtables = new Hashtable[bucketSize]; // always round up to the nearest integer so that it has at // least the initialCapacity int initialHashtableSize = (int) Math.ceil((double) initialCapacity / bucketSize); for (int i = 0; i < bucketSize; i++) { hashtables[i] = new Hashtable(initialHashtableSize, loadFactor); } }
From source file:Main.java
/** * Calculates the optimal hash capacity for given maximum size and the * load factor./*from www . j a v a 2 s. c o m*/ * * @param size maximum size of the collection * @param loadFactor usage percentage before a rehash occurs. Default value for * Collections framework is 0.75. Lower values result in less * chance of collisions at the expense of larger memory footprint * @return the optimal hash capacity */ public static int calcHashCapacity(int size, float loadFactor) { return (int) Math.ceil(size / loadFactor); }
From source file:com.mgmtp.perfload.perfalyzer.binning.BinManager.java
/** * @param domainStart/*from w ww . j a va2s. c o m*/ * the domain value where binning starts * @param binSize * the bin size */ public BinManager(final double domainStart, final int binSize) { this.domainStart = domainStart; this.binSize = binSize; this.indexOffset = (int) Math.ceil(domainStart / binSize); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java
/** * Returns a point based on (x, y) but constrained to be within the bounds * of the given rectangle. This method could be moved to JCommon. * * @param x the x-coordinate./*from w ww . j av a 2 s . c o m*/ * @param y the y-coordinate. * @param area the rectangle (<code>null</code> not permitted). * * @return A point within the rectangle. */ protected Point getPointInRectangle(int x, int y, Rectangle2D area) { x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX()))); y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY()))); return new Point(x, y); }
From source file:juicebox.tools.utils.juicer.hiccups.GPUController.java
public GPUController(int window, int matrixSize, int peakWidth, int divisor) { String kernelCode = GPUKernel.kernelCode(window, matrixSize, peakWidth, divisor); kernelLauncher = KernelLauncher.compile(kernelCode, GPUKernel.kernelName); //threads per block = block_size*block_size kernelLauncher.setBlockSize(blockSize, blockSize, 1); // for grid of blocks int gridSize = (int) Math.ceil(matrixSize * 1.0 / blockSize); kernelLauncher.setGridSize(gridSize, gridSize); }
From source file:es.udc.gii.common.eaf.algorithm.restart.IPOPRestartStrategy.java
@Override public void restart(EvolutionaryAlgorithm algorithm) { int curr_pop_size, new_pop_size; if (curr_num_restarts < max_num_restarts) { curr_num_restarts++;/*from ww w. jav a2 s. com*/ curr_pop_size = algorithm.getPopulation().getSize(); new_pop_size = (int) Math.ceil(curr_pop_size * Math.pow(this.incr_factor, this.curr_num_restarts)); //Re-configure the algorithm: algorithm.configure(EAFConfiguration.getInstance()); algorithm.setPopulationSize(new_pop_size); algorithm.setState(EvolutionaryAlgorithm.INIT_STATE); } else { //Continue with the algorithm: algorithm.setState(EvolutionaryAlgorithm.SELECT_STATE); } }