Headless Mode

Overview

If the CommandLineParser.cs script is in the scene, and you create a build of the scene, then you can process all the ScenarioParameters and run your simulation with or without graphics. 

Page Contents

Purpose

If the CommandLineParser.cs script is in the scene, and you create a build of the scene, then you can process all the ScenarioParameters and run your simulation with or without graphics. 

How to Use

Command Line Parser 

The Parameters used to run a scenario which tells what scenario file to load (defaultJsonPath ), how long to run the simulation (duration), how fast the simulation should run (timeScale), the log for the simulation output (logScenarioFile), how oftern to update the log with the new agents positions and other agent information.

The ScenarioParameters can be set in the scene or parsed from the command line using the command line parser.

If the CommandLineParser.cs script is in the scene, and you create a build of the scene, then you can process all the ScenarioParameters and run your simulation with or without graphics. See the headless mode below for more information about running without graphics.

To run the scenario with the ScenarioParameters calls the ExecuteScenario function in the Main.cs script:

FindObjectOfType<Main>().ExecuteScenario(m_parameters);

The Main.cs file contains ScenarioParameters as well as keyboard shortcuts for toggling the Debug Menu and controlling the camera.

				
					
public class ScenarioParameters
{
    public string defaultJsonPath = "Assets/Content/Scenarios/headless.json";
    public float duration = 1f;
    public float timeScale = 1f;
    public string logScenarioFile = "ScenarioOutput.json"; 
    public int updateRateLog = 10;//10 times per second
    public bool isWaitAndQuit = false;
    public bool isLogScenario = false;
    public bool isLoadAtStart = false;
}
				
			

Headless Mode

You can run your simulations without seeing any graphics output, and you can run lots of them, easily, over and over. Several .bat files are included to show examples of how to run your simulations.

Note

.bat files are simply a sequence of commands that are run from the command line automatically when double clicked.Run the executable build of the scene and tells Unity to run the scene with no graphical input. Therefore, to see the output you need to look in the scenario log file for the results.

RIDE.exe -batchmode -nographics 

The -json tells the simulation where to load the scenario file from:

-json “Assets/Content/Scenarios/ExampleTwoUnits.json”

The duration is how long to run the simulation for, and the timeScale is how fast the game loop runs where higher is faster, so 2 is twice normal speed and 0.5 is slower:

duration 5 -timeScale 1

The output of the simulation will be in the logScenarioFile and the ExampleLogScenario.cs script is provided to show you how you can save relevant data from the simulation for your research:

-logScenarioFile “TwoUnitsLog.json” -updateLogRate 10

If you want to quit after running the simulation so can run lots of simulations use the isWaitAndQuit parameter, otherwise, perhaps you want to run in graphics mode and interact with the simulation then set it to false:

-isWaitAndQuit true

Example .bat files included with the builds which you can copy and modify for your own needs:

Example1.bat, ExampleFastSimulation.bat, ExampleTwoUnits.bat