Esempio n. 1
0
    def runSearcher(self, emax, emin):
        modelbasics = modelBasics(self.modelName)
        modelFunction = self.modelName()
        anz = anzeigen()
        hi, lo, kooling, indepSize, thresh, iterations = modelFunction.eigenschaften()
        # emax, emin = modelbasics.baselining(self.modelName)
        sb = s = [randi(lo, hi) for z in xrange(indepSize)]
        eb = e = modelbasics.energy(s, emax, emin)
        enRec = dynamikliste()  # Creates a growing list.
        enRec[0] = 0
        # Since iterations start from 1, lets initialize enRec[0] to 0
        analyser = analyzer.analyser()
        epochs = 5 if self.early else iterations
        k = 1
        while epochs and k < iterations:
            sn = modelbasics.neighbour(s, hi, lo)
            en = modelbasics.energy(sn, emax, emin)
            t = k / iterations
            if en < eb:
                eb, sb, enRec[k] = en, sn, en
                if self.disp:
                    modelbasics.say("!")

            if en < e:
                s, e, enRec[k] = sn, en, en
                if self.disp:
                    modelbasics.say("+")

            if modelbasics.do_a_randJump(en, e, t, kooling):
                # The cooling factor needs to be really low for some reason!!
                s, e, enRec[k] = sn, en, en
                if self.disp:
                    modelbasics.say("?")
            else:
                enRec[k] = en
            if self.disp:
                modelbasics.say(".")
            if k % 50 == 0 and k > 50:
                # print enRec[:-10]
                proceed = analyser.isItGettinBetter(enRec[k - 100 :])
                if proceed:
                    epochs += 1
                else:
                    epochs -= 1
                # print enRec[k-40:] #
            k = k + 1
            if k % 40 == 0:
                if self.disp:
                    modelbasics.say("\n")  # sa.say(format(sb,'0.2f'))

        if self.disp:
            modelbasics.say("\n"),
        # Print Energy and best value.
        for i in xrange(k):
            if self.disp:
                if i % 50 == 0:
                    print anz.xtile(enRec[i - 50 :])
        if self.disp:
            modelbasics.say("\n")
        return eb
Esempio n. 2
0
  def runSearcher(self):
    modelbasics = modelBasics(self.modelName);
    modelFunction = self.modelName()
    anz = anzeigen();
    hi, lo, kooling, indepSize, iterations = \
     modelFunction.eigenschaften()
    emax, emin = self.emax, self.emin
    sb = s = [randi(lo, hi) for z in xrange(indepSize)];
    eb = e = modelbasics.energy(s, self.emax, self.emin)
    enRec = dynamikliste()  # Creates a growing list.
    enRec[0] = 0;  
    # Since iterations start from 1, lets initialize enRec[0] to 0
    analyser = analyzer.analyser()
    epochs = 3 if self.early else iterations;
    k = 1;
    while epochs and k < iterations:
      sn = modelbasics.neighbour(s, hi, lo)
      en = modelbasics.energy(sn, emax, emin)
      t = k / iterations
      if en < eb:
        eb, sb, enRec[k] = en, sn, en;
        #if self.disp: 
          #modelbasics.say('!')
      if en < e:
        s, e, enRec[k] = sn, en, en; 
        #if self.disp: 
          #modelbasics.say('+')

      if modelbasics.do_a_randJump(en, e, t, kooling):  
        # The cooling factor needs to be really low for some reason!!
        s, e, enRec[k] = sn, en, en; 
        #if self.disp: 
          #modelbasics.say('?')
      else:
        enRec[k] = en  
      #if self.disp:
      #  modelbasics.say('.')
      if k % 50 == 0 and k > 50:
        # print enRec[:-10]
        proceed = analyser.isItGettinBetter(enRec[k - 100:])
        if proceed:
          epochs += 1;
        else:
          epochs -= 1;
        # print enRec[k-40:] #
      k = k + 1
      era=1;
    
    # Print Energy and best value.
    for i in xrange(k):
      if self.disp:
        if i % 50 == 0:
          print era, anz.xtile(enRec[i - 50:], show='%0.2E') 
          era+=1
    if self.disp: 
      modelbasics.say('\n')
    return [eb, modelbasics.energyIndv(sb, emax, emin)]
Esempio n. 3
0
sys.dont_write_bytecode = True
rdivDemo=sk.rdivDemo

for x in [Schaffer, Kursawe, 
          Fonseca, ZDT1, ZDT3, Viennet3]:
          
  early=True
  E=[]
  for y in [GA,SimulatedAnnealer, MaxWalkSat]:
    eb=30*[0]
    print 'Model: ', x.__name__ 
    print 'Searcher: ', y.__name__ 
    print strftime("%a, %d %b %Y %H:%M:%S ", gmtime()), '\n'
    k=x()
    reps=30
    dspl=anzeigen();
    hi, lo, kooling, indepSize, iterations = k.eigenschaften()
    print 'Settings:'
    print 'min=', lo, ', max=', hi, ', Cooling Factor=', kooling, '\n'
    if early: print 'Early Termination!'  , '\n'
    for r in xrange(reps):
      a=y(x,disp=False,early=early)
      eb[r] =  a.runSearcher()
    eb.insert(0,y.__doc__)
    E.append(eb)
    #print dspl.xtile(eb[1:])
    """for r in xrange(reps):
      print dspl.xtile(eb[r:r+50], lo=lo, hi=hi)"""
    print 'Energy: ', "{:.3E}".format(Decimal(str(np.sum(eb[1:])/reps)))
  
  def _rDiv():