Example usage for java.lang Double MAX_VALUE

List of usage examples for java.lang Double MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Double MAX_VALUE.

Prototype

double MAX_VALUE

To view the source code for java.lang Double MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type double , (2-2-52)·21023.

Usage

From source file:com.github.rinde.rinsim.examples.demo.factory.FactoryExample.java

static ImmutableList<Point> getBorderNodes(Graph<?> g) {
    final Set<Point> points = g.getNodes();
    double xMin = Double.MAX_VALUE;
    double yMin = Double.MAX_VALUE;
    double xMax = Double.MIN_VALUE;
    double yMax = Double.MIN_VALUE;

    for (final Point p : points) {
        xMin = Math.min(xMin, p.x);
        yMin = Math.min(yMin, p.y);
        xMax = Math.max(xMax, p.x);
        yMax = Math.max(yMax, p.y);
    }/*from  w w  w .  j a v  a 2 s  . c  o m*/
    final ImmutableList.Builder<Point> builder = ImmutableList.builder();
    for (final Point p : points) {
        if (p.x == xMin || p.x == xMax || p.y == yMin || p.y == yMax) {
            builder.add(p);
        }
    }
    return builder.build();
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@BeforeClass
public static void initialSetup() {
    arrayB = new byte[] { 0, 1, 5, 50, 100 };
    arrayUS = new short[] { 0, 1, 5, 50, 100 };
    arrayS = new short[] { -10, 0, 5, 50, 100 };
    arrayI = new int[] { -10, 0, 5, 50, 100 };
    arrayF = new float[] { -10, 0, 5, 50, 100 };
    arrayD = new double[] { -10, 0, 5, 50, 100 };
    arrayL = new long[] { -10, 0, 5, 50, 100 };

    rangeB2bounds = RangeFactory.create((byte) 2, true, (byte) 60, true);
    rangeBpoint = RangeFactory.create(arrayB[2], true, arrayB[2], true);
    rangeU2bounds = RangeFactory.createU((short) 2, true, (short) 60, true);
    rangeUpoint = RangeFactory.createU(arrayUS[2], true, arrayUS[2], true);
    rangeS2bounds = RangeFactory.create((short) 1, true, (short) 60, true);
    rangeSpoint = RangeFactory.create(arrayS[2], true, arrayS[2], true);
    rangeI2bounds = RangeFactory.create(1, true, 60, true);
    rangeIpoint = RangeFactory.create(arrayI[2], true, arrayI[2], true);
    rangeF2bounds = RangeFactory.create(0.5f, true, 60.5f, true, false);
    rangeFpoint = RangeFactory.create(arrayF[2], true, arrayF[2], true, false);
    rangeD2bounds = RangeFactory.create(1.5d, true, 60.5d, true, false);
    rangeDpoint = RangeFactory.create(arrayD[2], true, arrayD[2], true, false);
    rangeL2bounds = RangeFactory.create(1L, true, 60L, true);
    rangeLpoint = RangeFactory.create(arrayL[2], true, arrayL[2], true);

    arrayBtest = new Byte[100];
    arrayStest = new Short[100];
    arrayItest = new Integer[100];
    arrayFtest = new Float[100];
    arrayDtest = new Double[100];

    // Random value creation for the various Ranges
    for (int j = 0; j < 100; j++) {
        double randomValue = Math.random();

        arrayBtest[j] = (byte) (randomValue * (Byte.MAX_VALUE - Byte.MIN_VALUE) + Byte.MIN_VALUE);
        arrayStest[j] = (short) (randomValue * (Short.MAX_VALUE - Short.MIN_VALUE) + Short.MIN_VALUE);
        arrayItest[j] = (int) (randomValue * (Integer.MAX_VALUE - Integer.MIN_VALUE) + Integer.MIN_VALUE);
        arrayFtest[j] = (float) (randomValue * (Float.MAX_VALUE - Float.MIN_VALUE) + Float.MIN_VALUE);
        arrayDtest[j] = (randomValue * (Double.MAX_VALUE - Double.MIN_VALUE) + Double.MIN_VALUE);
    }//w  w w .j  a v a2s .  c  om

    // JAI tools Ranges
    rangeJTB = org.jaitools.numeric.Range.create((byte) 1, true, (byte) 60, true);
    rangeJTS = org.jaitools.numeric.Range.create((short) 1, true, (short) 60, true);
    rangeJTI = org.jaitools.numeric.Range.create(1, true, 60, true);
    rangeJTF = org.jaitools.numeric.Range.create(0.5f, true, 60.5f, true);
    rangeJTD = org.jaitools.numeric.Range.create(1.5d, true, 60.5d, true);
    // 1 point Ranges
    rangeJTBpoint = org.jaitools.numeric.Range.create((byte) 5, true, (byte) 5, true);
    rangeJTSpoint = org.jaitools.numeric.Range.create((short) 5, true, (short) 5, true);
    rangeJTIpoint = org.jaitools.numeric.Range.create(5, true, 5, true);
    rangeJTFpoint = org.jaitools.numeric.Range.create(5f, true, 5f, true);
    rangeJTDpoint = org.jaitools.numeric.Range.create(5d, true, 5d, true);

    // JAI Ranges
    rangeJAIB = new javax.media.jai.util.Range(Byte.class, (byte) 1, true, (byte) 60, true);
    rangeJAIS = new javax.media.jai.util.Range(Short.class, (short) 1, true, (short) 60, true);
    rangeJAII = new javax.media.jai.util.Range(Integer.class, 1, true, 60, true);
    rangeJAIF = new javax.media.jai.util.Range(Float.class, 0.5f, true, 60.5f, true);
    rangeJAID = new javax.media.jai.util.Range(Double.class, 1.5d, true, 60.5d, true);
    // 1 point Ranges
    rangeJAIBpoint = new javax.media.jai.util.Range(Byte.class, (byte) 5, true, (byte) 5, true);
    rangeJAISpoint = new javax.media.jai.util.Range(Short.class, (short) 5, true, (short) 5, true);
    rangeJAIIpoint = new javax.media.jai.util.Range(Integer.class, 5, true, 5, true);
    rangeJAIFpoint = new javax.media.jai.util.Range(Float.class, 5f, true, 5f, true);
    rangeJAIDpoint = new javax.media.jai.util.Range(Double.class, 5d, true, 5d, true);

    // Apache Common Ranges
    rangeCommonsB = new org.apache.commons.lang.math.IntRange((byte) 1, (byte) 60);
    rangeCommonsS = new org.apache.commons.lang.math.IntRange((short) 1, (short) 60);
    rangeCommonsI = new org.apache.commons.lang.math.IntRange(1, 60);
    rangeCommonsF = new org.apache.commons.lang.math.FloatRange(0.5f, 60.5f);
    rangeCommonsD = new org.apache.commons.lang.math.DoubleRange(1.5d, 60.5d);
    // 1 point Ranges
    rangeCommonsBpoint = new org.apache.commons.lang.math.IntRange(5);
    rangeCommonsSpoint = new org.apache.commons.lang.math.IntRange(5);
    rangeCommonsIpoint = new org.apache.commons.lang.math.IntRange(5);
    rangeCommonsFpoint = new org.apache.commons.lang.math.FloatRange(5f);
    rangeCommonsDpoint = new org.apache.commons.lang.math.DoubleRange(5d);

    //        // GeoTools Ranges
    //        rangeGeoToolsB = new org.geotools.util.NumberRange<Byte>(Byte.class, (byte) 1, (byte) 60);
    //        rangeGeoToolsS = new org.geotools.util.NumberRange<Short>(Short.class, (short) 1,
    //                (short) 60);
    //        rangeGeoToolsI = new org.geotools.util.NumberRange<Integer>(Integer.class, 1, 60);
    //        rangeGeoToolsF = new org.geotools.util.NumberRange<Float>(Float.class, 0.5f, 60.5f);
    //        rangeGeoToolsD = new org.geotools.util.NumberRange<Double>(Double.class, 1.5d, 60.5d);
    //        // 1 point Ranges
    //        rangeGeoToolsBpoint = new org.geotools.util.NumberRange<Byte>(Byte.class, (byte) 5,
    //                (byte) 5);
    //        rangeGeoToolsSpoint = new org.geotools.util.NumberRange<Short>(Short.class, (short) 5,
    //                (short) 5);
    //        rangeGeoToolsIpoint = new org.geotools.util.NumberRange<Integer>(Integer.class, 5, 5);
    //        rangeGeoToolsFpoint = new org.geotools.util.NumberRange<Float>(Float.class, 5f, 5f);
    //        rangeGeoToolsDpoint = new org.geotools.util.NumberRange<Double>(Double.class, 5d, 5d);

    //        // Guava Ranges
    //        rangeGuavaB = com.google.common.collect.Range.closed((byte) 1, (byte) 60);
    //        rangeGuavaS = com.google.common.collect.Range.closed((short) 1, (short) 60);
    //        rangeGuavaI = com.google.common.collect.Range.closed(1, 60);
    //        rangeGuavaF = com.google.common.collect.Range.closed(0.5f, 60.5f);
    //        rangeGuavaD = com.google.common.collect.Range.closed(1.5d, 60.5d);
    //        // 1 point Ranges
    //        rangeGuavaBpoint = com.google.common.collect.Range.singleton((byte) 5);
    //        rangeGuavaSpoint = com.google.common.collect.Range.singleton((short) 5);
    //        rangeGuavaIpoint = com.google.common.collect.Range.singleton(5);
    //        rangeGuavaFpoint = com.google.common.collect.Range.singleton(5f);
    //        rangeGuavaDpoint = com.google.common.collect.Range.singleton(5d);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java

public void setData(double[] xValues, double[] yValues, double[][] zValues) {
    this.xValues = xValues;
    this.yValues = yValues;
    this.zValues = zValues;

    double minZValue = Double.MAX_VALUE;
    double maxZValue = Double.MIN_VALUE;
    int width = xValues.length;
    int height = yValues.length;
    int numCells = width * height;
    _log.debug("Number of cells in heat map: " + numCells);
    if (zValues.length != width || zValues[0].length != height)
        throw new RuntimeException(
                "PanelWithHeatMap: wrong number of z values for x and y values (" + zValues.length + " vs. "
                        + width + ", " + zValues[0].length + " vs. " + height + ", x/y first, z second)");
    DefaultXYZDataset theDataset = new DefaultXYZDataset();
    double[][] data = new double[3][numCells];
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            int cellIndex = (j * width) + i;
            data[0][cellIndex] = xValues[i];
            data[1][cellIndex] = yValues[j];
            data[2][cellIndex] = zValues[i][j];
            //keep track of lowest/highest z values
            minZValue = Math.min(zValues[i][j], minZValue);
            maxZValue = Math.max(zValues[i][j], maxZValue);
        }// w  w w. j  a  va 2  s .  c  om
    }
    lowerZBound = Rounder.round(minZValue, 3);
    upperZBound = Rounder.round(maxZValue, 3);
    if (lowerZBound == upperZBound)
        upperZBound += .0001;
    _log.debug("low,high values: " + lowerZBound + ", " + upperZBound);
    theDataset.addSeries("Range: " + lowerZBound + "-" + upperZBound, data);

    dataset = theDataset;
    if (renderer == null) {
        renderer = new XYBlockRenderer();
    }

    if (paintScale == null) {
        setPaintScale(createPaintScale(palette));
    }
    //This is necessary to get everything to line up
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM);

    if (getPlot() != null) {
        ((XYPlot) getPlot()).setDataset(dataset);
        ((XYPlot) getPlot()).setRenderer(renderer);

        invalidate();
        return;
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(dataSetName, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //        chart.addLegend(new LegendTitle(renderer));
    //        PaintScaleLegend legend = new PaintScaleLegend(paintScale, xAxis);
    //        chart.addLegend(legend);

    //        LegendItemCollection c1 = new LegendItemCollection();
    //
    //        LegendItem item1 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red,
    //                true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0),
    //                new BasicStroke(2.1f), Color.green);
    //        LegendItem item2 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0),
    //                true, Color.red, true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
    //                Color.green);
    //        c1.add(item1);
    //
    //        chart.getLegend().setSources(new LegendItemSource[]{renderer});

    init(chart);
}

From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java

@Test
public void test_convertAny() throws Exception {
    final Boolean result = (Boolean) AnyUtils.convertAny(this.any);

    Assert.assertTrue(result);/*from  w  ww.  j  a v a 2s  . c  o m*/

    Assert.assertNull(AnyUtils.convertAny(null));

    String str = (String) AnyUtils.convertAny(AnyUtils.toAny("2", TCKind.tk_string));
    Assert.assertEquals("2", str);
    str = (String) AnyUtils.convertAny(AnyUtils.toAny("3", TCKind.tk_wstring));
    Assert.assertEquals("3", str);
    final short b = (Short) AnyUtils.convertAny(AnyUtils.toAny(Byte.MAX_VALUE, TCKind.tk_octet));
    Assert.assertEquals(Byte.MAX_VALUE, b);
    char c = (Character) AnyUtils.convertAny(AnyUtils.toAny(Character.MAX_VALUE, TCKind.tk_char));
    Assert.assertEquals(Character.MAX_VALUE, c);
    c = (Character) AnyUtils.convertAny(AnyUtils.toAny(new Character('2'), TCKind.tk_wchar));
    Assert.assertEquals('2', c);
    final short s = (Short) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_short));
    Assert.assertEquals(Short.MAX_VALUE, s);
    final int i = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_long));
    Assert.assertEquals(Integer.MAX_VALUE, i);
    final long l = (Long) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_longlong));
    Assert.assertEquals(Long.MAX_VALUE, l);
    final float f = (Float) AnyUtils.convertAny(AnyUtils.toAny(Float.MAX_VALUE, TCKind.tk_float));
    Assert.assertEquals(Float.MAX_VALUE, f, 0.00001);
    final double d = (Double) AnyUtils.convertAny(AnyUtils.toAny(Double.MAX_VALUE, TCKind.tk_double));
    Assert.assertEquals(Double.MAX_VALUE, d, 0.00001);
    final int us = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_ushort));
    Assert.assertEquals(Short.MAX_VALUE, us);
    final long ui = (Long) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_ulong));
    Assert.assertEquals(Integer.MAX_VALUE, ui);
    final BigInteger ul = (BigInteger) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_ulonglong));
    Assert.assertEquals(Long.MAX_VALUE, ul.longValue());

    /** TODO Big Decimal not supported
    final BigDecimal fix = (BigDecimal) AnyUtils.convertAny(AnyUtils.toAny(new BigDecimal(1.0), TCKind.tk_fixed));
    Assert.assertEquals(1.0, fix.doubleValue(), 0.00001);
    */

    Any tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny(1, TCKind.tk_long), TCKind.tk_any));
    Assert.assertNotNull(tmpAny);
    Assert.assertEquals(1, tmpAny.extract_long());
    /** TODO Why do these not work in Jacorb? **/
    //      tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny((short) 1, TCKind.tk_short), TCKind.tk_value));
    //      Assert.assertNotNull(tmpAny);
    //      Assert.assertEquals((short) 1, tmpAny.extract_short());
    //      final TypeCode tmpType = (TypeCode) AnyUtils.convertAny(AnyUtils.toAny(tmpAny.type(), TCKind.tk_TypeCode));
    //      Assert.assertNotNull(tmpType);
    //      Assert.assertEquals(TCKind._tk_short, tmpType.kind().value());
    //      final Object obj = AnyUtils.convertAny(null, tmpType);
    //      Assert.assertNull(obj);
}

From source file:de.tuberlin.uebb.jdae.simulation.PendulumTest.java

@Test
public void testShortSimulationVariableStep() {

    dae.data[1][0] = 0.1;/*w w  w.j  a va  2 s .  co  m*/
    dae.initialize();

    runtime.simulateVariableStep(dae, 1, Double.MIN_VALUE, Double.MAX_VALUE, 1e-6, 1e-6);

    assertEquals(1, dae.data[0][0], 1e-8);
    assertEquals(-0.4354014183074412, dae.data[1][0], 1e-6);
}

From source file:edu.hawaii.soest.kilonalu.utilities.TextOutputPlugin.java

/**
 * Adds a progress listener to printout the status of the conversion
 * /* w  w w .j  av  a  2  s  . c o  m*/
 * @param textOutputPlugin  the TextOutputPlugin to monitor
 */
private static void setupProgressListener(TextOutputPlugin textOutputPlugin) {
    logger.debug("TextOutputPlugin.setupProgressListener() called.");
    textOutputPlugin.addTimeProgressListener(new TimeProgressListener() {
        public void progressUpdate(double estimatedDuration, double consumedTime) {
            if (estimatedDuration == Double.MAX_VALUE) {
                writeProgressMessage("Converted " + Math.round(consumedTime) + " seconds of data...");
            } else {
                writeProgressMessage("Conversion of data " + Math.round(100 * consumedTime / estimatedDuration)
                        + "% complete...");
            }
        }
    });
}

From source file:eu.juniper.MonitoringLib.java

/**
 * Retrieving data of a given metric with condition of another metric
 * /*w w  w. j  a va 2  s .  c  o m*/
 * @param appId Application ID
 * @param metricGet Metric which values are to be obtained
 * @param metricCond Metric which values are conditions
 * @param metricCondValue MetricCond value as positive filter for metricGet values
 * @return ArrayList of all metrics collected for the given application 
 * @throws ParseException
 * @throws FileNotFoundException
 * @throws IOException
 */
public ArrayList<String> getAppMetricsValuesByCondition(String appId, String metricGet, String metricCond,
        String metricCondValue) throws ParseException, FileNotFoundException, IOException {

    ArrayList<String> metricGetList = new ArrayList<String>();
    ArrayList<String> metricCondList = new ArrayList<String>();
    ArrayList<String> metricGetListSelected = new ArrayList<String>();
    ArrayList<Double> metricGetListSelectedNum = new ArrayList<Double>();
    String id = appId;
    String returnString = getResponse(monitoringServiceURL + id);
    metricGetList = parseJsonByTag(metricGetList, returnString, metricGet);
    metricCondList = parseJsonByTag(metricCondList, returnString, metricCond);
    iValue = 0;
    count = 0;
    min = Double.MAX_VALUE;
    max = Double.MIN_VALUE;
    avg = 0;
    sum = 0;
    System.out.println("metricCond = " + metricCond + "; metricCondValue = " + metricCondValue);

    for (int i = 0; i < metricGetList.size(); i++) {
        if (!metricGetList.get(i).equals("null")) {

            if (metricCondList.get(i).equals(metricCondValue) || metricCondList == null
                    || metricCondValue == null) {
                metricGetListSelected.add(metricGetList.get(i));

                iValue = new Double(metricGetList.get(i));
                count++;
                if (iValue < min)
                    min = iValue;
                if (iValue > max)
                    max = iValue;
                sum = sum + iValue;
                metricGetListSelectedNum.add(iValue);
            }
        }

        avg = sum / count;
    }

    return metricGetListSelected;
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationPropertiesWithDoubleArray() {
    ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray();

    Double doubleValue = config.doubleArray[0];

    assertEquals(Double.class, doubleValue.getClass());
    assertEquals(Double.MAX_VALUE, doubleValue.doubleValue(), 1);
    assertEquals(3, config.doubleArray.length);
}

From source file:ch.algotrader.service.algo.SlicingOrderService.java

private void sendNextOrder(SlicingOrder slicingOrder, SlicingOrderStateVO slicingOrderState) {

    Validate.notNull(slicingOrder, "slicingOrder missing");
    if (slicingOrderState == null) {
        return; // already done
    }//from  w w w. j  a  v a  2  s .  c  om

    Security security = slicingOrder.getSecurity();
    SecurityFamily family = security.getSecurityFamily();

    long remainingQuantity;
    OrderStatusVO orderStatus = this.orderExecutionService.getStatusByIntId(slicingOrder.getIntId());
    if (orderStatus != null) {
        remainingQuantity = orderStatus.getRemainingQuantity();
    } else {
        remainingQuantity = slicingOrder.getQuantity();
    }

    TickVO tick = (TickVO) this.marketDataCacheService.getCurrentMarketDataEvent(security.getId());
    if (tick == null) {
        throw new IllegalStateException("no market data subscription for " + security);
    }

    // limit (at least one tick above market but do not exceed the market)
    BigDecimal limit;
    long marketVolume;
    if (Side.BUY.equals(slicingOrder.getSide())) {

        marketVolume = tick.getVolAsk();
        limit = family.adjustPrice(null, tick.getAsk(), -slicingOrderState.getCurrentOffsetTicks());

        if (limit.compareTo(tick.getBid()) <= 0.0) {
            limit = family.adjustPrice(null, tick.getBid(), 1);
            slicingOrderState
                    .setCurrentOffsetTicks(family.getSpreadTicks(null, tick.getBid(), tick.getAsk()) - 1);
        }

        if (limit.compareTo(tick.getAsk()) > 0.0) {
            limit = tick.getAsk();
            slicingOrderState.setCurrentOffsetTicks(0);
        }

    } else {

        marketVolume = tick.getVolBid();
        limit = family.adjustPrice(null, tick.getBid(), slicingOrderState.getCurrentOffsetTicks());

        if (limit.compareTo(tick.getAsk()) >= 0.0) {
            limit = family.adjustPrice(null, tick.getAsk(), -1);
            slicingOrderState
                    .setCurrentOffsetTicks(family.getSpreadTicks(null, tick.getBid(), tick.getAsk()) - 1);
        }

        if (limit.compareTo(tick.getBid()) < 0.0) {
            limit = tick.getBid();
            slicingOrderState.setCurrentOffsetTicks(0);
        }
    }

    // ignore maxVolPct / maxQuantity if they are zero
    double maxVolPct = slicingOrder.getMaxVolPct() == 0.0 ? Double.MAX_VALUE : slicingOrder.getMaxVolPct();
    long maxQuantity = slicingOrder.getMaxQuantity() == 0 ? Long.MAX_VALUE : slicingOrder.getMaxQuantity();

    // evaluate the order minimum and maximum qty
    long orderMinQty = Math.max(Math.round(marketVolume * slicingOrder.getMinVolPct()),
            slicingOrder.getMinQuantity());
    long orderMaxQty = Math.min(Math.round(marketVolume * maxVolPct), maxQuantity);

    // orderMinQty cannot be greater than orderMaxQty
    if (orderMinQty > orderMaxQty) {
        orderMinQty = orderMaxQty;
    }

    // randomize the quantity between orderMinQty and orderMaxQty
    long quantity = Math.round(orderMinQty + Math.random() * (orderMaxQty - orderMinQty));

    // make sure that the remainingQty after the next slice is greater than minQuantity
    long remainingQuantityAfterSlice = remainingQuantity - quantity;
    if (slicingOrder.getMinQuantity() > 0 && slicingOrder.getMaxQuantity() > 0
            && remainingQuantityAfterSlice > 0 && remainingQuantityAfterSlice < slicingOrder.getMinQuantity()) {

        // if quantity is below half between minQuantity and maxQuantity
        if (quantity < (slicingOrder.getMinQuantity() + slicingOrder.getMaxQuantity()) / 2.0) {

            // take full remaining quantity but not more than orderMaxQty
            quantity = Math.min(remainingQuantity, orderMaxQty);
        } else {

            // make sure remaining after slice quantity is greater than minQuantity
            quantity = remainingQuantity - slicingOrder.getMinQuantity();
        }
    }

    // qty should be at least one
    quantity = Math.max(quantity, 1);

    // qty should be maximum remainingQuantity
    quantity = Math.min(quantity, remainingQuantity);

    // create the limit order
    LimitOrder order = LimitOrder.Factory.newInstance();
    order.setSecurity(security);
    order.setStrategy(slicingOrder.getStrategy());
    order.setSide(slicingOrder.getSide());
    order.setQuantity(quantity);
    order.setLimit(limit);
    order.setAccount(slicingOrder.getAccount());

    // associate the childOrder with the parentOrder(this)
    order.setParentOrder(slicingOrder);

    // store the current order and tick
    slicingOrderState.addPair(new Pair<>(order, tick));

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("next slice for {},currentOffsetTicks={},qty={},vol={},limit={},bid={},ask={}",
                slicingOrder.getDescription(), slicingOrderState.getCurrentOffsetTicks(), order.getQuantity(),
                (Side.BUY.equals(order.getSide()) ? tick.getVolAsk() : tick.getVolBid()), limit, tick.getBid(),
                tick.getAsk());
    }

    this.simpleOrderService.sendOrder(order);
}

From source file:com.net2plan.libraries.IPUtils.java

/**
 *
 * @param nodes List of nodes//from   w ww  .j a va2  s .c  o  m
 * @param links List of links
 * @param demands List of demands
 * @param linkWeightVector Cost per link vector
 * @return Forwarding rule mapping, where key is the demand-outgoing link pair and the value is the splitting ratio
 */
public static DoubleMatrix2D computeECMPForwardingRules_fde(List<Node> nodes, List<Link> links,
        List<Demand> demands, DoubleMatrix1D linkWeightVector) {
    final int N = nodes.size();
    DoubleMatrix2D splittingRatioMap = DoubleFactory2D.sparse.make(demands.size(), links.size());

    double[][] costMatrix = new double[N][N];
    for (int n = 0; n < N; n++) {
        Arrays.fill(costMatrix[n], Double.MAX_VALUE);
        costMatrix[n][n] = 0;
    }
    Map<Link, Double> linkWeightMap = CollectionUtils.toMap(links, linkWeightVector);
    Transformer<Link, Double> nev = JUNGUtils.getEdgeWeightTransformer(linkWeightMap);

    Map<Pair<Node, Node>, Set<Link>> linksPerNodePair = new LinkedHashMap<Pair<Node, Node>, Set<Link>>();
    for (Link link : links) {
        Pair<Node, Node> nodePair_thisLink = Pair.of(link.getOriginNode(), link.getDestinationNode());
        final int a_e = link.getOriginNode().getIndex();
        final int b_e = link.getDestinationNode().getIndex();
        costMatrix[a_e][b_e] = Math.min(costMatrix[a_e][b_e], nev.transform(link));

        Set<Link> links_thisNodePair = linksPerNodePair.get(nodePair_thisLink);
        if (links_thisNodePair == null) {
            links_thisNodePair = new LinkedHashSet<Link>();
            linksPerNodePair.put(nodePair_thisLink, links_thisNodePair);
        }

        links_thisNodePair.add(link);
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            if (i == k)
                continue;

            for (int j = 0; j < N; j++) {
                if (j == k || j == i)
                    continue;

                double newValue = costMatrix[i][k] + costMatrix[k][j];
                if (newValue < costMatrix[i][j])
                    costMatrix[i][j] = newValue;
            }
        }
    }

    for (Demand demand : demands) {
        final int b_d = demand.getEgressNode().getIndex();
        for (Node node : nodes) {
            final int n = node.getIndex();
            if (n == b_d)
                continue;

            double distNodeToEgress = costMatrix[n][b_d];
            if (distNodeToEgress == Double.MAX_VALUE)
                continue;

            Set<Link> A_t = new LinkedHashSet<Link>();
            for (Node intermediateNode : nodes) {
                if (node.equals(intermediateNode))
                    continue;

                final int m = intermediateNode.getIndex();

                double distIntermediateToEgress = costMatrix[m][b_d];
                if (distIntermediateToEgress == Double.MAX_VALUE)
                    continue;

                Collection<Link> linksFromNodeToIntermediate = linksPerNodePair
                        .get(Pair.of(node, intermediateNode));
                if (linksFromNodeToIntermediate == null)
                    continue;

                for (Link link : linksFromNodeToIntermediate) {
                    double weight_thisLink = linkWeightMap.get(link);
                    checkIPWeight(weight_thisLink);

                    if (Math.abs(weight_thisLink - (distNodeToEgress - distIntermediateToEgress)) < 1E-10)
                        A_t.add(link);
                }
            }

            int outdegree = A_t.size();

            if (outdegree > 0)
                for (Link link : A_t)
                    splittingRatioMap.set(demand.getIndex(), link.getIndex(), 1.0 / outdegree);
        }
    }

    return splittingRatioMap;
}