我会尽力解释,在数学语言的问题。 假设我有一组项目 X = {X_1,X_2,...,x_n} 。对中的每一项X 属于集中的一个 S_1,S_2,...,S_5 。我认为 X 所有由5个项目的子集: {x_i1,x_i2,...,xi5} 让 x_i1 属于 S_1 ,..., x_i5 $ belogns到 S_5 。 部分子集被认为是正确的,一些被认为是不正确的。子集被认为是正确的,如果它不包含冲突项目。我有一个函数f1至determing如果对项目发生冲突或没有。 我也有一个函数f2它可以比较这种正确的子集,并说这集是更好的(他们可能是等于为好)。 我需要找到最好不冲突的子集(S)。
I'll try to explain the problem in the math language. Assume I have a set of items X = {x_1, x_2, ..., x_n}. Each item of X belongs to one of the sets S_1, S_2, ..., S_5. I consider all the subsets of X consisting of 5 items: {x_i1, x_i2, ..., xi5} so x_i1 belongs to S_1, ..., x_i5 belogns to S_5. Some subsets are considered to be correct and some are considered to be not correct. Subset is considered to be correct if it does not contain conflicting items. I have a function f1 to determing if a pair of items conflict or not. I also have a function f2 which can compare such correct subsets and say which subset is better (they might be equal as well). I need to find the best not-conflicting subset(s).
算法中我使用: 我建所有的子集,丢弃未正确的子集。然后我整理使用F2作为排序功能正确的子集,并把第一个(我用的快速排序算法)最好的子集(S)。至于有一个巨大的亚群的数量这一过程花的时间不够。
Algo I used: I built all the subsets, discarded not-correct subsets. Then I sorted correct subsets using f2 as a sorting function and took first best subset(s) (I used quick-sort algorithm). As far as there were a huge number of subsets this procedure took insufficient amount of time.
有时间消费方面有更好的方法?
Is there a better approach in terms of time-consumption?
更新时间: 让我们考虑x_i的,如果是区间的整数端点。 F1返回true,如果2区间不相交,否则为假。 F2比较区间的长度总和在子集。
UPDATED Let's think of x_i as if it's interval with integer endpoints. f1 returns true if 2 intervals do not intersect and false otherwise. f2 compares sum lengths of intervals in subsets.
推荐答案这个问题是最大的加权区间调度算法的变化。该DP算法具有多项式复杂 O(N *日志(N))与为O(N)空间幼稚的问题,而 O(2 ^ G * N * LOGN(N))与 0的复杂性(2 ^ G * N)这种变化问题,其中 This problem is a variation of maximum weighted interval scheduling algorithm. The DP algorithm has polynomial complexity of O(N*log(N)) with O(N) space for the naive problem, and O(2^G * N * logn(N)) complexity with O(2^G * N) space for this variation problem, where G, N represent the total no of groups/subsets(5 here) & intervals respectively. 如果x_i不重新present间隔,那么问题是NP,这是其它解决方案已被证明。 If x_i doesn't represent intervals, then the problem is in NP, which other solutions have proved. 首先让我解释的最大加权区间调度的动态规划的解决方案,进而解决问题的变化。 First let me explain the dynamic programming solution for maximum weighted interval scheduling, and then solve the variation problem. 该解决方案的复杂性是 O(N *日志(N)+ N)。 N *日志(N)查找下一个(我)所有作业,而ñ 解决的子问题。空间是 O(N)保存子问题的解决方案。 Complexity of this solution is O(N*log(N) + N). N*log(N) for finding next(i) for all jobs, and N for solving the subproblems. Space is O(N) for saving subproblem solutions. 现在,让我们解决这个问题的变化。 Now, lets solve variation of this problem. 请注意,我可能已经错过了一些基本情况。 Note that I may have missed some base cases. 该算法中的复杂性是 O(2 ^ G * N * LOGN(N))与 O(2 ^ G * N)的空间。 2 ^ G *ñ重presents子问题大小。 Complexity of this algo is O(2^G * N * logn(N)) with O(2^G * N) space. 2^G * N represents the subproblem size. 作为估计,为 G&LT小值= 10 和的高值N&GT; = 100000 ,这种算法中快速运行pretty的。对于 G&GT中值= 20 , N'LT = 10000 应较低,以及该算法中收敛。而对于高值 G&GT;。= 40 ,该算法中不收敛 As an estimate, for small values of G<=10 and high values of N>=100000, this algo runs pretty quickly. For medium values of G>=20, N<=10000 should be low as well for this algo to converge. And for high values of G>=40, the algo doesn't converge.
更多推荐
算法找到在一定的约束项的最佳组合
发布评论