Previous: , Up: CLPFD Example Programs   [Contents][Index]


10.9.15.6 Rack Configuration

This example is a product configuration problem. There are two types of alveoles and 17 boards of four types. We want to plug in all boards using at most 5 alveoles at minimal cost.

alveole typepowerslotscostboard typepowerquantity
10.000119.510
2150.08150239.54
3200.016200349.52
474.51
:- use_module(library(lists), [append/2, transpose/2]).
:- use_module(library(clpfd)).

config(Alveoles, Boardss, Cost) :-
        problem(Alveoles, Boardss, Cost, Variables),
        labeling([minimize(Cost)], Variables).

problem(Alveoles, Boardss, Cost, Variables) :-
        length(Alveoles, 5),
        (   foreach(Alveole,Alveoles),
            foreach(Boards,Boardss),
            foreach(ACost,ACosts)
        do  alveole_constraints(Alveole, Boards, ACost)
        ),
        append(Boardss, BoardsFlat),
        domain(BoardsFlat, 0, 10),
        transpose(Boardss, [BoardT1, BoardT2, BoardT3, BoardT4]),
        sum(BoardT1, #=, 10),
        sum(BoardT2, #=, 4),
        sum(BoardT3, #=, 2),
        sum(BoardT4, #=, 1),
        sum(ACosts, #=, Cost),
        decreasing(Alveoles),
        append(Alveoles, BoardsFlat, Variables).

alveole_constraints(AType, [N1,N2,N3,N4], ACost) :-
        element(AType, [0.0, 150.0, 200.0], APower),
        element(AType, [0, 8, 16], ASlots),
        element(AType, [0, 150, 200], ACost),
        sum([N1,N2,N3,N4], #=<, ASlots),
        19.5 * float(N1) +
        39.5 * float(N2) +
        49.5 * float(N3) +
        74.5 * float(N4) $=< APower.

| ?- config(As, Cs, Cost).
As = [3,3,2,1,1],
Cs = [[0,3,0,1],[3,1,2,0],[7,0,0,0],[0,0,0,0],[0,0,0,0]],
Cost = 550

The optimal solution with cost 550 uses two type 3 alveoles, one type 2 alveole, and two type 1 (unused) alveoles. The first alveole contains three type 2 boards and one type 4 board, and so on.


Send feedback on this subject.