当前位置: 首页>>代码示例>>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;未经允许,请勿转载。