-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,9 @@ def select(L, solu): | |
| ret = None | ||
| for sub in L: | ||
| #print (sub) | ||
| if not(sub in solu): | ||
| if len(sub) > max_inter: | ||
| max_inter = len(sub) | ||
| ret = sub | ||
| if sub not in solu and len(sub) > max_inter: | ||
| max_inter = len(sub) | ||
| ret = sub | ||
| return ret | ||
|
|
||
|
|
||
|
|
@@ -16,40 +15,40 @@ def select(L, solu): | |
| if __name__ == "__main__": | ||
| #Definicao da demanda | ||
| k = 2 | ||
|
|
||
| #Definicao do grafo | ||
| #Tamanho dos conjuntos | ||
| #L = subconjuntos | ||
| #R = elementos | ||
| nL = 4 | ||
| nR = 5 | ||
|
|
||
| #Elementos | ||
| e1 = "e1" | ||
| e2 = "e2" | ||
| e3 = "e3" | ||
| e4 = "e4" | ||
| e5 = "e5" | ||
|
|
||
| #subconjuntos | ||
| s1 = [e2, e3] | ||
| s2 = [e1, e2, e3] | ||
| s3 = [e1, e2, e3, e4, e5] | ||
| s4 = [e2, e3, e5] | ||
|
|
||
| #Grafo | ||
| L = [s1, s2, s3, s4] | ||
| R = [e1, e2, e3, e4, e5] | ||
|
|
||
| #print (L) | ||
| #Heuristica | ||
| E = R | ||
| solucao = [] | ||
|
|
||
| while len(solucao) < k: | ||
| selected = select(L, solucao) | ||
| E = [selected] | ||
| solucao += [selected] | ||
|
|
||
|
Comment on lines
-19
to
+52
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the following improvement in Lines |
||
| print (solucao) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,7 @@ def biri(lastBiri): | |
| if lastBiri <= 1: | ||
| lastBiri = 2 | ||
| biriPorcent = randint(1, 2* (lastBiri)) | ||
| if lastBiri % biriPorcent == 0: | ||
| return (True, biriPorcent) | ||
| else: | ||
| return (False, 0) | ||
| return (True, biriPorcent) if lastBiri % biriPorcent == 0 else (False, 0) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def select(L, solu, biribi, rett = None) | ||
| biriInd = 0; | ||
|
|
@@ -32,18 +29,10 @@ def select(L, solu, biribi, rett = None) | |
| return (ret, biriRet) | ||
|
|
||
| def interc(A, B): | ||
| retu = 0 | ||
| for ele in A: | ||
| if ele in B: | ||
| retu += 1 | ||
| return retu | ||
| return sum(ele in B for ele in A) | ||
|
Comment on lines
-35
to
+32
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def intercc(A,B): | ||
| ret = [] | ||
| for ele in A: | ||
| if ele in B: | ||
| ret += [ele] | ||
| return ret | ||
| return [ele for ele in A if ele in B] | ||
|
Comment on lines
-42
to
+35
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def first(L1): | ||
| max = 0 | ||
|
|
@@ -57,92 +46,85 @@ def first(L1): | |
| def execute(xazam): | ||
| initialBiri = 2 | ||
| biribiri = initialBiri | ||
|
|
||
| resposta = ['1','3','4'] | ||
|
|
||
| grafo = open('instancias/especiais/baixa/20 20 baixa.txt', 'r') | ||
| demanda = open('instancias/especiais/baixa/demanda.txt', 'r') | ||
| #Definicao da demanda | ||
| k = int(demanda.read()) | ||
|
|
||
| demanda.close() | ||
| #Definicao do grafo | ||
| #Tamanho dos conjuntos | ||
| #L = subconjuntos | ||
| #R = elementos | ||
| vertices = grafo.readlines() | ||
| nL = int((vertices[0].split())[0]) | ||
| nR = int((vertices[0].split())[1]) | ||
|
|
||
| #print (vertices) | ||
|
|
||
| #print ("k = " +str(k)) | ||
| #print ("L = " +str(nL)) | ||
| #print ("R = " +str(nR)) | ||
|
|
||
| L = [] | ||
| R = [] | ||
| for i in range(1,nL+1): | ||
| S = [] | ||
| R += [i] | ||
| for j in range(0,nR): | ||
| if int((vertices[i].split())[j]) == 1: | ||
| S += [j+1] | ||
| #[int((vertices[i].split())[j]) == 1:] | ||
| L += [S] | ||
| #print (S) | ||
|
|
||
| grafo.close() | ||
|
|
||
|
|
||
| with open('instancias/especiais/baixa/20 20 baixa.txt', 'r') as grafo: | ||
| with open('instancias/especiais/baixa/demanda.txt', 'r') as demanda: | ||
| #Definicao da demanda | ||
| k = int(demanda.read()) | ||
|
|
||
| #Definicao do grafo | ||
| #Tamanho dos conjuntos | ||
| #L = subconjuntos | ||
| #R = elementos | ||
| vertices = grafo.readlines() | ||
| nL = int((vertices[0].split())[0]) | ||
| nR = int((vertices[0].split())[1]) | ||
|
|
||
| #print (vertices) | ||
|
|
||
| #print ("k = " +str(k)) | ||
| #print ("L = " +str(nL)) | ||
| #print ("R = " +str(nR)) | ||
|
|
||
| L = [] | ||
| R = [] | ||
| for i in range(1,nL+1): | ||
| R += [i] | ||
| S = [j+1 for j in range(nR) if int((vertices[i].split())[j]) == 1] | ||
| L += [S] | ||
| #print (S) | ||
|
|
||
| #print ("R = " +str(R)) | ||
| #print ("L = " +str(L)) | ||
|
|
||
| #Heuristica | ||
| E = R | ||
| solucao = [] | ||
| E = first(L) | ||
| solucao += [first(L)] | ||
|
|
||
| #print (solucao) | ||
| #print (E) | ||
|
|
||
| while len(solucao) < k: | ||
| selected = select(L, solucao, biribiri,E) | ||
| E = selected[0] | ||
| solucao += [selected[0]] | ||
| biribiri = selected[1] | ||
| inter = intercc(solucao[0], solucao[1]) | ||
|
|
||
| inter = intercc(solucao[0], solucao[1]) | ||
| if k > 2: | ||
| for u in range(2,k): | ||
| inter = intercc(inter, solucao[u]) | ||
|
|
||
| #print (resposta) | ||
| print (len(inter)) | ||
| #print (inter) | ||
| #print (solucao) | ||
|
|
||
|
Comment on lines
-60
to
+106
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| return (len(inter) == xazam, len(inter)) | ||
|
|
||
|
|
||
| # Main | ||
| if __name__ == "__main__": | ||
| resposta = 3 | ||
| acertos = 0 | ||
| for i in range(0,100): | ||
|
|
||
| for _ in range(100): | ||
| max = 0 | ||
| teste = execute(resposta) | ||
| if teste[0]: | ||
| acertos += 1 | ||
| if teste[1] > max: | ||
| max = teste[1] | ||
|
|
||
|
|
||
|
|
||
| print ("------acertos-----") | ||
| print (acertos) | ||
|
|
||
|
Comment on lines
-132
to
+127
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| print ("-----mais proximo----") | ||
| print (teste[1]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
selectrefactored with the following changes:merge-nested-ifs)de-morgan)