Created
October 23, 2015 15:38
-
-
Save Haylin-chama/12d71276f210daf67be2 to your computer and use it in GitHub Desktop.
Weviando con los flujos de redes
This file contains 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
#0. VALIDACIONES | |
def Validar(): | |
a=input("Valor: ") | |
if a.isdigit(): #Función para corroborar que una línea de caracteres corresponden exclusivamente a números | |
#Es una función bool de verdadero o falso | |
return int(a) | |
else: | |
print ("Ingrese un valor numérico.") | |
return Validar() | |
#Funcion que se llama a si misma en caso que no sea una linea | |
def Opcion(): | |
a=input("Respuesta: ") | |
if a=='S' or a=="s": | |
return 1 | |
if a=="N" or a=="n": | |
return 0 | |
else: | |
print ("Error. Ingrese S o N.") | |
Opcion() | |
#1. Funciones para crear matriz | |
def Agregar_Destino(G): | |
print("Desea agregar destinos?") | |
sn=Opcion() | |
if sn==0: | |
return G | |
if sn==1: | |
print ("Arista con el vertice ",len(G)+1,": ") | |
def GenerarMatriz(G): | |
print("Desea agregar vertices?") | |
sn=Opcion() | |
if sn==0: | |
return G | |
if sn==1: | |
print ("Vertice ",len(G)+1,": ") | |
agrdes=Opcion() | |
if agrdes==0: | |
G.extend([len(G)+1,[0,0],0]) | |
if agrdes==1: | |
G.extend([len(G)+1,Agregar_Destino(G)]) | |
return 0 | |
def CrearMatriz(G): | |
print ("Vertices: ") | |
v=Validar() | |
for origen in range(v): | |
Dest_pesos=[] | |
nodo=0 | |
print ("Pesos para el vertice",origen+1) | |
for destino in range(v): | |
print ("con la arista ",destino+1,": ") | |
pesos=Validar() | |
Dest_pesos.extend([destino,pesos]) | |
if pesos>0 and pesos<999999: | |
nodo=nodo+1 | |
Fila=[origen,Dest_pesos,nodo] | |
G.extend(Fila) | |
return G | |
#2. Funciones del flujo de redes | |
def obtCapacidad(G): | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment