How to model special set constraints using Choco solver framework for Java

671 views Asked by At

I'm having problems modelling a problem and solving it with Choco-solver in Java, and I am not that familiar with constraint programming to begin with, but have been tasked to make a seating app for conferences where:

  • Each table must have a minimum of 6 people, and there are always enough tables.
  • People should be seated with neighbors as to maximize shared interests.
  • On preceding days we want to minimize people being seated on tables with people they were seated with earlier.
  • People are either of class A or B, and we want to minimize occurrences of class A on each table.

So far we have a SetVar guest_list including 1 up to number of guests. then partition guest_list to SetVar[] tables.

But how do I make constraints saying that each table.size >= 6?

How do I make constraints between two sets, as to minimize membership/intersections?

And I have no idea how to model for neighbors within a set as to maximize shared interests.

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());
1

There are 1 answers

0
Jean-Guillaume Fages On

The set of available constraints is accessible from model, which implements IConstraintFactory. Look at ISetConstraintFactory.java in the source code. There are constraints related to set sizes, unions, partitions...