#region Namespaces
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
#endregion
namespace ScriptCode
{
/// <summary>
/// Optimization algorithm scripts are used to select the script parameter values to be used in the next optimization runs.
/// </summary>
public partial class MyOptimizationAlgorithm : OptimizationAlgorithmScriptBase // NEVER CHANGE THE CLASS NAME
{
#region Variables
// Variables Content
#endregion
#region OnInitialize
/// <summary>
/// This function is used for accepting the script parameters and for initializing the script prior to all other function calls.
/// Once the script is assigned to a desktop, its parameter values can be specified by the user.
/// </summary>
/// --------------------------------------------------------------------------------------------------
/// PLEASE USE THE SCRIPT WIZARD (CTRL+W) TO ADD, EDIT AND REMOVE THE SCRIPT PARAMETERS
/// --------------------------------------------------------------------------------------------------
/// YOU MUST SET A PARAM TAG FOR EACH PARAMETER ACCEPTED BY THIS FUNCTION.
/// ALL PARAM TAGS SHOULD BE SET IN THE 'OnInitialize' REGION, RIGHT ABOVE THE 'OnInitialize' FUNCTION.
/// THE ORDER OF THE TAGS MUST MATCH THE ORDER OF THE ACTUAL PARAMETERS.
/// REQUIRED ATTRIBUTES:
/// (1) name: The exact parameter name.
/// (2) type: The type of data to collect from the user:
/// Set to "Integer" when the data type is 'int'
/// Set to "IntegerArray" when the data type is 'int[]'
/// Set to "DateTime" when the data type is 'long'
/// Set to "DateTimeArray" when the data type is 'long[]'
/// Set to "Boolean" when the data type is 'bool'
/// Set to "BooleanArray" when the data type is 'bool[]'
/// Set to "Double" when the data type is 'double'
/// Set to "DoubleArray" when the data type is 'double[]'
/// Set to "String" when the data type is 'string'
/// Set to "StringArray" when the data type is 'string[]'
/// OPTIONAL ATTRIBUTES:
/// (3) default: The default parameter value is only valid when the type is Integer, Boolean, Double, String or an API Type.
/// (4) min: The minimum parameter value is only valid when the type is Integer or Double.
/// (5) max: The maximum parameter value is only valid when the type is Integer or Double.
/// EXAMPLE: <param name="" type="" default="" min="" max="">Enter the parameter description here.</param>
/// --------------------------------------------------------------------------------------------------
public void OnInitialize()
{
// OnInitialize Content
}
#endregion
#region OnSelectNextOptimizationVectors
/// <summary>
/// This function is called in order to select the next optimization vectors to be processed.
/// The function may be called multiple times in a row before the OnUpdateOptimizationVector function is called.
/// </summary>
/// <returns type="IntegerArray">The indexes of the next optimization vectors to process.</returns>
public override int[] OnSelectNextOptimizationVectors()
{
// Get the number of cores available.
int numberOfCores = (int) OptimizationProcessorCount();
// Create for holding whether vectors have already been selected.
Dictionary<int, bool> exists = new Dictionary<int, bool>();
// Create for holding the requested optimization vectors.
List<int> optimizationVectors = new List<int>();
// Iterate over all of the optimization vectors.
for (int i = 0; i < OptimizationVectorCount() && optimizationVectors.Count < numberOfCores; i++) {
// Check whether the optimization vector hasn't been processed and it hasn't yet been selected.
if (!OptimizationVectorIsProcessed(i) && !exists.ContainsKey(i)) {
// Add the optimization vector to the list of vectors to process.
optimizationVectors.Add(i);
// Set the vector index as already existing in the list.
exists.Add(i, true);
}
}
return optimizationVectors.ToArray();
}
#endregion
#region OnGetMaxVectors
/// <summary>
/// This function is called to get the number of optimization vectors that the algorithm will
/// select and run if the optimization process runs to completion.
/// </summary>
/// <returns type="Integer">The maximum number of optimization vectors to be run.</returns>
public override int OnGetMaxVectors()
{
return OptimizationVectorCount();
}
#endregion
#region OnUpdateOptimizationVector
/// <summary>
/// This function is called to notify the optimization algorithm that a vector has been processed.
/// </summary>
/// <param name="vectorIndex" type="Integer">The vector index of the optimization vector that has been processed</param>
public override void OnUpdateOptimizationVector(int vectorIndex)
{
// OnUpdateOptimizationVector Content
}
#endregion
#region OnShutdown
/// <summary>
/// This function is called when the script is shutdown.
/// </summary>
public override void OnShutdown()
{
// OnShutdown Content
}
#endregion
}
}