예제 #1
0
 def updatepbest(self):
     # This function updates the population Pbest
     if self.t == 1:
         self.pbest = list(self.p)
         for m in range(self.pop):
             self.pbest[m].makevlrep(self.swarm[m].getvlrep(), self.items)
     else:
         for m in range(self.pop):
             if self.p[m].getindex() != self.pbest[m].getindex():
                 # See if the new sol. m dominates the current personal best
                 if mop.dom(self.p[m].getfits(), self.pbest[m].getfits()):
                     self.pbest[m] = self.p[m]
                     self.pbest[m].makevlrep(self.swarm[m].getvlrep(), self.items)
                     print('     Swarm member', m, 'found new personal best!')
                 else:
                     if not mop.dom(self.pbest[m].getfits(), self.p[m].getfits()):
                         pbran = random.random()
                         if pbran < 0.5:
                             self.pbest[m] = self.p[m]
                             self.pbest[m].makevlrep(self.swarm[m].getvlrep(), self.items)
예제 #2
0
def fnds(setp):
    # This module performs the fast-non-dominated-sort described in Deb(2002).
    # To run this module, enable the following line:
    # from mop import dom
    numsol = len(setp)
    fronts = []
    sp = []
    fhold = []
    nps = []
    for p in range(numsol):
        shold = []
        nump = 0
        for q in range(numsol):
            if setp[p] != setp[q]:
                if mop.dom(setp[p].getfits(), setp[q].getfits()):
                    shold.append(setp[q])
                if mop.dom(setp[q].getfits(), setp[p].getfits()):
                    nump += 1
        sp.append(shold)
        nps.append(nump)
        if nump == 0:
            fhold.append(setp[p])
            setp[p].updaterank(1)
    fronts.append(fhold)  # Pareto set
    i = 0
    while fronts[i] != []:
        q = []
        for j in range(numsol):
            if setp[j] in fronts[i]:
                for k in range(numsol):
                    if setp[k] in sp[j]:
                        nps[k] -= 1
                        if nps[k] == 0:
                            setp[k].updaterank(i + 2)
                            q.append(setp[k])
        fronts.append(q)
        i += 1
    return setp, fronts
예제 #3
0
def approx(archive):
    # This module finds the final approximate set.
    numsol = len(archive)
    ndset = []
    for p in range(numsol):
        nump = 0  # number of sol. that dominate p
        for q in range(numsol):
            if archive[p] != archive[q]:
                if mop.dom(archive[q].getfits(), archive[p].getfits()):
                    nump += 1
        if nump == 0:
            ndset.append(archive[p])
    ndset = rmdupl(ndset)
    return ndset
def approx(archive):
    # This module finds the final approximate set.
    # To run this module, enable the following line:
    # from mop import dom
    numsol = len(archive)
    ndset = []
    for p in range(numsol):
        np = 0
        for q in range(numsol):
            if archive[p] != archive[q]:
                if dom(archive[q].getfits(), archive[p].getfits()):
                    np += 1
        if np == 0:
            ndset.append(archive[p])
    return ndset
예제 #5
0
 def paretols(self, m, nls, retrieve=False):
     # This function finds up to nls neighbors to check if they dominate
     # solution m of the new generation.
     x = m.getx()
     y = m.gety()
     neighbors = []
     for k in range(nls):
         newx, newy = self.binmutation(x, y)
         newfit = self.moop.calcfits(newx, newy)
         self.updatefe()
         # If we find a neighbor that is nondominated by solution m, add to q.
         if not mop.dom(m.getfits(), newfit):
             neighbors = self.addneighbor(newx, newy, newfit, neighbors)
     if retrieve is True:
         return neighbors
예제 #6
0
 def pls(self, maxmum):
     # This function performs the Pareto Local Search from Ke(2014).
     # Step 2 in MOMAD.
     # input: pp, pl, pe, maxmum
     # output: pl, pe
     m = 0
     while self.pp != [] and m < maxmum:
         palpha = []
         for x in range(len(self.pp)):
             print('     Searching near solution', self.pp[x].getindex())
             nofx = self.neighborhood(self.pp[x], 50)
             for y in range(len(nofx)):
                 self.update1(nofx[y])
                 if mop.dom(nofx[y].getfits(), self.pp[x].getfits()):
                     self.pe = self.update2(nofx[y], self.pe)
                     if nofx[y] in self.pe:
                         palpha = self.update2(nofx[y], palpha)
         self.pp = list(palpha)
         m += 1