Base optimizer class.
This class forms the basis of all optimizers. In itself it does not provide an optimization, but it provides all the infrastructure to make it easy to implement different optimization algorithms on top of this class.
There are a few key concepts to understand when implementing an optimizer based on this class. The optimizer consists of the following objects:
- A list of Optimization.Solution which make up the population
- A Optimization.Optimizer.Settings object providing optimizer settings (such as maximum number of iterations and population size)
- A Optimization.Storage.Storage object providing a way to store the optimization results
- Templates for the parameters and associated boundaries used in the optimization process
When implementing a new optimizer, you might want to use a subclassed settings class (Optimization.Optimizer.Settings) (if you want to add some settings specific to your optimizer and/or a custom subclass of a Optimization.Solution. The optimizer class implements a automatic discovery mechanism for finding subclasses of these two classes and will use them if it finds them. Therefore, you only need to subclass from for example Optimization.Solution and this class will be used to create solutions. This behavior can be overridden by overriding the Optimizer.CreateSettings and Optimizer.CreateSolution methods.
The usual optimization process usually consists of the following phases:
Repeat running solutions in the population as long as Optimizer.Next returns true. There is a helper class which can drive this process for you, including communicating with the master and dispatching the solutions (see Optimization.Application).
- Create a new optimizer object
- If needed, create a new storage object and assign it
- Call Optimizer.Initialize to initialize the initial population and the storage
- Evaluate all the solutions in the population (this should update the fitness of each solution)
- Call Optimizer.Next to generate a new population
Subclasses of an optimizer usually only need to override certain methods. It's useful to know what exactly happens when calling Optimizer.Next so that you can override the relevant methods.
- Update the current best solution (Optimizer.UpdateBest)
- Save the current iteration in the storage (Optimization.Storage.Storage.SaveIteration)
- Increment the current iteration (Optimizer.IncreaseIteration)
- Check if the optimization is finished (Optimizer.Finished)
- Create a new population (Optimizer.Update)
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
See Also: Inherited members from object.
⊟ Public Constructors
Optimizer ()Default constructor. ⊟ Public Properties
[read-only] Best Solution . Get the best best solution so far. [read-only] Boundaries List<Boundary> . Get list of boundaries. [read-only] Configuration Optimizer.Settings . Get optimizer configuration. CurrentIteration uint . The current iteration. [read-only] Description string . Optimizer description. [read-only] Extensions List<Extension> . Extensions. [read-only] Fitness Fitness . The fitness object template. [read-only] Name string . The optimizer name. [read-only] Parameters List<Parameter> . Get parameters. [read-only] Population List<Solution> . Current population of solutions. [read-only] State State . Optimizer state. Storage Optimization.Storage.Storage . Storage object. ⊟ Public Methods
Add (Solution) Add a new solution to the optimizer.AddExtension (Extension) Add extension.Boundary (string) : Boundary Retrieve boundary by name.CreateSolution (uint) : Solution Create a new solution.FromStorage (Optimization.Storage.Storage, Optimization.Storage.Records.Optimizer) Restore optimizer from storage.FromStorage (Optimization.Storage.Storage, Optimization.Storage.Records.Optimizer, Optimization.Storage.Records.Solution, Solution) Restore solution from storage.FromXml (System.Xml.XmlNode) Load optimizer from XML. staticGetDescription (Type) : string Get optimizer description.GetEnumerator () : IEnumerator<Solution> Get solution enumerator. staticGetName (Type) : string Get the optimizer name.HasBoundary (string) : bool Check boundary existence.HasParameter (string) : bool Check parameter existence.Initialize () Initialize optimizer.InitializePopulation () Initialize solution population.Log (string, string) Generic message logging.Log (string, string, params object[]) Generic message logging.Next () : bool Create new optimization iteration.Parameter (string) : Parameter Retrieve parameter by name.Remove (Solution) Remove solution from the population.Update () Update the current population.Update (Solution) Update the solution.⊟ Protected Methods
AddBoundary (Boundary) Add boundary.AddParameter (Parameter) Add parameter.CreateSettings () : Optimizer.Settings Create settings object.CreateState () : State Create state.Finished () : bool Check whether the optimization is finished.IncrementIteration () Increment the current iteration.SaveIteration () Save iteration to storage.Setup () Setup the optimizer.UpdateBest () Update the best solution so far.⊟ Explicitly Implemented Interface Members
IEnumerable.GetEnumerator Get solution enumerator.
⊟ Optimizer Constructor
Default constructor.
public Optimizer ()⊟ Remarks
Create new optimizer object.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Add Method
Add a new solution to the optimizer.
⊟ Parameters
- solution
- The solution to add.
⊟ Remarks
Add a new solution to the population of solutions in the optimizer. This can be useful if you want to generate an initial population externally, or just want to add some solutions at some point from your application.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ AddBoundary Method
Add boundary.
⊟ Parameters
- boundary
- Boundary.
⊟ Remarks
Add a boundary to the optimizer.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ AddExtension Method
Add extension.
⊟ Parameters
- ext
- Extension.
⊟ Remarks
Add an extension to the optimizer.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ AddParameter Method
Add parameter.
⊟ Parameters
- parameter
- A Parameter.
⊟ Remarks
Add parameter to the optimizer.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Best Property
Get the best best solution so far.
public Solution Best { get; }⊟ Value
The best solution so far.⊟ Remarks
The optimizer keeps track of the best solution so far and it can be accessed by this property.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Boundaries Property
Get list of boundaries.
public List<Boundary> Boundaries { get; }⊟ Value
The list of boundaries.⊟ Remarks
Get the list of boundaries registered on the optimizer.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Boundary Method
Retrieve boundary by name.
⊟ Parameters
- name
- Boundary name.
⊟ Returns
The boundary.⊟ Remarks
Get a boundary by name.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Configuration Property
Get optimizer configuration.
public Optimizer.Settings Configuration { get; }⊟ Value
Optimizer configuration.⊟ Remarks
The optimizer configuration contains settings which can easily be set by a job. Default settings for optimizer include the maximum number of iterations and the population size.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ CreateSettings Method
Create settings object.
protected virtual Optimizer.Settings CreateSettings ()⊟ Returns
A settings object.⊟ Remarks
If you want to add some settings, you can subclass the Optimization.Optimizer.Settings class and override this function in your optimizer to create an instance of this subclass. Note that the default implementation of this method will try to locate any subclasses of Optimization.Optimizer.Settings and use it if found. See Optimization.Optimizer.Settings for more information on implementing your own settings class.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ CreateSolution Method
Create a new solution.
⊟ Parameters
- idx
- Solution id.
⊟ Returns
A new solution.⊟ Remarks
This function creates a new solution object. You can override this to create a solution of a custom subclass. Note that the default implementation will already look for subclasses of Optimization.Solution, so you generally don't need to override this function. See Optimization.Solution for more information on implementing a custom solution class.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ CreateState Method
Create state.
protected virtual State CreateState ()⊟ Returns
New state.⊟ Remarks
Create a new state. Override this method to create a custom state subclass.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ CurrentIteration Property
The current iteration.
public uint CurrentIteration { set; get; }⊟ Value
The current iteration.⊟ Remarks
Represents the current optimization iteration.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Description Property
Optimizer description.
public string Description { get; }⊟ Value
Optimizer description.⊟ Remarks
Get the optimizer description.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Extensions Property
Extensions.
public List<Extension> Extensions { get; }⊟ Value
List of extensions.⊟ Remarks
Get list of extensions associated with the optimizer.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Finished Method
Check whether the optimization is finished.
protected virtual bool Finished ()⊟ Returns
true if the optimization is finished, false otherwise.⊟ Remarks
Override this method to implement your own way of determining when the optimization is finished. By default, there is a maximum iteration set by the MaxIterations setting.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Fitness Property
The fitness object template.
public Fitness Fitness { get; }⊟ Value
The fitness object.⊟ Remarks
The fitness object template associated with the optimizer. The fitness object is a template used by the solutions do calculate the fitness value of the solution, using a mathematical expression.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ FromStorage Method
Restore optimizer from storage.
public virtual void FromStorage (Optimization.Storage.Storage storage, Optimization.Storage.Records.Optimizer optimizer)⊟ Parameters
- storage
- The storage.
- optimizer
- The storage optimizer record.
⊟ Remarks
Restore the optimizer state from storage.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ FromStorage Method
Restore solution from storage.
public virtual void FromStorage (Optimization.Storage.Storage storage, Optimization.Storage.Records.Optimizer optimizer, Optimization.Storage.Records.Solution solution, Solution sol)⊟ Parameters
- storage
- The storage.
- optimizer
- The optimizer storage record.
- solution
- The solution storage record.
- sol
- The solution.
⊟ Remarks
Restore a solution from storage.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ FromXml Method
Load optimizer from XML.
public virtual void FromXml (System.Xml.XmlNode node)⊟ Parameters
- node
- XML node.
⊟ Remarks
Load optimizer settings, paramaters and boundaries from XML. Subclasses can override this and extract custom data from the XML. The passed node is the optimizer root node.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ GetDescription Method
Get optimizer description.
⊟ Parameters
- type
- Optimizer type.
⊟ Returns
The optimizer description, or null if there is no description available.⊟ Remarks
Gets the optimizer description from the Optimization.Attributes.OptimizerAttribute.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ GetEnumerator Method
Get solution enumerator.
public IEnumerator<Solution> GetEnumerator ()⊟ Returns
Solution enumerator.⊟ Remarks
Implements an enumerator which enumerates over the solutions in the optimizer population.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ GetName Method
Get the optimizer name.
⊟ Parameters
- type
- Optimizer type.
⊟ Returns
The optimizer name.⊟ Remarks
Get the optimizer name (see Optimization.Attributes.OptimizerAttribute). If the name is not set through an attribute, the class name is used.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ HasBoundary Method
Check boundary existence.
⊟ Parameters
- name
- Boundary name.
⊟ Returns
Whether the boundary exists.⊟ Remarks
Check whether a given boundary exists.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ HasParameter Method
Check parameter existence.
⊟ Parameters
- name
- Parameter name.
⊟ Returns
Whether the parameter exists.⊟ Remarks
Check whether a given parameter exists.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ IncrementIteration Method
Increment the current iteration.
protected virtual void IncrementIteration ()⊟ Remarks
This is usually called from Optimizer.Next to increase the current iteration count.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Initialize Method
Initialize optimizer.
public virtual void Initialize ()⊟ Remarks
Initialize the optimizer. This creates the initial population by calling Optimizer.InitializePopulation. It furthermore tells the storage that the optimization has begun. The application should call this before starting the optimization process.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ InitializePopulation Method
Initialize solution population.
public virtual void InitializePopulation ()⊟ Remarks
Initialize the solution population. By default, this will create a number of solutions according to the PopulationSize setting.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Log Method
Generic message logging.
⊟ Parameters
- type
- Log type.
- str
- Log message.
⊟ Remarks
The default implementation will log the message in the storage object.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Log Method
Generic message logging.
⊟ Parameters
- type
- Log type.
- format
- Log message format.
- args
- Format arguments.
⊟ Remarks
The default implementation will log the message in the storage object.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Name Property
The optimizer name.
public string Name { get; }⊟ Value
The optimizer name.⊟ Remarks
Get the optimizer name. The name is derived from the class name by default. If you want to specify an alternative name, you can apply the Optimization.Attributes.OptimizerAttribute to your optimizer subclass.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Next Method
Create new optimization iteration.
public virtual bool Next ()⊟ Returns
true if a new iteration was created, false if the optimization is finished.⊟ Remarks
Call this function when all the solutions in the current iteration have been processed and their fitnesses updated. This method will in turn:
- Update the current best solution
- Save the current iteration in the storage
- Increment the current iteration (Optimizer.IncreaseIteration)
- Check if the optimization is finished (Optimizer.Finished)
- Create a new population (Optimizer.Update)
⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Parameter Method
Retrieve parameter by name.
⊟ Parameters
- name
- Parameter name.
⊟ Returns
The parameter.⊟ Remarks
Get a parameter by name.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Parameters Property
Get parameters.
public List<Parameter> Parameters { get; }⊟ Value
List of parameters.⊟ Remarks
Get the list of parameters that serve as a template for parameters in the solutions.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Population Property
Current population of solutions.
public List<Solution> Population { get; }⊟ Value
List of solutions.⊟ Remarks
Get the current population of solutions.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Remove Method
Remove solution from the population.
⊟ Parameters
- solution
- Solution.
⊟ Remarks
Remove a solution from the current population.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ SaveIteration Method
Save iteration to storage.
protected virtual void SaveIteration ()⊟ Remarks
Save the current iteration to storage.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Setup Method
Setup the optimizer.
protected virtual void Setup ()⊟ Remarks
Setup the optimizer. This is called at the end of the Optimizer.Initialize method and at the end of the Optimizer.FromStorage method. Override this to setup anything after the initialization of the optimizer is complete.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ State Property
Optimizer state.
public State State { get; }⊟ Value
Optimizer state.⊟ Remarks
Get the optimizer state. The state contains certain state information that is shared with the solutions, such as a random number generator and the optimizer settings.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Storage Property
Storage object.
public Optimization.Storage.Storage Storage { set; get; }⊟ Value
Storage object.⊟ Remarks
Get or set the storage object used for storing the results. A storage object will be created by default when the optimizer is created, but if necessary you can assign a different one after the optimizer is constructed.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ System.Collections.IEnumerable.GetEnumerator Method
Get solution enumerator.
IEnumerator System.Collections.IEnumerable.GetEnumerator ()⊟ Returns
Solution enumerator.⊟ Remarks
Get enumerator which enumerates over the solutions in the current population.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Update Method
Update the current population.
public virtual void Update ()⊟ Remarks
Update the current solution population using the fitnesses of each solution. This is usually called from the Optimizer.Next method and should not be needed to be called by the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Update Method
Update the solution.
⊟ Parameters
- solution
- Solution to update.
⊟ Remarks
Convenient function to update a single solution. The default implementation of Optimizer.Update will call this function for each solution in the population. If this does not make sense for your particular optimization, you should override Optimizer.Update.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ UpdateBest Method
Update the best solution so far.
protected virtual void UpdateBest ()⊟ Remarks
Update the best solution by looking at the fitnesses of all the solutions in the current population. This function is called from Optimizer.UpdateBest and should not have to be called by the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)