Optimization Example-02-SCH Video
This example shows the setup for a simple multi-objective optimization algorithm. This example uses the SCH test function optimization problem— Schaffer function N.1 Test_functions_for_optimization. For a more complex example using Optimo see BIM-based Parametric Building Energy Performance Multi- Objective Optimization.
The test functions are useful to evaluate the optimization algorithm. The SCH test function tries to minimize two conflicting objectives as demonstrated in the image below. When trying to minimize one of the fitness functions, the other function value increases. You can replace the SCH fitness functions to create your own optimization problem.
The Dynamo graph for the SCH test function is provided in the image below. As you can see the number of objectives is changed to two to match with the SCH problem definition. The results of fitness function 1 and 2 are put into a list of fitness functions using “List.Create” node.
The “NSGA-II Function” custom package is similar for all Optimo examples. You can see the graph of this custom package below.
As mentioned before, there are multiple optimal solutions (Pareto Optimal solutions) for contrasting objective functions. The image below shows a set of best solutions for the SCH test.
To Set Up Optimo Version 0.0.7:
Setting up the Dynamo code below:
Note: This version of Optimo has been improved to allow the user to set their own fitness functions much more easily. Instead of having to change the fitness function in two different places in Dynamo, now the user can set their fitness function only once as a custom node. Also, the function loop has been changed slightly, although the functionality remains the same. Future versions of Optimo will include the SMPSO and MOEAD algorithms.
The NSGA_II.InitialSolutionList node creates a list of numbers(initial population) within the range specified and with the number of defined variables. The number of variables can be changed by adding or removing an index to both the Lower Limit List and Upper Limit List nodes (they must have the same number of indexes).
The population size is simply the number of elements defined in the population node. The objectives are the functions that are going to be optimized.
The output of the NSGA_II.InitialSolutionList node is a list of lists (lists of variables and objectives). The objectives are all zero when they come out of InitialSolutionList and will be overwritten in the Function.Apply node. This node evaluates the fitness of each member of the population and sends that data to the AssignFitnessFuncResults node, where the zeroes that were created in the initial population node get overwritten.
In the image above, two functions: x^2 and (x-2)^2 are used as fitness functions for this problem. These functions form the SCH optimization problem, which is being used as an example. You can replace the SCH functions (Schaffer function N.1 http://en.wikipedia.org/wiki/Test_functions_for_optimization) in the main graph to create your own optimization problem.
To do this, a custom node must be created with the function desired as shown below.
Objective functions can be added and removed, but the numObjectives input has to match the number of objective functions.
The Dynamo code below is contained inside of the NSGA_II Function custom node. The function of this node is to run the NSGA II algorithm recursively to generate the specified number of generations. The first input to this custom node, "init" is a list containing two elements.
The first element in the list is a counter which keeps track of how many times the function has run. This is needed in the Loop Completion Check node (discussed later)
The second element in the list is the population from the previous generation. This gets fed into the NSGA_II.GenerationAlgorithm as an input along with the lowerLimits and upperLimits (which serve the same purpose as in the main Dynamo file). The Generation Algorithm creates a new population based on the previous generation. This new generation is then tested with the same fitness functions as the main Dynamo file (x^2 and (x-2)^2), and the fitness function results override the objectives in this new generation.
The NSGA_II.Sorting node takes the previous generation as well as the current generation, and re-arranges them in order based on their fitness (best results first).
The result gets added to a list which contains all of the previous generations' data. The data from all of the generations will be exported to a file when the algorithm finishes running.
The Loop Completion Check node (pictured below) simply compares the counter from the NSGA_II Function node and compares it to the Iteration Number (the max number of iterations that the algorithm should run). When the counter reaches the Iteration Number, the algorithm stops looping and displays the result.