Main optimization application class.
This class provides the main machinery for executing a Optimization.Job. It will connect to the master process and sends populations of solutions as batched tasks to the master. It then receives responses back from the master and updates the solutions in the optimizer according to their evaluated fitnesses. It then drives the optimizer to generate new populations when all solutions are properly evaluated.
The usual way of using this class is to create a new instance, passing it command line arguments to parse. Then create a new Optimization.Job (either from an XML or manually) and pass it to Application.Run. The run method implements a main loop which will block until the optimization has completed (or when a critical error has occurred). You might want to consider to create or implement a Optimization.Visual to show any messages (status, error) and/or progress of the optimization.
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
See Also: Inherited members from object.
⊟ Public Constructors
Application (ref string[])Create new application. ⊟ Public Properties
Job Job . The currently running job. [read-only] WaitHandle System.Threading.EventWaitHandle . Main loop wait handle. ⊟ Public Methods
⊟ Protected Methods
AddOptions (NDesk.Options.OptionSet) Add command line options to the option set.Close () Called when connection from master is closed.Done (Solution) Called when a solution has been evaluated.Error (string) Fire the Application.OnError event.Error (string, params object[]) Fire the Application.OnError event.FailureToString (Optimization.Messages.Response.FailureType) : string Convert a response failure type to a string.Initialize () Application initialization.NewIteration () Start new optimization iteration.OnChallenge (Optimization.Messages.Response) Handle a challenge response.OnFailed (Optimization.Messages.Response) Handle a failed response message.OnSuccess (Optimization.Messages.Response) Handle a success response message.ParseArguments (ref string[]) Parse command line arguments.Send () : bool Send current population to the master in a batch.ShowMessage (string) Show a message to the user.ShowMessage (string, params object[]) Show a formatted message to the user.Status (string) Show a status message to the user.Status (string, params object[]) Show a formatted status message to the user.⊟ Public Events
OnError Fired when an error has occurred. OnIterate Fired to give listeners some time to do some work on the main thread. OnJob Fired when a new job is started. OnMessage Message event. OnProgress Fired when there is some progress in the optimization. OnStatus Fired when there is some status update. OnWarning Warning event.
⊟ Application Constructor
Create new application.
public Application (ref string[] args)⊟ Parameters
- args
- Command line arguments.
⊟ Remarks
Create new application.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ AddOptions Method
Add command line options to the option set.
protected virtual void AddOptions (NDesk.Options.OptionSet optionSet)⊟ Parameters
- optionSet
- The option set.
⊟ Remarks
Add command line options to the option set. Subclasses can override this to set their own command line options in the option set.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Close Method
Called when connection from master is closed.
protected virtual void Close ()⊟ Remarks
Called when the connection with the master is closed. This will stop the main application loop.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Done Method
Called when a solution has been evaluated.
⊟ Parameters
- solution
- The solution.
⊟ Remarks
Called when a solution has been evaluated. This method checks if this was the last solution in the iteration and if so will start a new iteration.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Error Method
Fire the Application.OnError event.
⊟ Parameters
- str
- Error message.
⊟ Remarks
Fire the .Application.OnError event.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Error Method
Fire the Application.OnError event.
⊟ Parameters
- format
- Format string.
- args
- Format arguments.
⊟ Remarks
Fire the .Application.OnError event.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ FailureToString Method
Convert a response failure type to a string.
protected string FailureToString (Optimization.Messages.Response.FailureType failure)⊟ Parameters
- failure
- Response failure.
⊟ Returns
The string representation of the failure type.⊟ Remarks
Convert a response failure type to a string.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Initialize Method
Application initialization.
protected virtual void Initialize ()⊟ Remarks
Called during the initialization of the application.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Job Property
The currently running job.
public Job Job { set; get; }⊟ Value
A job.⊟ Remarks
Get or set the currently running job.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ NewIteration Method
Start new optimization iteration.
protected virtual void NewIteration ()⊟ Remarks
This will call Optimization.Optimizer.Next and will fire the Application.OnProgress event accordingly. If the optimization is fininshed, the main loop is quitted, otherwise a batch of new solutions will be send to the master.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnChallenge Method
Handle a challenge response.
protected virtual void OnChallenge (Optimization.Messages.Response response)⊟ Parameters
- response
- A response.
⊟ Remarks
Handles a challenge response message. It will encode the challenge with the job token and send a token message back to the master.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnError Event
Fired when an error has occurred.
public event Application.MessageHandler OnError⊟ Remarks
Fired when an error has occurred.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnFailed Method
Handle a failed response message.
protected virtual void OnFailed (Optimization.Messages.Response response)⊟ Parameters
- response
- A response.
⊟ Remarks
Handles a failed response message. The fitness of the solution that failed will be marked with a 0 fitness.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnIterate Event
Fired to give listeners some time to do some work on the main thread.
public event EventHandler OnIterate⊟ Remarks
Fired to give listeners some time to do some work on the main thread. This is used by for instance visualizers that need some interation, or some time to draw their interfaces. If a visual needs to be updated periodically, it should periodically signal the Application.WaitHandle so that Application.OnIterate is called.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnJob Event
Fired when a new job is started.
public event Application.JobHandler OnJob⊟ Remarks
Fired when a new job is started.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnMessage Event
Message event.
public event Application.MessageHandler OnMessage⊟ Remarks
This event is emitted when there is a general message that should be reported to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnProgress Event
Fired when there is some progress in the optimization.
public event Application.ProgressHandler OnProgress⊟ Remarks
Fired when there is some progress in the optimization.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnStatus Event
Fired when there is some status update.
public event Application.MessageHandler OnStatus⊟ Remarks
Fired when there is some status update.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnSuccess Method
Handle a success response message.
protected virtual void OnSuccess (Optimization.Messages.Response response)⊟ Parameters
- response
- A response.
⊟ Remarks
Handles a success response message. This will update the fitness of the solution according to the received fitness. Additionally any data that was transmitted with the response will be added/set in the solution.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ OnWarning Event
Warning event.
public event Application.MessageHandler OnWarning⊟ Remarks
This event is emitted when there is a warning that should be displayed to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ ParseArguments Method
Parse command line arguments.
⊟ Parameters
- args
- Arguments to parse.
⊟ Remarks
Subclasses can override this to do their own command line parsing, or to setup data needed for command line parsing (see Application.AddOptions).⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Run Method
Run an optimization job.
⊟ Parameters
- job
- A job.
⊟ Remarks
This method will run one optimization job. It will batch tasks to the master prococess as long as the optimization is running and will process any responses from the master to update the solution fitnesses and drive the optimization.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Send Method
Send current population to the master in a batch.
protected virtual bool Send ()⊟ Returns
True if the batch was successfully send.⊟ Remarks
Send current population to the master in a batch.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ ShowMessage Method
Show a message to the user.
⊟ Parameters
- str
- The message.
⊟ Remarks
Show a message to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ ShowMessage Method
Show a formatted message to the user.
⊟ Parameters
- format
- The format string.
- args
- The format string arguments.
⊟ Remarks
Show a formatted message to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Status Method
Show a status message to the user.
⊟ Parameters
- str
- Status message.
⊟ Remarks
Show a status message to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Status Method
Show a formatted status message to the user.
⊟ Parameters
- format
- The format string.
- args
- The format string arguments.
⊟ Remarks
Show a formatted status message to the user.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ Stop Method
Stop the current job.
public void Stop ()⊟ Remarks
Stop the currently running job.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)
⊟ WaitHandle Property
Main loop wait handle.
public System.Threading.EventWaitHandle WaitHandle { get; }⊟ Value
The wait handle.⊟ Remarks
Get the main loop wait handle. The main loop runs on the main thread and uses a message queue and a wait handle to process messages from other threads. To run an iteration of the application main loop, you can use System.Threading.WaitHandle.Set. This will in turn handle any received messages, fire Application.OnIterate and check if the job should be stopped.⊟ Requirements
Namespace: Optimization
Assembly: Optimization (in Optimization.dll)