本文整理汇总了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;
}
示例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;
}