C#算法计算出不同的可能组合组合、算法、计算出、不同

2023-09-06 06:29:12 作者:恨我的人别放弃

我有10个箱子,每个箱子能装一个项目,从项目的一组/类型,每个组类型只适用于10箱类型之一。该项目池可以有一个项目n多。该集团有完全不同的项目。每个项目都有一个价格,我想一个算法,会产生各种不同的可能性,这样我就可以计算出不同的价位VS定制等级/权重分配到每个项目,根据项目属性。

I have 10 boxes, each box can hold one item from a group/type of items, each 'group' type only fits in one of the 10 box types. The item pool can have n number of items. The groups have completely distinct items. Each item has a price, i want an algorithm that will generate all the different possibilities, so i can figure out different price points vs custom rank/weight assignment to each of the items, based on item attributes.

所以这个问题的一个较小的图片

so a smaller picture of the problem

BOX A - 可以在它的项目1,2,3,4

BOX A - can have item 1,2,3,4 in it

乙栏 - 可以品6,7,8,9,10,11,12

BOX B - can have item 6,7,8,9,10,11,12

BOXÇ - 可以有项目13,15,16,20,21

BOX C - can have item 13,15,16,20,21

更多详细信息 该解决方案将是一个集箱A,B盒,和Box的C,具有基于集箱的最大级别。每个盒子只能包含为该方格的项目之一。 一个项目是一个对象,该对象具有3属性(硬度,弹性,强度)。每个属性都可以有1-100的分数。的目标是进入一个重量为每个属性,则逻辑将通过所有项目运行,并确定基于所述权重为每个属性的排名靠前的项目组合。我已经使用3个属性的每个项目,为了便于说明,但项目可以有大约10种不同的属性。

More Detail The solution would be a set of BOX A, BOX B, AND BOX C, having the greatest rank based on the set of boxes. Each box can only contain ONE of the designated items for that box. An item is an object, the object has 3 attributes(firmness, elasticity, strength). Each attribute can have 1-100 for a score. The goal is to enter a weight for each attribute, then the logic will run through ALL items and determine the top ranked item combinations based on the weights for each attribute. I have used 3 attributes for each item for ease of explanation, but items can have about 10 different attributes.

该项目被存储在一个数据库,它们具有代表哪个箱子,他们可以在一列,所有盒类型存储在一个数组中,我可以把项目中的一个通用的清单。任何人看到一个简单的方法来做到这一点。

The items are stored in a db, they have a column which denotes which box they can go in. All box types are stored in an array, and I can put the items in a generic list. Anyone see a straightforward way to do this.

我曾尝试做10嵌套的foreach的,看看我能找到一个更简单的方法。嵌套循环会需要几个小时来运行。嵌套每个基本上拉所有组合,然后计算每个组合的一个等级,并存储为输出项的前10位的组合

I have tried doing 10 nested foreach's to see if i could find a simpler way. The nested loops will take MANY hours to run. the nested for each's basically pull all combinations, then calculate a rank for each combination, and store the top 10 ranked combination of items for output

推荐答案

这看起来像一个二进制程序,其中

This looks like a binary program, where

maximize $\sum_i c_i x_i$ (value function)


$x_i \in \{ 0, 1 \} \forall i$ (binary constraint)

$x_1 + x_2 + x_3 + x_4 = 1$ (exactly one item in box a constraint)

$x_6 + x_7 + x_8 + x_9 + x_{10} + x_{11} + x_{12} = 1$

$x_{13} + x_{15} + x_{16} + x_{20} + x_{21} = 1$

$\sum_i p_i x_i <= P$ (price constraint)

(粘贴到上述乳胶评估,像math.se,看到符号)

(paste the above into a LaTeX evaluator, like math.se, to see the symbols)

这可以通过使用分支定界比评估每一个组合要少得多的步骤。优化

This can be optimized using branch-and-bound in far fewer steps than evaluating every combination.