Sourcery refactored master branch#2
Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
Open
Conversation
Comment on lines
-6
to
+8
| 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 |
Author
There was a problem hiding this comment.
Function select refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs) - Simplify logical expression using De Morgan identities (
de-morgan)
Comment on lines
-19
to
+52
|
|
||
| #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] | ||
|
|
Author
There was a problem hiding this comment.
Found the following improvement in Lines 19-53:
| 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.
Function biri refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
Comment on lines
-35
to
+32
| retu = 0 | ||
| for ele in A: | ||
| if ele in B: | ||
| retu += 1 | ||
| return retu | ||
| return sum(ele in B for ele in A) |
Author
There was a problem hiding this comment.
Function interc refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast) - Simplify constant sum() call (
simplify-constant-sum)
Comment on lines
-42
to
+35
| ret = [] | ||
| for ele in A: | ||
| if ele in B: | ||
| ret += [ele] | ||
| return ret | ||
| return [ele for ele in A if ele in B] |
Author
There was a problem hiding this comment.
Function intercc refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
Comment on lines
-60
to
+106
|
|
||
| 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) | ||
|
|
Author
There was a problem hiding this comment.
Function execute refactored with the following changes:
- Use
withwhen opening file to ensure closure [×2] (ensure-file-closed) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace range(0, x) with range(x) (
remove-zero-from-range) - Convert for loop into list comprehension (
list-comprehension)
This removes the following comments ( why? ):
#[int((vertices[i].split())[j]) == 1:]
Comment on lines
-132
to
+127
| 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) | ||
|
|
Author
There was a problem hiding this comment.
Lines 132-145 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Replace range(0, x) with range(x) (
remove-zero-from-range)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!