我在建模问题并使用 Java 中的 Choco-solver 解决问题时遇到问题,而且我对约束编程一开始并不熟悉,但我的任务是为以下会议制作一个座位应用程序:
- 每张桌子必须至少有 6 人,并且总是有足够的桌子。
- 人们应该与邻居坐在一起,以最大限度地提高共同利益。
- 在前几天,我们希望尽量减少与之前坐过的人一起坐在桌子上的人。
- 人们要么属于 A 类,要么属于 B 类,我们希望在每张桌子上尽量减少 A 类的出现。
到目前为止,我们有一个 SetVar guest_list,其中包括最多 1 个客人。然后将 guest_list 分区到 SetVar[] 表。
但是我如何让约束说每个 table.size >= 6?
如何在两组之间进行约束,以最小化成员/交叉点?
而且我不知道如何为一组中的邻居建模以最大化共同利益。
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.SetVar;
// constant value declarations
int number_of_guests = 100;
int table_size = 8;
int tables_needed = number_of_guests / table_size + 1;
// this will later be passed as argument, generated for testing
int[] guest_ids = new int[number_of_guests];
for (int i = 0; i < number_of_guests; i++) {
guest_ids[i] = i;
}
// Model and variables
Model model = new Model("Seating solver");
IntVar min_guests_at_tables = model.intVar(6);
// a list containing all guests in its LB
SetVar guest_list = model.setVar("guests", guest_ids);
// making empty sets for each table needed, UB is all guests
SetVar[] tables = model.setVarArray(tables_needed, new int[]{}, guest_ids);
// log over table seatings from earlier days, starts empty for day 1.
// want to minimize how many members from tables[x] share with any ser of logged_tables
SetVar[] logged_tables = model.setVarArray(0, new int[]{}, new int[]{});
// a setvar of all interests for each guest, will be imported later.
SetVar[] guest_interests = model.setVarArray(number_of_guests, new int[]{}, new int[]{});
// set of all those members of group A
// random test values inserted
SetVar group_A_members = model.setVar(1,23,54,2);
// Constraints unsure about all of these
// each set must be unique
model.allDifferent(tables);
for (SetVar table : tables) {
// TODO trying to constrain sizes of each table set to 6 or greater
model.arithm(model.intVar(table.getLB().size()), ">=", min_guests_at_tables);
// TODO trying to minimize number of shared members in tables, with whats in logged_tables
for (SetVar old_table : logged_tables) {
// no idea
}
// TODO trying to maximize the amount of interest neigbors in a set share
// no idea
// TODO minimize shared members from table with group_A_members
// no idea how to minimize or maximize
}
// Solving
Solution s = model.getSolver().findSolution();
if (s != null) System.out.println(s.toString());