拼图搜索过程的树表示

时间:2014-03-30 22:25:59

标签: algorithm optimization prolog artificial-intelligence graph-algorithm

我应该在架子上放置1个大的和3个小盒子,如下图所示,使用最少的能量

大盒子的长度和重量是小盒子的两倍。货架的长度是小箱子长度的三倍。上部货架的高度是下部货架的两倍。

我如何表示搜索过程的树(例如,使用Uinform-cost搜索)?

1 个答案:

答案 0 :(得分:1)

你可以使用Constraint Logic Programming(这里是ECLiPSe)来解决这个问题。您使用数字域中的变量对问题建模,并调用内置搜索例程。为简单起见,我假设长度=重量。

:- lib(ic).
:- lib(branch_and_bound).

solve(Vars, Energy) :-

    Vars = [TopSmall, TopLarge, BotSmall, BotLarge],

    TopSmall :: 0..3,                       % how many small boxes on top
    BotSmall :: 0..3,                       % how many small boxes on bottom
    TopLarge :: 0..1,                       % how many large boxes on top
    BotLarge :: 0..1,                       % how many large boxes on bottom

    TopSmall + BotSmall #= 3,               % total small boxes
    TopLarge + BotLarge #= 1,               % total large boxes

    TopWeight #= TopSmall*1 + TopLarge*2,   % total on top
    BotWeight #= BotSmall*1 + BotLarge*2,   % total on bottom

    TopWeight #=< 3,                        % shelf capacities
    BotWeight #=< 3,

    Energy #= 2*TopWeight + 1*BotWeight,    % Top shelf at double height

    minimize(labeling(Vars), Energy).       % find a minimal solution
    % labeling(Vars).                       % alternatively, find all solutions
相关问题