Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:mase.spec.BasicHybridExchangerDunn.java

@Override
protected void mergeProcess(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));
            }//from   www . j av a 2  s  .c  o  m
        }
    }
    distanceMatrix = distanceMatrix(mpBehavs, state);
    Pair<MetaPopulation, MetaPopulation> nextMerge = metaPops.size() >= 3 ? findNextMerge(distanceMatrix, state)
            : null;

    // Merge if they are similar
    if (nextMerge != null) {
        state.output.message("*************************** Merging " + nextMerge.getLeft() + " with "
                + nextMerge.getRight() + " ***************************");
        merges++;
        MetaPopulation mpNew = mergePopulations(nextMerge.getLeft(), nextMerge.getRight(), state);
        metaPops.remove(nextMerge.getLeft());
        metaPops.remove(nextMerge.getRight());
        metaPops.add(mpNew);
    }
}

From source file:net.duckling.ddl.util.EncodeUtil.java

private static int getRandomNumber() {
    double a = Math.random() * 10;
    a = Math.ceil(a);
    int decimal = new Double(a).intValue();
    return decimal % 10;
}

From source file:org.jamwiki.utils.ImageUtil.java

/**
 *
 *///ww w  . ja  v  a  2s  .c o  m
private static int calculateImageIncrement(int maxDimension) {
    int increment = Environment.getIntValue(Environment.PROP_IMAGE_RESIZE_INCREMENT);
    double result = Math.ceil((double) maxDimension / (double) increment) * increment;
    return (int) result;
}

From source file:brickhouse.udf.bloom.BloomFactory.java

public static Filter NewBloomInstance(int expectedNumberOfElements, double falsePositiveProbability) {
    return NewBloomInstance(Math.ceil(-(Math.log(falsePositiveProbability) / Math.log(2))) / Math.log(2), // c = k / ln(2)
            expectedNumberOfElements, (int) Math.ceil(-(Math.log(falsePositiveProbability) / Math.log(2)))); // k = ceil(-log_2(false prob.))

}

From source file:Main.java

private static boolean unprotectedTest(int i) {
    for (int n = 2, max = (int) Math.ceil(Math.sqrt(i)); n <= max; n++) {
        if (i % n == 0) {
            return false;
        }//from  w  w  w . j  a  v a  2 s .c om
    }
    return true;
}

From source file:myjpa.guest.control.GuestController.java

@RequestMapping("/show.htm")
public String show(Model model, @RequestParam(value = "no", defaultValue = "0") int pageNo) {
    final int PAGE_SIZE = 3;
    // Calculate start record by page number and page size
    int start = pageNo * PAGE_SIZE;

    int numPage = (int) Math.ceil(guests.count() / PAGE_SIZE);

    List<Guest> list = guests.findAll(start, PAGE_SIZE);

    model.addAttribute("list", list);
    model.addAttribute("guest", new Guest());

    model.addAttribute("numPage", numPage);

    return "show";
}

From source file:com.websystique.springmvc.dao.LessonDAO.java

@SuppressWarnings("unchecked")
public SearchPair<Lesson> getLessons(int page, String orderby, String sorter) {
    String sql = "SELECT * FROM lessons ORDER BY " + orderby + " " + sorter;
    Query query = getSession().createSQLQuery(sql).addEntity(Lesson.class);

    query.setFirstResult(Parameters.maxLessonsInResult * page);
    query.setMaxResults(Parameters.maxLessonsInResult);

    List<Lesson> list = query.list();
    int total = 0;
    sql = "SELECT COUNT(id) FROM lessons";
    query = getSession().createSQLQuery(sql);
    total = (int) Math.ceil(((Integer) query.uniqueResult()) / Parameters.maxLessonsInResult);

    return new <Lesson>SearchPair(list, total);
}

From source file:simulation.LoadBalancer.java

public void addLoad(List<SimVehicle> vehicles) {
    int groupPartition = 0;
    int vehiclesPerGroup = (int) Math.ceil((double) vehicles.size() / 15);

    if (!vehicles.isEmpty()) {
        for (List<SimVehicle> partition : Lists.partition(vehicles, vehiclesPerGroup)) {
            vehicleLists.get(groupPartition).addAll(partition);
            groupPartition++;//www  . j  a va  2 s. co m
        }
    } else {
        System.out.println("Vehiclelist Empty");
    }
}

From source file:com.linkedin.pinot.core.segment.creator.impl.fwd.SingleValueUnsortedForwardIndexCreator.java

public static int getNumOfBits(int dictionarySize) {
    if (dictionarySize < 2) {
        return 1;
    }//from   w  w  w  .j  a  va  2 s . co  m
    int ret = (int) Math.ceil(Math.log(dictionarySize) / Math.log(2));
    if (ret == 0) {
        ret = 1;
    }
    return ret;
}

From source file:joinery.impl.Display.java

public static <C extends Container, V> C draw(final DataFrame<V> df, final C container, final PlotType type) {
    final List<XChartPanel> panels = new LinkedList<>();
    final DataFrame<Number> numeric = df.numeric().fillna(0);
    final int rows = (int) Math.ceil(Math.sqrt(numeric.size()));
    final int cols = numeric.size() / rows + 1;

    final List<Object> xdata = new ArrayList<>(df.length());
    final Iterator<Object> it = df.index().iterator();
    for (int i = 0; i < df.length(); i++) {
        final Object value = it.hasNext() ? it.next() : i;
        if (value instanceof Number || value instanceof Date) {
            xdata.add(value);//from  w ww.  jav  a  2 s . co m
        } else if (PlotType.BAR.equals(type)) {
            xdata.add(String.valueOf(value));
        } else {
            xdata.add(i);
        }
    }

    if (EnumSet.of(PlotType.GRID, PlotType.GRID_WITH_TREND).contains(type)) {
        for (final Object col : numeric.columns()) {
            final Chart chart = new ChartBuilder().chartType(chartType(type)).width(800 / cols)
                    .height(800 / cols).title(String.valueOf(col)).build();
            final Series series = chart.addSeries(String.valueOf(col), xdata, numeric.col(col));
            if (type == PlotType.GRID_WITH_TREND) {
                addTrend(chart, series, xdata);
                series.setLineStyle(SeriesLineStyle.NONE);
            }
            chart.getStyleManager().setLegendVisible(false);
            chart.getStyleManager().setDatePattern(dateFormat(xdata));
            panels.add(new XChartPanel(chart));
        }
    } else {
        final Chart chart = new ChartBuilder().chartType(chartType(type)).build();

        chart.getStyleManager().setDatePattern(dateFormat(xdata));
        switch (type) {
        case SCATTER:
        case SCATTER_WITH_TREND:
        case LINE_AND_POINTS:
            break;
        default:
            chart.getStyleManager().setMarkerSize(0);
            break;
        }

        for (final Object col : numeric.columns()) {
            final Series series = chart.addSeries(String.valueOf(col), xdata, numeric.col(col));
            if (type == PlotType.SCATTER_WITH_TREND) {
                addTrend(chart, series, xdata);
                series.setLineStyle(SeriesLineStyle.NONE);
            }
        }

        panels.add(new XChartPanel(chart));
    }

    if (panels.size() > 1) {
        container.setLayout(new GridLayout(rows, cols));
    }
    for (final XChartPanel p : panels) {
        container.add(p);
    }

    return container;
}