Exemplo n.º 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))
Exemplo n.º 2
0
import sys, time

import utils.verification as vf
import utils.random as rd
import utils.graphics as gp
import heuristic.greedy as gd

def printf(format, *args):
    sys.stdout.write(format % args)

# Example I
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))