List of usage examples for java.util TreeMap lastEntry
public Map.Entry<K, V> lastEntry()
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(2, "two"); treemap.put(1, "one"); treemap.put(3, "three"); treemap.put(6, "six"); treemap.put(5, "from java2s.com"); // getting the value with greatest key System.out.println("Checking last entry"); System.out.println("Value is: " + treemap.lastEntry()); }
From source file:edu.utexas.cs.tactex.utilityestimation.UtilityArchitectureTariffRevoker.java
private List<TariffSpecification> selectTariffsToRevoke(int currentTimeslot, TreeMap<Double, TariffSpecification> sortedTariffs, Set<TariffSpecification> myExistingTariffs) { Double bestUtil = sortedTariffs.lastEntry().getKey(); TariffSpecification specToRevoke = sortedTariffs.lastEntry().getValue(); // currently returning just one - the estimated best List<TariffSpecification> specsToRevoke = new ArrayList<TariffSpecification>(); if (specToRevoke != null) { // null is no-op specsToRevoke.add(specToRevoke); }//from w w w . j a v a2 s . com return specsToRevoke; }
From source file:edu.utexas.cs.tactex.interfaces.TariffOptimizerBase.java
protected TariffSpecification extractBestTariffSpec(TreeMap<Double, TariffSpecification> sortedTariffs) { Entry<Double, TariffSpecification> bestEntry = sortedTariffs.lastEntry(); while (bestEntry != null && bestEntry.getValue() == null) { bestEntry = sortedTariffs.lowerEntry(bestEntry.getKey()); }//from w w w.j av a2s .com if (bestEntry != null) { return bestEntry.getValue(); } else { return null; } }
From source file:edu.utexas.cs.tactex.utilityestimation.UtilityArchitectureActionGenerator.java
private List<TariffMessage> selectBestActions(int currentTimeslot, TreeMap<Double, TariffMessage> sortedTariffActions, Set<TariffSpecification> myExistingTariffs) { Double bestUtil = sortedTariffActions.lastEntry().getKey(); TariffMessage tariffAction = sortedTariffActions.lastEntry().getValue(); if (currentTimeslot < 360 + 6) { if (null == tariffAction) { log.warn("Force publishing before ts 366"); Entry<Double, TariffMessage> lowerEntry = sortedTariffActions .lowerEntry(sortedTariffActions.lastEntry().getKey()); while (lowerEntry.getValue().getClass() != TariffSpecification.class) { lowerEntry = sortedTariffActions.lowerEntry(lowerEntry.getKey()); }// w w w .j a va2s . co m bestUtil = lowerEntry.getKey(); tariffAction = lowerEntry.getValue(); } } // currently returning just one - the estimated best List<TariffMessage> tariffActions = new ArrayList<TariffMessage>(); if (tariffAction != null) { // null is no-op tariffActions.add(tariffAction); } return tariffActions; }
From source file:de.unidue.langtech.teaching.rp.detector.LanguageDetectorWeb1T.java
private void setTextProbability(TreeMap<Double, String> langProbs, Map<String, Double> textLogProbability) { System.out.println("LangProb: " + langProbs); System.out.println("Highest Prob: " + langProbs.lastEntry()); Double previousValue = textLogProbability.get(langProbs.get(langProbs.lastKey())); if (previousValue == null) { previousValue = 0.0;/* w w w. j a v a 2s.co m*/ } textLogProbability.put(langProbs.get(langProbs.lastKey()), 1 + previousValue); System.out.println("TextLogProb: " + textLogProbability); }
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerIncremental.java
@Override public TreeMap<Double, TariffSpecification> optimizeTariffs( HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy, List<TariffSpecification> competingTariffs, MarketManager marketManager, ContextManager contextManager, CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me) { // seed will be the best fixed-rate tariff TreeMap<Double, TariffSpecification> sortedTariffs = tariffOptimizerOneShot.optimizeTariffs( tariffSubscriptions, customer2estimatedEnergy, competingTariffs, marketManager, contextManager, costCurvesPredictor, currentTimeslot, me); TariffSpecification fixedRateSeed = extractBestTariffSpec(sortedTariffs); // this provides objective function evaluations TariffUtilityEstimateImpl tariffUtilityEstimate = new TariffUtilityEstimateImpl(utilityEstimator, NUM_RATES, fixedRateSeed, withdrawFeesOptimizer, tariffSubscriptions, competingTariffs, customer2estimatedEnergy, marketPredictionManager, costCurvesPredictor, configuratorFactoryService, currentTimeslot, me);//w ww. j av a2 s. c o m try { TreeMap<Double, TariffSpecification> touTariffs = optimizerWrapper.findOptimum(tariffUtilityEstimate, NUM_RATES, NUM_EVAL); Entry<Double, TariffSpecification> optimum = touTariffs.lastEntry(); sortedTariffs.putAll(touTariffs); // adding all tariffs // just printing TariffSpecification delete = optimum.getValue(); log.info("Daniel TOU BEST Candidate " + delete + " util " + optimum.getKey()); for (Rate r : delete.getRates()) { log.info(r); } } catch (Exception e) { log.error("caught exception from incremental tariff optimization, falling back to fixed-rate ", e); } return sortedTariffs; }
From source file:com.opengamma.analytics.math.statistics.descriptive.ModeCalculator.java
/** * @param x The array of data, not null or empty * @return The arithmetic mean/*from w w w. ja v a 2 s . co m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final TreeMap<Integer, Double> counts = new TreeMap<Integer, Double>(); int count = 1; for (int i = 1; i < x1.length; i++) { if (Math.abs(x1[i] - x1[i - 1]) < EPS) { count++; } else { counts.put(count, x1[i - 1]); count = 1; } } if (counts.lastKey() == 1) { throw new MathException("Could not find mode for array; no repeated values"); } return counts.lastEntry().getValue(); }
From source file:com.norconex.importer.handler.tagger.impl.TitleGeneratorTagger.java
private String getCarrotTitle(String text) throws IOException { // Use Carrot2 to try get an OK title. int maxSectionSize = Math.max(MIN_SECTION_MAX_BREAK_SIZE, text.length() / NUM_SECTIONS); if (LOG.isDebugEnabled()) { LOG.debug("Content-length: " + text.length() + "; maxSectionSize: " + maxSectionSize); }/*from w ww.jav a2s.c o m*/ List<Document> sections = new ArrayList<Document>(); try (TextReader reader = new TextReader(new StringReader(text), maxSectionSize)) { String section = null; while ((section = reader.readText()) != null) { sections.add(new Document(section)); } } final ProcessingResult byDomainClusters = controller.process(sections, null, STCClusteringAlgorithm.class); final List<Cluster> clusters = byDomainClusters.getClusters(); if (LOG.isDebugEnabled()) { LOG.debug("Title generator clusters= " + clusters); } TreeMap<Double, String> titles = new TreeMap<>(); for (Cluster cluster : clusters) { titles.put(cluster.getScore(), cluster.getLabel()); if (LOG.isDebugEnabled()) { LOG.info(cluster.getScore() + "=" + cluster.getLabel()); } } Entry<Double, String> titleEntry = titles.lastEntry(); if (titleEntry == null || titleEntry.getKey() < MIN_ACCEPTABLE_SCORE) { return null; } return titleEntry.getValue(); }
From source file:com.inmobi.databus.local.LocalStreamService.java
private void populateCheckpointPathForCollector(Map<String, FileStatus> checkpointPaths, TreeMap<String, FileStatus> collectorPaths, String checkpointKey) { // Last file in sorted ascending order to be checkpointed for this collector if (collectorPaths != null && collectorPaths.size() > 0) { Entry<String, FileStatus> entry = collectorPaths.lastEntry(); checkpointPaths.put(checkpointKey, entry.getValue()); }//from w w w . j av a2 s.c o m }
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerBinaryOneShot.java
/** * evaluate suggestedSpecs(index), and record result to utilToIndex * and result/*w w w . j a v a 2 s.co m*/ * * @param index * @param utilToIndex * @param result * @param suggestedSpecs * @param consideredTariffActions * @param tariffSubscriptions * @param competingTariffs * @param costCurvesPredictor * @param currentTimeslot * @param me * @param customer2ShiftedEnergy * @param customer2RelevantTariffCharges * @param customer2NonShiftedEnergy */ private void evaluateAndRecord(int index, TreeMap<Double, Integer> utilToIndex, TreeMap<Double, TariffSpecification> result, List<TariffSpecification> suggestedSpecs, ArrayList<TariffSpecification> consideredTariffActions, HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, List<TariffSpecification> competingTariffs, CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me, HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy, HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy, HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2RelevantTariffCharges) { TreeMap<Double, TariffSpecification> sortedTariffs; consideredTariffActions.clear(); consideredTariffActions.add(suggestedSpecs.get(index)); //log.info("computing utilities"); sortedTariffs = utilityEstimator.estimateUtilities(consideredTariffActions, tariffSubscriptions, competingTariffs, customer2RelevantTariffCharges, customer2ShiftedEnergy, customer2NonShiftedEnergy, marketPredictionManager, costCurvesPredictor, currentTimeslot, me); utilToIndex.put(sortedTariffs.lastEntry().getKey(), index); // maintain top 3 if (utilToIndex.size() > 3) { utilToIndex.remove(utilToIndex.firstKey()); } result.putAll(sortedTariffs); }