def fitness(x, *args): """Compute the value of the fitness function """ weights = loadWeights() utopiaNadir = loadUtopiaNadir() v = args[0] startPos = args[1] endPos = args[2] flutParam = {"speed": np.sqrt(v[0] * v[0] + v[2] * v[2]), "operators": x.reshape(3, 18)} comTrajList = cm.main(flutParam=flutParam) if objSel == None: Et = fitnessTarget(comTrajList, endPos, un=utopiaNadir[0]) Ev = fitnessVelocity(comTrajList, startPos, endPos, un=utopiaNadir[1]) Ed = fitnessDeviation(comTrajList, un=utopiaNadir[2]) fit = Et * weights[0] + Ev * weights[1] + Ed * weights[2] else: if objSel == "target": fit = fitnessTarget(comTrajList, endPos, un=utopiaNadir[0]) if objSel == "velocity": fit = fitnessVelocity(comTrajList, startPos, endPos, un=utopiaNadir[1]) if objSel == "deviation": fit = fitnessDeviation(comTrajList, un=utopiaNadir[2]) return fit
def fitness(x, indGen, indX, options): """Computing the value of the fitness function This is a weighted sum of energy, velocity and deviation components. The individual fitness function can be normalised with the nadir and utopia points, and can be sumed up with different weights. """ objSel = options['objSel'] weightActive = options['weights'] utopiaActive = options['utopiaNadir'] if __OP_BETA__ == True: vel = options['vel'] weights = loadWeights(active=weightActive) utopiaNadir = loadUtopiaNadir(active=utopiaActive) saveParam(x, indGen, indX) optParam = {'indGen':indGen, 'indX':indX} cm.main(optParam=optParam) if __OP_BETA__ == True: return fitnessVelocity(indGen, indX, un=utopiaNadir[1], velbeta=vel) if objSel == None: Em = fitnessEnergy(indGen, indX, un=utopiaNadir[0]) Ev = fitnessVelocity(indGen, indX, un=utopiaNadir[1], velbeta=vel) Ed = fitnessDeviation(indGen, indX, un=utopiaNadir[2]) fit = weights[0]*Em + weights[1]*Ev + weights[2]*Ed else: if objSel == 'energy': fit = fitnessEnergy(indGen, indX, un=utopiaNadir[0]) if objSel == 'torque': fit = fitnessVelocity(indGen, indX, un=utopiaNadir[1]) if objSel == 'deviation': fit = fitnessDeviation(indGen, indX, un=utopiaNadir[2]) return fit
def findNadirPoints(): """Find the nadir points for each separate objection function """ objs = ['energy', 'torque', 'deviation'] res_f = [] paretoPoints = loadParetoPoints() for obj in objs: nadirFit = 0 nadirX = [] for p in paretoPoints: saveParam(p, standard=True) cm.main() if obj == 'energy': fit = fitnessEnergy(standard=True) if obj == 'torque': fit = fitnessVelocity(standard=True) if obj == 'deviation': fit = fitnessDeviation(standard=True) if fit > maxfit: nadirFit = fit nadirX = p res_f.append(np.insert(nadirX, 0, nadirFit)) np.savetxt('param/nadir_cpg.txt', res_f, fmt='%.5f')