Optimization Example-03-BBox Video

This example shows the process of setting up Optimo for single objective optimization. The objective of this example is to find the smallest bounding box for any arbitrary object. The parametric variables are the x, y, and z rotations of the object being bound. In the optimization process, the object will be rotated until the optimum rotation is reached- when the volume of the bounding box for that rotation of that object is as small as possible.

The conceptual mass family below is the object that will be optimized in this example.

BBox_RevitObject

To open and use this example, first open Revit 2015. Then, open the Optimization Example-03-BBox.rfa Revit family file, found in the extras folder in the Dynamo Packages folder (the way to get to that folder is shown in Setup Tutorial. When you have the correct file open, click on the Add-Ins tab in Revit, and click on Dynamo 0.7. When Dynamo opens, navigate to that same extras folder and open the Optimization Example-03-BBox.dyn file in Dynamo. Then, in the Select Model Element node, click on Change, navigate to the Revit window, and click on the object in Revit.

The user can modify population number, lower and upper limits of optimization variables, and the number of objectives (in this example, only one objective is present).

BBox_Full

The “NSGA-II.InitialSolutionList” node creates a list of random numbers (the size of which is the population size) for each variable (initial population list) within the specified range. In this example we have 3 variables which are changing between -180 to 180 to create angle change to X, Y, and Z axis of the object in degree. The population list includes a placeholder for fitness function results which will be assigned when the fitness function results are evaluated. The fitness function in this example is the volume of the bounding box. The output of the “Function.Apply” node is a list of lists of 3 variables and a list of fitness function that is calculated by applying the BBox fitness function to the list of variables.

BBox_Initial

The purpose of the bounding box fitness function is simply to rotate the object by the provided angles in the list and find the volume of the bounding box. The fitness function takes in the element and the the result of the InitialSolutionList node. Based on the the values of the indices 0,1, and 2 of the list of variables, the fitness function rotates the object along X, Y, and Z axis respectively and finds the volume of the resulting bounding box. The goal is to minimize this volume.

BBox_FF

The “NSGA-II.AssignFitnessFunction” node assigns the fitness function values to the population list.

The Dynamo graph below is contained inside 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 the counter that controls the number of iterations. The Fitness Function gets fed into the “NSGA_II Function” custom node as an input along with the lowerLimits and upperLimits.

The GenerationAlgorithm creates a new population based on the previous generation. This new generation is then evaluated with the same fitness functions, and the fitness function results overwrite the objectives’ values in this new generation. The “NSGA_II.Sorting” node takes the previous generation as well as the current generation, and ranks them in the equally optimal solution front based on their fitness (best results first).

The “LoopWhile” node is essentially running in the “NSGA_II Function” node recursively. The number of loops depends on the iteration number inserted into LoopCompleteionCheck as an input. The init input gets incremented by one in each loop, and once init reaches the same value as completionCheck, the loop ends and the Dynamo program continues. The LoopBody input is the output from the NSGA_II function (it becomes the input for the recursive call to the NSGA_II Function node). The output gets written to a .csv file for viewing later, and is also drawn on screen in Dynamo to help visualize the solution.

The bottom part of the Dynamo graph simply shows the original object and the optimized ()version, takes the volume of both the original bounding box and the final optimized bounding box and displays them.

BBox_Results

The result of running the Bounding Box example 50 times is shown below.

Results