제약 논리 프로그래밍 (여기 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