简体   繁体   English

Python 中可变长度数组的可能排列

[英]Possible permutation of variable length arrays in Python

I have 3 different product (A, B, C) to produce.我有 3 种不同的产品(A、B、C)要生产。
The quantities to produce are fix: A=3, B=3, C=2.要生产的数量是固定的:A=3,B=3,C=2。 So all together 8 products.所以总共有 8 个产品。
The problem is that I only have 2 preparation lines for 3 production lines each for a specific product: LineA, LineB, LineC.问题是我只有 2 条准备线,每条生产线用于特定产品:LineA、LineB、LineC。
The preparation lines can prepare all 3 type of products That means that I can only have 2 active production lines, the 3rd one is idle for that shift.准备线可以准备所有 3 种类型的产品 这意味着我只能有 2 条活跃的生产线,第 3 条闲置用于该班次。
The duration of each working shift is equal.每个工作班次的持续时间是相等的。

So all together I'll have 4 working shifts (8 products / 2 preparation lines)所以总共我将有 4 个工作班次(8 个产品/2 条准备线)

My question is: How can I write a algorithm which shows me all possible permutations.我的问题是:如何编写一个算法来显示所有可能的排列。 The output would be something similar to this (this is just one permutation, I'd need all possibilities to see the idle shifts) :输出将与此类似(这只是一种排列,我需要所有可能性才能看到空闲班次):

LineA LineB LineC
  A     B     -
  A     -     C
  -     B     C
  A     B     -

EDIT:编辑:
The actual lists for the above mentioned output are:上述输出的实际列表是:

AAA
BBB
CC

EDIT2编辑2
The itertools functions are not working here as they are not taking into account the finite number of items in each list. itertools 函数在这里不起作用,因为它们没有考虑每个列表中的有限项数。 I have a finite number of items so I need a list of list of all possible permutations/combination (in this example I would need n times of 4x3 matrix)我的项目数量有限,所以我需要一个所有可能排列/组合的列表(在这个例子中,我需要 n 次 4x3 矩阵)
First I would need a first combination (like drawn in the example) than I would need all the possible combination of that.首先,我需要第一个组合(如示例中绘制的),而不是所有可能的组合。
Of course as the number is increasing there will be a bigger n for a ?x3 matrix当然,随着数量的增加,对于 ?x3 矩阵会有更大的 n
You can also forget the empty values, so in this case the result for the above mentioned example would be n times of a 4x2 matrix您也可以忘记空值,因此在这种情况下,上述示例的结果将是 4x2 矩阵的 n 倍

If I am not overlooking something, the set of combinations A,B,C,- is constant.如果我没有忽略某些东西,组合A,B,C,-的集合是恒定的。 It is exactly those from your example.这正是你的例子中的那些。 I cannot see a way to produce the numbers required any other way.我看不出有其他方法可以生成所需的数字。 So what you have to do is produce all permutations of the 4(3) production states you showed.所以你需要做的是产生你展示的 4(3) 产生状态的所有排列。 If preparation lines are allowed to be idle, then things get markedly more interesting.如果允许准备线闲置,那么事情就会变得更加有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM