List of usage examples for java.lang Double MAX_VALUE
double MAX_VALUE
To view the source code for java.lang Double MAX_VALUE.
Click Source Link
From source file:acromusashi.stream.ml.clustering.kmeans.KmeansCalculator.java
/** * ??????????//from w ww . j ava2 s . c o m * * @param targetPoint ? * @param dataSet * @return ?????? */ public static KmeansResult classify(KmeansPoint targetPoint, KmeansDataSet dataSet) { // KMean? int nearestCentroidIndex = 0; Double minDistance = Double.MAX_VALUE; double[] currentCentroid = null; Double currentDistance; for (int index = 0; index < dataSet.getCentroids().length; index++) { currentCentroid = dataSet.getCentroids()[index]; if (currentCentroid != null) { currentDistance = MathUtils.distance(targetPoint.getDataPoint(), currentCentroid); if (currentDistance < minDistance) { minDistance = currentDistance; nearestCentroidIndex = index; } } } currentCentroid = dataSet.getCentroids()[nearestCentroidIndex]; KmeansResult result = new KmeansResult(); result.setDataPoint(targetPoint.getDataPoint()); result.setCentroidIndex(nearestCentroidIndex); result.setCentroid(currentCentroid); result.setDistance(minDistance); return result; }
From source file:eu.crisis_economics.abm.algorithms.optimization.BrentLineSearch.java
/** * Compute the maximum distance a line search may travel whilst * still remaining within the coordinate box specified by a pair * of (upper/lower) domain bounds./*from w w w. j a v a2 s . c o m*/ * * @param startingPoint (P) * The starting point (root) of a line search. * @param vectorDirection (V) * The vector direction of the line search. * @param domainMaxima * Upper bounds for each coordinate to test during the line * search. * @param domainMinima * Lower bounds for each coordinate to test during the line * search. * @return * The maximum distance along the *normalized* direction V * that a line search may travel, starting at P, such that * no coordinates are outside of the domain bounds. */ static private double computeMaximumSearchDistanceFromDomainBounds(final double[] startingPoint, final double[] vectorDirection, final double[] domainMaxima, final double[] domainMinima) { // Check whether the starting point is inside the boundary domain. for (int i = 0; i < startingPoint.length; ++i) { Preconditions.checkArgument(startingPoint[i] >= domainMinima[i]); Preconditions.checkArgument(startingPoint[i] <= domainMaxima[i]); } // Normalize the line search direction. double[] normalizedSearchDirection = new double[startingPoint.length]; double norm = 0.; for (int i = 0; i < vectorDirection.length; ++i) norm += vectorDirection[i] * vectorDirection[i]; norm = Math.sqrt(norm); if (norm == 0) return 0.; double maximumDistanceToTravel = Double.MAX_VALUE; // Identify the limiting step size for each coordinate direction. for (int i = 0; i < vectorDirection.length; ++i) { normalizedSearchDirection[i] = vectorDirection[i] / norm; double distanceLimitForThisCoordinate = 0.; if (normalizedSearchDirection[i] == 0) continue; else if (normalizedSearchDirection[i] > 0.) distanceLimitForThisCoordinate = (domainMaxima[i] - startingPoint[i]) / normalizedSearchDirection[i]; else distanceLimitForThisCoordinate = -(startingPoint[i] - domainMinima[i]) / normalizedSearchDirection[i]; maximumDistanceToTravel = Math.min(maximumDistanceToTravel, distanceLimitForThisCoordinate); } return maximumDistanceToTravel; }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
public static double[] findMinAndMax(double[] buffer, int pixelStride, int numBands) { double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; for (int i = 0; i < buffer.length; i += numBands) { for (int j = 0; j < pixelStride; ++j) { double value = buffer[i + j]; if (!Double.isInfinite(value)) { if (value < min) min = value;/*from w ww . j ava 2s. com*/ if (value > max) max = value; } } } return new double[] { min, max }; }
From source file:at.wada811.utils.CameraUtils.java
/** * Returns the best preview size/*from ww w . j av a 2 s .c o m*/ * * @param context * @param camera */ public static Size getOptimalPreviewSize(Context context, Camera camera) { final List<Size> sizes = camera.getParameters().getSupportedPreviewSizes(); final double ASPECT_TOLERANCE = 0.07; final boolean isPortrait = DisplayUtils.isPortrait(context); final Size pictureSize = camera.getParameters().getPictureSize(); final int width = pictureSize.width; final int height = pictureSize.height; if (DEBUG) { LogUtils.v("width: " + width); } if (DEBUG) { LogUtils.v("height: " + height); } final double targetRatio = isPortrait ? (double) height / width : (double) width / height; final int targetHeight = isPortrait ? width : height; Size optimalSize = null; double minDiff = Double.MAX_VALUE; if (DEBUG) { LogUtils.v("targetRatio: " + targetRatio); } for (Size size : sizes) { double previewRatio = isPortrait ? (double) size.height / size.width : (double) size.width / size.height; previewRatio = (double) size.width / size.height; if (DEBUG) { LogUtils.v("size.width: " + size.width); } if (DEBUG) { LogUtils.v("size.height: " + size.height); } if (DEBUG) { LogUtils.v("previewRatio: " + previewRatio); } if (Math.abs(previewRatio - targetRatio) > ASPECT_TOLERANCE) { continue; } if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } if (DEBUG) { LogUtils.v("optimalSize.width: " + optimalSize.width); } if (DEBUG) { LogUtils.v("optimalSize.height: " + optimalSize.height); } return optimalSize; }
From source file:fr.inria.soctrace.tools.ocelotl.core.caches.DataCache.java
/** * Check parameter against the cached data parameters, and return the most * appropriate data cache/*w w w. j a v a 2 s. co m*/ * * @param parameters * parameters to be tested * @return the File of the cached data file if a correspondence was found, * null otherwise */ public File checkCache(OcelotlParameters parameters) { rebuildDirty = false; CacheParameters cache = null; currentDirtyRatio = Double.MAX_VALUE; double bestRatio = Double.MAX_VALUE; CacheParameters cParam = new CacheParameters(parameters); String uniqueID = buildTraceUniqueID(parameters.getTrace()); // Look for the correct trace if (!cacheIndex.containsKey(uniqueID)) { logger.debug("No datacache was found (1)"); return null; } for (CacheParameters op : cacheIndex.get(uniqueID)) { if (similarParameters(cParam, op)) { // If first iteration if (cache == null) { // Init cache = op; bestRatio = currentDirtyRatio; } else { // If the dirty ratio of the cache is better than the // current best if (bestRatio < currentDirtyRatio) { // Set it as the best candidate cache = op; bestRatio = currentDirtyRatio; } } // If perfect cache if (currentDirtyRatio == 0) { cache = op; // There is no better solution so stop looking break; } } } if (cache == null) { logger.debug("No datacache was found (2)"); return null; } else { similarParameters(cParam, cache); parameters.setTimeSliceFactor(timeSliceFactor); return cachedData.get(cache); } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override protected void initialize() { CoolMapObject obj = getCoolMapObject(); if (!canRender(obj.getViewClass())) { return;/*from ww w . j a v a 2 s . c om*/ } double minValue = Double.MAX_VALUE; double maxValue = -Double.MAX_VALUE; for (int i = 0; i < obj.getViewNumRows(); i++) { for (int j = 0; j < obj.getViewNumColumns(); j++) { try { Double v = (Double) obj.getViewValue(i, j); if (v == null || v.isNaN()) { continue; } else { if (v < minValue) { minValue = v; } if (v > maxValue) { maxValue = v; } } } catch (Exception e) { } } } minValueField.setText(minValue + ""); maxValueField.setText(maxValue + ""); updateRenderer(); }
From source file:edu.oregonstate.eecs.mcplan.search.UctNegamaxSearch.java
private ActionNode selectAction(final StateNode sn, final ActionGenerator<S, ? extends A> actions) { assert (actions.size() > 0); double max_value = -Double.MAX_VALUE; ActionNode max_sa = null;/*from www . j a va2s. c om*/ while (actions.hasNext()) { final A a = actions.next(); final ActionNode sa = sn.action(a); if (sa.n == 0) { max_sa = sa; break; } else { final double exploit = sa.q(); final double explore = c_ * Math.sqrt(Math.log(sn.n) / sa.n); final double v = explore + exploit; if (v > max_value) { max_sa = sa; max_value = v; } } } return max_sa; }
From source file:lib.regressions.MultipleRegression.java
/** * Constructor with no limits on X or Y. * * @param numVars Number of independent variables. * @param timeDecayConstantSeconds Decay constant (in seconds). *///from w w w .j a va 2s . c om public MultipleRegression(int numVars, double timeDecayConstantSeconds) { this(numVars, timeDecayConstantSeconds, true, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE); }
From source file:com.ib.client.EReader.java
/** Overridden in subclass. */ protected boolean processMsg(int msgId) throws IOException { if (msgId == -1) return false; switch (msgId) { case TICK_PRICE: { int version = readInt(); int tickerId = readInt(); int tickType = readInt(); double price = readDouble(); int size = 0; if (version >= 2) { size = readInt();//ww w . j ava2 s . c o m } int canAutoExecute = 0; if (version >= 3) { canAutoExecute = readInt(); } eWrapper().tickPrice(tickerId, tickType, price, canAutoExecute); if (version >= 2) { int sizeTickType = -1; // not a tick switch (tickType) { case 1: // BID sizeTickType = 0; // BID_SIZE break; case 2: // ASK sizeTickType = 3; // ASK_SIZE break; case 4: // LAST sizeTickType = 5; // LAST_SIZE break; } if (sizeTickType != -1) { eWrapper().tickSize(tickerId, sizeTickType, size); } } break; } case TICK_SIZE: { int version = readInt(); log.debug("version:{}", version); int tickerId = readInt(); int tickType = readInt(); int size = readInt(); eWrapper().tickSize(tickerId, tickType, size); break; } case POSITION: { int version = readInt(); String account = readStr(); Contract contract = new Contract(); contract.m_conId = readInt(); contract.m_symbol = readStr(); contract.m_secType = readStr(); contract.m_expiry = readStr(); contract.m_strike = readDouble(); contract.m_right = readStr(); contract.m_multiplier = readStr(); contract.m_exchange = readStr(); contract.m_currency = readStr(); contract.m_localSymbol = readStr(); if (version >= 2) { contract.m_tradingClass = readStr(); } int pos = readInt(); double avgCost = 0; if (version >= 3) { avgCost = readDouble(); } eWrapper().position(account, contract, pos, avgCost); break; } case POSITION_END: { int version = readInt(); log.debug("version:{}", version); eWrapper().positionEnd(); break; } case ACCOUNT_SUMMARY: { int version = readInt(); log.debug("version:{}", version); int reqId = readInt(); String account = readStr(); String tag = readStr(); String value = readStr(); String currency = readStr(); eWrapper().accountSummary(reqId, account, tag, value, currency); break; } case ACCOUNT_SUMMARY_END: { int version = readInt(); log.debug("version:{}", version); int reqId = readInt(); eWrapper().accountSummaryEnd(reqId); break; } case TICK_OPTION_COMPUTATION: { int version = readInt(); int tickerId = readInt(); int tickType = readInt(); double impliedVol = readDouble(); if (impliedVol < 0) { // -1 is the "not yet computed" indicator impliedVol = Double.MAX_VALUE; } double delta = readDouble(); if (Math.abs(delta) > 1) { // -2 is the "not yet computed" indicator delta = Double.MAX_VALUE; } double optPrice = Double.MAX_VALUE; double pvDividend = Double.MAX_VALUE; double gamma = Double.MAX_VALUE; double vega = Double.MAX_VALUE; double theta = Double.MAX_VALUE; double undPrice = Double.MAX_VALUE; if (version >= 6 || tickType == TickType.MODEL_OPTION) { // introduced // in // version // == 5 optPrice = readDouble(); if (optPrice < 0) { // -1 is the "not yet computed" indicator optPrice = Double.MAX_VALUE; } pvDividend = readDouble(); if (pvDividend < 0) { // -1 is the "not yet computed" indicator pvDividend = Double.MAX_VALUE; } } if (version >= 6) { gamma = readDouble(); if (Math.abs(gamma) > 1) { // -2 is the "not yet computed" // indicator gamma = Double.MAX_VALUE; } vega = readDouble(); if (Math.abs(vega) > 1) { // -2 is the "not yet computed" // indicator vega = Double.MAX_VALUE; } theta = readDouble(); if (Math.abs(theta) > 1) { // -2 is the "not yet computed" // indicator theta = Double.MAX_VALUE; } undPrice = readDouble(); if (undPrice < 0) { // -1 is the "not yet computed" indicator undPrice = Double.MAX_VALUE; } } eWrapper().tickOptionComputation(tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice); break; } case TICK_GENERIC: { int version = readInt(); log.debug("version:{}", version); int tickerId = readInt(); int tickType = readInt(); double value = readDouble(); eWrapper().tickGeneric(tickerId, tickType, value); break; } case TICK_STRING: { int version = readInt(); log.debug("version:{}", version); int tickerId = readInt(); int tickType = readInt(); String value = readStr(); eWrapper().tickString(tickerId, tickType, value); break; } case TICK_EFP: { int version = readInt(); log.debug("version:{}", version); int tickerId = readInt(); int tickType = readInt(); double basisPoints = readDouble(); String formattedBasisPoints = readStr(); double impliedFuturesPrice = readDouble(); int holdDays = readInt(); String futureExpiry = readStr(); double dividendImpact = readDouble(); double dividendsToExpiry = readDouble(); eWrapper().tickEFP(tickerId, tickType, basisPoints, formattedBasisPoints, impliedFuturesPrice, holdDays, futureExpiry, dividendImpact, dividendsToExpiry); break; } case ORDER_STATUS: { int version = readInt(); int id = readInt(); String status = readStr(); int filled = readInt(); int remaining = readInt(); double avgFillPrice = readDouble(); int permId = 0; if (version >= 2) { permId = readInt(); } int parentId = 0; if (version >= 3) { parentId = readInt(); } double lastFillPrice = 0; if (version >= 4) { lastFillPrice = readDouble(); } int clientId = 0; if (version >= 5) { clientId = readInt(); } String whyHeld = null; if (version >= 6) { whyHeld = readStr(); } eWrapper().orderStatus(id, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld); break; } case ACCT_VALUE: { int version = readInt(); String key = readStr(); String val = readStr(); String cur = readStr(); String accountName = null; if (version >= 2) { accountName = readStr(); } eWrapper().updateAccountValue(key, val, cur, accountName); break; } case PORTFOLIO_VALUE: { int version = readInt(); Contract contract = new Contract(); if (version >= 6) { contract.m_conId = readInt(); } contract.m_symbol = readStr(); contract.m_secType = readStr(); contract.m_expiry = readStr(); contract.m_strike = readDouble(); contract.m_right = readStr(); if (version >= 7) { contract.m_multiplier = readStr(); contract.m_primaryExch = readStr(); } contract.m_currency = readStr(); if (version >= 2) { contract.m_localSymbol = readStr(); } if (version >= 8) { contract.m_tradingClass = readStr(); } int position = readInt(); double marketPrice = readDouble(); double marketValue = readDouble(); double averageCost = 0.0; double unrealizedPNL = 0.0; double realizedPNL = 0.0; if (version >= 3) { averageCost = readDouble(); unrealizedPNL = readDouble(); realizedPNL = readDouble(); } String accountName = null; if (version >= 4) { accountName = readStr(); } if (version == 6 && m_parent.serverVersion() == 39) { contract.m_primaryExch = readStr(); } eWrapper().updatePortfolio(contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName); break; } case ACCT_UPDATE_TIME: { int version = readInt(); log.debug("version:{}", version); String timeStamp = readStr(); eWrapper().updateAccountTime(timeStamp); break; } case ERR_MSG: { int version = readInt(); if (version < 2) { String msg = readStr(); m_parent.error(msg); } else { int id = readInt(); int errorCode = readInt(); String errorMsg = readStr(); m_parent.error(id, errorCode, errorMsg); } break; } case OPEN_ORDER: { // read version int version = readInt(); // read order id Order order = new Order(); order.m_orderId = readInt(); // read contract fields Contract contract = new Contract(); if (version >= 17) { contract.m_conId = readInt(); } contract.m_symbol = readStr(); contract.m_secType = readStr(); contract.m_expiry = readStr(); contract.m_strike = readDouble(); contract.m_right = readStr(); if (version >= 32) { contract.m_multiplier = readStr(); } contract.m_exchange = readStr(); contract.m_currency = readStr(); if (version >= 2) { contract.m_localSymbol = readStr(); } if (version >= 32) { contract.m_tradingClass = readStr(); } // read order fields order.m_action = readStr(); order.m_totalQuantity = readInt(); order.m_orderType = readStr(); if (version < 29) { order.m_lmtPrice = readDouble(); } else { order.m_lmtPrice = readDoubleMax(); } if (version < 30) { order.m_auxPrice = readDouble(); } else { order.m_auxPrice = readDoubleMax(); } order.m_tif = readStr(); order.m_ocaGroup = readStr(); order.m_account = readStr(); order.m_openClose = readStr(); order.m_origin = readInt(); order.m_orderRef = readStr(); if (version >= 3) { order.m_clientId = readInt(); } if (version >= 4) { order.m_permId = readInt(); if (version < 18) { // will never happen /* order.m_ignoreRth = */readBoolFromInt(); } else { order.m_outsideRth = readBoolFromInt(); } order.m_hidden = readInt() == 1; order.m_discretionaryAmt = readDouble(); } if (version >= 5) { order.m_goodAfterTime = readStr(); } if (version >= 6) { // skip deprecated sharesAllocation field readStr(); } if (version >= 7) { order.m_faGroup = readStr(); order.m_faMethod = readStr(); order.m_faPercentage = readStr(); order.m_faProfile = readStr(); } if (version >= 8) { order.m_goodTillDate = readStr(); } if (version >= 9) { order.m_rule80A = readStr(); order.m_percentOffset = readDoubleMax(); order.m_settlingFirm = readStr(); order.m_shortSaleSlot = readInt(); order.m_designatedLocation = readStr(); if (m_parent.serverVersion() == 51) { readInt(); // exemptCode } else if (version >= 23) { order.m_exemptCode = readInt(); } order.m_auctionStrategy = readInt(); order.m_startingPrice = readDoubleMax(); order.m_stockRefPrice = readDoubleMax(); order.m_delta = readDoubleMax(); order.m_stockRangeLower = readDoubleMax(); order.m_stockRangeUpper = readDoubleMax(); order.m_displaySize = readInt(); if (version < 18) { // will never happen /* order.m_rthOnly = */readBoolFromInt(); } order.m_blockOrder = readBoolFromInt(); order.m_sweepToFill = readBoolFromInt(); order.m_allOrNone = readBoolFromInt(); order.m_minQty = readIntMax(); order.m_ocaType = readInt(); order.m_eTradeOnly = readBoolFromInt(); order.m_firmQuoteOnly = readBoolFromInt(); order.m_nbboPriceCap = readDoubleMax(); } if (version >= 10) { order.m_parentId = readInt(); order.m_triggerMethod = readInt(); } if (version >= 11) { order.m_volatility = readDoubleMax(); order.m_volatilityType = readInt(); if (version == 11) { int receivedInt = readInt(); order.m_deltaNeutralOrderType = ((receivedInt == 0) ? "NONE" : "MKT"); } else { // version 12 and up order.m_deltaNeutralOrderType = readStr(); order.m_deltaNeutralAuxPrice = readDoubleMax(); if (version >= 27 && !Util.StringIsEmpty(order.m_deltaNeutralOrderType)) { order.m_deltaNeutralConId = readInt(); order.m_deltaNeutralSettlingFirm = readStr(); order.m_deltaNeutralClearingAccount = readStr(); order.m_deltaNeutralClearingIntent = readStr(); } if (version >= 31 && !Util.StringIsEmpty(order.m_deltaNeutralOrderType)) { order.m_deltaNeutralOpenClose = readStr(); order.m_deltaNeutralShortSale = readBoolFromInt(); order.m_deltaNeutralShortSaleSlot = readInt(); order.m_deltaNeutralDesignatedLocation = readStr(); } } order.m_continuousUpdate = readInt(); if (m_parent.serverVersion() == 26) { order.m_stockRangeLower = readDouble(); order.m_stockRangeUpper = readDouble(); } order.m_referencePriceType = readInt(); } if (version >= 13) { order.m_trailStopPrice = readDoubleMax(); } if (version >= 30) { order.m_trailingPercent = readDoubleMax(); } if (version >= 14) { order.m_basisPoints = readDoubleMax(); order.m_basisPointsType = readIntMax(); contract.m_comboLegsDescrip = readStr(); } if (version >= 29) { int comboLegsCount = readInt(); if (comboLegsCount > 0) { contract.m_comboLegs = new Vector<ComboLeg>(comboLegsCount); for (int i = 0; i < comboLegsCount; ++i) { int conId = readInt(); int ratio = readInt(); String action = readStr(); String exchange = readStr(); int openClose = readInt(); int shortSaleSlot = readInt(); String designatedLocation = readStr(); int exemptCode = readInt(); ComboLeg comboLeg = new ComboLeg(conId, ratio, action, exchange, openClose, shortSaleSlot, designatedLocation, exemptCode); contract.m_comboLegs.add(comboLeg); } } int orderComboLegsCount = readInt(); if (orderComboLegsCount > 0) { order.m_orderComboLegs = new Vector<OrderComboLeg>(orderComboLegsCount); for (int i = 0; i < orderComboLegsCount; ++i) { double price = readDoubleMax(); OrderComboLeg orderComboLeg = new OrderComboLeg(price); order.m_orderComboLegs.add(orderComboLeg); } } } if (version >= 26) { int smartComboRoutingParamsCount = readInt(); if (smartComboRoutingParamsCount > 0) { order.m_smartComboRoutingParams = new Vector<TagValue>(smartComboRoutingParamsCount); for (int i = 0; i < smartComboRoutingParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.m_tag = readStr(); tagValue.m_value = readStr(); order.m_smartComboRoutingParams.add(tagValue); } } } if (version >= 15) { if (version >= 20) { order.m_scaleInitLevelSize = readIntMax(); order.m_scaleSubsLevelSize = readIntMax(); } else { /* int notSuppScaleNumComponents = */readIntMax(); order.m_scaleInitLevelSize = readIntMax(); } order.m_scalePriceIncrement = readDoubleMax(); } if (version >= 28 && order.m_scalePriceIncrement > 0.0 && order.m_scalePriceIncrement != Double.MAX_VALUE) { order.m_scalePriceAdjustValue = readDoubleMax(); order.m_scalePriceAdjustInterval = readIntMax(); order.m_scaleProfitOffset = readDoubleMax(); order.m_scaleAutoReset = readBoolFromInt(); order.m_scaleInitPosition = readIntMax(); order.m_scaleInitFillQty = readIntMax(); order.m_scaleRandomPercent = readBoolFromInt(); } if (version >= 24) { order.m_hedgeType = readStr(); if (!Util.StringIsEmpty(order.m_hedgeType)) { order.m_hedgeParam = readStr(); } } if (version >= 25) { order.m_optOutSmartRouting = readBoolFromInt(); } if (version >= 19) { order.m_clearingAccount = readStr(); order.m_clearingIntent = readStr(); } if (version >= 22) { order.m_notHeld = readBoolFromInt(); } if (version >= 20) { if (readBoolFromInt()) { UnderComp underComp = new UnderComp(); underComp.m_conId = readInt(); underComp.m_delta = readDouble(); underComp.m_price = readDouble(); contract.m_underComp = underComp; } } if (version >= 21) { order.m_algoStrategy = readStr(); if (!Util.StringIsEmpty(order.m_algoStrategy)) { int algoParamsCount = readInt(); if (algoParamsCount > 0) { order.m_algoParams = new Vector<TagValue>(algoParamsCount); for (int i = 0; i < algoParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.m_tag = readStr(); tagValue.m_value = readStr(); order.m_algoParams.add(tagValue); } } } } OrderState orderState = new OrderState(); if (version >= 16) { order.m_whatIf = readBoolFromInt(); orderState.m_status = readStr(); orderState.m_initMargin = readStr(); orderState.m_maintMargin = readStr(); orderState.m_equityWithLoan = readStr(); orderState.m_commission = readDoubleMax(); orderState.m_minCommission = readDoubleMax(); orderState.m_maxCommission = readDoubleMax(); orderState.m_commissionCurrency = readStr(); orderState.m_warningText = readStr(); } eWrapper().openOrder(order.m_orderId, contract, order, orderState); break; } case NEXT_VALID_ID: { int version = readInt(); log.debug("version:{}", version); int orderId = readInt(); eWrapper().nextValidId(orderId); break; } case SCANNER_DATA: { ContractDetails contract = new ContractDetails(); int version = readInt(); int tickerId = readInt(); int numberOfElements = readInt(); for (int ctr = 0; ctr < numberOfElements; ctr++) { int rank = readInt(); if (version >= 3) { contract.m_summary.m_conId = readInt(); } contract.m_summary.m_symbol = readStr(); contract.m_summary.m_secType = readStr(); contract.m_summary.m_expiry = readStr(); contract.m_summary.m_strike = readDouble(); contract.m_summary.m_right = readStr(); contract.m_summary.m_exchange = readStr(); contract.m_summary.m_currency = readStr(); contract.m_summary.m_localSymbol = readStr(); contract.m_marketName = readStr(); contract.m_summary.m_tradingClass = readStr(); String distance = readStr(); String benchmark = readStr(); String projection = readStr(); String legsStr = null; if (version >= 2) { legsStr = readStr(); } eWrapper().scannerData(tickerId, rank, contract, distance, benchmark, projection, legsStr); } eWrapper().scannerDataEnd(tickerId); break; } case CONTRACT_DATA: { int version = readInt(); int reqId = -1; if (version >= 3) { reqId = readInt(); } ContractDetails contract = new ContractDetails(); contract.m_summary.m_symbol = readStr(); contract.m_summary.m_secType = readStr(); contract.m_summary.m_expiry = readStr(); contract.m_summary.m_strike = readDouble(); contract.m_summary.m_right = readStr(); contract.m_summary.m_exchange = readStr(); contract.m_summary.m_currency = readStr(); contract.m_summary.m_localSymbol = readStr(); contract.m_marketName = readStr(); contract.m_summary.m_tradingClass = readStr(); contract.m_summary.m_conId = readInt(); contract.m_minTick = readDouble(); contract.m_summary.m_multiplier = readStr(); contract.m_orderTypes = readStr(); contract.m_validExchanges = readStr(); if (version >= 2) { contract.m_priceMagnifier = readInt(); } if (version >= 4) { contract.m_underConId = readInt(); } if (version >= 5) { contract.m_longName = readStr(); contract.m_summary.m_primaryExch = readStr(); } if (version >= 6) { contract.m_contractMonth = readStr(); contract.m_industry = readStr(); contract.m_category = readStr(); contract.m_subcategory = readStr(); contract.m_timeZoneId = readStr(); contract.m_tradingHours = readStr(); contract.m_liquidHours = readStr(); } if (version >= 8) { contract.m_evRule = readStr(); contract.m_evMultiplier = readDouble(); } if (version >= 7) { int secIdListCount = readInt(); if (secIdListCount > 0) { contract.m_secIdList = new Vector<TagValue>(secIdListCount); for (int i = 0; i < secIdListCount; ++i) { TagValue tagValue = new TagValue(); tagValue.m_tag = readStr(); tagValue.m_value = readStr(); contract.m_secIdList.add(tagValue); } } } eWrapper().contractDetails(reqId, contract); break; } case BOND_CONTRACT_DATA: { int version = readInt(); int reqId = -1; if (version >= 3) { reqId = readInt(); } ContractDetails contract = new ContractDetails(); contract.m_summary.m_symbol = readStr(); contract.m_summary.m_secType = readStr(); contract.m_cusip = readStr(); contract.m_coupon = readDouble(); contract.m_maturity = readStr(); contract.m_issueDate = readStr(); contract.m_ratings = readStr(); contract.m_bondType = readStr(); contract.m_couponType = readStr(); contract.m_convertible = readBoolFromInt(); contract.m_callable = readBoolFromInt(); contract.m_putable = readBoolFromInt(); contract.m_descAppend = readStr(); contract.m_summary.m_exchange = readStr(); contract.m_summary.m_currency = readStr(); contract.m_marketName = readStr(); contract.m_summary.m_tradingClass = readStr(); contract.m_summary.m_conId = readInt(); contract.m_minTick = readDouble(); contract.m_orderTypes = readStr(); contract.m_validExchanges = readStr(); if (version >= 2) { contract.m_nextOptionDate = readStr(); contract.m_nextOptionType = readStr(); contract.m_nextOptionPartial = readBoolFromInt(); contract.m_notes = readStr(); } if (version >= 4) { contract.m_longName = readStr(); } if (version >= 6) { contract.m_evRule = readStr(); contract.m_evMultiplier = readDouble(); } if (version >= 5) { int secIdListCount = readInt(); if (secIdListCount > 0) { contract.m_secIdList = new Vector<TagValue>(secIdListCount); for (int i = 0; i < secIdListCount; ++i) { TagValue tagValue = new TagValue(); tagValue.m_tag = readStr(); tagValue.m_value = readStr(); contract.m_secIdList.add(tagValue); } } } eWrapper().bondContractDetails(reqId, contract); break; } case EXECUTION_DATA: { int version = readInt(); int reqId = -1; if (version >= 7) { reqId = readInt(); } int orderId = readInt(); // read contract fields Contract contract = new Contract(); if (version >= 5) { contract.m_conId = readInt(); } contract.m_symbol = readStr(); contract.m_secType = readStr(); contract.m_expiry = readStr(); contract.m_strike = readDouble(); contract.m_right = readStr(); if (version >= 9) { contract.m_multiplier = readStr(); } contract.m_exchange = readStr(); contract.m_currency = readStr(); contract.m_localSymbol = readStr(); if (version >= 10) { contract.m_tradingClass = readStr(); } Execution exec = new Execution(); exec.m_orderId = orderId; exec.m_execId = readStr(); exec.m_time = readStr(); exec.m_acctNumber = readStr(); exec.m_exchange = readStr(); exec.m_side = readStr(); exec.m_shares = readInt(); exec.m_price = readDouble(); if (version >= 2) { exec.m_permId = readInt(); } if (version >= 3) { exec.m_clientId = readInt(); } if (version >= 4) { exec.m_liquidation = readInt(); } if (version >= 6) { exec.m_cumQty = readInt(); exec.m_avgPrice = readDouble(); } if (version >= 8) { exec.m_orderRef = readStr(); } if (version >= 9) { exec.m_evRule = readStr(); exec.m_evMultiplier = readDouble(); } eWrapper().execDetails(reqId, contract, exec); break; } case MARKET_DEPTH: { int version = readInt(); log.debug("version:{}", version); int id = readInt(); int position = readInt(); int operation = readInt(); int side = readInt(); double price = readDouble(); int size = readInt(); eWrapper().updateMktDepth(id, position, operation, side, price, size); break; } case MARKET_DEPTH_L2: { int version = readInt(); log.debug("version:{}", version); int id = readInt(); int position = readInt(); String marketMaker = readStr(); int operation = readInt(); int side = readInt(); double price = readDouble(); int size = readInt(); eWrapper().updateMktDepthL2(id, position, marketMaker, operation, side, price, size); break; } case NEWS_BULLETINS: { int version = readInt(); log.debug("version:{}", version); int newsMsgId = readInt(); int newsMsgType = readInt(); String newsMessage = readStr(); String originatingExch = readStr(); eWrapper().updateNewsBulletin(newsMsgId, newsMsgType, newsMessage, originatingExch); break; } case MANAGED_ACCTS: { int version = readInt(); log.debug("version:{}", version); String accountsList = readStr(); eWrapper().managedAccounts(accountsList); break; } case RECEIVE_FA: { int version = readInt(); log.debug("version:{}", version); int faDataType = readInt(); String xml = readStr(); eWrapper().receiveFA(faDataType, xml); break; } case HISTORICAL_DATA: { int version = readInt(); int reqId = readInt(); String startDateStr; String endDateStr; String completedIndicator = "finished"; if (version >= 2) { startDateStr = readStr(); endDateStr = readStr(); completedIndicator += "-" + startDateStr + "-" + endDateStr; } int itemCount = readInt(); for (int ctr = 0; ctr < itemCount; ctr++) { String date = readStr(); double open = readDouble(); double high = readDouble(); double low = readDouble(); double close = readDouble(); int volume = readInt(); double WAP = readDouble(); String hasGaps = readStr(); int barCount = -1; if (version >= 3) { barCount = readInt(); } eWrapper().historicalData(reqId, date, open, high, low, close, volume, barCount, WAP, Boolean.valueOf(hasGaps).booleanValue()); } // send end of dataset marker eWrapper().historicalData(reqId, completedIndicator, -1, -1, -1, -1, -1, -1, -1, false); break; } case SCANNER_PARAMETERS: { int version = readInt(); log.debug("version:{}", version); String xml = readStr(); eWrapper().scannerParameters(xml); break; } case CURRENT_TIME: { /* int version = */readInt(); long time = readLong(); eWrapper().currentTime(time); break; } case REAL_TIME_BARS: { /* int version = */readInt(); int reqId = readInt(); long time = readLong(); double open = readDouble(); double high = readDouble(); double low = readDouble(); double close = readDouble(); long volume = readLong(); double wap = readDouble(); int count = readInt(); eWrapper().realtimeBar(reqId, time, open, high, low, close, volume, wap, count); break; } case FUNDAMENTAL_DATA: { /* int version = */readInt(); int reqId = readInt(); String data = readStr(); eWrapper().fundamentalData(reqId, data); break; } case CONTRACT_DATA_END: { /* int version = */readInt(); int reqId = readInt(); eWrapper().contractDetailsEnd(reqId); break; } case OPEN_ORDER_END: { /* int version = */readInt(); eWrapper().openOrderEnd(); break; } case ACCT_DOWNLOAD_END: { /* int version = */readInt(); String accountName = readStr(); eWrapper().accountDownloadEnd(accountName); break; } case EXECUTION_DATA_END: { /* int version = */readInt(); int reqId = readInt(); eWrapper().execDetailsEnd(reqId); break; } case DELTA_NEUTRAL_VALIDATION: { /* int version = */readInt(); int reqId = readInt(); UnderComp underComp = new UnderComp(); underComp.m_conId = readInt(); underComp.m_delta = readDouble(); underComp.m_price = readDouble(); eWrapper().deltaNeutralValidation(reqId, underComp); break; } case TICK_SNAPSHOT_END: { /* int version = */readInt(); int reqId = readInt(); eWrapper().tickSnapshotEnd(reqId); break; } case MARKET_DATA_TYPE: { /* int version = */readInt(); int reqId = readInt(); int marketDataType = readInt(); eWrapper().marketDataType(reqId, marketDataType); break; } case COMMISSION_REPORT: { /* int version = */readInt(); CommissionReport commissionReport = new CommissionReport(); commissionReport.m_execId = readStr(); commissionReport.m_commission = readDouble(); commissionReport.m_currency = readStr(); commissionReport.m_realizedPNL = readDouble(); commissionReport.m_yield = readDouble(); commissionReport.m_yieldRedemptionDate = readInt(); eWrapper().commissionReport(commissionReport); break; } case VERIFY_MESSAGE_API: { /* int version = */readInt(); String apiData = readStr(); eWrapper().verifyMessageAPI(apiData); break; } case VERIFY_COMPLETED: { /* int version = */readInt(); String isSuccessfulStr = readStr(); boolean isSuccessful = "true".equals(isSuccessfulStr); String errorText = readStr(); if (isSuccessful) { m_parent.startAPI(); } eWrapper().verifyCompleted(isSuccessful, errorText); break; } case DISPLAY_GROUP_LIST: { /* int version = */readInt(); int reqId = readInt(); String groups = readStr(); eWrapper().displayGroupList(reqId, groups); break; } case DISPLAY_GROUP_UPDATED: { /* int version = */readInt(); int reqId = readInt(); String contractInfo = readStr(); eWrapper().displayGroupUpdated(reqId, contractInfo); break; } default: { m_parent.error(EClientErrors.NO_VALID_ID, EClientErrors.UNKNOWN_ID.code(), EClientErrors.UNKNOWN_ID.msg()); return false; } } return true; }
From source file:com.net2plan.internal.sim.SimStats.java
private void checkAndCreateLayer(long layerId) { if (!accum_avgLinkLengthInKm.containsKey(layerId)) { /* Initialize layer information */ accum_layerTotalTime.put(layerId, new MutableDouble()); accum_avgNumLinks.put(layerId, new MutableDouble()); accum_avgNumDemands.put(layerId, new MutableDouble()); accum_avgTotalOfferedTraffic.put(layerId, new MutableDouble()); maxTotalOfferedTraffic.put(layerId, new MutableDouble()); minTotalOfferedTraffic.put(layerId, new MutableDouble(Double.MAX_VALUE)); accum_avgTotalCarriedTraffic.put(layerId, new MutableDouble()); maxTotalCarriedTraffic.put(layerId, new MutableDouble()); minTotalCarriedTraffic.put(layerId, new MutableDouble(Double.MAX_VALUE)); accum_avgTotalCapacity.put(layerId, new MutableDouble()); maxTotalCapacity.put(layerId, new MutableDouble()); minTotalCapacity.put(layerId, new MutableDouble(Double.MAX_VALUE)); accum_avgCongestion.put(layerId, new MutableDouble()); maxCongestion.put(layerId, new MutableDouble()); minCongestion.put(layerId, new MutableDouble(Double.MAX_VALUE)); accum_availabilityClassic.put(layerId, new MutableDouble()); accum_availabilityWeighted.put(layerId, new MutableDouble()); worstDemandAvailabilityClassic.put(layerId, new MutableDouble(1)); worstDemandAvailabilityWeighted.put(layerId, new MutableDouble(1)); maxNumLinks.put(layerId, 0);//from w w w . ja v a2s. c om minNumLinks.put(layerId, Integer.MAX_VALUE); maxNumDemands.put(layerId, 0); minNumDemands.put(layerId, Integer.MAX_VALUE); /* Initialize node information in this layer */ accum_avgNodeInDegree.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minNodeInDegree.put(layerId, new LinkedHashMap<Long, Integer>()); maxNodeInDegree.put(layerId, new LinkedHashMap<Long, Integer>()); accum_avgNodeOutDegree.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minNodeOutDegree.put(layerId, new LinkedHashMap<Long, Integer>()); maxNodeOutDegree.put(layerId, new LinkedHashMap<Long, Integer>()); accum_avgNodeIngressTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxNodeIngressTraffic.put(layerId, new LinkedHashMap<Long, Double>()); minNodeIngressTraffic.put(layerId, new LinkedHashMap<Long, Double>()); accum_avgNodeEgressTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxNodeEgressTraffic.put(layerId, new LinkedHashMap<Long, Double>()); minNodeEgressTraffic.put(layerId, new LinkedHashMap<Long, Double>()); /* Initialize link information in this layer */ accum_avgLinkLengthInKm.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minLinkLengthInKm.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxLinkLengthInKm.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgLinkOccupiedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minLinkOccupiedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxLinkOccupiedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgUtilization.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minUtilization.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxUtilization.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgOversubscribedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minOversubscribedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxOversubscribedCapacity.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_linkOversubscribedTime.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_linkUpTime.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_linkTotalTime.put(layerId, new LinkedHashMap<Long, MutableDouble>()); /* Initialize demand information in this layer */ accum_avgDemandOfferedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minDemandOfferedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxDemandOfferedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgDemandCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minDemandCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxDemandCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgDemandBlockedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minDemandBlockedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxDemandBlockedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_avgExcessCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); minDemandExcessCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); maxDemandExcessCarriedTraffic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_demandAvailabilityClassic.put(layerId, new LinkedHashMap<Long, MutableDouble>()); accum_demandAvailabilityWeighted.put(layerId, new LinkedHashMap<Long, MutableDouble>()); excessDemandCarriedTrafficTime.put(layerId, new LinkedHashMap<Long, MutableDouble>()); demandTotalTime.put(layerId, new LinkedHashMap<Long, MutableDouble>()); } }