Skip to content

Enumerate all solutions to a subset of variables #3345

@olarozenfeld

Description

@olarozenfeld

Additional context: https://groups.google.com/g/or-tools-discuss/c/JKiZLEzEo9E

I'm using CP-SAT to enumerate all feasible solutions, however in my problem there are variables that I "care about" and others are just "helper variables". A toy example: x,y,z with the constraint x=y, but I only want to enumerate all possible assignments to {x,y}.
So far, I found two ways to do that:

  1. Run Solve(cp_model) in a loop, adding an Or constraint after every solution to fix at least one literal different to the current solution.
  2. Run with the NewFeasibleSolutionObserver and iterate over all full assignments, computing a hash key for each one based on my key variables and thus merging the equivalent assignments manually.

Both of these are quite inefficient, for different reasons. On the problem I'm trying to solve, both these approaches proved effectively infeasible, no matter how much I tried reducing the problem space.

I would like to amend the solver to allow adding key_variables in solver parameters, and then having NewFeasibleSolutionObserver only iterate over different assignments to these key variables. From the or-tools-discuss thread, it looks like the feature would be helpful to a few other users as well.

I'm thinking of trying to implement this myself, and I would really appreciate any tips. Does this sound like a good idea? Is this feasible? Pointers to key sections of the code?

Thank you!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions