Skip to content

Decouple CP model from component constraint generators using context/state/result pattern#436

Draft
juaninf wants to merge 9 commits intodevelopfrom
decoupling_model_in_cp_components
Draft

Decouple CP model from component constraint generators using context/state/result pattern#436
juaninf wants to merge 9 commits intodevelopfrom
decoupling_model_in_cp_components

Conversation

@juaninf
Copy link
Copy Markdown
Collaborator

@juaninf juaninf commented Apr 3, 2026

Remove cp_/minizinc_ dispatch in build_generic and decouple CP model from constraint generators

  • Introduce CpBuildContext (frozen), CpBuildState (mutable), and CpComponentBuildResult dataclasses to decouple CP model state from component constraint methods.
  • Migrate all ~56 cp_* constraint methods across 16 component files to accept (context, state) and return CpComponentBuildResult instead of mutating the model directly.
  • Update all 9 CP model files to use the new context/state/result protocol.
  • Remove the if/else dispatch in build_generic_cp_model_from_dictionary that branched on model_type.startswith("cp_") vs minizinc_; the method now exclusively calls cp_ methods with (context, state).
  • Fix pre-existing bug in mzn_xor_differential_model_arx_optimized.py where weight_constraints() return value was incorrectly tuple-unpacked.
  • Update all affected unit tests (component + model tests).

Below a diagram showing the interaction between classes/methods/objects involved in the generation of CP models according to the refactor

cp_refactor_uml_sequence

@juaninf juaninf changed the title refactor: rename model.c and probability to component_probability_index/indices Refactor: Decoupling_model_from_cp_components Apr 4, 2026
@juaninf juaninf marked this pull request as draft April 13, 2026 05:21
@juaninf juaninf changed the title Refactor: Decoupling_model_from_cp_components Renaming variables involved in decoupling model task Apr 14, 2026
…from constraint generators

- Introduce CpBuildContext (frozen), CpBuildState (mutable), and
  CpComponentBuildResult dataclasses to decouple CP model state from
  component constraint methods.
- Migrate all ~56 cp_* constraint methods across 16 component files to
  accept (context, state) and return CpComponentBuildResult instead of
  mutating the model directly.
- Update all 9 CP model files to use the new context/state/result protocol.
- Remove the if/else dispatch in build_generic_cp_model_from_dictionary
  that branched on model_type.startswith("cp_") vs minizinc_*; the method
  now exclusively calls cp_* methods with (context, state).
- Update all affected unit tests (component + model tests).
@juaninf juaninf changed the title Renaming variables involved in decoupling model task Decouple CP model from component constraint generators using context/state/result pattern Apr 14, 2026
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant