【问题标题】:Framing painter's canvases (optimization or AI?)构图画家的画布(优化还是人工智能?)
【发布时间】:2014-05-29 12:16:25
【问题描述】:

这是我想提出的一个问题: 画家打算以厘米为单位将他的不同尺寸的方形画布框起来:

25cm x 35cm -- 20 件, 50 x 30 -- 30 个, 90 x 50 - 40 个, 110 x 60 -- 25 个,

画家将购买 200 厘米的木制担架并进行相应的切割。 条件是“每个框架边缘应该是单个连续条。没有胶合”。

提供长度为 200 厘米的无限木制担架。 画家应该买多少条(200 厘米)? 如何计算最优化的条数,减少条数的浪费?

这个问题与优化(数学编程)或人工智能有关吗? 欢迎使用 PHP、Perl、vbscript 代码。

=============== 为澄清起见,以下是 200 厘米棒材的确切长度。

LENGTH      PIECES        TOTAL LENGTH 
110  cm      50   pcs      5500   cm
90   cm      80   pcs      7200   cm
60   cm      50   pcs      3000   cm
50   cm      140  pcs      7000   cm
35   cm      40   pcs      1400   cm
30   cm      60   pcs      1800   cm
25   cm      40   pcs      1000   cm
===========================================
            ALL TOTAL:     26900   cm

如果允许我们粘上剩余的小块,它等于 134.5 条。

指导油漆工应该从每根钢筋上剪下多少长度是很实用的。 否则他将不知道如何处理提供的酒吧。

【问题讨论】:

  • 这是一个数学规划问题。您需要最少数量为 2m 的库存棒材的最佳切割清单。我假设您应该忽略拐角斜接所需的额外部分(即钢筋的有效宽度为零),因此您的切割清单为 40 x 25cm、60 x 30cm、40 x 35cm、140 x 50cm、50 x 60cm 、80 x 90 厘米和 50 x 110 厘米
  • 请考虑条形零宽度。

标签: php perl vbscript artificial-intelligence mathematical-optimization


【解决方案1】:

您需要拉伸条的宽度来计算角度的长度(为画布的每一侧花费额外的2*$stretcher_width

use strict;
use warnings;

my $stretcher_length = 200;
my $stretcher_width = 0;
my $wasted_per_side = 2*$stretcher_width;
my @sc = (
   {w=> 25,  h=> 35, pcs=> 20},
   {w=> 50,  h=> 30, pcs=> 30},
   {w=> 90,  h=> 50, pcs=> 40},
   {w=> 110, h=> 60, pcs=> 25},
);
# all possible bars needed from longest to shortest
my @all = sort { $b <=> $a } map {
  (
    ($_->{w}+$wasted_per_side) x2, ($_->{h}+$wasted_per_side) x2
  )x $_->{pcs};
}
@sc;

# lets cut from 200cm bars
my @rest;
for my $len (@all) {

  my $cut_from;
  # do we already have bar which can be used?
  for my $len_have (@rest) {
    # yes, we have
    if ($len_have >= $len) { $cut_from = \$len_have; last; }
  }
  # no, we need another 200cm bar
  if (!$cut_from) {
    print "Taking new $stretcher_length cm bar\n";
    push @rest, $stretcher_length;
    $cut_from = \$rest[-1];
  }
  # cut it
  print "Now you have at least one bar $$cut_from long and cut away $len\n";
  $$cut_from -= $len;

  # keep @rest bars sorted from shortest to longest
  @rest = sort { $a <=> $b } @rest;
}

print scalar @rest;
# print "@rest\n"; # left overs

【讨论】:

  • 检查您的代码。同时,yr 代码的结果是 116 条。框架所需的实际长度为 26900 厘米 = 134.5 条,如果我们使用单个长条,则不会浪费。
  • @user3687431 stackoverflow.com/revisions/… 无废版。 (将 $stretcher_width 设置为零)
  • @user3687431 是的,它总是寻找最小的可重用条。
【解决方案2】:

其实是断货问题 Wikipedia article

有一个 C 实现 CPSOL 用 135 根棍子解决上述问题。

很遗憾,找不到 Perl 实现

【讨论】:

    猜你喜欢
    • 2020-09-11
    • 2012-03-28
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    相关资源
    最近更新 更多