# CTUG-NSGA2.tz (c) 2010 Jacob Schrum. # See Simulation.tz for more copyright information @use Abstract. @use File. @include "Constants.tz". @include "Selection.tz". @include "NSGA2.tz". NSGA2 : CTUG-NSGA2 { + variables: goal-constraints (list). absolute-mins (list). + to set-goal-constraints from fitness-info (list): i (int). goal-constraints = {}. absolute-mins = {}. for i = 0, i < |fitness-info|, i++ : { if (fitness-info{i}{SLOT_USE_GOAL}) : { push (fitness-info{i}{SLOT_GOAL}) onto goal-constraints. push (fitness-info{i}{SLOT_MIN}) onto absolute-mins. } } #print "Constraints: $goal-constraints". + to init: + to total-constraint-violation of point (list): i (int). result (double). result = 0. for i = 0, i < |point|, i++ : { if (point{i} < goal-constraints{i}) : { result += | ((goal-constraints{i} - point{i}) / (objective-maxes{i} - absolute-mins{i})) |. } } #print "$point violates by: $result". return result. + to is-feasible point x (list): i (int). for i = 0, i < |x|, i++ : { if (x{i} < goal-constraints{i}) : { #print "not feasible: $x". return 0. } } #print "feasible: $x". return 1. # sol1: a list of fitness objective scores # sol2: a list of fitness objective scores # - |sol1| == |sol2| + to dominate this sol1 (list) dominates sol2 (list): feasible1 (int). feasible2 (int). feasible1 = (self is-feasible point sol1). feasible2 = (self is-feasible point sol2). if ((feasible1 == 1) && (feasible2 == 0)) : { return 1. } else if ((feasible1 == 1) && (feasible2 == 1)) : { return (super dominate this sol1 dominates sol2). } else if ((feasible1 == 0) && (feasible2 == 0)) : { return ((self total-constraint-violation of sol1) < (self total-constraint-violation of sol2)). } return 0. }