- java.lang.Object
-
- org.chocosolver.solver.Settings
-
public class Settings extends Object
Settings for Model and Solver. Can be modified programmatically and can be defined in a Model only on creation.Project: choco-solver.
- Since:
- 14/12/2017.
- Author:
- Charles Prud'homme
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
checkDeclaredConstraints()
boolean
checkDeclaredMonitors()
boolean
checkDeclaredViews()
boolean
checkModel(Solver solver)
boolean
cloneVariableArrayInPropagator()
static Settings
dev()
Define and returns settings adapted to development environment.boolean
enableDecompositionOfBooleanSum()
byte
enableHybridizationOfPropagationEngine()
boolean
enableIncrementalityOnBoolSum(int nbvars)
boolean
enableSAT()
boolean
enableTableSubstitution()
boolean
enableViews()
boolean
explainGlobalFailureInSum()
Settings
explainGlobalFailureInSum(boolean b)
Set to true to allow additional clauses to be learned from sum's global failureObject
get(String key)
ICondition
getEnvironmentHistorySimulationCondition()
Deprecated.double
getIbexContractionRatio()
boolean
getIbexRestoreRounding()
int
getLearntClausesDominancePerimeter()
When a clause is learnt from a conflict, it may happen that it dominates previously learnt ones.int
getMaxDomSizeForEnumerated()
int
getMaxLearntClauseCardinality()
int
getMaxPropagatorPriority()
int
getMaxTupleSizeForSubstitution()
int
getMinCardForSumDecomposition()
int
getNbMaxLearntClauses()
float
getRatioForClauseStoreReduction()
when clauses store need to be reduced, 'ratio' of them are kept (between 0.1 and .99)static Settings
init()
Create a new instance of `Settings` which can then be adapted to requirements.Solver
initSolver(Model model)
This method is called inModel(IEnvironment, String, Settings)
to create the solver to associate with a model.AbstractStrategy<?>
makeDefaultSearch(Model model)
Creates a default search strategy for the input modelboolean
printAllUndeclaredConstraints()
static Settings
prod()
Define and returns settings adapted to production environment.Settings
set(String key, Object value)
Settings
setCheckDeclaredConstraints(boolean checkDeclaredConstraints)
Indicate if the declared constraints are either posted or reified.Settings
setCheckDeclaredMonitors(boolean check)
Settings
setCheckDeclaredViews(boolean checkDeclaredViews)
Check if a view already semantically exists before creating it.Settings
setCloneVariableArrayInPropagator(boolean cloneVariableArrayInPropagator)
If this setting is set to true (default value), a clone of the input variable array is made in any propagator constructors.Settings
setDefaultSearch(Function<Model,AbstractStrategy<?>> defaultSearch)
Define a default search strategy for the input modelSettings
setEnableDecompositionOfBooleanSum(boolean enableDecompositionOfBooleanSum)
Define if boolean sums should be decomposed into an equality constraint + arithmetic constraintSettings
setEnableIncrementalityOnBoolSum(IntPredicate enableIncrementalityOnBoolSum)
Define the predicate to choose incremental sum, based on number variables declaredSettings
setEnableSAT(boolean enableSAT)
Indicate if clauses are managed by a unique SAT solver.Settings
setEnableTableSubstitution(boolean enableTableSubstitution)
Define whether some intension constraints are replaced by extension constraintsSettings
setEnableViews(boolean enableViews)
Set to 'true' to allow the creation of views in theModel
.Settings
setEnvironmentHistorySimulationCondition(ICondition environmentHistorySimulationCondition)
Deprecated.Settings
setHybridizationOfPropagationEngine(byte hybrid)
Define behavior of the propagation engine.void
setIbexContractionRatio(double ibexContractionRatio)
Defines the ratio that real domains must be contracted by ibex to compute the constraint.Settings
setIbexRestoreRounding(boolean ibexRestoreRounding)
If preserve_rounding is true, Ibex will restore the default Java rounding method when coming back from Ibex, which is transparent for Java but causes a little loss of efficiency.Settings
setInitSolver(Function<Model,Solver> initSolver)
Define the solver initializationSettings
setLearntClausesDominancePerimeter(int n)
When a clause is learnt from a conflict, it may happen that it dominates previously learnt ones.Settings
setMaxDomSizeForEnumerated(int maxDomSizeForEnumerated)
Define the minimum number of cardinality threshold to a sum/scalar constraint to be decomposed in intermediate sub-sums.Settings
setMaxLearntClauseCardinality(int n)
Set the maximum learnt clause cardinality, clauses beyond this value are ignored.Settings
setMaxPropagatorPriority(int maxPropagatorPriority)
Increase the number of priority for propagators (default isPropagatorPriority.VERY_SLOW
).Settings
setMaxTupleSizeForSubstitution(int maxTupleSizeForSubstitution)
Define the maximum domain size threshold to replace intension constraints by extension constraints Only checked whenenableTableSubstitution()
returnstrue
Settings
setMinCardinalityForSumDecomposition(int defaultMinCardinalityForSumDecomposition)
Define the default minimum number of cardinality threshold to a sum/scalar constraint to be decomposed into intermediate sub-sums.Settings
setModelChecker(Predicate<Solver> modelChecker)
Define what to do when a solution is found.Settings
setNbMaxLearntClauses(int n)
Set the maximum of number of learnt clauses to store before running a reduction of the store.Settings
setPrintAllUndeclaredConstraints(boolean printAllUndeclaredConstraints)
Indicate if all undeclared constraints are listed on console whencheckDeclaredConstraints()
is on.Settings
setRatioForClauseStoreReduction(float f)
when clauses store need to be reduced, 'ratio' of them are kept (between 0.1 and .99).Settings
setSortPropagatorActivationWRTPriority(boolean sortPropagatorActivationWRTPriority)
Set whether propagators are sorted wrt their priority inPropagationEngine
when dealing with propagator activation.Settings
setSwapOnPassivate(boolean swapOnPassivate)
Define if passivation of propagator swap it in variables' listSettings
setWarnUser(boolean warnUser)
To be informed of warnings detected during modeling/solvingboolean
sortPropagatorActivationWRTPriority()
boolean
swapOnPassivate()
boolean
warnUser()
-
-
-
Method Detail
-
init
public static Settings init()
Create a new instance of `Settings` which can then be adapted to requirements.
-
prod
public static Settings prod()
Define and returns settings adapted to production environment. All checks and warnings are turned off.- Returns:
- a settings adapted to production environment.
-
dev
public static Settings dev()
Define and returns settings adapted to development environment. All checks and warnings are turned on.- Returns:
- a settings adapted to development environment.
-
checkModel
public boolean checkModel(Solver solver)
- Parameters:
solver
- the solver- Returns:
- true if the model is OK wrt the checker, false otherwise
-
setModelChecker
public Settings setModelChecker(Predicate<Solver> modelChecker)
Define what to do when a solution is found. By default, it makes a weak check of the model:return !ESat.FALSE.equals(solver.isSatisfied());
return ESat.TRUE.equals(solver.isSatisfied());
- Parameters:
modelChecker
- a predicate to check the solution- Returns:
- the current instance
-
cloneVariableArrayInPropagator
public boolean cloneVariableArrayInPropagator()
- Returns:
- true if all propagators should clone the input variable array instead of simply referencing it.
-
setCloneVariableArrayInPropagator
public Settings setCloneVariableArrayInPropagator(boolean cloneVariableArrayInPropagator)
If this setting is set to true (default value), a clone of the input variable array is made in any propagator constructors. This prevents, for instance, wrong behavior when permutations occurred on the input array (e.g., sorting variables). Setting this to false may limit the memory consumption during modelling.- Parameters:
cloneVariableArrayInPropagator
-true
to clone variables array on constructor- Returns:
- the current instance
-
enableViews
public boolean enableViews()
- Returns:
- true if views are enabled.
-
setEnableViews
public Settings setEnableViews(boolean enableViews)
Set to 'true' to allow the creation of views in theModel
. Creates new variables with channeling constraints otherwise.- Parameters:
enableViews
-true
to enable views- Returns:
- the current instance
-
getMaxDomSizeForEnumerated
public int getMaxDomSizeForEnumerated()
- Returns:
- maximum domain size threshold to force integer variable to be enumerated
-
setMaxDomSizeForEnumerated
public Settings setMaxDomSizeForEnumerated(int maxDomSizeForEnumerated)
Define the minimum number of cardinality threshold to a sum/scalar constraint to be decomposed in intermediate sub-sums.- Parameters:
maxDomSizeForEnumerated
- cardinality threshold- Returns:
- the current instance
-
getMinCardForSumDecomposition
public int getMinCardForSumDecomposition()
- Returns:
- minimum number of cardinality threshold to a sum constraint to be decomposed
-
setMinCardinalityForSumDecomposition
public Settings setMinCardinalityForSumDecomposition(int defaultMinCardinalityForSumDecomposition)
Define the default minimum number of cardinality threshold to a sum/scalar constraint to be decomposed into intermediate sub-sums.- Parameters:
defaultMinCardinalityForSumDecomposition
- cardinality threshold- Returns:
- the current instance
-
enableTableSubstitution
public boolean enableTableSubstitution()
- Returns:
- true if some intension constraints can be replaced by extension constraints
-
setEnableTableSubstitution
public Settings setEnableTableSubstitution(boolean enableTableSubstitution)
Define whether some intension constraints are replaced by extension constraints- Parameters:
enableTableSubstitution
- enable table substitution- Returns:
- the current instance
-
getMaxTupleSizeForSubstitution
public int getMaxTupleSizeForSubstitution()
- Returns:
- maximum domain size threshold to replace intension constraints by extension constraints
-
setMaxTupleSizeForSubstitution
public Settings setMaxTupleSizeForSubstitution(int maxTupleSizeForSubstitution)
Define the maximum domain size threshold to replace intension constraints by extension constraints Only checked whenenableTableSubstitution()
returnstrue
- Parameters:
maxTupleSizeForSubstitution
- threshold to substitute intension constraint by table one.- Returns:
- the current instance
-
sortPropagatorActivationWRTPriority
public boolean sortPropagatorActivationWRTPriority()
- Returns:
true
if propagators are sorted wrt their priority on initial activation.
-
setSortPropagatorActivationWRTPriority
public Settings setSortPropagatorActivationWRTPriority(boolean sortPropagatorActivationWRTPriority)
Set whether propagators are sorted wrt their priority inPropagationEngine
when dealing with propagator activation.- Parameters:
sortPropagatorActivationWRTPriority
-true
to allow sorting static propagators.- Returns:
- the current instance
-
getMaxPropagatorPriority
public int getMaxPropagatorPriority()
- Returns:
- the maximum priority any propagators can have (default is 7)
-
setMaxPropagatorPriority
public Settings setMaxPropagatorPriority(int maxPropagatorPriority)
Increase the number of priority for propagators (default isPropagatorPriority.VERY_SLOW
). This directly impacts the number of queues to schedule propagators in the propagation engine.- Parameters:
maxPropagatorPriority
- the new maximum prioirity any propagator can declare- Returns:
- the current instance
-
makeDefaultSearch
public AbstractStrategy<?> makeDefaultSearch(Model model)
Creates a default search strategy for the input model- Parameters:
model
- a model requiring a default search strategy- Returns:
- a default search strategy for model
- See Also:
Search.defaultSearch(Model)
-
setDefaultSearch
public Settings setDefaultSearch(Function<Model,AbstractStrategy<?>> defaultSearch)
Define a default search strategy for the input model- Parameters:
defaultSearch
- what default search strategy should be- Returns:
- the current instance
-
getEnvironmentHistorySimulationCondition
@Deprecated public ICondition getEnvironmentHistorySimulationCondition()
Deprecated.
-
setEnvironmentHistorySimulationCondition
@Deprecated public Settings setEnvironmentHistorySimulationCondition(ICondition environmentHistorySimulationCondition)
Deprecated.
-
warnUser
public boolean warnUser()
- Returns:
- true if warnings detected during modeling/solving are output.
-
setWarnUser
public Settings setWarnUser(boolean warnUser)
To be informed of warnings detected during modeling/solving- Parameters:
warnUser
-true
to be print warnings on console- Returns:
- the current instance
-
enableDecompositionOfBooleanSum
public boolean enableDecompositionOfBooleanSum()
- Returns:
true
if boolean sum should be decomposed into an equality constraint and an arithmetic constraint,false
if a single constraint should be used instead.
-
setEnableDecompositionOfBooleanSum
public Settings setEnableDecompositionOfBooleanSum(boolean enableDecompositionOfBooleanSum)
Define if boolean sums should be decomposed into an equality constraint + arithmetic constraint- Parameters:
enableDecompositionOfBooleanSum
-true
to enable decomposition- Returns:
- the current instance
-
enableIncrementalityOnBoolSum
public boolean enableIncrementalityOnBoolSum(int nbvars)
- Parameters:
nbvars
- number of variables in the constraint- Returns:
true
if the incrementality is enabled on boolean sum, based on the number of variables involved.
-
setEnableIncrementalityOnBoolSum
public Settings setEnableIncrementalityOnBoolSum(IntPredicate enableIncrementalityOnBoolSum)
Define the predicate to choose incremental sum, based on number variables declared- Parameters:
enableIncrementalityOnBoolSum
- predicate to pick declare sum- Returns:
- the current instance
-
enableSAT
public boolean enableSAT()
- Returns:
- true when an underlying SAT solver is used to manage clauses declared through
ISatFactory
, false when clauses are managed with CSP constraints only.
-
setEnableSAT
public Settings setEnableSAT(boolean enableSAT)
Indicate if clauses are managed by a unique SAT solver.- Parameters:
enableSAT
-true
to rely on SAT Solver to handle clauses- Returns:
- the current instance
-
swapOnPassivate
public boolean swapOnPassivate()
- Returns:
- true if, on propagator passivation, the propagator is swapped from active to passive in its variables' propagators list. false if, on propagator passivation, only the propagator's state is set to PASSIVE.
-
setSwapOnPassivate
public Settings setSwapOnPassivate(boolean swapOnPassivate)
Define if passivation of propagator swap it in variables' list- Parameters:
swapOnPassivate
-true
to enable swapping- Returns:
- the current instance
-
checkDeclaredConstraints
public boolean checkDeclaredConstraints()
- Returns:
- true (default value) to check if all declared constraints are not free anymore, that is either posted or reified, before running the resolution. false to skip the control.
-
setCheckDeclaredConstraints
public Settings setCheckDeclaredConstraints(boolean checkDeclaredConstraints)
Indicate if the declared constraints are either posted or reified.- Parameters:
checkDeclaredConstraints
-true
to check constraints before resolution- Returns:
- the current instance
-
printAllUndeclaredConstraints
public boolean printAllUndeclaredConstraints()
- Returns:
- true to list all undeclared constraint, false (default value) otherwise.
Only active when
checkDeclaredConstraints()
is on.
-
setPrintAllUndeclaredConstraints
public Settings setPrintAllUndeclaredConstraints(boolean printAllUndeclaredConstraints)
Indicate if all undeclared constraints are listed on console whencheckDeclaredConstraints()
is on.- Parameters:
printAllUndeclaredConstraints
-true
to list all undeclared constraints- Returns:
- the current instance
-
checkDeclaredViews
public boolean checkDeclaredViews()
- Returns:
- true (default value) to check prior to creation if a view already semantically exists.
-
setCheckDeclaredViews
public Settings setCheckDeclaredViews(boolean checkDeclaredViews)
Check if a view already semantically exists before creating it.- Parameters:
checkDeclaredViews
-true
to check views before creation- Returns:
- the current instance
-
setCheckDeclaredMonitors
public Settings setCheckDeclaredMonitors(boolean check)
-
checkDeclaredMonitors
public boolean checkDeclaredMonitors()
-
initSolver
public Solver initSolver(Model model)
This method is called inModel(IEnvironment, String, Settings)
to create the solver to associate with a model.- Parameters:
model
- a model to initialize with a solver- Returns:
- the new solver
-
setInitSolver
public Settings setInitSolver(Function<Model,Solver> initSolver)
Define the solver initialization- Parameters:
initSolver
- function to initialize the solver- Returns:
- the current instance
-
enableHybridizationOfPropagationEngine
public byte enableHybridizationOfPropagationEngine()
- Returns:
- 0b00 if constraint-oriented propagation engine, 0b01 if hybridization between variable and constraint oriented and 0b10 if variable-oriented.
-
setHybridizationOfPropagationEngine
public Settings setHybridizationOfPropagationEngine(byte hybrid)
Define behavior of the propagation engine.- Parameters:
hybrid
- When set to '0b00', this works as a constraint-oriented propagation engine; when set to '0b01', this workds as an hybridization between variable and constraint oriented propagation engine. when set to '0b10', this workds as a variable- oriented propagation engine.- Returns:
- the current instance
-
getNbMaxLearntClauses
public int getNbMaxLearntClauses()
- Returns:
- maximum number of learnt clauses to store. When reached, a reduction is applied.
- See Also:
setNbMaxLearntClauses(int)
,setRatioForClauseStoreReduction(float)
,getRatioForClauseStoreReduction()
,setMaxLearntClauseCardinality(int)
,getMaxLearntClauseCardinality()
-
setNbMaxLearntClauses
public Settings setNbMaxLearntClauses(int n)
Set the maximum of number of learnt clauses to store before running a reduction of the store.- Parameters:
n
- maximum number of learnt clauses before reducing the store.- Returns:
- the current instance
- See Also:
getNbMaxLearntClauses()
,setRatioForClauseStoreReduction(float)
,getRatioForClauseStoreReduction()
,setMaxLearntClauseCardinality(int)
,getMaxLearntClauseCardinality()
-
getRatioForClauseStoreReduction
public float getRatioForClauseStoreReduction()
when clauses store need to be reduced, 'ratio' of them are kept (between 0.1 and .99)
-
setRatioForClauseStoreReduction
public Settings setRatioForClauseStoreReduction(float f)
when clauses store need to be reduced, 'ratio' of them are kept (between 0.1 and .99). A call to this defines 'ratio'.- Parameters:
f
- ratio for clause store reduction- Returns:
- the current instance
- See Also:
getRatioForClauseStoreReduction()
,setNbMaxLearntClauses(int)
,getNbMaxLearntClauses()
,setMaxLearntClauseCardinality(int)
,getMaxLearntClauseCardinality()
-
getMaxLearntClauseCardinality
public int getMaxLearntClauseCardinality()
- Returns:
- maximum learnt clause cardinality, clauses beyond this value are ignored.
- See Also:
setMaxLearntClauseCardinality(int)
,setNbMaxLearntClauses(int)
,setRatioForClauseStoreReduction(float)
,getRatioForClauseStoreReduction()
,setRatioForClauseStoreReduction(float)
-
setMaxLearntClauseCardinality
public Settings setMaxLearntClauseCardinality(int n)
Set the maximum learnt clause cardinality, clauses beyond this value are ignored.- Parameters:
n
- maximum learnt clause cardinality.- Returns:
- the current instance
- See Also:
getMaxLearntClauseCardinality()
,getNbMaxLearntClauses()
,setRatioForClauseStoreReduction(float)
,getRatioForClauseStoreReduction()
,setRatioForClauseStoreReduction(float)
-
getLearntClausesDominancePerimeter
public int getLearntClausesDominancePerimeter()
When a clause is learnt from a conflict, it may happen that it dominates previously learnt ones. The dominance will be evaluated with the n last learnt clauses. n = 0 means no dominance check, n =Integer.MAX_VALUE
means checking all clauses with the last one.- Returns:
- dominance perimeter
-
setLearntClausesDominancePerimeter
public Settings setLearntClausesDominancePerimeter(int n)
When a clause is learnt from a conflict, it may happen that it dominates previously learnt ones. The dominance will be evaluated with the n last learnt clauses. n = 0 means no dominance check, n =Integer.MAX_VALUE
means checking all clauses with the last one.- Returns:
- dominance perimeter
-
explainGlobalFailureInSum
public boolean explainGlobalFailureInSum()
- Returns:
- true if additional clauses can be learned from sum's global failure
-
explainGlobalFailureInSum
public Settings explainGlobalFailureInSum(boolean b)
Set to true to allow additional clauses to be learned from sum's global failure
-
getIbexContractionRatio
public double getIbexContractionRatio()
- Returns:
- the ratio that a domains must be contracted by ibex to compute the constraint.
-
setIbexContractionRatio
public void setIbexContractionRatio(double ibexContractionRatio)
Defines the ratio that real domains must be contracted by ibex to compute the constraint. A contraction is considered as significant when at least {@param ratio} of a domain has been reduced. If the contraction is not meet, then it is considered as insufficient and therefore ignored. A too small ratio can degrade the ibex performance. The default value is 1% (0.01). See issue #653.Example: given x = [0.0, 100.0], y = [0.5,0.5] and CSTR(x > y) - When the ratio is 1% (0.01) bounds of X are kept as [0.0, 100.0] because it's contraction is less than 1%. - When the ratio is 0.1% (0.001) bounds of X are update to [0.5, 100.0] because it's contraction is greater than 0.1%.
- Parameters:
ibexContractionRatio
- defines the ratio that a domains must be contract to compute the constraint.
-
setIbexRestoreRounding
public Settings setIbexRestoreRounding(boolean ibexRestoreRounding)
If preserve_rounding is true, Ibex will restore the default Java rounding method when coming back from Ibex, which is transparent for Java but causes a little loss of efficiency. To improve the running time, ibex changes the rounding system for double values during contraction. In Linux/MACOS environments it leads to different results in calculations like `Math.pow(10, 6)`. See issue #740.- Parameters:
ibexRestoreRounding
- either Java or ibex rounding method
-
getIbexRestoreRounding
public boolean getIbexRestoreRounding()
- Returns:
- if ibex must restore java rounding mode when returning a call.
-
-