Skip to content

Sourcery refactored master branch#2

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#2
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Nov 30, 2022

Branch master refactored 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from rahelmartim November 30, 2022 19:59
Comment thread biri.py
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function select refactored with the following changes:

Comment thread biri.py
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]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the following improvement in Lines 19-53:

Comment thread biriBIRI.py
return (True, biriPorcent)
else:
return (False, 0)
return (True, biriPorcent) if lastBiri % biriPorcent == 0 else (False, 0)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function biri refactored with the following changes:

Comment thread biriBIRI.py
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function interc refactored with the following changes:

Comment thread biriBIRI.py
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]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function intercc refactored with the following changes:

Comment thread biriBIRI.py
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function execute refactored with the following changes:

This removes the following comments ( why? ):

#[int((vertices[i].split())[j]) == 1:]

Comment thread biriBIRI.py
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 132-145 refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants