Example #1
0
def sim_greedy(M, min_f, max_f, debug):
    
    samples = np.random.randint(2, size=M*(M-1)/2)
    C = rd.random_compatibities(samples, M)
    F = []
    A = np.zeros((M), dtype=int)
    
    debugf(debug,'\nCompatibity matrix = \n%s\n', C)
        
    retry = 0
    f=min_f
    
    while sum(a==0 for a in A) <> 0:
        while (f in F):
            f = np.random.randint(min_f, max_f)
        
        F.append(f)
        gd.solve(A, C, F)
        retry += 1
        debugf(debug, '\nRetry count: %s\n', retry)
        debugf(debug, 'Frequencies = %s\n', F)
        debugf(debug, 'Assignment matrix = %s\n', A)

    if (debug):
        vf.verify_compatibility(A, C)
        #gp.color_graph(C, A, F)
        #gp.heatmap(A, F)
        #plt.show()
        
    return A, C, F, 1-(len(F)/(len(A)*1.0))
Example #2
0
M = 20 # total stations
# samples = np.random.randint(2, size=M*(M-1)/2)
samples = [1,0,1,1,0,1,0,1,1,1,0,0,0,1,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,1,1,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1,1,0,1,1]
print samples
C = rd.random_compatibities(samples, M)
print C
#print C.transpose()
#print C-C.transpose()
F = range(1,21)
#F = [np.random.randint(100, 1000)]
A = np.zeros((M), dtype=int)

printf('Assignment matrix =\n%s\n', A)
# print 'Compataility Matrix =\n%s\n' % C

# print '### Result ####\n'
# result = gd.solve(A, C, F)

while sum(a==0 for a in A) <> 0:
    #F.append(np.random.randint(100, 1000))
    result = gd.solve(A, C, F)
    printf('\nFrequencies = %s\n', F)
    printf('Assigned frequencies = %s\n', A)

print '\n### Summary ###\n'
printf('# reused ratio = %s / %s\n', len(A) - len(F), len(A))
printf('Efficiency = %1.3f\n', len(F)/(len(A)*1.0))

vf.verify_compatibility(A, C)
# gp.color_graph(C, A, [15, 16, 17, 18, 19, 20])
# gp.heatmap(A, F)