Skip to content

Conversation

@tias
Copy link
Collaborator

@tias tias commented Sep 10, 2025

this needs more extensive testing...

(but its small test-case works)

also, there was a tricky aspect of using direct encoding (with weight 0 literals) in the objective... henk could you have a look?

@tias tias requested a review from hbierlee September 10, 2025 16:34
Copy link
Contributor

@hbierlee hbierlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks good to me!

The transform_objective should become part of the int2bool encode_expr (as it just encodes a linear sum, which is implemented that as part of encoding a linear constraint). This can wait until we need it for other optimization-compatible Boolean solvers.

else:
raise NotImplementedError(f"CPM_rc2: Non supported term {w,x} in objective {flat_obj} (yet?)")

# positive weights only, flip negative
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have only_positive_coefficients for this? Or are you not using that because it's a Comparison?

# make sure that `SolverLookup.get(solver)` works
# also add exclusions to the 3 EXCLUDE_* below as needed
SOLVERNAMES = [name for name, solver in SolverLookup.base_solvers() if solver.supported()]
SOLVERNAMES = [n for n in SOLVERNAMES if n not in ["rc2"]] # only supports optimisation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on or the other line should be removed?

self.assertTrue(solved)
self.assertIsNotNone(solver.objective_value())
# The optimal solution should have x[0]=True, x[1]=True, x[2]=True for objective value 3
# But RC2 might find a different solution due to the constraints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, what? Why won't it just find the optimal solution where all vars are assigned true?


def test_incremental(self, solver):
if solver == "rc2":
pytest.skip("not incremental")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought rc2 was incremental?

self.assertTrue(solved)
self.assertEqual(solver.objective_value(), 3)
self.assertEqual(list(x.value()), [False, True])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we can have a test for incrementally updating the objective (ie adding additional soft clauses)? Or do we not expose this yet?

@tias tias added this to the v.0.9.28 milestone Oct 6, 2025
@hbierlee
Copy link
Contributor

hbierlee commented Nov 3, 2025

@tias

as discussed in the meeting, more important than the above review questions, is that we should consider whether we can add RC2 as a subsolver? Just from a user perspective, should "Pysat" and "RC2" seen side by side, or RC2 as part/subsolver of Pysat?

If subsolver, I can try to refactor that. If not, probably I can still remove some duplication by perhaps subclassing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants