List of usage examples for java.lang Float POSITIVE_INFINITY
float POSITIVE_INFINITY
To view the source code for java.lang Float POSITIVE_INFINITY.
Click Source Link
From source file:org.energy_home.jemma.ah.ebrain.algo.ParticleSwarmScheduler.java
public boolean evolve() { // 2-step process: 1st evaluate fitness of all particles boolean isSwarmImproving = false; // keep track of the worst particle in the swarm //ProfileScheduleParticle worstParticle = swarm[0]; // For each i iterating over all Particles in the Swarm for (int i = 0; i < swarmSize; ++i) { // Compute current Constraints violation as overload amount for Particle(i) float overload = energyAllocator.computeOverload(swarm[i]); // Store such overload for Particle(i) swarm[i].setCurrentOverload(overload); double penalty = overload * OVERLOAD_WEIGHT; // Compute cost and tardiness only if it's a feasible schedule (no overload) float energyCost = Float.POSITIVE_INFINITY; float tardiness = Float.POSITIVE_INFINITY; if (penalty == 0) { // Set energyCost to current Particle(i)'s Energy Cost energyCost = energyAllocator.computeEnergyCost(swarm[i]); // Store such energyCost for Particle(i) swarm[i].setCurrentCost(energyCost); // Set tardiness to current Particle(i)'s Tardiness tardiness = swarm[i].getCurrentTardiness(); // Add to penalty (energyCost multiplied by ENERGY_COST_WEIGHT) plus (tardiness multiplied by TARDINESS_WEIGHT) penalty += energyCost * ENERGY_COST_WEIGHT + tardiness * TARDINESS_WEIGHT; }//from w ww .j a v a 2 s .c o m // Update Particle(i)'s penalty: If the new penalty is less than Particle(i)'s previous penalty Then Set Particle(i)'s bestPostion to its currentPosition boolean isParticleImproving = swarm[i].updatePenalty(penalty); // If penaly is less than leastPenalty if (penalty < leastPenalty) { leastPenalty = penalty; leastOverload = overload; leastCost = energyCost; leastTardiness = tardiness; bestParticle = swarm[i]; isSwarmImproving = true; } //if (penalty > worstParticle.getCurrentPenalty()) worstParticle = swarm[i]; } // with a certain probability reinitialize the worst particle to a random position //if (Math.random() < REINIT_WORST_PARTICLE_PROBABILITY) worstParticle.randomizePositions(); // 2nd step: do a random flight // For each i iterating over all Particles in the Swarm for (int i = 0; i < swarmSize; ++i) { // Perform Particle(i) nextRandomFlight swarm[i].nextRandomStep(bestParticle); } return isSwarmImproving; }
From source file:Main.java
/** * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>, ignoring any instances of <tt>noDataValue</tt> * .//from w w w .j ava2 s.c o m * * @param multi * @param noDataValue * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum */ public static float[] minMax(float[][] multi, float noDataValue) { float[] ret = null; float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY; float val; for (int i = 0; i < multi.length; i++) { for (int j = 0; j < multi[i].length; j++) { val = multi[i][j]; if (val != noDataValue) { min = (val < min) ? val : min; max = (val > max) ? val : max; } } } if (!Float.isInfinite(min) & !Float.isInfinite(max)) { ret = new float[] { min, max }; } return ret; }
From source file:com.ericsson.deviceaccess.spi.impl.GenericDevicePropertiesImplTest.java
@Before public void setup() throws Exception { metadataFloat = context.mock(GDPropertyMetadata.class, "metadataFloat"); metadataArr = new ArrayList<>(); metadataArr.add(metadataFloat);/*from www . ja v a 2s . c o m*/ context.checking(new Expectations() { { allowing(metadataFloat).getDefaultNumberValue(); will(returnValue(42.0f)); allowing(metadataFloat).getDefaultStringValue(); will(returnValue("42.0")); allowing(metadataFloat).getName(); will(returnValue("fProp")); allowing(metadataFloat).getType(); will(returnValue(Float.class)); allowing(metadataFloat).getTypeName(); will(returnValue("Float")); allowing(metadataFloat).getValidValues(); will(returnValue(new String[0])); allowing(metadataFloat).getMinValue(); will(returnValue(Float.NEGATIVE_INFINITY)); allowing(metadataFloat).getMaxValue(); will(returnValue(Float.POSITIVE_INFINITY)); allowing(metadataFloat).serialize(Format.JSON); will(returnValue("{\"type\":\"float\"}")); } }); props = new GDPropertiesImpl(metadataArr, null); }
From source file:gdsc.smlm.results.DensityManager.java
private void initialise(float[] xcoord, float[] ycoord, Rectangle bounds) { if (xcoord == null || ycoord == null || xcoord.length == 0 || xcoord.length != ycoord.length) throw new IllegalArgumentException("Results are null or empty or mismatched in length"); this.xcoord = xcoord; this.ycoord = ycoord; // Assign localisations & get min bounds minXCoord = Float.POSITIVE_INFINITY; minYCoord = Float.POSITIVE_INFINITY; for (int i = 0; i < xcoord.length; i++) { if (minXCoord > xcoord[i]) minXCoord = xcoord[i];/*from w w w .j a v a 2s . c o m*/ if (minYCoord > ycoord[i]) minYCoord = ycoord[i]; } // Round down and shift to origin minXCoord = (int) Math.floor(minXCoord); minYCoord = (int) Math.floor(minYCoord); // Get max bounds maxXCoord = 0; maxYCoord = 0; for (int i = 0; i < xcoord.length; i++) { xcoord[i] -= minXCoord; ycoord[i] -= minYCoord; if (maxXCoord < xcoord[i]) maxXCoord = xcoord[i]; if (maxYCoord < ycoord[i]) maxYCoord = ycoord[i]; } // Store the area of the input results area = bounds.width * bounds.height; }
From source file:org.opentripplanner.routing.algorithm.strategies.WeightTable.java
/** * Build the weight table, parallelized according to the number of processors *//*from ww w. j av a2s . co m*/ public void buildTable() { ArrayList<TransitStop> stopVertices; LOG.debug("Number of vertices: " + g.getVertices().size()); stopVertices = new ArrayList<TransitStop>(); for (Vertex gv : g.getVertices()) if (gv instanceof TransitStop) stopVertices.add((TransitStop) gv); int nStops = stopVertices.size(); stopIndices = new IdentityHashMap<Vertex, Integer>(nStops); for (int i = 0; i < nStops; i++) stopIndices.put(stopVertices.get(i), i); LOG.debug("Number of stops: " + nStops); table = new float[nStops][nStops]; for (float[] row : table) Arrays.fill(row, Float.POSITIVE_INFINITY); LOG.debug("Performing search at each transit stop."); int nThreads = Runtime.getRuntime().availableProcessors(); LOG.debug("number of threads: " + nThreads); ArrayBlockingQueue<Runnable> taskQueue = new ArrayBlockingQueue<Runnable>(nStops); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(nThreads, nThreads, 10, TimeUnit.SECONDS, taskQueue); GenericObjectPool heapPool = new GenericObjectPool( new PoolableBinHeapFactory<State>(g.getVertices().size()), nThreads); // make one heap and recycle it RoutingRequest options = new RoutingRequest(); // TODO LG Check this change: options.setWalkSpeed(maxWalkSpeed); final double MAX_WEIGHT = 60 * 60 * options.walkReluctance; final double OPTIMISTIC_BOARD_COST = options.getBoardCostLowerBound(); // create a task for each transit stop in the graph ArrayList<Callable<Void>> tasks = new ArrayList<Callable<Void>>(); for (TransitStop origin : stopVertices) { SPTComputer task = new SPTComputer(heapPool, options, MAX_WEIGHT, OPTIMISTIC_BOARD_COST, origin); tasks.add(task); } try { //invoke all of tasks. threadPool.invokeAll(tasks); threadPool.shutdown(); } catch (InterruptedException e) { throw new RuntimeException(e); } floyd(); }
From source file:org.energy_home.jemma.ah.ebrain.algo.DailyTariff.java
public EnergyCostInfo computeMinMaxCosts(Calendar calendar, long duration, double deltaEnergy) { float[] slotTariff = getSlotDailyTariffProfile(calendar); // NOTE: the tariff is Kwatt/hour, while the 'energy' parameter is in watt/hour // therefore the necessary division by 1000 double energy = deltaEnergy * 0.001; int slotDuration = CalendarUtil.slotsFromMillis(duration); double oneSlotEnergy = energy / slotDuration; int tariffSlot = CalendarUtil.getSlotOf(calendar); double cost = 0; float min = Float.POSITIVE_INFINITY; float max = 0; while (slotDuration-- > 0) { cost += slotTariff[tariffSlot] * oneSlotEnergy; if (min > slotTariff[tariffSlot]) min = slotTariff[tariffSlot]; if (max < slotTariff[tariffSlot]) max = slotTariff[tariffSlot]; if (++tariffSlot >= slotTariff.length) { // roll to the day after tariffSlot = 0;//w w w . j av a 2 s. co m calendar.add(Calendar.DAY_OF_MONTH, 1); slotTariff = getSlotDailyTariffProfile(calendar); } } min *= energy; max *= energy; return new EnergyCostInfo((float) cost, min, max, deltaEnergy); }
From source file:com.ericsson.deviceaccess.spi.impl.GenericDeviceServiceImplTest.java
@Before public void setup() throws Exception { action = context.mock(GDAction.class); eventManager = context.mock(EventManager.class); device = context.mock(GenericDeviceImpl.class); metadataFloat = context.mock(GDPropertyMetadata.class, "metadataFloat"); metadataInt = context.mock(GDPropertyMetadata.class, "metadataInt"); metadataString = context.mock(GDPropertyMetadata.class, "metadataString"); metadataArr = new ArrayList<>(); metadataArr.add(metadataFloat);/*from www . j a v a2 s . c o m*/ metadataArr.add(metadataInt); metadataArr.add(metadataString); ReflectionTestUtil.setField(GDActivator.class, "eventManager", eventManager); context.checking(new Expectations() { { allowing(device).getId(); will(returnValue("devId")); allowing(device).getURN(); will(returnValue("devUrn")); allowing(device).getName(); will(returnValue("dev")); allowing(device).getProtocol(); will(returnValue("prot")); allowing(device).isOnline(); will(returnValue(true)); allowing(metadataFloat).getDefaultNumberValue(); will(returnValue(42.0f)); allowing(metadataFloat).getDefaultStringValue(); will(returnValue("42.0")); allowing(metadataFloat).getName(); will(returnValue("fProp")); allowing(metadataFloat).getType(); will(returnValue(Float.class)); allowing(metadataFloat).getTypeName(); will(returnValue("Float")); allowing(metadataFloat).getValidValues(); will(returnValue(null)); allowing(metadataFloat).getMinValue(); will(returnValue(Float.NEGATIVE_INFINITY)); allowing(metadataFloat).getMaxValue(); will(returnValue(Float.POSITIVE_INFINITY)); allowing(metadataFloat).serialize(Format.JSON); will(returnValue("{\"type\":\"float\"}")); allowing(metadataInt).getDefaultNumberValue(); will(returnValue(42)); allowing(metadataInt).getDefaultStringValue(); will(returnValue("42")); allowing(metadataInt).getName(); will(returnValue("iProp")); allowing(metadataInt).getType(); will(returnValue(Integer.class)); allowing(metadataInt).getTypeName(); will(returnValue("Integer")); allowing(metadataInt).getValidValues(); will(returnValue(null)); allowing(metadataInt).getMinValue(); will(returnValue(Integer.MIN_VALUE)); allowing(metadataInt).getMaxValue(); will(returnValue(Integer.MAX_VALUE)); allowing(metadataInt).serialize(Format.JSON); will(returnValue("{\"type\":\"int\"}")); allowing(metadataString).getDefaultNumberValue(); will(returnValue(null)); allowing(metadataString).getDefaultStringValue(); will(returnValue("Forty-two")); allowing(metadataString).getName(); will(returnValue("sProp")); allowing(metadataString).getType(); will(returnValue(String.class)); allowing(metadataString).getTypeName(); will(returnValue("String")); allowing(metadataString).getValidValues(); will(returnValue(null)); allowing(metadataString).getMinValue(); will(returnValue(null)); allowing(metadataString).getMaxValue(); will(returnValue(null)); allowing(metadataString).serialize(Format.JSON); will(returnValue("{\"type\":\"string\"}")); allowing(action).getName(); will(returnValue("action1")); allowing(action).updatePath(with(aNonNull(String.class))); allowing(action).getArgumentsMetadata(); will(returnValue(new HashMap<>())); allowing(action).getResultMetadata(); will(returnValue(new HashMap<>())); } }); service = new GDServiceImpl("srv", metadataArr); service.setParentDevice(device); service.putAction(action); props = new GDPropertiesImpl(metadataArr, service); }
From source file:com.callidusrobotics.rrb4j.AbstractRasPiRobot.java
@SuppressWarnings("PMD.PrematureDeclaration") @Override// w ww.j a v a 2 s . c o m public float getRangeCm() throws IOException { // Pulse the trigger pin for 10 microseconds rangeTriggerPin.setState(PinState.HIGH); delayMicroseconds(TRIGGER_MICROS); rangeTriggerPin.setState(PinState.LOW); // Wait for start of echo pulse from the rangefinder (rising edge of echo pin) if (!waitForEvent(rangeEchoPin, PinState.HIGH, ECHO_DELAY_MICROS)) { throw new IOException("Rangefinder is not connected"); } final long sendTime = currentTimeNanos(); // Measure pulse width (time until falling edge of echo pin) if (!waitForEvent(rangeEchoPin, PinState.LOW, MAX_PULSE_MICROS)) { // Echo went beyond maximum measurable distance return Float.POSITIVE_INFINITY; } final long receiveTime = currentTimeNanos(); // Compute distance traveled (halved to account for round-trip duration) final long durationMicros = (receiveTime - sendTime) / (1000L * 2); final float distMm = SOS_MM_MICROS * durationMicros; return distMm / 10.0f; }
From source file:pl.mg6.android.maps.extensions.impl.GridClusteringStrategy.java
@Override public float getMinZoomLevelNotClustered(Marker marker) { if (!markers.containsKey(marker)) { throw new UnsupportedOperationException("marker is not visible or is a cluster"); }// www.j a v a 2 s . c o m int zoom = 0; while (zoom <= 25 && hasCollision(marker, zoom)) { zoom++; } if (zoom > 25) { return Float.POSITIVE_INFINITY; } return zoom; }
From source file:com.alibaba.citrus.util.internal.apache.lang.EqualsBuilderTests.java
public void testFloat() { float o1 = 1; float o2 = 2; assertTrue(new EqualsBuilder().append(o1, o1).isEquals()); assertTrue(!new EqualsBuilder().append(o1, o2).isEquals()); assertTrue(!new EqualsBuilder().append(o1, Float.NaN).isEquals()); assertTrue(new EqualsBuilder().append(Float.NaN, Float.NaN).isEquals()); assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isEquals()); }