【问题标题】:How to get all Variations/Combinations with Variables and Constraints? Python 3.6如何获得具有变量和约束的所有变体/组合?蟒蛇 3.6
【发布时间】:2020-03-03 22:16:33
【问题描述】:

我需要运筹学项目的帮助,因为我需要以下所有组合/变体:

我有四种不同长度的轮廓,长度为 2.8m ; 3.2m; 3.8m; 4.2m;它们结合起来给了我一个总长度 --> 一个组合,因为这个例子 1x 2.8m 和 1x 3.2m 和 1x 3.8m 和 0x 4.2m 给了我 11.2m

现在我需要这四个长度的所有可能组合,但最大总长度为 12m,最小为 9.2m

如何在 Python 3.6 中做到这一点,有哪些可能的解决方案?

【问题讨论】:

    标签: python-3.x constraints combinations variations


    【解决方案1】:

    这应该可行

    combinations = [(a * 2.8, b * 3.2, c * 3.8, d * 4.2) 
                    for a in range(2) 
                    for b in range(2) 
                    for c in range(2) 
                    for d in range(2)]
    matches = [x for x in combinations if 9.2 <= sum(x) <= 12]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 2013-03-05
      相关资源
      最近更新 更多