Exemplo n.º 1
0
def de(mod):
    frontier_size = 50
    max_tries = 40
    f = 0.75
    cf = 0.3
    epsilon = 0.1
    ib = 0
    frontier = generate_frontier(frontier_size, mod)
    eb = init_score(mod, frontier)
    prev = []
    lives = 5
    p = 1
    for k in range(max_tries):
        Utility.say(str(p) + "|")
        total, n, eb, ib, frontier, cur = update(mod, f, cf, ib, frontier, eb)
        if not prev:
            prev = cur[:]
        else:
            lives += Utility.check_type2(prev, cur)
            prev = cur[:]
        if lives is 0:
            break
        p += max_tries
        Utility.say("\n")
    f1, f2 = mod.objs(frontier[ib])
    Utility.printOutput("Success", f1, f2, frontier[ib], eb)
    return frontier[ib]
Exemplo n.º 2
0
def mws(mod):
    max_tries = 25
    max_changes = 100
    threshold = 0.01
    p = 0.05
    lives = 3
    best_sn = mod.generate()
    norm = mod.baseline_study()
    norm, best_sc = mod.get_energy(best_sn,norm)

    prev = []
    k = 1
    for i in range(max_tries):
        sn = mod.generate()
        cur = []
        Utility.say(str(k)+"|")
        for j in range(max_changes):
            norm,score = mod.get_energy(sn,norm)
            if score < threshold:
                f1,f2 = mod.objs(sn)
                norm,score = mod.get_energy(sn,norm)
                best_sn = sn[:]
                best_sc = score
                Utility.printOutput("Success", f1,f2,best_sn,f1+f2)
                return best_sn
            limit = len(mod.decisons)-1 if len(mod.decisons) > 0 else 0
            c = random.randint(0,limit)
            if p < random.random():
                temp = mutate(mod,sn,c)
                if mod.checkconstraint(temp):
                    sn = temp[:]
                    Utility.say('?')
                else:
                    Utility.say('.')
            else:
                changed, sn = maximizesolution(mod,sn,c,norm)
                if changed:
                    norm,local_sc = mod.get_energy(sn,norm)
                    if Utility.check_type1(mod,sn,best_sn):
                        best_sc = local_sc
                        best_sn = sn[:]
                    sn = sn[:]
                    Utility.say('+')
                else:
                    Utility.say('!')
            norm,local_sc = mod.get_energy(sn,norm)
            cur.append(local_sc)
        if not prev:
            prev = cur[:]
        else:
            lives += Utility.check_type2(prev,cur)
            prev = cur[:]
        if lives is 0:
            break
        k += max_changes
        Utility.say("\n")
    f1,f2 = mod.objs(sn)
    Utility.printOutput('Failure',f1,f2,best_sn,f1+f2)
    return best_sn
Exemplo n.º 3
0
def mws(mod):
    max_tries = 25
    max_changes = 100
    threshold = 0.01
    p = 0.05
    lives = 3
    best_sn = mod.generate()
    norm = mod.baseline_study()
    norm, best_sc = mod.get_energy(best_sn, norm)

    prev = []
    k = 1
    for i in range(max_tries):
        sn = mod.generate()
        cur = []
        Utility.say(str(k) + "|")
        for j in range(max_changes):
            norm, score = mod.get_energy(sn, norm)
            if score < threshold:
                f1, f2 = mod.objs(sn)
                norm, score = mod.get_energy(sn, norm)
                best_sn = sn[:]
                best_sc = score
                Utility.printOutput("Success", f1, f2, best_sn, f1 + f2)
                return best_sn
            limit = len(mod.decisons) - 1 if len(mod.decisons) > 0 else 0
            c = random.randint(0, limit)
            if p < random.random():
                temp = mutate(mod, sn, c)
                if mod.checkconstraint(temp):
                    sn = temp[:]
                    Utility.say('?')
                else:
                    Utility.say('.')
            else:
                changed, sn = maximizesolution(mod, sn, c, norm)
                if changed:
                    norm, local_sc = mod.get_energy(sn, norm)
                    if Utility.check_type1(mod, sn, best_sn):
                        best_sc = local_sc
                        best_sn = sn[:]
                    sn = sn[:]
                    Utility.say('+')
                else:
                    Utility.say('!')
            norm, local_sc = mod.get_energy(sn, norm)
            cur.append(local_sc)
        if not prev:
            prev = cur[:]
        else:
            lives += Utility.check_type2(prev, cur)
            prev = cur[:]
        if lives is 0:
            break
        k += max_changes
        Utility.say("\n")
    f1, f2 = mod.objs(sn)
    Utility.printOutput('Failure', f1, f2, best_sn, f1 + f2)
    return best_sn
Exemplo n.º 4
0
def sa(mod):
    s = mod.generate()
    norm = mod.baseline_study()
    norm,e = mod.get_energy(s,norm)
    sb = s[:]
    eb = e
    k = 1.0
    kmax = 999.0
    lives = 5
    Utility.say("1|")
    prev = []
    cur = []
    while k < kmax:
      sn = mod.generate()
      norm, en = mod.get_energy(sn,norm)

      if Utility.check_type1(mod,sn,sb):
        sb = sn[:]
        eb = en
        Utility.say("!")
      if Utility.check_type1(mod,sn,s):
        s = sn[:]
        e = en
        Utility.say("+")
      elif mod.prob(e, en, k*7/(kmax)) < random.random():
        s = sn
        e = en
        Utility.say("?")
      Utility.say(".")
      cur.append(en)

      k = k + 1
      if k % 50 == 0:
        #cur = map(Utility.mean, zip(*cur))
        if not prev:
            prev = cur[:]
        else:
            lives += Utility.check_type2(prev,cur)
            prev = cur[:]
        if lives is 0:
            break
        cur = []
        Utility.say("\n"+str(int(k))+"|")

    f1,f2 = mod.objs(sb)
    Utility.printOutput('Success',f1,f2,sb,f1+f2)
    return sb
Exemplo n.º 5
0
def sa(mod):
    s = mod.generate()
    norm = mod.baseline_study()
    norm, e = mod.get_energy(s, norm)
    sb = s[:]
    eb = e
    k = 1.0
    kmax = 999.0
    lives = 5
    Utility.say("1|")
    prev = []
    cur = []
    while k < kmax:
        sn = mod.generate()
        norm, en = mod.get_energy(sn, norm)

        if Utility.check_type1(mod, sn, sb):
            sb = sn[:]
            eb = en
            Utility.say("!")
        if Utility.check_type1(mod, sn, s):
            s = sn[:]
            e = en
            Utility.say("+")
        elif mod.prob(e, en, k * 7 / (kmax)) < random.random():
            s = sn
            e = en
            Utility.say("?")
        Utility.say(".")
        cur.append(en)

        k = k + 1
        if k % 50 == 0:
            #cur = map(Utility.mean, zip(*cur))
            if not prev:
                prev = cur[:]
            else:
                lives += Utility.check_type2(prev, cur)
                prev = cur[:]
            if lives is 0:
                break
            cur = []
            Utility.say("\n" + str(int(k)) + "|")

    f1, f2 = mod.objs(sb)
    Utility.printOutput('Success', f1, f2, sb, f1 + f2)
    return sb