Outputting a Report File

  1. Reading input arguments for the increment value and the number of iteration
  2. Registering the variables to increment
  3. Registering the targets to have in the report
  4. Implementing the incrementation of the variables
  5. Implementing the reception of the new measures
  6. Implementing the check to finish the iteration loop
  7. Outputting a report file

Retrieving the Report File

First, you need to retrieve the report file by implementing the SetSimulationInfos() method.

Note: The report is a HTML file report. However, you can write in other files, but they will not be displayed in the Speos tree.
private string _simulationName = string.Empty;
private string _reportPath = string.Empty;

// ...

/// <summary>
///     Callback called to inform the simulation details
/// </summary>
/// <param name="simulationName"></param>
/// <param name="reportPath"></param>
public void SetSimulationInfos(string simulationName, string reportPath)
{
    reportPath = reportPath ?? string.Empty;
    simulationName= simulationName ?? string.Empty;
}

Creating the WriteReport method to Write the Report

Then, you need to create a new method named WriteReport to write the report.

The WriteReport method creates an html table with the values of the targets for each iteration.

private void WriteReport()
{
    var stringBuilder = new StringBuilder();
    stringBuilder.AppendLine("<html><body><table>");

    stringBuilder.AppendLine("<tr><th>Iteration Number</th>");

    var parameterIdOrder = new string[_targetNames.Count];

    var idx = 0;
    foreach(var names in _targetNames)
    {
        stringBuilder.AppendLine($"<th>{names.Value}</th>");
        parameterIdOrder[idx] = names.Key;
        idx++;
    }
    stringBuilder.AppendLine("<tr/>");

    idx = 0;
    foreach (var iterationResult in _iterationResults)
    {
        stringBuilder.AppendLine("<tr>");
        stringBuilder.AppendLine($"<td>{idx}</td>");
        foreach(var id in parameterIdOrder)
        {
            stringBuilder.AppendLine($"<td>{iterationResult[id]}</td>");
        }
        stringBuilder.AppendLine("<tr/>");
        idx++;
    }

    stringBuilder.AppendLine("</table></body></html>");

    File.WriteAllText(_reportPath, stringBuilder.ToString());
}

Calling the WriteReport method Before Stopping the Iteration Loop

Finally, you need to call the WriteReport before stopping the iteration loop. Therefore you call it before returning false in the StartIteration method.

/// <summary>
///     Callback called upon starting a new iteration in the optimization loop
/// </summary>
/// <param name="iteration">the iteration that is starting</param>
/// <returns> whether we should continue on this iteration or not</returns>
public bool StartIteration(int iteration)
{
    if(iteration >= _iterationNumber)
    {
        // Start : new line to write the report
        WriteReport();
        // End : new line to write the report
        return false;
    }
    foreach(var key in _variableValues.Keys)
    {
        _variableValues[key] = _variableValues[key] + _incrementValue;
    }

    return true; // we want to continue looping on this iteration
}