Skip to content

Commit

Permalink
Few modifications in RegParser options
Browse files Browse the repository at this point in the history
  • Loading branch information
cprudhom committed Jan 18, 2024
1 parent 59f4217 commit 41ce787
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
10 changes: 5 additions & 5 deletions parsers/src/main/java/org/chocosolver/parser/RegParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public abstract class RegParser implements IParser {
@Option(name = "-varsel",
handler = VarSelHandler.class,
depends = {"-f"},
forbids = {"-varh", "-tie", "-flush"},
usage = "Define the variable selector to use. Expected format: [varsel,tie,flush] as [String,String,int] -- no space allowed.")
forbids = {"-varh", "-flush"},
usage = "Define the variable selector to use. Expected format: [varsel,flush] as [String,int] -- no space allowed.")
public SearchParams.VarSelConf varsel;

@Option(name = "-valh", aliases = {"--valHeuristic"},
Expand Down Expand Up @@ -133,15 +133,15 @@ public abstract class RegParser implements IParser {
handler = ValSelHandler.class,
depends = {"-f"},
forbids = {"-valh", "-best", "-bestRate", "-last"},
usage = "Define the variable selector to use. Expected format: [valsel,best,bestRate,last] " +
usage = "Define the variable selector to use. Expected format: [valh,best,bestRate,last] " +
"as [String,boolean,int,boolean] -- no space allowed.")
public SearchParams.ValSelConf valsel;

@Option(name = "-restarts",
handler = RestartHandler.class,
depends = {"-f"},
usage = "Define the restart heuristic to use. Expected format: [policy,cutoff,geo?,offset] " +
"as [String,int,double?,int] -- no space allowed.")
usage = "Define the restart heuristic to use. Expected format: [policy,cutoff,geo?,offset,resetOnSolution] " +
"as [String,int,double?,int,boolean] -- no space allowed.")
public SearchParams.ResConf restarts =
new SearchParams.ResConf(SearchParams.Restart.GEOMETRIC, 10, 1.05, 50_000, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public VarSelHandler(CmdLineParser parser, OptionDef option, Setter<? super Sear
*/
@Override
public String getDefaultMetaVariable() {
return "[String,String,int]";
return "[String,int]";
}


Expand All @@ -45,10 +45,10 @@ protected SearchParams.VarSelConf parse(String argument) throws NumberFormatExce
if (argument.startsWith("[")) argument = argument.substring(1);
if (argument.endsWith("]")) argument = argument.substring(0, argument.length() - 1);
String[] pars = argument.split(",");
if (pars.length == 3) {
if (pars.length == 2) {
return new SearchParams.VarSelConf(
SearchParams.VariableSelection.valueOf(pars[0].toUpperCase()),
Integer.parseInt(pars[2])
Integer.parseInt(pars[1])
);
}
throw new CmdLineException(owner,
Expand Down
28 changes: 28 additions & 0 deletions parsers/src/test/java/org/chocosolver/parser/RegParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,34 @@ public void testValsel1() throws CmdLineException {
Assert.assertEquals(parser.valsel, new SearchParams.ValSelConf(SearchParams.ValueSelection.MAX, true, 32, true));
}

@Test(groups = "1s")
public void testValsel2() throws CmdLineException {
CmdLineParser p = new CmdLineParser(parser);
p.parseArgument("/file");
Assert.assertNull(parser.valsel);
p.parseArgument("-f", "-valsel", "[MIN,true,32,true]", "-varh", "DOMWDEG", "-lc", "2",
"-restarts", "[luby,500,0,50000]",
"/file");
Assert.assertEquals(parser.valsel, new SearchParams.ValSelConf(SearchParams.ValueSelection.MIN, true, 32, true));
}

@Test(groups = "1s")
public void testValsel3() throws CmdLineException {
CmdLineParser p = new CmdLineParser(parser);
p.parseArgument("/file");
Assert.assertNull(parser.valsel);
p.parseArgument("-f", "-valh", "MIN", "-best", "-last", "-varh", "DOMWDEG", "-lc", "2",
"-restarts", "[luby,500,50000,true]",
"/file");
Assert.assertEquals(parser.valH, SearchParams.ValueSelection.MIN);
Assert.assertTrue(parser.best);
Assert.assertTrue(parser.last);
Assert.assertEquals(parser.varH, SearchParams.VariableSelection.DOMWDEG);
Assert.assertEquals(parser.lc, 2);
Assert.assertEquals(parser.restarts, new SearchParams.ResConf(SearchParams.Restart.LUBY, 500, 50000, true));

}

@Test(groups = "1s")
public void test() throws CmdLineException {
CmdLineParser p = new CmdLineParser(parser);
Expand Down

0 comments on commit 41ce787

Please sign in to comment.