Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions labs/01/graph.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
digraph G {
rankdir=LR
node [shape=circle]
0 -> 1
0 -> 0
1 -> 1
0 -> 3
3 -> 0
3 -> 3
2 -> 2
1 -> 0
}
79 changes: 79 additions & 0 deletions labs/01/graphviz.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 75 additions & 23 deletions labs/01/relation_analyser.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,88 @@
import graphviz # https://graphviz.readthedocs.io/en/stable/index.html
import graphviz

def analyze(val):
"""
Here goes your code to do the analysis
1. Reflexive: aRa for all a in X,
2. Symmetric: aRb implies bRa for all a,b in X
3. Transitive: aRb and bRc imply aRc for all a,b,c in X,
"""
Reflexive = False
Symmetric = False
Transitive = False

return Reflexive,Symmetric,Transitive

def plot():
"""
Here goes your code to do the plot of the set
"""
g = graphviz.Digraph('G', filename='hello.gv')
g.edge('Hello', 'World')
g.view()
"""
Here goes your code to do the analysis
1. Reflexive: aRa for all a in X,
2. Symmetric: aRb implies bRa for all a,b in X
3. Transitive: aRb and bRc imply aRc for all a,b,c in X,
"""

Reflexive = False
Symmetric = False
Transitive = False
##PRIMERO REALIZAMOS EL ANALISIS DE REFLEXIVO
##OBTENEMOS EL ALFABETO
value = ""
alfabeto = []
for i in range(len(val)):
value = list(val)[i]
#print (value)
for j in range(len(value)):
#print (value[j])
while j < len(value):
if value[j] not in alfabeto:
alfabeto.append(value[j])
j = j+1
#print("alfabeto: ", alfabeto)
##AHORA COMPROBAREMOS QUE TODOS LOS SIMBOLOS TENGAN REFLEXION
cont = len(alfabeto)
for x in val:
if x[0] == x[1]:
cont = cont - 1
if cont == 0:
Reflexive = True

##ANALISIS SIMETRICO
cont= len(val)
for x in val:
index0 = x[0]
index1 = x[1]
for y in val:
if y[0] == index1 and y[1] == index0:
#print ("Cumple simetria", index1, "," , index0)
cont = cont - 1
if cont == 0:
Symmetric = True

##ANALISIS TRANSITIVO
for i in val:
if i[0] != i[1]:
for j in val:
if (j[0] == i[1] and j[1] != i[0] and j[0] != j[1]):
for k in val:
if k[0] == i[0] and k[1] == j[1]:
#print ("Cumple transitividad", i[0], "," , i[1], "," , j[1])
Transitive = True


return Reflexive,Symmetric,Transitive

def plot(val):
"""
Here goes your code to do the plot of the set
"""
g = graphviz.Digraph('G', filename='graph.log')
g.attr(rankdir='LR')
g.attr('node',shape='circle')

for i in val:
g.edge(str(i[0]),str(i[1]))

g.view()


def main():
print("Hello World analyzing input!")
val = input("Enter your set: ")
print(val)
#val = input("Enter your set: ")
val = { (0,0), (0,1), (0,3), (1,0), (1,1), (2,2), (3,0), (3,3) }

Reflexive,Symmetric,Transitive = analyze(val)
print(f"\
1. Reflexive: {Reflexive} \
2. Symmetric: {Symmetric} \
3. Transitive: {Transitive}")
plot()
plot(val)

if __name__ == "__main__":
main()