Exemple #1
0
def set_problema() -> PMD:
    while True:
        tipo = input(
            '¿Se trata de un problema de minimización o maximización? (min/max): '
        )
        if not (tipo.lower() == 'min' or tipo.lower() == 'max'):
            print('Ingrese una opción válida...')
            continue
        break
    print('Por favor ingrese los datos del PMD: ')
    m = get_param('m')
    k = get_param('k')
    return PMD(m, k, tipo=tipo)
 def __init__(self,
              m: int,
              k: int,
              matrices_decision: Dict = None,
              tipo: str = 'min'):
     super().__init__(m, k, matrices_decision, tipo)
     self.matriz_de_coeficientes = []
     self.variables = [{
         'name': f'V{i}',
         'value': 0
     } for i in range(0, self.m + 1)]
     self.get_costos()
     self.politica = []
     self.matriz_politica = None
     self.alpha = get_alpha()
     self.epsilon = get_param('epsilon (error tolerado)', 'float')
     self.n = get_param('n (número de iteraciones)')
Exemple #3
0
 def print_ruta(self):
     while True:
         j = get_param('j', 1, self.dim) - 1
         if j == self.nodo_inicial:
             print('*** No es necesario calcular la ruta más corta al nodo inicial. ***')
         else:
             print(f'La ruta más corta entre {self.nodo_inicial + 1} y {j + 1} pesa {self.distancias[j]} y es: ')
             print(self.get_ruta(j))
         if not confirmacion('¿Desea calcular otra ruta?'):
             break
Exemple #4
0
 def switcher(self, opc):
     if opc is 1:
         print('La matriz del problema original es:')
         print_m(self.matriz_original, 1000)
     elif opc is 2:
         print('La matriz de adyacencia con los pesos calculados es:')
         print_m(self.matriz_pesos, 1000)
     elif opc is 3:
         print('La matriz de de las rutas es:')
         print_m(self.matriz_rutas)
     elif opc is 4:
         while True:
             i = get_param('i', 1, self.dim) - 1
             j = get_param('j', 1, self.dim) - 1
             print(
                 f'La ruta más corta entre {i + 1} y {j + 1} pesa {self.matriz_pesos[i][j]} y es: '
             )
             print(self.calcular_ruta(i, j))
             if not confirmacion('¿Desea calcular otra ruta?'):
                 break
Exemple #5
0
 def menu(self):
     clear_screen()
     self.nodo_inicial = get_param('el nodo inicial', 1, self.dim) - 1
     self.iniciar_algoritmo()
     while True:
         clear_screen()
         opc = self.get_opc()
         if opc == 4:
             print('Saliendo del método...')
             break
         self.switcher(opc)
         input('\nPulse enter para continuar...')
Exemple #6
0
def ingresar_ppl_manualmente() -> Tuple:
    while True:
        num_var = check_int(input('Ingrese el número de variables: '))
        if num_var is not None and num_var > 0:
            break
        else:
            print('Ingrese un número entero mayor a 0...')
    z, tipo_ppl, binario = get_z_ppl(num_var)
    print('Sea n el número de restricciones...')
    n = get_param('n', 1)
    restricciones, lado_derecho = get_restricciones_ppl(n, num_var)
    return z, tipo_ppl, restricciones, lado_derecho, binario
Exemple #7
0
 def reiniciar_algoritmo(self):
     self.anterior = [None] * self.dim
     self.visitados = [False] * self.dim
     self.nodos_pendientes = PriorityQueue()
     self.nodo_inicial = get_param('el nuevo nodo inicial', 1, self.dim) - 1
     self.iniciar_algoritmo()