choco-solver icon indicating copy to clipboard operation
choco-solver copied to clipboard

`Settings` object should become immutable once the model is setup

Open cprudhom opened this issue 1 year ago • 2 comments

This way of declaring settings is correct:

Model model = new Model(Settings.init().setWarnUser(false));

because the Settings instance is not stored and cannot be modified once the model is created. But the following declaration makes possible to change the settings afterward:

Settings settings = Settings.init().setWarnUser(false);
Model model = new Model(settings);
settings.setWarnUser(true);

I suppose the settings must be set immutable or the model should have a deep copy of it.

cprudhom avatar Nov 08 '23 08:11 cprudhom

I see your point, but I would not tag it as a bug.

It is true that some settings cannot be modified afterwards (I think only the setInitSolver is concerned, because the initSolver is called in the constructor). Nevertheless, for the vast majority of the settings, we can update their value without problem, and I find the following code more convenient than going through the model constructor : Model model = new Model(); model.getSettings().setEnableSAT(true); So, even if I agree that we could have something cleaner/safer, it may make the models heavier... so I may prefer to keep it as it is (not a strong opinion either).

Did you want to somehow "factorise" the same settings object for several Models ?

jgFages avatar Nov 15 '23 19:11 jgFages

I think it is not really a problem that settings can be modified after the model has been created. However, maybe we could make them immutable once a call to propagate() or solve() has been done. But even for this, I don't really see the point (except avoiding concurrent modification).

ArthurGodet avatar Nov 18 '23 15:11 ArthurGodet