Exemple #1
0
 def generate_children(self, particle, neighbors):
     if particle.tokens > 0:
         child = SEParticle(particle, specpbest=True, specnbestid=-1)
         child.pbestpos = particle.pos
         self.specex.just_move(child)
         yield child
         i = 1
         while i < particle.tokens:
             i += 1
             child = SEParticle(child, specpbest=True, specnbestid=-1)
             child.pbestpos = child.pos
             self.specex.just_move(child)
             yield child
Exemple #2
0
 def generate_children(self, particle, neighbors):
     """Just speculate two children, the two where we assume we didn't get
     an nbest update.
     """
     # Create child guessing that pbest was not updated
     child = SEParticle(particle, specpbest=False, specnbestid=-1)
     self.specex.just_move(child)
     yield child
     # And now guessing that pbest was updated
     child = SEParticle(particle, specpbest=True, specnbestid=-1)
     child.pbestpos = particle.pos
     self.specex.just_move(child)
     yield child
Exemple #3
0
    def generate_children(self, particle, neighbors):
        """Given the particle and neighbors at iteration i, yield all possible
        speculative children for iteration i+1."""
        # Create children guessing that pbest was not updated
        child = SEParticle(particle, specpbest=False, specnbestid=-1)
        self.specex.just_move(child)
        yield child
        for n in neighbors:
            if n.id != particle.id:
                child = SEParticle(particle, specpbest=False, specnbestid=n.id)
                child.nbestpos = n.pos
                self.specex.just_move(child)
                yield child

        # Create children guessing that pbest was updated
        child = SEParticle(particle, specpbest=True, specnbestid=-1)
        child.pbestpos = particle.pos
        self.specex.just_move(child)
        yield child
        for n in neighbors:
            child = SEParticle(particle, specpbest=True, specnbestid=n.id)
            child.nbestpos = n.pos
            child.pbestpos = particle.pos
            self.specex.just_move(child)
            yield child
Exemple #4
0
 def generate_children(self, particle, neighbors):
     if particle.tokens > 0:
         children = []
         # Create child guessing that neither pbest nor nbest was updated
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         children.append((False, -1))
         yield child
     if particle.tokens > 1:
         # And now guessing that pbest was updated
         child = SEParticle(particle, specpbest=True, specnbestid=-1)
         child.pbestpos = particle.pos
         self.specex.just_move(child)
         children.append((True, -1))
         yield child
     if particle.tokens > 2:
         # And now for the last branch that was taken
         if particle.lastbranch[0] == True:
             specpbest = True
         else:
             specpbest = False
         specnbestid = particle.lastbranch[1]
         if specnbestid != -1:
             child = SEParticle(particle, specpbest=specpbest,
                     specnbestid=specnbestid)
             self.specex.just_move(child)
         else:
             rand = self.specex.neighborhood_rand(particle)
             specnbestid = rand.randrange(len(neighbors))
             child = SEParticle(particle, specpbest=specpbest,
                     specnbestid=specnbestid)
             self.specex.just_move(child)
         children.append((specpbest, specnbestid))
         yield child
     if particle.tokens > 3:
         for i in range(particle.tokens-3):
             tries = 0
             failed = False
             while (specpbest, specnbestid) in children:
                 tries += 1
                 if tries > 10:
                     failed = True
                     break
                 if particle.rand.randrange(2):
                     specpbest = True
                 else:
                     specpbest = False
                 specnbestid = particle.rand.randrange(len(neighbors))
             if failed:
                 break
             child = SEParticle(particle, specpbest=specpbest,
                     specnbestid=specnbestid)
             self.specex.just_move(child)
             children.append((specpbest, specnbestid))
             yield child
Exemple #5
0
 def generate_children(self, particle, neighbors):
     if particle.tokens > 0:
         # Iteration 2, NN
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 1:
         # Iteration 2, YN
         child = SEParticle(particle, specpbest=True, specnbestid=-1)
         child.pbestpos = particle.pos
         self.specex.just_move(child)
         yield child
     if particle.tokens > 2:
         # Iteration 3, NN-NN
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child = SEParticle(child, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 3:
         # Iteration 3, NN-YN
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child.pbestpos = child.pos
         child = SEParticle(child, specpbest=True, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 4:
         # Iteration 3, YN-NN
         child = SEParticle(particle, specpbest=True, specnbestid=-1)
         child.pbestpos = particle.pos
         self.specex.just_move(child)
         child = SEParticle(child, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 5:
         # Iteration 3, YN-YN
         child = SEParticle(particle, specpbest=True, specnbestid=-1)
         child.pbestpos = particle.pos
         self.specex.just_move(child)
         child.pbestpos = child.pos
         child = SEParticle(child, specpbest=True, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 6:
         # Iteration 4, NN-NN-NN
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child = SEParticle(child, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child = SEParticle(child, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         yield child
     if particle.tokens > 7:
         # Iteration 4, NN-NN-YN
         child = SEParticle(particle, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child = SEParticle(child, specpbest=False, specnbestid=-1)
         self.specex.just_move(child)
         child.pbestpos = child.pos
         child = SEParticle(child, specpbest=True, specnbestid=-1)
         self.specex.just_move(child)
         yield child