The number of generations, population size, and number of children are basic parameters in genetic algorithm optimization that determine how the search proceeds, and they interact to affect the quality and an amount of calculations of the search.
The population size determines the number of designs evaluated simultaneously per generation and is responsible for the “breadth” of the search.
The number of children controls the number of new designs generated in each generation and affects the extent to which the designs change and evolve.
Meanwhile, the maximum number of generations determines how many times generations will be repeated and specifies the “depth” of the search.
This script sets the parameters and evaluation options for topology optimization.
Preconditions
- One or more study that supports topology optimization has been created.
This script runs on the active study in the project tree. - A topology optimization condition has been set.
Script Function
- Set the topology optimization engine and its parameters.
The optimization engine is set to genetic algorithm (topology), the number of generations is set to 10, the population size is set to 60, and the number of children is set to 55.
The continuous shape evaluation is set to “Limit parts separation”.
The result evaluation is set to “Save the best objective function case from each generation”.
# Copyright (c) 2026 JSOL CORPORATION
#
# This script is released under the MIT License.
# See the full license text at:
# https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/
def setTopologyOptimizationOption(optimTable, engine, maxGen, numPop, numChild):
"""Set topology optimization options"""
mapping = {
# Optimization engine: Each key item in Genetic Algorithm (Topology))
"jsol_ga": (u"jsol_ga_max_generation",
u"jsol_ga_num_population",
u"jsol_ga_num_children",
u"jsol_ga_shape_evalution",
u"jsol_ga_result_evaluation"),
# Optimization engine: Key items in Multi-Objective Genetic Algorithm (Topology)
"jsol_moga2": (u"jsol_moga2_max_generation",
u"jsol_moga2_num_population",
u"jsol_moga2_num_children",
u"jsol_moga2_shape_evalution",
u"jsol_moga2_result_evaluation"),
}
keyMagGen, keyNumPop, keyNumChild, keyShapeEval, keyResultEval = mapping[engine]
optimTable.SetParameter(u"engine", engine)
optimTable.SetParameter(keyMagGen, maxGen)
optimTable.SetParameter(keyNumPop, numPop)
optimTable.SetParameter(keyNumChild, numChild)
# Continuous Shapve Evaluation Parameters
# 0:Do not use the continuity of the shape as an evaluation criterion
# 1:Limit parts separation
# 2:Limit parts separation to no more than the maximum of 2 independent regions
optimTable.SetParameter(keyShapeEval, 1)
# Results Evaluation Parameters
# 0:Save the specified number of best objective cases(Optimization Engine:Genetic Algorithm (Topology))
# 0:Save results for cases on Pareto front(Optimization Engine:Multi-Objective Genetic Algorithm (Topology))
# 1:Save the best objective function case from each generation
# 2:Save the results of all cases
optimTable.SetParameter(keyResultEval, 1)
app = designer.GetApplication()
study = app.GetCurrentStudy()
engine = u"jsol_ga"
maxGeneration = 10
numPopulation = 60
numChildren = 55
setTopologyOptimizationOption(
study.GetOptimizationTable(), engine, maxGeneration, numPopulation, numChildren)


