Example usage for java.lang Double POSITIVE_INFINITY

List of usage examples for java.lang Double POSITIVE_INFINITY

Introduction

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

Prototype

double POSITIVE_INFINITY

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

Click Source Link

Document

A constant holding the positive infinity of type double .

Usage

From source file:org.powertac.auctioneer.AuctionService.java

public boolean validateOrder(Order order) {
    if (order.getMWh().equals(Double.NaN) || order.getMWh().equals(Double.POSITIVE_INFINITY)
            || order.getMWh().equals(Double.NEGATIVE_INFINITY)) {
        log.warn("Order from " + order.getBroker().getUsername() + " with invalid quantity " + order.getMWh());
        return false;
    }//ww  w  . jav a2  s .co  m

    double minQuantity = Competition.currentCompetition().getMinimumOrderQuantity();
    if (Math.abs(order.getMWh()) < minQuantity) {
        log.warn("Order from " + order.getBroker().getUsername() + " with quantity " + order.getMWh()
                + " < minimum quantity " + minQuantity);
        return false;
    }

    if (!timeslotRepo.isTimeslotEnabled(order.getTimeslot())) {
        OrderStatus status = new OrderStatus(order.getBroker(), order.getId());
        brokerProxyService.sendMessage(order.getBroker(), status);
        log.warn("Order from " + order.getBroker().getUsername() + " for disabled timeslot "
                + order.getTimeslot());
        return false;
    }
    return true;
}

From source file:com.squarespace.template.plugins.platform.CommerceUtils.java

public static double getTotalStockRemaining(JsonNode item) {
    ProductType type = getProductType(item);
    JsonNode structuredContent = item.path("structuredContent");

    if (EnumSet.of(ProductType.DIGITAL, ProductType.GIFT_CARD).contains(type)) {
        return Double.POSITIVE_INFINITY;
    } else {//from   w  ww.jav a 2 s. c  o m
        int total = 0;
        JsonNode variants = structuredContent.path("variants");
        for (int i = 0; i < variants.size(); i++) {
            JsonNode variant = variants.get(i);
            if (isTruthy(variant.path("unlimited"))) {
                return Double.POSITIVE_INFINITY;
            } else {
                total += variant.path("qtyInStock").asLong();
            }
        }
        return total;
    }
}

From source file:com.rapidminer.operator.preprocessing.filter.InfiniteValueReplenishment.java

@Override
public List<ParameterType> getParameterTypes() {
    List<ParameterType> types = super.getParameterTypes();
    ParameterType type = new ParameterTypeCategory(PARAMETER_REPLENISHMENT_WHAT,
            "Decides if positive or negative infite values will be replaced.", WHAT_NAMES, 0, false);
    types.add(type);//  ww  w  . j  a v  a  2s  .  c om

    type = new ParameterTypeDouble(PARAMETER_REPLENISHMENT_VALUE,
            "This value will be inserted instead of infinity.", Double.NEGATIVE_INFINITY,
            Double.POSITIVE_INFINITY, true);
    type.registerDependencyCondition(
            new EqualTypeCondition(this, PARAMETER_DEFAULT, getFunctionNames(), true, VALUE));
    types.add(type);
    return types;
}

From source file:com.rapidminer.gui.graphs.SimilarityGraphCreator.java

private void addEdges() {
    // remove old edges if available
    Iterator<String> e = edgeLabelMap.keySet().iterator();
    while (e.hasNext()) {
        graph.removeEdge(e.next());/*from w w  w. ja v a  2s  .c  o  m*/
    }
    edgeLabelMap.clear();

    boolean isDistance = measure.isDistance();
    Attribute id = exampleSet.getAttributes().getId();
    List<SortableEdge> sortableEdges = new LinkedList<SortableEdge>();
    for (int i = 0; i < exampleSet.size(); i++) {
        Example example = exampleSet.getExample(i);
        for (int j = i + 1; j < exampleSet.size(); j++) {
            Example comExample = exampleSet.getExample(j);
            if (isDistance) {
                sortableEdges.add(new SortableEdge(example.getValueAsString(id),
                        comExample.getValueAsString(id), null, measure.calculateDistance(example, comExample),
                        SortableEdge.DIRECTION_INCREASE));
            } else {
                sortableEdges.add(new SortableEdge(example.getValueAsString(id),
                        comExample.getValueAsString(id), null, measure.calculateSimilarity(example, comExample),
                        SortableEdge.DIRECTION_DECREASE));
            }
        }
    }

    Collections.sort(sortableEdges);

    int numberOfEdges = distanceSlider.getValue();
    int counter = 0;
    double minStrength = Double.POSITIVE_INFINITY;
    double maxStrength = Double.NEGATIVE_INFINITY;
    Map<String, Double> strengthMap = new HashMap<String, Double>();
    for (SortableEdge sortableEdge : sortableEdges) {
        if (counter > numberOfEdges) {
            break;
        }

        String idString = edgeFactory.create();
        graph.addEdge(idString, sortableEdge.getFirstVertex(), sortableEdge.getSecondVertex(),
                EdgeType.UNDIRECTED);
        edgeLabelMap.put(idString, Tools.formatIntegerIfPossible(sortableEdge.getEdgeValue()));

        double strength = sortableEdge.getEdgeValue();

        minStrength = Math.min(minStrength, strength);
        maxStrength = Math.max(maxStrength, strength);

        strengthMap.put(idString, strength);

        counter++;
    }

    for (Entry<String, Double> entry : strengthMap.entrySet()) {
        edgeStrengthMap.put(entry.getKey(), (entry.getValue() - minStrength) / (maxStrength - minStrength));
    }
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

/**
 * Constructor with logger object//from  ww  w  . jav a2  s. com
 * @param X
 * @param leaf_size
 * @param dist
 * @param logger
 */
protected NearestNeighborHeapSearch(final double[][] X, int leaf_size, DistanceMetric dist, Loggable logger) {
    this.data_arr = MatUtils.copy(X);
    this.leaf_size = leaf_size;
    this.logger = logger;

    if (leaf_size < 1)
        throw new IllegalArgumentException("illegal leaf size: " + leaf_size);

    if (!checkValidDistMet(dist)) {
        if (null != logger)
            logger.warn(dist + " is not valid for " + this.getClass() + ". Reverting to " + DEF_DIST);
        this.dist_metric = DEF_DIST;
    } else {
        this.dist_metric = dist;
    }

    // Whether the algorithm is using the infinity distance (Chebyshev)
    this.infinity_dist = this.dist_metric.getP() == Double.POSITIVE_INFINITY
            || Double.isInfinite(this.dist_metric.getP());

    // determine number of levels in the tree, and from this
    // the number of nodes in the tree.  This results in leaf nodes
    // with numbers of points between leaf_size and 2 * leaf_size
    MatUtils.checkDims(this.data_arr);
    N_SAMPLES = data_arr.length;
    N_FEATURES = X[0].length;

    /*
    // Should round up or always take floor function?...
    double nlev = FastMath.log(2, FastMath.max(1, (N_SAMPLES-1)/leaf_size)) + 1;
    this.n_levels = (int)FastMath.round(nlev);
    this.n_nodes = (int)(FastMath.pow(2, nlev) - 1);
    */

    this.n_levels = (int) (FastMath.log(2, FastMath.max(1, (N_SAMPLES - 1) / leaf_size)) + 1);
    this.n_nodes = (int) (FastMath.pow(2, n_levels) - 1);

    // allocate arrays for storage
    this.idx_array = VecUtils.arange(N_SAMPLES);

    // Add new NodeData objs to node_data arr
    this.node_data = new NodeData[n_nodes];
    for (int i = 0; i < node_data.length; i++)
        node_data[i] = new NodeData();

    // allocate tree specific data
    allocateData(this, n_nodes, N_FEATURES);
    recursiveBuild(0, 0, N_SAMPLES);
}

From source file:mulavito.algorithms.shortestpath.ksp.Eppstein.java

/**
 * Create <math>\delta(e)</math> for each edge in graph {@link #g}.
 * /*ww  w  .  j  a  v a 2s  . c  o  m*/
 * @param target
 *            The target
 * @return The delta edge weight.
 */
private Transformer<E, Double> prepareTransformations(V target) {
    Map<V, Double> lengthMap = new HashMap<V, Double>(); // d(x, t)
    Map<E, Double> edgeMap = new HashMap<E, Double>();

    // Search the shortest path from "target" to any vertex,
    // and store the length in a map.
    for (V v : graph.getVertices()) {
        Number dist = dijkstra.getDistance(v, target);

        if (dist != null) // target is reachable from v.
            lengthMap.put(v, dist.doubleValue());
        else {
            // Block edges from or to unreachable vertices.
            for (E e : graph.getIncidentEdges(v))
                edgeMap.put(e, Double.POSITIVE_INFINITY);
        }
    }

    // Calculate delta(e)
    for (E e : graph.getEdges()) {
        if (edgeMap.get(e) == null) {
            // Only consider edges to reachable vertices.
            double l = nev.transform(e).doubleValue() /* l(e) */
                    + lengthMap.get(graph.getDest(e)) /* d(head(e), t) */
                    - lengthMap.get(graph.getSource(e)) /* d(tail(e), t) */;
            edgeMap.put(e, l);
        }
    }

    return MapTransformer.getInstance(edgeMap);
}

From source file:egat.replicatordynamics.SymmetricConstrainedFeasibleAmoebaSearch.java

public Strategy run(Strategy initialStrategy, Set<Action> restrictedActions, boolean randomize,
        Action[] actions, PayoffMatrix pm) {

    boolean[] mask = new boolean[actions.length];

    int restrictedCount = 0;

    for (int i = 0; i < actions.length; i++) {

        mask[i] = restrictedActions.contains(actions[i]);

        if (mask[i]) {

            restrictedCount++;//from   w w w.  j a  v a  2  s. c o  m

        }

    }

    int[] restricted = new int[restrictedCount];

    for (int i = 0, restrictedIndex = 0; i < actions.length; i++) {

        if (mask[i]) {

            restricted[restrictedIndex++] = i;

        }
    }

    // Normalize to a uniform distribution
    double[] distribution = new double[actions.length];

    double[] bestDist = new double[actions.length];

    if (initialStrategy == null) {
        double sum = 0.0;
        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] = Math.random();
                sum += bestDist[i];
            }
        }

        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] /= sum;
            }
        }

    } else {
        for (int i = 0; i < actions.length; i++) {
            if (mask[i]) {
                bestDist[i] = initialStrategy.getProbability(actions[i]).doubleValue();
            }
        }
    }

    double bestRegret = pm.regret(bestDist);

    // Initialize current strategy
    Strategy currentStrategy = buildStrategy(actions, bestDist, restricted);

    fireUpdatedStrategy(currentStrategy, 0, Double.NaN);

    int SIMPLICES = restricted.length;
    double[][] X = new double[SIMPLICES][SIMPLICES - 1];
    double[] centroid = new double[SIMPLICES - 1];
    double[] reflect = new double[SIMPLICES - 1];
    double[] expand = new double[SIMPLICES - 1];
    double[] contract = new double[SIMPLICES - 1];
    double[] V = new double[SIMPLICES];
    double[] cur = distribution.clone();

    if (!randomize) {
        for (int r = 0, n = SIMPLICES - 1; r < n; r++) {
            X[0][r] = 0.0;
        }

        V[0] = calculateObjective(pm, X[0], restricted, distribution);

        for (int s = 1; s < SIMPLICES; s++) {
            System.arraycopy(X[0], 0, X[s], 0, SIMPLICES - 1);

            X[s][s - 1] = 1.0;

            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    } else {

        for (int s = 0; s < SIMPLICES; s++) {
            generateSimplex(X[s]);
            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    }

    int highest = -1;
    int lowest = -1;
    int second = -1;

    for (int s = 0; s < SIMPLICES; s++) {
        if (lowest < 0 || V[s] < V[lowest]) {
            lowest = s;
        }

        if (second < 0 || V[s] > V[second]) {

            if (highest < 0 || V[s] > V[highest]) {
                second = highest;
                highest = s;
            } else {
                second = s;
            }

        }
    }

    double curRegret = Double.POSITIVE_INFINITY;

    loop: for (int iteration = 1; SIMPLICES > 1; iteration++) {

        generateCentroid(centroid, X, SIMPLICES, highest);

        generateFeasibleTowards(reflect, centroid, X[highest], 1.0, pm, restricted, distribution);

        double reflectV = calculateObjective(pm, reflect, restricted, distribution);

        // Reflect
        if (V[lowest] <= reflectV && reflectV < V[second]) {
            replaceHighest(reflect, reflectV, X, V, highest);

            // Expand
        } else if (reflectV < V[lowest]) {

            generateFeasibleTowards(expand, centroid, X[highest], 2.0, pm, restricted, distribution);

            double expandV = calculateObjective(pm, expand, restricted, distribution);

            if (expandV < reflectV) {
                replaceHighest(expand, expandV, X, V, highest);
            } else {
                replaceHighest(reflect, reflectV, X, V, highest);
            }

            // Contract
        } else {

            generateAway(contract, X[highest], centroid, 0.5);

            double contractV = calculateObjective(pm, contract, restricted, distribution);

            if (contractV < V[highest]) {
                replaceHighest(contract, contractV, X, V, highest);

                // Reduction
            } else {
                for (int s = 0; s < SIMPLICES; s++) {
                    if (s != lowest) {

                        generateAway(X[s], X[lowest], X[s], 0.5);

                        V[s] = calculateObjective(pm, X[s], restricted, distribution);
                    }
                }
            }
        }

        highest = -1;
        lowest = -1;
        second = -1;

        for (int s = 0; s < SIMPLICES; s++) {
            if (lowest < 0 || V[s] < V[lowest]) {
                lowest = s;
            }

            if (second < 0 || V[s] > V[second]) {

                if (highest < 0 || V[s] > V[highest]) {
                    second = highest;
                    highest = s;
                } else {
                    second = s;
                }

            }
        }

        Arrays.fill(cur, 0.0);
        double sum = 0.0;
        for (int r = 0; r < restricted.length - 1; r++) {
            cur[restricted[r]] = Math.max(0, X[lowest][r]);
            sum += cur[restricted[r]];
        }

        cur[restricted[restricted.length - 1]] = Math.max(0.0, 1 - sum);
        sum += cur[restricted[restricted.length - 1]];

        for (int r = 0; r < restricted.length; r++) {
            cur[restricted[r]] /= sum;
        }

        curRegret = pm.regret(cur);

        if (curRegret < bestRegret) {
            System.arraycopy(cur, 0, bestDist, 0, cur.length);
            bestRegret = curRegret;
        }

        // Build the new strategy
        currentStrategy = buildStrategy(actions, bestDist, restricted);

        fireUpdatedStrategy(currentStrategy, iteration, bestRegret);

        // Calculate the norm
        double norm = V[highest] - V[lowest];

        // Check termination condition
        if (terminate(norm, iteration))
            break;
    }

    return currentStrategy;
}

From source file:cl.smartcities.isci.transportinspector.backend.Bus.java

/**
 * Fills the bus data based on the given JSONObject. Note that the JSONObject contains the info
 * given by the server. Note that the flag "valido" determines wich info is present.
 *
 * @throws JSONException/*from www.  j  a  va  2s  . c o  m*/
 */
private void fillData(JSONObject jsonObj) throws JSONException {
    this.valid = jsonObj.getInt("valido");
    this.service = jsonObj.getString("servicio");

    if (valid == 0) {
        this.descriptionError = jsonObj.getString("descripcionError");
        this.busIcon = Constants.BUS_LIST.get(0);
        this.activeMapBusIcon = Constants.ACTIVE_BUS_LIST.get(0);
        this.defaultMapBusIcon = Constants.MAP_BUS_LIST.get(0);
    } else if (valid == 1) {
        this.busIcon = Constants.BUS_LIST.get(jsonObj.getInt("color"));
        this.activeMapBusIcon = Constants.ACTIVE_BUS_LIST.get(jsonObj.getInt("color"));
        this.defaultMapBusIcon = Constants.MAP_BUS_LIST.get(jsonObj.getInt("color"));
        this.color = Constants.BUS_COLOR.get(jsonObj.getInt("color"));
        this.licensePlate = jsonObj.getString("patente");
        this.time = timeToString(jsonObj.getString("tiempoV2"));
        this.distance = jsonObj.getString("distanciaV2");
        this.realDistance = jsonObj.getInt("distanciaMts");
        this.direction = jsonObj.getString("sentido");
        this.events = new ArrayList<>();
        if (!jsonObj.getBoolean("random")) {
            this.latitude = jsonObj.getDouble("lat");
            this.longitude = jsonObj.getDouble("lon");
        } else {
            this.latitude = Double.POSITIVE_INFINITY;
            this.longitude = Double.POSITIVE_INFINITY;
        }
        this.passengerNumber = jsonObj.getInt("tienePasajeros");
        try {
            JSONArray jsonEvents = jsonObj.getJSONArray("eventos");
            for (int i = 0; i < jsonEvents.length(); i++) {
                Event event = new Event(jsonEvents.getJSONObject(i));
                this.events.add(event);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.jfree.data.general.DefaultHeatMapDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from  www . j a  v  a  2 s  . c o m
@Test
public void testSerialization() {
    DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(2, 3, -1.0, 4.0, -2.0, 5.0);
    d1.setZValue(0, 0, 10.0);
    d1.setZValue(0, 1, Double.NEGATIVE_INFINITY);
    d1.setZValue(0, 2, Double.POSITIVE_INFINITY);
    d1.setZValue(1, 0, Double.NaN);
    DefaultHeatMapDataset d2 = (DefaultHeatMapDataset) TestUtilities.serialised(d1);
    assertEquals(d1, d2);
}

From source file:com.rapidminer.operator.preprocessing.sampling.BootstrappingOperator.java

@Override
public List<ParameterType> getParameterTypes() {
    List<ParameterType> types = super.getParameterTypes();
    ParameterType type = new ParameterTypeCategory(PARAMETER_SAMPLE,
            "Determines how the amount of data is specified.", SAMPLE_MODES, SAMPLE_RELATIVE);
    type.setExpert(false);/* w ww .j a  v  a  2 s .  co  m*/
    types.add(type);
    type = new ParameterTypeInt(PARAMETER_SAMPLE_SIZE, "The number of examples which should be sampled", 1,
            Integer.MAX_VALUE, 100);
    type.registerDependencyCondition(
            new EqualTypeCondition(this, PARAMETER_SAMPLE, SAMPLE_MODES, true, SAMPLE_ABSOLUTE));
    type.setExpert(false);
    types.add(type);
    type = new ParameterTypeDouble(PARAMETER_SAMPLE_RATIO,
            "This ratio determines the size of the new example set.", 0.0d, Double.POSITIVE_INFINITY, 1.0d);
    type.registerDependencyCondition(
            new EqualTypeCondition(this, PARAMETER_SAMPLE, SAMPLE_MODES, true, SAMPLE_RELATIVE));
    type.setExpert(false);
    types.add(type);
    type = new ParameterTypeBoolean(PARAMETER_USE_WEIGHTS,
            "If checked, example weights will be considered during the bootstrapping if such weights are present.",
            true);
    type.setExpert(false);
    types.add(type);
    types.addAll(RandomGenerator.getRandomGeneratorParameters(this));
    return types;
}