Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove randomness by default of BBox strategies" #1068

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions parsers/src/main/java/org/chocosolver/parser/RegParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ public abstract class RegParser implements IParser {
usage = "Define the variable heuristic to use.")
public SearchParams.VariableSelection varH = SearchParams.VariableSelection.DOMWDEG_CACD;

@SuppressWarnings("FieldMayBeFinal")
@Option(name = "-tie",
forbids = {"-varsel"},
usage = "Define the variable tie breaker to use with black-box strategies.")
private SearchParams.VariableTieBreaker tie = SearchParams.VariableTieBreaker.SMALLEST_DOMAIN;

@Option(name = "-flush",
forbids = {"-varsel"},
usage = "Autoflush weights on black-box strategies (default: 32).")
Expand Down Expand Up @@ -179,9 +173,6 @@ public abstract class RegParser implements IParser {
@Option(name = "-dfx", usage = "Force default explanation algorithm.")
public boolean dftexp = false;

@Option(name = "-gpa", usage = "Use the Generating Partial Assignment procedure (default: false).")
public boolean gpa = false;

/**
* Default settings to apply
*/
Expand Down Expand Up @@ -263,7 +254,7 @@ public final boolean setUp(String... args) throws SetUpException {
System.out.printf("%s\n", Arrays.toString(args));
}
if(varsel == null){
varsel = new SearchParams.VarSelConf(varH, tie, flushRate);
varsel = new SearchParams.VarSelConf(varH, flushRate);
}
if(valsel == null){
valsel = new SearchParams.ValSelConf(valH, best, bestRate, last);
Expand Down
53 changes: 19 additions & 34 deletions parsers/src/main/java/org/chocosolver/parser/flatzinc/Flatzinc.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,40 +209,25 @@ public void parse(Model target, Datas data, InputStream is) {
@Override
public void freesearch(Solver solver) {
BlackBoxConfigurator bb = BlackBoxConfigurator.init();
if (solver.getObjectiveManager().isOptimization()) {
// For COP
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, true, 16, true);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG_CACD, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.GEOMETRIC, 5, 1.05, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// complementary settings
bb.setNogoodOnRestart(true)
.setRestartOnSolution(true)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 4));
}else{
// For CSP
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, false, 16, false);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.GEOMETRIC, 5, 1.05, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// complementary settings
bb.setNogoodOnRestart(false)
.setRestartOnSolution(false)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 1));
boolean opt = solver.getObjectiveManager().isOptimization();
// variable selection
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, opt, 1, opt);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, Integer.MAX_VALUE);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.LUBY, 500, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// other parameters
bb.setNogoodOnRestart(true)
.setRestartOnSolution(true)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 1));
if (level.isLoggable(Level.INFO)) {
solver.log().println(bb.toString());
}
bb.make(solver.getModel());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static VariableSelector<IntVar> variableSelector(IntVar[] variables, Var
case max_regret:
return new MaxRegret();
case dom_w_deg:
return new DomOverWDeg<>(variables);
return new DomOverWDeg<>(variables, variables[0].getModel().getSeed());
default:
System.err.println("% No implementation for " + varChoice.name() + ". Set default.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected SearchParams.VarSelConf parse(String argument) throws NumberFormatExce
if (pars.length == 3) {
return new SearchParams.VarSelConf(
SearchParams.VariableSelection.valueOf(pars[0].toUpperCase()),
SearchParams.VariableTieBreaker.valueOf(pars[1].toUpperCase()),
Integer.parseInt(pars[2])
);
}
Expand Down
53 changes: 17 additions & 36 deletions parsers/src/main/java/org/chocosolver/parser/xcsp/XCSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,42 +142,23 @@ public void parse(Model target, XCSPParser parser) throws Exception {
@Override
public void freesearch(Solver solver) {
BlackBoxConfigurator bb = BlackBoxConfigurator.init();
if (solver.getObjectiveManager().isOptimization()) {
// For COP
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, true, 16, true);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.GEOMETRIC, 10, 1.05, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// complementary settings
bb.setNogoodOnRestart(true)
.setRestartOnSolution(true)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 1))
.setRefinedPartialAssignmentGeneration(gpa);
} else {
// For CSP
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, false, 16, true);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG_CACD, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.GEOMETRIC, 5, 1.05, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// complementary settings
bb.setNogoodOnRestart(true)
.setRestartOnSolution(false)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 4));
}
boolean opt = solver.getObjectiveManager().isOptimization();
// variable selection
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, opt, 1, opt);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, Integer.MAX_VALUE);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.LUBY, 500, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
// other parameters
bb.setNogoodOnRestart(true)
.setRestartOnSolution(true)
.setExcludeObjective(true)
.setExcludeViews(false)
.setMetaStrategy(m -> Search.lastConflict(m, 1));
if (level.isLoggable(Level.INFO)) {
solver.log().println(bb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testVarsel1() throws CmdLineException {
Assert.assertNull(parser.varsel);
p.parseArgument("-f", "-varsel", "[CHS,LARGEST_DOMAIN,64]", "/file");
Assert.assertEquals(parser.varsel, new SearchParams.VarSelConf(
SearchParams.VariableSelection.CHS, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 64));
SearchParams.VariableSelection.CHS, 64));
}

@Test(groups = "1s")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -451,7 +451,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.CHS, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.CHS, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -465,7 +465,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG_CACD, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG_CACD, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -479,7 +479,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.FRBA, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.FRBA, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -493,7 +493,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.ACTIVITY, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
SearchParams.VariableSelection.ACTIVITY, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -504,7 +504,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG_CACD, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG_CACD, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -515,7 +515,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -529,7 +529,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.FRBA, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
SearchParams.VariableSelection.FRBA, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 2));
Expand All @@ -540,7 +540,7 @@ private void configureModel(int workerID) {
SearchParams.ValueSelection.MIN, opt, 16, true);
intValSel = intValConf.make();
intVarConf = new SearchParams.VarSelConf(
SearchParams.VariableSelection.CHS, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.CHS, 32);
intVarSel = intVarConf.make();
bb.setIntVarStrategy((vars) -> intVarSel.apply(vars, intValSel.apply(worker)));
bb.setMetaStrategy(m -> Search.lastConflict(m, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.chocosolver.solver.ResolutionPolicy;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.search.restart.AbstractRestart;
import org.chocosolver.solver.search.restart.GeometricalCutoff;
import org.chocosolver.solver.search.restart.Restarter;
import org.chocosolver.solver.search.strategy.selectors.values.RealDomainMax;
import org.chocosolver.solver.search.strategy.selectors.values.RealDomainMin;
import org.chocosolver.solver.search.strategy.selectors.variables.Cyclic;
Expand Down Expand Up @@ -159,12 +161,11 @@ public static BlackBoxConfigurator forCSP() {
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, false, 16, true);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG_CACD, SearchParams.VariableTieBreaker.LARGEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG_CACD, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
SearchParams.Restart.GEOMETRIC, 5, 1.05, 50_000, true);
bb.setRestartPolicy(defaultResConf.make());
bb.setRestartPolicy(s -> new Restarter(new GeometricalCutoff(5, 1.05),
c -> s.getFailCount() >= c, 50_000, true));
// complementary settings
bb.setNogoodOnRestart(true)
.setRestartOnSolution(false)
Expand All @@ -185,7 +186,7 @@ public static BlackBoxConfigurator forCOP() {
SearchParams.ValSelConf defaultValSel = new SearchParams.ValSelConf(
SearchParams.ValueSelection.MIN, true, 16, true);
SearchParams.VarSelConf defaultVarSel = new SearchParams.VarSelConf(
SearchParams.VariableSelection.DOMWDEG, SearchParams.VariableTieBreaker.SMALLEST_DOMAIN, 32);
SearchParams.VariableSelection.DOMWDEG, 32);
bb.setIntVarStrategy((vars) -> defaultVarSel.make().apply(vars, defaultValSel.make().apply(vars[0].getModel())));
// restart policy
SearchParams.ResConf defaultResConf = new SearchParams.ResConf(
Expand Down
Loading
Loading