Skip to content

Commit f50e17a

Browse files
committed
Allow to inject random seed
1 parent b51b326 commit f50e17a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/main/java/magma/tools/benchmark/controller/BenchmarkController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import hso.autonomy.util.commandline.Argument;
2525
import hso.autonomy.util.commandline.EnumArgument;
2626
import hso.autonomy.util.commandline.HelpArgument;
27+
import hso.autonomy.util.commandline.IntegerArgument;
2728
import hso.autonomy.util.commandline.StringArgument;
2829
import java.awt.event.ActionEvent;
2930
import java.awt.event.ActionListener;
@@ -68,6 +69,8 @@ public static void run(String[] args, UserInterface userInterface)
6869
StringArgument defaultPathArgument =
6970
new StringArgument("defaultPath", "examples", "the initial path to use for file dialogs");
7071

72+
IntegerArgument defaultRandomSeed = new IntegerArgument("randomSeed", (int) BenchmarkConfiguration.DEFAULT_RANDOM_SEED, 0, "the random seed to use");
73+
7174
new HelpArgument(challengeArgument, startScriptFolderArgument, roboVizServerArgument, defaultPathArgument)
7275
.parse(args);
7376

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

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

87-
new BenchmarkController(userInterface, challenge, startScriptFolder, roboVizServer, defaultPath);
91+
new BenchmarkController(userInterface, challenge, startScriptFolder, roboVizServer, defaultPath, randomSeed);
8892
}
8993

9094
public BenchmarkController(UserInterface userInterface, ChallengeType challenge, String startScriptFolder,
91-
String roboVizServer, String defaultPath)
95+
String roboVizServer, String defaultPath, int randomSeed)
9296
{
9397
this.startScriptFolder = startScriptFolder;
9498
this.roboVizServer = roboVizServer;
@@ -97,7 +101,8 @@ public BenchmarkController(UserInterface userInterface, ChallengeType challenge,
97101

98102
switch (userInterface) {
99103
case CLI:
100-
model.start(new BenchmarkConfiguration(roboVizServer),
104+
System.out.println("Using random seed: " + randomSeed);
105+
model.start(new BenchmarkConfiguration(roboVizServer, randomSeed),
101106
Collections.singletonList(new TeamConfiguration("magma", startScriptFolder, 0.4f)));
102107
break;
103108
case GUI:

src/main/java/magma/tools/benchmark/model/BenchmarkConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
public class BenchmarkConfiguration
2929
{
30+
public static final long DEFAULT_RANDOM_SEED = 123L;
31+
3032
public static final String DEFAULT_SERVER_IP = "localhost";
3133

3234
public static final int DEFAULT_SERVER_PORT = 3100;
@@ -61,10 +63,10 @@ public class BenchmarkConfiguration
6163

6264
private final String roboVizServer;
6365

64-
public BenchmarkConfiguration(String roboVizServer)
66+
public BenchmarkConfiguration(String roboVizServer, int randomSeed)
6567
{
6668
this(DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_PROXY_PORT, DEFAULT_TRAINER_PORT, DEFAULT_AVERAGE_OUT_RUNS,
67-
DEFAULT_RUNTIME, DEFAULT_VERBOSE, false, 123L, roboVizServer);
69+
DEFAULT_RUNTIME, DEFAULT_VERBOSE, false, randomSeed, roboVizServer);
6870
}
6971

7072
/**

src/main/java/magma/tools/benchmark/view/BenchmarkView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void focusLost(FocusEvent e)
209209
panel.add(lblSeedBox);
210210

211211
seedBox = new JTextField();
212-
seedBox.setText(String.valueOf(123));
212+
seedBox.setText(String.valueOf(BenchmarkConfiguration.DEFAULT_RANDOM_SEED));
213213
panel.add(seedBox);
214214
seedBox.setColumns(5);
215215

0 commit comments

Comments
 (0)