List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.firesoft.member.Model.HomeModel.java
public void getServiceTypeListMore() { servicetypelistRequest request = new servicetypelistRequest(); request.by_no = (int) Math.ceil(publicServiceTypeList.size() * 1.0 / NUMPERPAGE) + 1; ;//from w w w . j av a2 s. c om request.count = NUMPERPAGE; request.sid = SESSION.getInstance().sid; request.uid = SESSION.getInstance().uid; request.ver = MemberAppConst.VERSION_CODE; BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() { @Override public void callback(String url, JSONObject jo, AjaxStatus status) { try { HomeModel.this.callback(this, url, jo, status); if (null != jo) { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(jo); publicMore = response.more; if (response.succeed == 1) { publicServiceTypeList.addAll(response.services); publicServiceTypeLisSort.addAll(response.services); sortList(); HomeModel.this.OnMessageResponse(url, jo, status); } else { HomeModel.this.callback(url, response.error_code, response.error_desc); } } } catch (JSONException e) { } } ; }; Map<String, Object> params = new HashMap<String, Object>(); try { params.put("json", request.toJson().toString()); } catch (JSONException e) { } if (isSendingMessage(ApiInterface.SERVICETYPE_LIST)) { return; } cb.url(ApiInterface.SERVICETYPE_LIST).type(JSONObject.class).params(params); ajax(cb); }
From source file:com.insthub.O2OMobile.Model.HomeModel.java
public void getServiceTypeListMore() { servicetypelistRequest request = new servicetypelistRequest(); request.by_no = (int) Math.ceil(publicServiceTypeList.size() * 1.0 / NUMPERPAGE) + 1; ;/*from ww w . j a va 2s . c om*/ request.count = NUMPERPAGE; request.sid = SESSION.getInstance().sid; request.uid = SESSION.getInstance().uid; request.ver = O2OMobileAppConst.VERSION_CODE; BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() { @Override public void callback(String url, JSONObject jo, AjaxStatus status) { try { HomeModel.this.callback(this, url, jo, status); if (null != jo) { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(jo); publicMore = response.more; if (response.succeed == 1) { publicServiceTypeList.addAll(response.services); publicServiceTypeLisSort.addAll(response.services); sortList(); HomeModel.this.OnMessageResponse(url, jo, status); } else { HomeModel.this.callback(url, response.error_code, response.error_desc); } } } catch (JSONException e) { } } ; }; Map<String, Object> params = new HashMap<String, Object>(); try { params.put("json", request.toJson().toString()); } catch (JSONException e) { } if (isSendingMessage(ApiInterface.SERVICETYPE_LIST)) { return; } cb.url(ApiInterface.SERVICETYPE_LIST).type(JSONObject.class).params(params); ajax(cb); }
From source file:edu.oregonstate.eecs.mcplan.domains.voyager.policies.AttackPolicy.java
@Override public VoyagerAction getAction() { final ArrayList<Planet> friendly_planets = Voyager.playerPlanets(s_, self_); final ArrayList<Planet> enemy_planets = Voyager.playerPlanets(s_, self_.enemy()); // Consider launch actions: // 1. Find the closest friendly-{enemy, neutral} pair. // TODO: Need to make sure it's not already targeted // 2. If we can safely capture from the nearest planet, do it. // 3. If not, transfer some Soldiers from another planet to the // friendly planet. // 4. If all else fails, see if we would like to re-balance workers. if (friendly_planets.size() == 0 || enemy_planets.size() == 0) { return new NothingAction(); }/*from w ww.j av a 2s .c om*/ double nn_strength = Voyager.defense_strength(target_.population()); final int enemy_strength = Fn.sum(Fn.map(new Fn.IntFunction1<Planet>() { @Override public int apply(final Planet p) { return Voyager.defense_strength(p.population()); } }, new Fn.ArraySlice<Planet>(s_.planets))); nn_strength += win_margin_ * enemy_strength; final int points_needed = Math.max((int) Math.ceil(nn_strength), 1); final Planet near_friendly = Voyager.nearest(target_, friendly_planets); final int[] nf_pop = Arrays.copyOf(near_friendly.population(), Unit.values().length); nf_pop[Unit.Worker.ordinal()] = (int) Math.floor(combat_worker_ratio_ * nf_pop[Unit.Worker.ordinal()]); final int nf_strength = Voyager.defense_strength(nf_pop); final int spare_workers = Math.max(0, nf_pop[Unit.Worker.ordinal()] - 1); final int spare_soldiers = Math.max(0, nf_pop[Unit.Soldier.ordinal()] - 1); // FIXME: Sending workers is pointless since they now have 0 strength. // Fix it better! final int usable_workers = 0; //Math.min( target_.capacity, spare_workers ); final int soldiers_needed = Math.max(0, (int) Math.ceil(points_needed / (double) Unit.Soldier.attack())); if (spare_soldiers >= soldiers_needed) { final int[] launch_pop = new int[Unit.values().length]; launch_pop[Unit.Soldier.ordinal()] = soldiers_needed; launch_pop[Unit.Worker.ordinal()] = usable_workers; return new LaunchAction(near_friendly, target_, launch_pop); } { // Can't take near_nonfriendly directly; reinforce near_friendly. final Planet n = near_friendly; Collections.sort(friendly_planets, new Comparator<Planet>() { @Override public int compare(final Planet a, final Planet b) { return (int) (Voyager.sq_distance(a, n) - Voyager.sq_distance(b, n)); } }); for (final Planet p : friendly_planets) { // TODO: Magic number 2 if (p.id != near_friendly.id && p.population(Unit.Soldier) > 2) { final int[] launch_pop = new int[Unit.values().length]; launch_pop[Unit.Soldier.ordinal()] = (int) Math .floor(reinforce_soldier_ratio_ * p.population(Unit.Soldier)); return new LaunchAction(p, near_friendly, launch_pop); } } } return new NothingAction(); }
From source file:com.intel.stl.ui.common.view.DistributionPiePanel.java
public void setLabels(String[] itemNames, ImageIcon[] icons, int labelColumns) { if (icons.length != itemNames.length) { throw new IllegalArgumentException( "Inconsistent number of items. " + " itemNames=" + itemNames.length + " icons=" + icons.length); }// w w w.j ava 2 s. c o m labels = new JLabel[icons.length]; for (int i = 0; i < icons.length; i++) { labels[i] = new JLabel(itemNames[i], icons[i], JLabel.LEFT); } int rows = 1; if (labelColumns <= 0) { labelPanel.setLayout(new FlowLayout()); for (JLabel label : labels) { labelPanel.add(label); } } else { BoxLayout layout = new BoxLayout(labelPanel, BoxLayout.X_AXIS); labelPanel.setLayout(layout); JPanel[] columns = new JPanel[labelColumns]; for (int i = 0; i < columns.length; i++) { labelPanel.add(Box.createHorizontalGlue()); columns[i] = new JPanel(); columns[i].setOpaque(false); columns[i].setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3)); BoxLayout cLayout = new BoxLayout(columns[i], BoxLayout.Y_AXIS); columns[i].setLayout(cLayout); labelPanel.add(columns[i]); } labelPanel.add(Box.createHorizontalGlue()); rows = (int) Math.ceil((double) labels.length / labelColumns); int index = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < labelColumns; j++) { columns[i].add(index < labels.length ? labels[index] : Box.createGlue()); index += 1; } } } }
From source file:cc.redberry.core.number.Exponentiation.java
public static Complex findIntegerRoot(Complex base, BigInteger power) { BigInteger rDenominator = ((Rational) base.getReal()).getDenominator(); BigInteger iDenominator = ((Rational) base.getImaginary()).getDenominator(); BigInteger lcm = rDenominator.gcd(iDenominator); lcm = rDenominator.divide(lcm);/* w w w . j a v a 2 s . com*/ lcm = lcm.multiply(iDenominator); BigInteger lcmRoot = findIntegerRoot(lcm, power); if (lcm == null) return null; base = base.multiply(lcm); Complex numericValue = base.pow(1.0 / power.doubleValue()); double real = numericValue.getReal().doubleValue(); double imaginary = numericValue.getImaginary().doubleValue(); int ceilReal = (int) Math.ceil(real), floorReal = (int) Math.floor(real), ceilImaginary = (int) Math.ceil(imaginary), floorImaginary = (int) Math.floor(imaginary); Complex candidate; if ((candidate = new Complex(ceilReal, ceilImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(floorReal, ceilImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(ceilReal, floorImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); if ((candidate = new Complex(floorReal, floorImaginary)).pow(power).equals(base)) return candidate.divide(lcmRoot); return null; }
From source file:com.sw.plugins.customer.organization.service.MemberOrganizationService.java
/** * ??MAP?/*from w ww.j av a 2 s. c o m*/ */ public Map<String, Object> getGrid(MemberOrganization entity) throws Exception { List<MemberOrganization> resultList = null; Map<String, Object> map = new Hashtable<String, Object>(); // resultList = getPaginatedList(entity); // long record = this.getRecordCount(entity); // int pageCount = (int) Math.ceil(record / (double) entity.getRows()); map.put("rows", resultList); map.put("page", entity.getPage()); map.put("total", pageCount); map.put("records", record); return map; }
From source file:gdsc.smlm.ij.results.PSFImagePeakResults.java
private void addPeak(int peak, int origX, int origY, float origValue, double chiSquared, float noise, float[] params, float[] paramsDev) { float x = (params[3] - bounds.x) * scale; float y = (params[4] - bounds.y) * scale; // Check bounds if (x < 0 || x > xlimit || y < 0 || y > ylimit) return;// w ww. j ava 2 s. c o m checkAndUpdateToFrame(peak); // Initialise for a free Gaussian function: // f(x,y) = A exp(-(a(x-x0)(x-x0) + 2b(x-x0)(y-y0) + c(y-y0)(y-y0))) // See: http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function final float amplitude = ((displayFlags & DISPLAY_SIGNAL) != 0) ? PeakResult.getAmplitude(params) : 1; final double[] psfParams; if (fixedWidth) { psfParams = fixedParams; } else { // Precalculate multiplication factors final double t, sx, sy; if (calculatedPrecision && nmPerPixel > 0) { t = 0.0; final double N = params[Gaussian2DFunction.SIGNAL] / gain; final double s = (params[Gaussian2DFunction.X_SD] + params[Gaussian2DFunction.Y_SD]) * 0.5 * nmPerPixel; final double precision = PeakResult.getPrecision(nmPerPixel, s, N, noise / gain, emCCD); sx = sy = (precision / nmPerPixel); } else { t = params[Gaussian2DFunction.ANGLE]; sx = params[Gaussian2DFunction.X_SD]; sy = params[Gaussian2DFunction.Y_SD]; } psfParams = setPSFParameters(t, sx, sy, new double[5]); } final double a = psfParams[0]; final double b = psfParams[1]; final double c = psfParams[2]; final double width = psfParams[3]; final double height = psfParams[4]; // Use 0.5 offset to centre the value in the middle of each pixel x -= 0.5 / scale; y -= 0.5 / scale; int xmin = (int) Math.floor(x - width * scale); int xmax = (int) Math.ceil(x + width * scale); int ymin = (int) Math.floor(y - height * scale); int ymax = (int) Math.ceil(y + height * scale); // Clip range xmin = FastMath.max(xmin, 0); xmax = (int) FastMath.min(xmax, xlimit); ymin = FastMath.max(ymin, 0); ymax = (int) FastMath.min(ymax, ylimit); // Compute Gaussian PSF final int[] index = new int[(xmax - xmin + 1) * (ymax - ymin + 1)]; final float[] value = new float[index.length]; int i = 0; for (int y0 = ymin; y0 <= ymax; y0++) for (int x0 = xmin; x0 <= xmax; x0++) { int ii = y0 * imageWidth + x0; index[i] = ii; final float dx = (x0 - x) / scale; final float dy = (y0 - y) / scale; value[i] = (float) (amplitude * FastMath.exp(a * dx * dx + b * dx * dy + c * dy * dy)); i++; } // Now add the values to the configured indices synchronized (data) { size++; while (i-- > 0) { data[index[i]] += value[i]; } } }
From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java
@Override public Map<String, UUID> call() throws Exception { final Map<String, UUID> uuidMap = new HashMap<>(); final int requests = (int) Math.ceil(this.names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { final HttpURLConnection connection = createConnection(); final String body = JSONArray .toJSONString(this.names.subList(i * 100, Math.min((i + 1) * 100, this.names.size()))); writeBody(connection, body);//from w ww . ja v a2s . c om final JSONArray array = (JSONArray) this.jsonParser .parse(new InputStreamReader(connection.getInputStream())); for (final Object profile : array) { final JSONObject jsonProfile = (JSONObject) profile; final String id = (String) jsonProfile.get("id"); final String name = (String) jsonProfile.get("name"); final UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (this.rateLimiting && (i != (requests - 1))) { Thread.sleep(100L); } } return uuidMap; }
From source file:edu.scripps.fl.curves.plot.GCurvePlot.java
public String getURL() { XYLineChart chart = GCharts.newXYLineChart(lines); chart.setLegendPosition(LegendPosition.BOTTOM); chart.setSize(getWidth(), getHeight()); chart.setTitle(title, Color.BLACK, 14); // Defining axis info and styles AxisStyle axisStyle = AxisStyle.newAxisStyle(Color.BLACK, 12, AxisTextAlignment.CENTER); AxisLabels yAxis = AxisLabelsFactory.newNumericRangeAxisLabels(-25, 125, 25); yAxis.setAxisStyle(axisStyle);//from w ww.java 2 s . c om AxisLabels xAxis = AxisLabelsFactory.newNumericRangeAxisLabels(Math.floor(minX), Math.ceil(maxX), 1.0); xAxis.setAxisStyle(axisStyle); chart.addYAxisLabels(yAxis); chart.addXAxisLabels(xAxis); // chart.setGrid(100, 6.78, 5, 0); // Defining background and chart fills. chart.setBackgroundFill(Fills.newSolidFill(getBackgroundColor())); chart.setAreaFill(Fills.newSolidFill(getBackgroundColor())); String url = chart.toURLString(); return url; }
From source file:com.clust4j.algo.preprocess.impute.BootstrapImputation.java
@Override public double[][] transform(final double[][] dat) { checkMat(dat);//from ww w .java2 s. c o m final LogTimer timer = new LogTimer(); final boolean mean = ctm.equals(CentralTendencyMethod.MEAN); final double[][] complete = MatUtils.completeCases(dat); if (complete.length == 0) { error(new NaNException("(" + getName() + ") no complete records in matrix")); } final int m = dat.length, n = dat[0].length; final int mc = complete.length; final int ms = (int) Math.ceil(ratio * mc); final double[][] sampled = strap.sample(complete, ms, getSeed()); info("(" + getName() + ") performing bootstrap imputation on " + m + " x " + n + " dataset"); info("(" + getName() + ") " + mc + " complete records found in matrix, " + ms + " records sampled for imputation"); final double[][] copy = MatUtils.copy(dat); for (int col = 0; col < n; col++) { double val; if (mean) { double sum = 0; for (int row = 0; row < ms; row++) sum += sampled[row][col]; val = sum / (double) ms; } else { val = VecUtils.median(MatUtils.getColumn(sampled, col)); } // Impute int nanCt = 0; for (int row = 0; row < m; row++) { if (Double.isNaN(copy[row][col])) { copy[row][col] = val; nanCt++; } } info("(" + getName() + ") " + nanCt + " NaN" + (nanCt != 1 ? "s" : "") + " identified in column " + col + " (imputation value=" + mean + ")"); } sayBye(timer); return copy; }