{"id":425,"date":"2023-04-25T16:19:27","date_gmt":"2023-04-25T16:19:27","guid":{"rendered":"https:\/\/rodamoya.com\/?p=425"},"modified":"2023-05-03T08:06:48","modified_gmt":"2023-05-03T08:06:48","slug":"flight-searcher-simulator","status":"publish","type":"post","link":"https:\/\/rodamoya.com\/index.php\/2023\/04\/25\/flight-searcher-simulator\/","title":{"rendered":"Flight searcher simulator"},"content":{"rendered":"\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The next program is a project done for the AI subject in my university, in these projects we had to create a flight searcher, that return the optimal route between a two airports, a cording to the distance or price. In order to create this program we used the informed search and uninformed search, through the &#8220;A*&#8221; and Uniform cost search algorithms.<\/p>\n\n\n\n<p>The A* alghorism, use the information of the location of the airports, to &#8220;open\/search&#8221; the best rutes. Next we are going to see how the A* alghorims works.<\/p>\n\n\n\n<p>While the optimal route is not the final destination:<br>     -&gt; Search the destinatios of the origin.<br>     -&gt; For each destination:<br>          + Calculate the distance of each flight<br>          + Add the accumulated distance of the previus flights (except in the first, since there are no flights    previously made)<br>          + Add the distance betweeen the destination airport and the final destination passed by the user.<br>     Save in the Search_dictionary ( destination: distance)<br>     -&gt; Add the Search_dictionary to all the possibles rutes already serched in other iterations.<br>     -&gt; Select the destination with a lower distance to research the optimal route.<\/p>\n\n\n\n<p>However the Uniform cost search only search\/open the cheper rute wthout using the distance between airports. For this reson, this alghorism make more iterations, to arrive to the same solution. However, even making more iteration the proccesing time is lower, dur to calculating distances using logitud and latitud have is a hard task.<\/p>\n\n\n\n<p>The display the program was neccesary to create a UI, to be able to make the reasearch in a esasy way.<\/p>\n\n\n\n<div style=\"height:47px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">UI and Terminal:<\/h2>\n\n\n\n<div style=\"height:33px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/04\/Buscador.png\" alt=\"\" class=\"wp-image-429\" width=\"771\" height=\"459\" srcset=\"https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/04\/Buscador.png 726w, https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/04\/Buscador-300x178.png 300w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><figcaption class=\"wp-element-caption\">Tkinter interface<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/04\/Terminal.png\" alt=\"\" class=\"wp-image-430\" width=\"764\" height=\"665\"\/><figcaption class=\"wp-element-caption\">Code output<\/figcaption><\/figure><\/div>\n\n\n<div style=\"height:26px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nimport math\nimport time\nimport tkinter as tk\n\n# Llegir la informaci\u00f3 del excel:\ndf_V = pd.read_excel(\"Vols.xlsx\")\ndf_A = pd.read_excel(\"Aeroports_2.0.xlsx\")\n\n# CREAR DICIONARI_________________________________________________________________________________________\n# Optenir la informaci\u00f3 dels destins del df:\ndef destins(IATA, df_Vols):\n    \n    desti_1 = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"IATA_DESTI\"].iloc&#91;0]\n    \n    desti_2 = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"IATA_DESTI 2\"].iloc&#91;0]\n    \n    desti_3 = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"IATA_DESTI 3\"].iloc&#91;0]\n        \n    return(desti_1, desti_2, desti_3)\n\n# Obtenir preu del df:\ndef destins_preu(IATA, df_Vols):\n    \n    desti_1_Cost = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 1,PREU\"].iloc&#91;0]\n    \n    desti_2_Cost = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 2,PREU \"].iloc&#91;0]\n    \n    desti_3_Cost = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 3,PREU\"].iloc&#91;0]\n    \n    return(desti_1_Cost, desti_2_Cost, desti_3_Cost)\n\n# Obtenir distancia:\ndef destins_dist(IATA, df_Vols):\n    \n    desti_1_dist = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 1, DIST\"].iloc&#91;0]\n    \n    desti_2_dist = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 2,DIST\"].iloc&#91;0]\n    \n    desti_3_dist = df_Vols&#91;df_Vols&#91;\"IATA_ORIGEN\"]==IATA]&#91;\"COST 3,DIST\"].iloc&#91;0]\n    \n    return(desti_1_dist, desti_2_dist, desti_3_dist)\n\n\n# Crear el dicionar amb el que treballarem:\ndef create_dic(df_V):\n    # Crear un dicionari buit\n    dic_costos = {}\n    # Contar numero de aeoroports\n    total = df_V&#91;\"IATA_ORIGEN\"].count()\n    i = 0\n    # Loop que llegeix totes els aeoroports\n    while i &lt; total:\n        # Nom del aeorport origen:\n        name = df_V&#91;\"IATA_ORIGEN\"].iloc&#91;i]\n        \n        # Funcci\u00f3 que retorna els destins del aeorport origen\n        desti_1, desti_2, desti_3 = destins(name, df_V)\n        \n        # Funcci\u00f3 que retorna els preus dels destins des de l'aeorport origen\n        desti_1_Cost, desti_2_Cost, desti_3_Cost= destins_preu(name, df_V)\n        \n        # Funcci\u00f3 que retorna la distancia dels destins des de l'aeorport origen\n        desti_1_dist, desti_2_dist, desti_3_dist = destins_dist(name, df_V)\n        \n        # Ompli el dicionari amb la informaci\u00f3\n        dic_costos&#91;name] =  &#91;&#91;desti_1, desti_1_Cost, desti_1_dist], &#91;desti_2, desti_2_Cost, desti_2_dist], &#91;desti_3, desti_3_Cost, desti_3_dist]]\n    \n        i = i + 1\n    \n    # Retorna el dicionari\n    return dic_costos\n# HEULISTICA___________________________________________________________\n# Heulistica: EXPLICAR !!!\ndef heuristica(lon1,lon2, lat1 ,lat2  ):\n    \n    rad=math.pi\/180\n    dlat=lat2-lat1\n    dlon=lon2-lon1\n    R=6372.795477598\n    \n    a=(math.sin(rad*dlat\/2))**2 + math.cos(rad*lat1)*math.cos(rad*lat2)*(math.sin(rad*dlon\/2))**2\n    distancia=2*R*math.asin(math.sqrt(a))\n    \n    return distancia\n\n# Obtenir longitut i latitud d'un aeroport:\ndef longitud_i_latitud(IATA, df_Vols):    \n\n    latitud= df_Vols&#91;df_Vols&#91;\"CODI_IATA\"]==IATA]&#91;\"LATITUD\"].iloc&#91;0]\n    longitud = df_Vols&#91;df_Vols&#91;\"CODI_IATA\"]==IATA]&#91;\"LONGITUD\"].iloc&#91;0]\n    \n    return(latitud, longitud ) \n\n# obtenir la key amb el value de un diccionari:\ndef get_key(val, dict_resulsts):\n    for key, value in dict_resulsts.items():\n         if val == value:             \n            return key \n    return \"There is no such Key\"\n\n# AlGORISME DE A ESTRELLA:\n    \n# Obrir els nous origens:\ndef obrir_opcio_aestrella(origen,dic_costos, destino, recorido, cost_acumulado, opcio ):\n    \n    fin = False\n    orige_des = dic_costos&#91;origen]\n    \n    # lista distancia destins\n    list_dist_destins = &#91;]\n\n    #dictionaramb tots results:\n    dict_resulsts = {}\n    \n    \n    \n    list_recorido = str(recorido).split(\"'\")\n    #print(\"recorido:\", recorido, \"Lista : \", list_recorido)                    \n                        \n    \n    # bucle ficar distancia destins en una llista\n                    \n    for des in orige_des:\n        \n        name = des&#91;0]\n        \n        # que no passi pel mateix lloc                \n        if name in list_recorido:\n            pass\n        if name not in list_recorido:\n                    \n            cost_dest_taula = des&#91;opcio]\n\n            \n            latitud_Origen, longitud_Origen = longitud_i_latitud(name, df_A)\n            latitud_Destino, longitud_Destino = longitud_i_latitud(destino, df_A)\n            \n            \n            helistica = heuristica(longitud_Origen, longitud_Destino,  latitud_Origen, latitud_Destino)\n\n\n            #print(\"Calcul costdes + heul:\", cost_dest_taula ,\"+\", helistica )\n            \n            cost_dest = cost_dest_taula + cost_acumulado + helistica\n            print(\"Calcular a estrella per\",name,\"--&gt;\",  cost_dest_taula ,\"+\",cost_acumulado, \"+\", helistica, \"=\" ,cost_dest)\n            #print(\"Dsglos amb cost + acum :\", cost_dest_taula ,\"+\", cost_acumulado , \"=\", cost_dest)\n            \n\n\n            list_dist_destins.append(cost_dest)\n            name = des&#91;0]\n\n            recorido_optimo = recorido , name\n\n\n            dict_resulsts&#91;recorido_optimo] = cost_dest\n\n\n    \n    # agafar el valor minim y treure la direcci\u00f3\n    minimo  = min(list_dist_destins)\n    pos = list_dist_destins.index(minimo)\n    \n    name_des = dic_costos&#91;origen]&#91;pos]&#91;0]\n\n    \n    \n    return pos,name_des,minimo, dict_resulsts \n\n# Alghorime:\ndef A_ESTRELLA_(destino, origen, dic_costos, opcio):\n    \n\n    dict_save = {}\n    recorido = origen\n    df_redundancies = pd.DataFrame(columns = &#91;\"IATA\",\"COST\"])\n    add = 0\n    count = 0\n    count_Iteracions= 0\n    fin = False\n    dic_saved = {}\n    value_del = \"\"\n    \n    while fin != True:\n        \n        try:\n            del dic_saved&#91;value_del]\n\n        except: \n            \n            pass\n\n        count_Iteracions = count_Iteracions +1\n        print(\"Iteraci\u00f3:\", count_Iteracions)\n        pos, name_des ,minimo, dict_resulsts = obrir_opcio_aestrella(origen,dic_costos, destino, recorido, add, opcio  )       \n        \n\n    \n        \n        dic_saved.update(dict_resulsts)\n     \n        \n        \n        #Ha de ser despues de donar la llista final --&gt; DOnar llista final y  de la borar de la nova\n        value_min = min(list(dic_saved.values()))\n        value_del = get_key(value_min, dic_saved)  \n        \n        \n        \n        desti_min = str(str(value_del).split(\",\")&#91;-1]).split(\"'\")&#91;1]  \n\n        \n        \n\n        # canviar el minim de open per el minim de total       \n        latitud_Origen, longitud_Origen = longitud_i_latitud(desti_min, df_A)\n        latitud_Destino, longitud_Destino = longitud_i_latitud(destino, df_A)\n        helistica_restar = heuristica(longitud_Origen, longitud_Destino, latitud_Origen, latitud_Destino)\n        \n\n        value_add = value_min - helistica_restar\n        \n        \n        \n        print(\"Rutes possibles:\",dic_saved )\n        print(\"Ruta optima:\", value_del, \"km de la ruta\", value_add)\n        \n        \n        add = value_add \n    \n        \n        \n        # detectar el desti amb haulistica mes petita y converitlo e origen \n        origen = desti_min\n        \n        \n        recorido = value_del\n        \n        if desti_min == destino:\n            fin = True\n        \n        print(\"S'ha arribat a la soluci\u00f3 final ?\", fin)\n        print(\"\")    \n        \n        \n        \n        desti_final = str(value_del)\n        \n        \n    return dict_resulsts, dic_saved, count_Iteracions, value_min, desti_final\n\n# Obtenir el dicionari\ndic_costos = create_dic(df_V)\n\n# Alghorime A estrella eliminant redundancies:\n\ndef A_ESTRELLA_SENSE_REDUNDANCIES(destino, origen, dic_costos, opcio):\n    \n    # declarar variables:\n    dict_save = {}\n    recorido = origen\n    df_redundancies = pd.DataFrame(columns = &#91;\"IATA\",\"COST\"])\n    add = 0\n    count = 0\n    count_Iteracions= 0\n    fin = False\n    dic_saved = {}\n    value_del = \"\"\n    \n    while fin != True:\n        \n        try:\n            del dic_saved&#91;value_del]\n\n        except: \n            \n            pass\n\n        count_Iteracions = count_Iteracions + 1\n        print(\"Iteraci\u00f3:\", count_Iteracions)\n        \n        # Funci\u00f3 de obrir nou origen ruta:\n        pos, name_des ,minimo, dict_resulsts = obrir_opcio_aestrella(origen,dic_costos, destino, recorido, add, opcio  )       \n        \n\n        # No treballar amb el dicionary original:\n        dic_Saved_old = dic_saved\n      \n        \n        ## Eliminar redundancies:        \n        # Crear un df amb els les destins i el cost per mirar si es repeteixen i saber quin cost es inferior:\n        list_keys = list(dic_Saved_old.keys())      \n        \n        #Contador:\n        count = 0\n        \n        \n        for i in list_keys:    \n\n            last_aer= str(i).split(\"'\")&#91;-2]\n            cost = dic_saved&#91;i]\n\n            # An\u00f1adir nueva row el df\n            count = count + 1  \n            # entra el aeripuerto destino i su coste\n            df_redundancies.loc&#91;count] = pd.Series({'IATA': last_aer, 'COST': cost })\n\n        print(\"\")\n        print(\"DF amb els destins ja oberts i els km:\")\n        print(df_redundancies)\n        \n        # Comparar els resultats obtinguts amb els historics:\n        \n        \n        loopdict_resulsts = dict_resulsts\n        lista_nevos_destinos_redundantes = &#91;]\n        \n        for i in loopdict_resulsts:  \n            \n            \n            # Obtener lel ultimo destino\n            last_aer= str(i).split(\"'\")&#91;-2]\n            # Obtener el coste de dicho destino\n            cost = loopdict_resulsts&#91;i]\n            \n            \n            saved_destins = list(df_redundancies&#91;\"IATA\"])\n            \n            if last_aer in saved_destins:\n                cost_historic = df_redundancies&#91;df_redundancies&#91;\"IATA\"]== last_aer]&#91;\"COST\"].iloc&#91;0]\n\n                if cost_historic &gt; cost:\n                    #(\"Coste historic pitjor, delet del dictionari  i introduir el nou al df\")\n                    # delet del dic_saved el historic\n                    redundant = get_key(cost_historic, dic_saved)\n                    del dic_saved&#91;redundant]\n                    \n                    # Canviar el valor del df_re\n                    df_redundancies.loc&#91; df_redundancies&#91;\"IATA\"] == last_aer, \"COST\"] = cost                    \n                    \n                    \n                    \n                if cost_historic &lt; cost:\n                    #(\"Coste new pitjor, delet de la llsita de a\u00f1adir al dic_resultados\")\n                    # delet del dic_resulys\n                    lista_nevos_destinos_redundantes.append(i)\n                    \n                \n                \n                \n        \n    \n        # Eliminar els camins redundants de la llista de resultats\n        for red in lista_nevos_destinos_redundantes:\n            del dict_resulsts&#91;red]\n\n            \n            \n        dic_saved.update(dict_resulsts)\n        print(\"\")\n        print(\"Totes les rutes:\", dic_saved)\n        \n        #dic_saved.pop('uno')\n        \n        \n        #Ha de ser despues de donar la llista final --&gt; DOnar llista final y  de la borar de la nova\n        value_min = min(list(dic_saved.values()))\n        value_del = get_key(value_min, dic_saved) \n        \n        desti_min = str(str(value_del).split(\",\")&#91;-1]).split(\"'\")&#91;1]        \n        \n        \n        # canviar el minim de open per el minim de total       \n        latitud_Origen, longitud_Origen = longitud_i_latitud(desti_min, df_A)\n        latitud_Destino, longitud_Destino = longitud_i_latitud(destino, df_A)\n        helistica_restar = heuristica(longitud_Origen, longitud_Destino, latitud_Origen, latitud_Destino)\n        \n        value_add = value_min - helistica_restar\n        \n        \n        print(\"Ruta optima --&gt;\", value_del, \"km de la ruta optima --&gt;\", value_add)\n        \n        \n        add = value_add \n    \n        \n        \n        # detectar el desti amb haulistica mes petita y converitlo e origen \n        origen = desti_min\n        \n        #print(add, value_min)\n        recorido = value_del\n        \n        if desti_min == destino:\n            fin = True\n        \n        print(\"S'ha arribat a la soluci\u00f3 final ?\", fin)\n        print(\"\")\n        \n        \n        ruta_optima = str(value_del)\n        \n        \n    return dict_resulsts, dic_saved, count_Iteracions, value_min, ruta_optima\n\n# algorisme CCU_______________________________________________________________________________________________\n## Obrir nou origen del CCU\ndef obrir_opcio_2(origen, dic_costos, destino, recorido, cost_acumulado ):\n    \n    fin = False\n    orige_des = dic_costos&#91;origen]\n    \n    # lista distancia destins\n    list_dist_destins = &#91;]\n\n    #dictionaramb tots results:\n    dict_resulsts = {}\n    \n    # bucle ficar distancia destins en una llista\n    for des in orige_des:\n    \n        cost_dest = des&#91;2]\n        \n        cost_dest = cost_dest + cost_acumulado\n        print(\"Calcul obrir:\", cost_dest ,\"+\", cost_acumulado , \"=\", cost_dest)\n        \n        \n        list_dist_destins.append(cost_dest)\n        name = des&#91;0]\n                \n        recorido_optimo = recorido , name\n        \n    \n        dict_resulsts&#91;recorido_optimo] = cost_dest\n\n    \n    # agafar el valor minim y treure la direcci\u00f3\n    minimo  = min(list_dist_destins)\n    pos = list_dist_destins.index(minimo)\n    \n    name_des = dic_costos&#91;origen]&#91;pos]&#91;0]\n\n    \n    \n    return pos,name_des,minimo, dict_resulsts \n\n#alghorimse:\ndef A_CCU_(destino, origen, dic_costos):\n\n    dict_save = {}\n    recorido = origen\n    add = 0\n    count = 0\n    fin = False\n    dic_saved = {}\n    value_del = \"\"\n    while fin != True:\n        \n        try:\n            del dic_saved&#91;value_del]\n\n        except: \n            \n            pass\n\n        count = count +1\n        print(\"Iteraci\u00f3:\", count)\n        pos, name_des ,minimo, dict_resulsts = obrir_opcio_2(origen,dic_costos, destino, recorido, add  )       \n        \n        \n        opened = list(list(dict_resulsts.keys())&#91;pos])\n    \n        \n        \n        \n        dic_saved.update(dict_resulsts)\n        \n        \n        \n        #Ha de ser despues de donar la llista final --&gt; DOnar llista final y  de la borar de la nova\n        value_min = min(list(dic_saved.values()))\n        value_del = get_key(value_min, dic_saved)        \n       \n        \n        desti_min = str(str(value_del).split(\",\")&#91;-1]).split(\"'\")&#91;1]\n        \n        \n        \n        \n        \n        \n        \n        \n        print(\"\")\n        print(\"Todas las rutas  --&gt; \", dic_saved)\n        \n        print(\"Ruta optima --&gt;\", value_del, \"Km --&gt;\", value_min)\n        \n        # canviar el minim de open per el minim de total\n        add = value_min \n    \n        \n        #print( \"Resultado del abierto:\", dict_resulsts, fin)\n        \n        # detectar el desti amb haulistica mes petita y converitlo e origen \n        origen = desti_min\n        \n        \n        recorido = value_del\n        \n        if desti_min == destino:\n            fin = True\n        \n        print(fin)\n        print(\"\")\n        \n        ruta_optima = str(value_del)\n        \n        \n        \n    return dict_resulsts, dic_saved, count, value_min, ruta_optima\n\n#OBTENIR INFORMACI\u00d3___________________________________________________________________________\n# Converir ruta a text i numero de escales:\ndef convert_ruta_to_text(ruta_optima):\n    # Clean la tubla de ruta final:\n    ruta_optima = ruta_optima.replace(\"(\", \"\")\n    ruta_optima = ruta_optima.replace(\"'\", \"\")\n    ruta_optima = ruta_optima.replace(\")\", \"\")\n    ruta_optima = ruta_optima.replace(\" \", \"\")\n    # Obtenir llista amb IATA dels aeropots\n    lista_ruta = ruta_optima.split(\",\")\n    \n    numero_numero_escales = (len(lista_ruta)) - 1\n    llistas_aeroports = \"\"\n    \n    # Converir IATA a llistat dels noms \n    for i in lista_ruta:\n        \n        aero = get_Aerport_Name_from_IATA(i)\n    \n        llistas_aeroports = llistas_aeroports + aero + \" --&gt; \"\n    \n    llistas_aeroports = llistas_aeroports&#91;:-5]\n    \n    return llistas_aeroports, numero_numero_escales\n\n\n# Obtenir el nom dels aeroports per el nom de la ciutat\ndef get_Aerport_Name(city):      \n    name_aerport = df_A&#91;df_A&#91;\"CIUTAT\"]== city]&#91;\"NOM\"].iloc&#91;0]    \n    \n    return name_aerport   \n\n# Obtenir el Codi IATA dels aeroports per el nom de la ciutat\ndef get_Aerport_IATA(city):       \n    iata_aerport = df_A&#91;df_A&#91;\"CIUTAT\"]== city]&#91;\"CODI_IATA\"].iloc&#91;0]   \n    \n    return iata_aerport  \n\n# Obtenir el nom dels aeroports per el IATA de la aeroport\ndef get_Aerport_Name_from_IATA(IATA):    \n    name_aerport = df_A&#91;df_A&#91;\"CODI_IATA\"]== IATA]&#91;\"NOM\"].iloc&#91;0]\n    \n    \n    return name_aerport  \n\n# Crear ventana\nventana = tk.Tk()\nventana.attributes('-fullscreen', True)\n\n# Declarar Variables:\nalghorimse_selecionat = tk.StringVar()\norigen_selecionat = tk.StringVar()\ndesti_selecionat = tk.StringVar()\nnumero_iteracions = tk.StringVar()\nruta_optima_alhgorisme = tk.StringVar()\nn_escales = tk.StringVar()\ntext_ruta_de_aeroports = tk.StringVar()\nname_aerport = tk.StringVar()\ncost_ruta = tk.StringVar()\n\n\n\ndef calcular():\n    \n    \n    algorisme = var.get()\n    origen = var_origen.get()\n    desti = var_desti.get()\n    \n    # Obtener codi IATA\n    origen_IATA = get_Aerport_IATA(origen)\n    desti_IATA = get_Aerport_IATA(desti)\n    \n    \n    # Executar alghorisme\n    if algorisme == \"A estrella\":        \n        dict_resulsts, dic_saved, count_iteracions, value_min, ruta_optima = A_ESTRELLA_(desti_IATA, origen_IATA, dic_costos, 2)\n        \n        \n    if algorisme == \"CCU\":\n        dict_resulsts, dic_saved, count_iteracions, value_min, ruta_optima = A_CCU_(desti_IATA, origen_IATA, dic_costos)\n        \n    \n    if algorisme == \"A estrella eliminant camins redudants\":\n        dict_resulsts, dic_saved, count_iteracions, value_min, ruta_optima = A_ESTRELLA_SENSE_REDUNDANCIES(desti_IATA, origen_IATA, dic_costos, 2)\n    \n    \n    # Convertir la tubla en text:\n    ruta_de_aeroport_text, num_escales = convert_ruta_to_text(ruta_optima)\n     \n    \n    \n    \n    \n    return alghorimse_selecionat.set(algorisme), ruta_optima_alhgorisme.set(ruta_optima), text_ruta_de_aeroports.set(ruta_de_aeroport_text), numero_iteracions.set(count_iteracions), n_escales.set(num_escales), cost_ruta.set(value_min)                      \n\n\n\n\n# Titulo Ventana\ntitulo = tk.Label(ventana, text = \"Projecte IA Group 2\", bg=\"ivory3\")\ntitulo.pack(padx = 5, pady = 10, ipadx = 5, fill = tk.X )\n# Titulo:\ntext_Titul = tk.Label(ventana , text = \"Cercador de vols\" )\ntext_Titul.config(font=(\"Courier\", 44))\ntext_Titul.pack()\ntext_Titul.place( x = 250, y = 100, height=44 )\n\n\n#__________________________________________________________________________________________________________________________\n#Seleccionar algorismo\n# Texto:\ntext_select_algh = tk.Label(ventana , text = \"Seleciona el alghorismo deseado:\" )\ntext_select_algh.pack()\ntext_select_algh.place( x = 50, y = 200, height=20 )\n\n#Desplegable\nvar = tk.StringVar(ventana)\nvar.set('A estrella')\nopciones = &#91;'A estrella', 'CCU', 'A estrella eliminant camins redudants' ]\nopcion = tk.OptionMenu(ventana, var, *opciones)\nopcion.config ( width = 50)\nopcion.pack( ) \nopcion.place( x = 300, y = 200, height=20 )\n\n\n#__________________________________________________________________________________________________________________________\n# Obtenir Origen i dest\u00ed\n# Origen:\n#________________\n# Texto:\ntext_select_Origen = tk.Label(ventana , text = \"Seleciona el origen:\" )\ntext_select_Origen.pack()\ntext_select_Origen.place( x = 50, y = 250, height=20 )\n\n# Desplegable\nvar_origen = tk.StringVar(ventana)\nvar_origen.set('Barcelona')\nopciones_Origen = list(df_A&#91;\"CIUTAT\"])\nopcion_origen = tk.OptionMenu(ventana, var_origen, *opciones_Origen)\nopcion_origen.config ( width = 30)\nopcion_origen.pack( ) \nopcion_origen.place( x = 300, y = 250, height=20 )\n\n\n# Destino:\n#________________\n# Texto:\ntext_select_Desti = tk.Label(ventana , text = \"Seleciona el destino:\" )\ntext_select_Desti.pack()\ntext_select_Desti.place( x = 50, y = 300, height=20 )\n\n# Desplegable\nvar_desti = tk.StringVar(ventana)\nvar_desti.set('Hong Kong')\nopciones_desti = tk.OptionMenu(ventana, var_desti, *opciones_Origen)\nopciones_desti.config ( width = 30)\nopciones_desti.pack( ) \nopciones_desti.place( x = 300, y = 300, height=20 )\n\n\n\n\n# Aeoroport seleccionado:\n\n\n\n#color = tk.Label(ventana, bg = \"ivory3\", textvariable = var, padx = 5, pady = 5 , width = 50 )\n\n\n\n\nboton = tk.Button(ventana, text = \"Calcular\", fg = \"black\", command = calcular )\nboton.pack()\nboton.place( x = 300, y = 350, height=20 )\n\n##LABEL:\ntext_ruta_1 = tk.Label(ventana, text = \"Kilometros de la ruta:\" )\ntext_ruta_1.pack( ) \ntext_ruta_1.place( x = 50, y = 450, height=20 )\n\n# Resultst:\n##Ruta:\n###Tubla:\nruta_tub = tk.Label(ventana,  textvariable = cost_ruta )\nruta_tub.pack( ) \nruta_tub.place( x = 250, y = 450, height=20 )\n\n### Ruta en text:\ntext_ruta_2 = tk.Label(ventana,  text = \"Aquestsa \u00e9s la ruta de aeroport: \" )\ntext_ruta_2.pack( ) \ntext_ruta_2.place( x = 50, y = 500, height=20 )\n\nruta_text_ = tk.Label(ventana,  textvariable = text_ruta_de_aeroports )\nruta_text_.pack( ) \nruta_text_.place( x = 250, y = 500, height=20 )\n\n### Numero de escales:\ntext_ruta_2 = tk.Label(ventana,  text = \"Numero d'escales: \" )\ntext_ruta_2.pack( ) \ntext_ruta_2.place( x = 50, y = 550, height=20 )\n\nruta_text_ = tk.Label(ventana,  textvariable = n_escales )\nruta_text_.pack( ) \nruta_text_.place( x = 250, y = 550, height=20 )\n\n\n### Numero de iteracions:\ntext_ruta_2 = tk.Label(ventana,  text = \"Numero d'iteracionst: \" )\ntext_ruta_2.pack( ) \ntext_ruta_2.place( x = 50, y = 600, height=20 )\n\nruta_text_ = tk.Label(ventana,  textvariable = numero_iteracions )\nruta_text_.pack( ) \nruta_text_.place( x = 250, y = 600, height=20 )\n\n\n\n\n\n\n\n\n\n\nventana.mainloop()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The next program is a project done for the AI subject in my university, in these projects we had to create a flight searcher, that return the optimal route between a two airports, a cording to the distance or price. In order to create this program we used the informed search and uninformed search, through &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rodamoya.com\/index.php\/2023\/04\/25\/flight-searcher-simulator\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> &#8220;Flight searcher simulator&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/425"}],"collection":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":5,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/425\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}