示例#1
0
文件: DTLZ7.py 项目: nkudige/x9115DMN
 def type2(self, era_one, era_two):
     for objective in self.get_objectives():
         era_one_objective = []
         era_two_objective = []
         for i in xrange(0, len(era_one)):
             era_one_objective.append(objective(era_one[i]))
             era_two_objective.append(objective(era_two[i]))
         if (a12(era_one_objective, era_two_objective) > 0.56):
             return 5
     return -1
示例#2
0
文件: DTLZ7.py 项目: nkudige/x9115DMN
 def type2(self, era_one, era_two):
     for objective in self.get_objectives():
         era_one_objective = []
         era_two_objective = []
         for i in xrange(0, len(era_one)):
             era_one_objective.append(objective(era_one[i]))
             era_two_objective.append(objective(era_two[i]))
         if (a12(era_one_objective, era_two_objective) > 0.56):
             return 5
     return -1
示例#3
0
 def run(self):
         max_tries = 100
         max_changes = 50
         self.model.resetBaselines()
         best_state = self.model.get_random_state()
         output = str()
         lives = 5
         ERA_LENGTH = 25
         current_era = []
         eras = []
         for _ in range(0, max_tries):
                 current_state = self.model.get_random_state()
                 for i in range(0, max_changes):
                         if self.model.energy(current_state) < self.threshold:
                                 return current_state
                         else:
                                 new_state = self.retry(current_state)
                         operation = ""
                         if self.model.energy(new_state) > self.model.energy(best_state):
                                 best_state = new_state
                                 operation = "!"
                         elif self.model.energy(new_state) > self.model.energy(current_state):
                                 operation = "+"        
                         elif self.model.energy(new_state) < self.model.energy(current_state):
                                 operation = "."
                         output += operation
                         current_era.append(self.model.normalize_energy(self.model.energy(current_state), self.model.baseline_low, self.model.baseline_high))
                         if len(current_era) == ERA_LENGTH and len(eras) > 0:
                                 if a12(current_era, eras[-1]) < 0.56:
                                         lives -= 1
                                         #print "reducing the life by 1 lives: " + str(lives)
                                 else:
                                         lives = 5
                         if lives <= 0:
                                 print "Early termination"
                                 return
                         if len(current_era) == ERA_LENGTH:
                                 eras.append(current_era)
                                 current_era = []
                         if len(output) == 50:
                                 print "Lives: " + str(lives) + " " + output + " current best state energy(normalized) = " + str(self.model.energy(best_state)) + " Evaluations: " + str(self.evals)
                                 output = ""
         print output + " current best state energy(normalized) = " + str(self.model.aggregate_energy(best_state)) + " Evaluations: " + str(self.evals)
         return best_state
示例#4
0
文件: analyzer.py 项目: rahlk/sbse
 def same(): return a12(new, old)<=0.56
 if self.less:
示例#5
0
文件: SA.py 项目: nkudige/x9115DMN
 def run(self):
   kmax = 1000
   max_e = -0.1
   output = ''
   
   current_s = self.model.get_random_state()
   best_s = current_s
   
   current_e = self.model.normalize_energy(self.model.energy(current_s), self.model.baseline_low, self.model.baseline_high)
   best_e = current_e
   
   k = 1
   current_era = []
   eras = []
   lives = 5
   ERA_LENGTH = 10
   while k < kmax and current_e > max_e:
     neighbor_s = self.model.get_random_state()
     # print 'Neighbor: ' + str(neighbor_s)
     neighbor_e = self.model.normalize_energy(self.model.energy(neighbor_s), self.model.baseline_low, self.model.baseline_high)
     # print current_e, neighbor_e, tmp
     
     if neighbor_e < best_e:
       best_s, best_e = neighbor_s, neighbor_e
       output += ' !'
     
     if neighbor_e < current_e:
       current_s, current_e = neighbor_s, neighbor_e
       output += ' +'
       
     elif self.P(current_e, neighbor_e, (1-(float(k)/kmax))**5) > random.random():
       current_s, current_e = neighbor_s, neighbor_e
       output += ' ?'
       
     else:
       output += ' .'
     
     current_era.append(self.model.normalize_energy(current_e, self.model.baseline_low, self.model.baseline_high))
     if len(current_era) == ERA_LENGTH and len(eras) > 0:
       if a12(current_era, eras[-1]) < 0.56:
         lives -= 1
         print "Lives:" + str(lives) + " a12 statistic:" + str(a12(current_era, eras[-1])),
       else:
         lives = 5
     if len(current_era) == ERA_LENGTH:
       eras.append(current_era)
       current_era = []
       if lives <= 0:
         print "Early termination"
         break
     if k % 25 == 0:
       print ', %4d, : %d, %25s' % (k, self.model.denormalize_energy(best_e), output)
       output = ''
   
     k += 1
     
   print
   print 'Best State Found: ' + str(best_s)
   print 'Energy At Best State: ' + str(self.model.denormalize_energy(best_e))
   print
   
   return best_e
示例#6
0
    def run(self):
        kmax = 1000
        max_e = -0.1
        output = ''

        current_s = self.model.get_random_state()
        best_s = current_s

        current_e = self.model.normalize_energy(self.model.energy(current_s),
                                                self.model.baseline_low,
                                                self.model.baseline_high)
        best_e = current_e

        k = 1
        current_era = []
        eras = []
        lives = 5
        ERA_LENGTH = 10
        while k < kmax and current_e > max_e:
            neighbor_s = self.model.get_random_state()
            # print 'Neighbor: ' + str(neighbor_s)
            neighbor_e = self.model.normalize_energy(
                self.model.energy(neighbor_s), self.model.baseline_low,
                self.model.baseline_high)
            # print current_e, neighbor_e, tmp

            if neighbor_e < best_e:
                best_s, best_e = neighbor_s, neighbor_e
                output += ' !'

            if neighbor_e < current_e:
                current_s, current_e = neighbor_s, neighbor_e
                output += ' +'

            elif self.P(current_e, neighbor_e,
                        (1 - (float(k) / kmax))**5) > random.random():
                current_s, current_e = neighbor_s, neighbor_e
                output += ' ?'

            else:
                output += ' .'

            current_era.append(
                self.model.normalize_energy(current_e, self.model.baseline_low,
                                            self.model.baseline_high))
            if len(current_era) == ERA_LENGTH and len(eras) > 0:
                if a12(current_era, eras[-1]) < 0.56:
                    lives -= 1
                    print "Lives:" + str(lives) + " a12 statistic:" + str(
                        a12(current_era, eras[-1])),
                else:
                    lives = 5
            if len(current_era) == ERA_LENGTH:
                eras.append(current_era)
                current_era = []
                if lives <= 0:
                    print "Early termination"
                    break
            if k % 25 == 0:
                print ', %4d, : %d, %25s' % (
                    k, self.model.denormalize_energy(best_e), output)
                output = ''

            k += 1

        print
        print 'Best State Found: ' + str(best_s)
        print 'Energy At Best State: ' + str(
            self.model.denormalize_energy(best_e))
        print

        return best_e