最小化阵列的相邻项目功能 [英] Minimize function in adjacent items of an array

查看:197
本文介绍了最小化阵列的相邻项目功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组(改编)的元素,和函数( F )是需要2元和返回一个数字。

I have an array (arr) of elements, and a function (f) that takes 2 elements and returns a number.

我需要阵列的排列,使得 F(ARR [我],编曲[I + 1])是尽可能少的每个改编。 (它应该循环,也就是说,它也应该尽量减少 F(ARR [arr.length - 1],ARR [0])

I need a permutation of the array, such that f(arr[i], arr[i+1]) is as little as possible for each i in arr. (and it should loop, ie. it should also minimize f(arr[arr.length - 1], arr[0]))

此外, F 的作品有点像的距离,所以 F(A,B)= = F(B,A)

Also, f works sort of like a distance, so f(a,b) == f(b,a)

我并不需要的最佳解决方案,如果它的效率太低,而是一个合理的工作很好,速度很快,因为我需要计算它们pretty的很多实时(我不知道该怎么<$的长度C $ C>改编是,但我认为这可能是一些围绕30)

I don't need the optimum solution if it's too inefficient, but one that works reasonable well and is fast since I need to calculate them pretty much in realtime (I don't know what to length of arr is, but I think it could be something around 30)

推荐答案

什么是使得f(ARR [我],编曲[I + 1])是尽可能少的每一个我在改编是什么意思?你想减少的的?你希望尽量减少最大的那些?是否要最大限度地减少F(改编[0],改编[1]),然后再是最大限度地减少这种所有解决方案中,挑选一个最小化F(改编[1],ARR [2])等,等对?

What does "such that f(arr[i], arr[i+1]) is as little as possible for each i in arr" mean? Do you want minimize the sum? Do you want to minimize the largest of those? Do you want to minimize f(arr[0],arr[1]) first, then among all solutions that minimize this, pick the one that minimizes f(arr[1],arr[2]), etc., and so on?

如果你想减少的的,这是的完全的在其全部一般性旅行商问题(当然,指标TSP,也许,如果你的F公司的确形成一个度量)。有聪明的优化,以天真的解决方案,它会给你确切的最佳以及有关运行在合理的时间n = 30;你可以使用其中的一个,或者说给你近似的启发之一。

If you want to minimize the sum, this is exactly the Traveling Salesman Problem in its full generality (well, "metric TSP", maybe, if your f's indeed form a metric). There are clever optimizations to the naive solution that will give you the exact optimum and run in reasonable time for about n=30; you could use one of those, or one of the heuristics that give you approximations.

如果你想减少的最大的,这是一个简单的问题,虽然仍然NP难:你可以做的答案二进制搜索;对于特定的值d,绘制边缘的量有f对(X,Y)

如果你希望尽量减少它的 lexiocographically 的,这是微不足道的:挑对的最短距离,并把它作为ARR [0],编曲[1],然后选择ARR [2]这是最接近给Arr [1],等等。

If you want to minimize the maximum, it is a simpler problem although still NP-hard: you can do binary search on the answer; for a particular value d, draw edges for pairs which have f(x,y)

If you want to minimize it lexiocographically, it's trivial: pick the pair with the shortest distance and put it as arr[0],arr[1], then pick arr[2] that is closest to arr[1], and so on.

根据在您的F(,)s是未来,这可能是比TSP更简单的问题;这将是对您有用提到这一点。

Depending on where your f(,)s are coming from, this might be a much easier problem than TSP; it would be useful for you to mention that as well.

这篇关于最小化阵列的相邻项目功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆