當前位置: 首頁>>代碼示例>>Java>>正文


Java Object2DoubleLinkedOpenHashMap類代碼示例

本文整理匯總了Java中it.unimi.dsi.fastutil.objects.Object2DoubleLinkedOpenHashMap的典型用法代碼示例。如果您正苦於以下問題:Java Object2DoubleLinkedOpenHashMap類的具體用法?Java Object2DoubleLinkedOpenHashMap怎麽用?Java Object2DoubleLinkedOpenHashMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Object2DoubleLinkedOpenHashMap類屬於it.unimi.dsi.fastutil.objects包,在下文中一共展示了Object2DoubleLinkedOpenHashMap類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: computeCost

import it.unimi.dsi.fastutil.objects.Object2DoubleLinkedOpenHashMap; //導入依賴的package包/類
static <C, T> double computeCost(Schedule<C, T> s, int row,
    ImmutableList<T> newRoute,
    Object2DoubleLinkedOpenHashMap<ImmutableList<T>> cache) {
  if (cache.containsKey(newRoute)) {
    return cache.getAndMoveToFirst(newRoute);
  }
  final double newCost = s.evaluator.computeCost(s.context, row, newRoute);
  cache.putAndMoveToFirst(newRoute, newCost);
  if (cache.size() > CACHE_SIZE) {
    cache.removeLastDouble();
  }
  return newCost;
}
 
開發者ID:rinde,項目名稱:RinLog,代碼行數:14,代碼來源:Swaps.java

示例2: opt2

import it.unimi.dsi.fastutil.objects.Object2DoubleLinkedOpenHashMap; //導入依賴的package包/類
static <C, T> ImmutableList<ImmutableList<T>> opt2(
    ImmutableList<ImmutableList<T>> schedule,
    IntList startIndices,
    C context,
    RouteEvaluator<C, T> evaluator,
    boolean depthFirst,
    Optional<RandomGenerator> rng,
    Optional<? extends ProgressListener<T>> listener)
        throws InterruptedException {

  checkArgument(schedule.size() == startIndices.size());

  final Schedule<C, T> baseSchedule = Schedule.create(context, schedule,
    startIndices, evaluator);

  final Object2DoubleLinkedOpenHashMap<ImmutableList<T>> routeCostCache =
    new Object2DoubleLinkedOpenHashMap<>(CACHE_SIZE);

  for (int i = 0; i < baseSchedule.routes.size(); i++) {
    routeCostCache.put(baseSchedule.routes.get(i),
      baseSchedule.objectiveValues.getDouble(i));
  }

  Schedule<C, T> bestSchedule = baseSchedule;
  boolean isImproving = true;
  while (isImproving) {
    isImproving = false;

    final Schedule<C, T> curBest = bestSchedule;
    Iterator<Swap<T>> it = swapIterator(curBest);
    if (depthFirst) {
      // randomize ordering of swaps
      final List<Swap<T>> swaps = newArrayList(it);
      Collections.shuffle(swaps, new RandomAdaptor(rng.get()));
      it = swaps.iterator();
    }

    while (it.hasNext()) {
      if (Thread.interrupted()) {
        throw new InterruptedException();
      }
      final Swap<T> swapOperation = it.next();
      final Optional<Schedule<C, T>> newSchedule = swap(curBest,
        swapOperation,
        bestSchedule.objectiveValue - curBest.objectiveValue,
        routeCostCache);

      if (newSchedule.isPresent()) {
        isImproving = true;
        bestSchedule = newSchedule.get();

        if (listener.isPresent()) {
          listener.get().notify(bestSchedule.routes,
            bestSchedule.objectiveValue);
        }
        if (depthFirst) {
          // first improving swap is chosen as new starting point (depth
          // first).
          break;
        }
      }
    }
  }
  return bestSchedule.routes;
}
 
開發者ID:rinde,項目名稱:RinLog,代碼行數:66,代碼來源:Swaps.java


注:本文中的it.unimi.dsi.fastutil.objects.Object2DoubleLinkedOpenHashMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。