Skip to content

Commit

Permalink
Allow to inject random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
klausdorer committed Jul 4, 2023
1 parent b51b326 commit f50e17a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import hso.autonomy.util.commandline.Argument;
import hso.autonomy.util.commandline.EnumArgument;
import hso.autonomy.util.commandline.HelpArgument;
import hso.autonomy.util.commandline.IntegerArgument;
import hso.autonomy.util.commandline.StringArgument;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -68,6 +69,8 @@ public static void run(String[] args, UserInterface userInterface)
StringArgument defaultPathArgument =
new StringArgument("defaultPath", "examples", "the initial path to use for file dialogs");

IntegerArgument defaultRandomSeed = new IntegerArgument("randomSeed", (int) BenchmarkConfiguration.DEFAULT_RANDOM_SEED, 0, "the random seed to use");

new HelpArgument(challengeArgument, startScriptFolderArgument, roboVizServerArgument, defaultPathArgument)
.parse(args);

Expand All @@ -80,15 +83,16 @@ public static void run(String[] args, UserInterface userInterface)
String startScriptFolder = startScriptFolderArgument.parse(args);
String roboVizServer = roboVizServerArgument.parse(args);
String defaultPath = defaultPathArgument.parse(args);
int randomSeed = defaultRandomSeed.parse(args);
Argument.endParse(args);

defaultPath = defaultPath.replaceFirst("^~", System.getProperty("user.home"));

new BenchmarkController(userInterface, challenge, startScriptFolder, roboVizServer, defaultPath);
new BenchmarkController(userInterface, challenge, startScriptFolder, roboVizServer, defaultPath, randomSeed);
}

public BenchmarkController(UserInterface userInterface, ChallengeType challenge, String startScriptFolder,
String roboVizServer, String defaultPath)
String roboVizServer, String defaultPath, int randomSeed)
{
this.startScriptFolder = startScriptFolder;
this.roboVizServer = roboVizServer;
Expand All @@ -97,7 +101,8 @@ public BenchmarkController(UserInterface userInterface, ChallengeType challenge,

switch (userInterface) {
case CLI:
model.start(new BenchmarkConfiguration(roboVizServer),
System.out.println("Using random seed: " + randomSeed);
model.start(new BenchmarkConfiguration(roboVizServer, randomSeed),
Collections.singletonList(new TeamConfiguration("magma", startScriptFolder, 0.4f)));
break;
case GUI:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
public class BenchmarkConfiguration
{
public static final long DEFAULT_RANDOM_SEED = 123L;

public static final String DEFAULT_SERVER_IP = "localhost";

public static final int DEFAULT_SERVER_PORT = 3100;
Expand Down Expand Up @@ -61,10 +63,10 @@ public class BenchmarkConfiguration

private final String roboVizServer;

public BenchmarkConfiguration(String roboVizServer)
public BenchmarkConfiguration(String roboVizServer, int randomSeed)
{
this(DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_PROXY_PORT, DEFAULT_TRAINER_PORT, DEFAULT_AVERAGE_OUT_RUNS,
DEFAULT_RUNTIME, DEFAULT_VERBOSE, false, 123L, roboVizServer);
DEFAULT_RUNTIME, DEFAULT_VERBOSE, false, randomSeed, roboVizServer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void focusLost(FocusEvent e)
panel.add(lblSeedBox);

seedBox = new JTextField();
seedBox.setText(String.valueOf(123));
seedBox.setText(String.valueOf(BenchmarkConfiguration.DEFAULT_RANDOM_SEED));
panel.add(seedBox);
seedBox.setColumns(5);

Expand Down

0 comments on commit f50e17a

Please sign in to comment.