def BlockedMatrix(n,m): res = np.zeros((n, n)) cluster = [[] for x in range(m)] for i in range(n): r = randint(0, m-1) cluster[r].append(i) print cluster for j in range(m): for k in range(len(cluster[j])): local_sum = 0 row = cluster[j][k] for l in range (len(cluster[j])): col = cluster[j][l] if(l!=k): res[row][col]=randint(1, 3) local_sum = local_sum + res[row][col] res[row][row] = -local_sum print res plotGraph(res, "orignal") for c1 in range(m): for c2 in range(m): if c1 != c2 and len(cluster[c1])>0 and len(cluster[c2]) > 0: row = cluster[c1][randint(0, len(cluster[c1])-1)] col = cluster[c2][randint(0, len(cluster[c2])-1)] res[row][col] = 1 res[row][row] = res[row][row] - res[row][col] print (row, col) return res
def exit_Drive(self, DATA, num): DATA.FinishDrive = DATA.getTime() DATA.print2file() print "Finished generating log.txt" if (not (DATA.MyPathLst==[])): plotGraph(DATA) self._result.success = num self._result.plan = "finished driving car" self._result.description = "finished driving car"
y = 0 for f in c['flores']: x += f['x'] y += f['y'] x = x / n y = y / n if (not compare(x, c['x']) or not compare(y, c['y'])): m = 1 c['x'] = x c['y'] = y return m for t in list(range(3)): flores = [] lerFlores() centroids = getCentroids(t + 1) mudou = 1 numero = 1 while (mudou): calculaDistFlorCentroid() acharMelhorCentroid() mudou = recalcularCentroid() numero += 1 import plotGraph as plot plot.plotGraph(centroids)
endtime = duration * (1.0/ fraction) - duration printString = str("\rextracted %9d timestamps [%s] ETA = %s" %(counter,"|"*int(fraction*20.0)+"\\|/-"[counter%4]+"-"*(19-int(fraction*20.0)), eta(endtime))) print printString, sys.stdout.flush() counter+=1 # progressbar end plotrb = [] plotwb = [] for key in sorted(rbSum.keys()): plotrb.append(rbSum[key]) for key in sorted(wbSum.keys()): plotwb.append(wbSum[key]) #------------------------------------------------------------------------------ time_end = time.time() print "end with no errors in: " + str(time_end - time_start) #----------------------------------------------------------------------------- list_of_list = [] list_of_list.append(sorted(rbSum.keys())) list_of_list.append(plotrb) list_of_list.append(sorted(wbSum.keys())) list_of_list.append(plotwb) plotGraph.plotGraph(list_of_list, 'ich bin ein Test!')
def print_job(self, job): check_job = self.c.execute(''' select * from jobs where id = ? ''', (job,)) if not check_job: print 'No such job: ', job sys.exit(0) sum_nid = db.get_sum_nids_to_job(job) if sum_nid: jobid = job db.c.execute(''' select jobs.jobid, users.username from jobs, users where jobs.id = ? and users.id = jobs.owner''', (jobid,)) job_info = db.c.fetchone() title = 'Job_' + str(job_info[0]) + '__Owner_' + str(job_info[1]) List_of_lists = [] read_sum = [] write_sum = [] io_sum = [] for nid in sum_nid: #(start, end, timeMapRB, timeMapWB, timeMapRIO, timeMapWIO, nidList) start = nid[0] end = nid[1] readDic = nid[2] writeDic = nid[3] rioDic = nid[4] wioDic = nid[5] #print 'dic keys =',sorted(rioDic.keys()) == sorted(writeDic.keys()) readY = [] writeY = [] ioread = [] iowrite = [] writeX = sorted(writeDic.keys()) readX = sorted(readDic.keys()) for timeStamp in readX: readY.append(float(-readDic[timeStamp]) / (60 * 1000000)) writeY.append(float(writeDic[timeStamp]) / (60 * 1000000)) read_sum.append(readDic[timeStamp]) write_sum.append(writeDic[timeStamp]) io_sum.append(rioDic[timeStamp] + wioDic[timeStamp]) ioread.append(-rioDic[timeStamp]) iowrite.append(wioDic[timeStamp]) if readX and readY and writeY and writeX: List_of_lists.append(readX) List_of_lists.append(readY) List_of_lists.append(writeX) List_of_lists.append(writeY) print 'Plot: ', title write_sum_b = sum(write_sum) read_sum_b = sum(read_sum) io_sum_b = sum(io_sum) query = ''' UPDATE jobs SET r_sum = ?, w_sum = ?, reqs_sum = ? where jobs.id = ? ''' self.c.execute(query, (read_sum_b, write_sum_b, io_sum_b, job)) plotGraph(List_of_lists, title)
cluster[r].append(i) print cluster for j in range(m): for k in range(len(cluster[j])): local_sum = 0 row = cluster[j][k] for l in range (len(cluster[j])): col = cluster[j][l] if(l!=k): res[row][col]=randint(1, 3) local_sum = local_sum + res[row][col] res[row][row] = -local_sum print res plotGraph(res, "orignal") for c1 in range(m): for c2 in range(m): if c1 != c2 and len(cluster[c1])>0 and len(cluster[c2]) > 0: row = cluster[c1][randint(0, len(cluster[c1])-1)] col = cluster[c2][randint(0, len(cluster[c2])-1)] res[row][col] = 1 res[row][row] = res[row][row] - res[row][col] print (row, col) return res '''__main()''' if __name__ == "__main__": n = 100 m = 4 Q = BlockedMatrix(n, m) plotGraph(Q, "general")
def stop(Q, i): if i % 5 == 4: diff = np.max(Q**2 - Q) - np.min(Q**2 - Q) if diff == 0: return True return False def getCluster(Q): cluster = [] n = Q.shape[0] visited = [False] * n i = 0; while(i < n): if visited[i] is True: i = i + 1 else: temp, = np.where(Q[i,:] > 0) temp = temp.tolist() for j in temp: visited[j] = True cluster.append(temp) i = i + 1 return cluster if __name__ == "__main__": Q = BlockedMatrix(20,3) Q[0][2] = 1 plotGraph(Q, "MCL_Graph") print MCL(Q)
##################################################### from MultiLevel import MultiLevel from BlockedMatrix import BlockedMatrix import time import sys import numpy as np from plotGraph import plotGraph from GaussSeidel import GaussSeidel # CompareStragies is used to compare the performance of basic grouping strategy # and the MCL clustering strategy. n = int(sys.argv[1]) m = int(sys.argv[2]) Q = BlockedMatrix(n, m) plotGraph(Q, "blockmatrix") P = np.transpose(Q) # MCL start = time.time() pi, iterations = MultiLevel(P, strategy = 3) end = time.time() print "Number of Iterations: ", iterations print "Number of States: ", n print "Time Elapsed: ", end-start, " seconds" # Basic strategy start = time.time() pi_1, iterations_1 = MultiLevel(P, strategy = 1) end = time.time() print "Number of Iterations: ", iterations_1 print "Number of States: ", n print "Time Elapsed: ", end-start, " seconds"