Beispiel #1
0
def bobo(c, alpha, beta, pmig, df, logger, x):

    #chave = 'c=%.2f,alpha=%.2f,beta=%.2f,m=%.2f,pA=0.'%(c,alpha,beta,pmig)
    #if df.has_key(chave):
    #    freqA, it = df[chave]
    #else:
    pA = 0.
    freqA, it = gera_simulacao(N,n,pA,c,mu,alpha,beta,pmig,max_it,x,retorna_td=True)
    #    df[chave] = [freqA,it]
    logger.info('Simulacao com pA=0.: termina em %f em %d its' %(freqA, it))
    if it < max_it:
        return 1, it 

    #chave = 'c=%.2f,alpha=%.2f,beta=%.2f,m=%.2f,pA=1.0'%(c,alpha,beta,pmig)
    #if df.has_key(chave):
    #    freqA, it = df[chave]
    #else:
    #    pA = 1.
    #    freqA, it = gera_simulacao(N,n,pA,c,mu,alpha,beta,pmig,max_it,retorna_td=True)
    #    df[chave] = [freqA,it]
    #logger.info('Simulacao com pA=1.0: termina em %f em %d its' %(freqA, it))
    #if it < max_it:
    #    return 0, it 

    #df_aux = df[(df.c==c)&(df.alpha==alpha)&(df.beta==beta)&(df.m==pmig)]
    #if len(df_aux) != 0:
    #    res = zip(df_aux['freqA'].tolist(),df_aux['numIT'].tolist())
   
    #chave = 'c=%.2f,alpha=%.2f,beta=%.2f,m=%.2f'%(c,alpha,beta,pmig)
    #if df.has_key(chave):
    #    res = df[chave]
    #    #salva_em_df = False
    #else:
    pA = 0.
    nc = mp.cpu_count() -1 
    res = Parallel(n_jobs=nc)(delayed(sim)(c,alpha,beta,pA,pmig,x+1+i) for i in xrange(20))
        #df[chave] = res
        #salva_em_df = True
    # Mostra quantas simulacoes acabaram antes do maximo e a media de iteracoes que elas levaram
    l_its = []
    for (freqA,num_its) in res:
        l_its.append(num_its)
        #if salva_em_df:
        #    entrada = {'c': c, 'alpha': alpha, 'beta': beta, 'm': pmig, \
        #                'freqA': freqA, 'numIT': num_its}
        #    df = df.append(entrada)
    v = np.array(l_its)<max_it
    if np.count_nonzero(v)>0:
        w = np.take(l_its, np.nonzero(v)[0])
        n_geracoes = sum(w)/len(w)
    else:
        n_geracoes = max_it 
    logger.info('Simulacao termina antes do fim para %d de 20 sims, levando na media: %d'%(np.count_nonzero(v), n_geracoes))
    return np.count_nonzero(v), n_geracoes
Beispiel #2
0
def bobo(c, alpha, beta, pmig):

    pA = 0.5
    it = gera_simulacao(N, n, pA, c, mu, alpha, beta, pmig, max_it)
    if it < max_it:
        return 1, it
    pA = 1.0
    it = gera_simulacao(N, n, pA, c, mu, alpha, beta, pmig, max_it)
    if it < max_it:
        return 0, it
    pA = 0.5
    nc = mp.cpu_count() - 1
    l_its = Parallel(n_jobs=nc)(delayed(sim)(c, alpha, beta, pA, pmig, i) for i in xrange(10))

    # Mostra quantas simulacoes acabaram antes do maximo e a media de iteracoes que elas levaram
    v = np.array(l_its) < max_it
    if np.count_nonzero(v) > 0:
        w = np.take(l_its, np.nonzero(v)[0])
        n_geracoes = sum(w) / len(w)
    else:
        n_geracoes = max_it
    return np.count_nonzero(v), n_geracoes
Beispiel #3
0
def sim(c, alpha, beta, pA, pmig):
    return gera_simulacao(N, n, pA, c, mu, alpha, beta, pmig, max_it, retorna_td=True)
Beispiel #4
0
def sim(c, alpha, beta, pA, pmig, i):
    return gera_simulacao(N, n, pA, c, mu, alpha, beta, pmig, max_it)