Which algorithm could solve my wedding table issue?

后端 未结 4 876
无人共我
无人共我 2021-02-08 07:59

I have x guests for my wedding and y tables with z seats. Guest A can sit on the same table as guest B and guest C can not sit on the same table as guest D, ....

Given

4条回答
  •  轮回少年
    2021-02-08 08:19

    If you require an exact solution, formulate it as an 0-1 integer program and use GLPK to solve it.

    Let x_ij be 1 if person i is assigned to table j and 0 otherwise. Consider the following constraint set:

    (i) sum_{j=1...y} x_ij = 1 for i=1...x

    (ii) sum_{i=1...x} x_ij <= z for j=1...y

    (iii) x_ij + x_kj <=1 for j=1...y

    (iv) x_ij is binary

    Constraints (i) make sure everyone is assigned. Constraints (ii) prevents overloading a table. Constraints (iii) are defined for each person pair (i,k) that can't sit together.

    Plug it into GLPK, CPLEX, or GUROBI and you're in business, provided that the problem is not too large. As the others have mentioned, NP-hardness means things could get ugly.

提交回复
热议问题