<jupyter_start><jupyter_text>Ejercicio 2 - AscensorEn un edificio existen tres ascensores que funcionan de manera simultanea. Se quiere crear un sistema que para cada  llamada realizada por cualquier usuario en cualquier piso asigne a cada ascensor un nivel de prioridad dependiendo de el estado en el que se encuentre y seleccione a aquel con mayor prioridad a la respuesta de dicho llamado.Los elementos a tener en cuenta son: Distancia relativaDistancia entre la llamada y la ubicación actual del ascensor.Se calcula como:DR = 0 Si el ascensor está en camino al piso llamado   IF Está quieto       DR= |PISO ACTUAL - PISO DEL LLAMADO|   ELSE DR= |PISO DESTINO MAS CERCANO - PISO DEL LLAMADO|Los conjuntos de pertenencia estarán dados de la siguiente manera:            Triangular[0 0 2]Baja                Triangular[1 3 6]Media                 Trapecio[5 8 9 9]Alta     Tiempo de esperaTE =|PISO ACTUAL - PISO DEL LLAMADO|            Trapecio[0 0 2 4]Corto                Triangular[2 4.5 7]Medio                 Trapecio[5 7 9 9]Largo     Capacidad            Trapecio[0 0 2 4]Baja                Triangular[2 4.5 7]Media                 Trapecio[5 7 9 9]Alta     Prioridad            Triangular[0 0 0.5]Baja                Triangular[0.25 0.5 0.75]Media                 Triangular[0.5 1 1]Alta      - Definir un conjunto de reglas para establecer las prioridades a asignar en cada caso - Hacer diversas pruebas y verificar que los resultados sean consistentes<jupyter_code>%matplotlib inline
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Fuente: https://github.com/shubhamgupta1404/Fuzzy-Elevator-Control-System/blob/master/FuzzyLogicElevatorSystemPaper.pdf  AntecendentesDefinir y graficar los antecedentes para el problema.<jupyter_code>relative_dis = ctrl.Antecedent(np.arange(0, 10, 1), "relative_dis")
relative_dis["low"] = fuzz.trimf(relative_dis.universe, [0, 0, 2])
relative_dis["medium"] = fuzz.trimf(relative_dis.universe, [1, 3, 6])
relative_dis["high"] = fuzz.trapmf(relative_dis.universe, [5, 8, 9, 9])
relative_dis.view()<jupyter_output>G:\Anaconda\lib\site-packages\skfuzzy\control\fuzzyvariable.py:122: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  fig.show()<jupyter_text>Awaiting time<jupyter_code>aw_time = ctrl.Antecedent(np.arange(0, 10, 1), "aw_time")
aw_time["low"] = fuzz.trapmf(relative_dis.universe, [0, 0, 2, 4])
aw_time["medium"] = fuzz.trimf(relative_dis.universe, [2, 4.5, 7])
aw_time["high"] = fuzz.trapmf(relative_dis.universe, [5, 7, 9, 9])
aw_time.view()<jupyter_output>G:\Anaconda\lib\site-packages\skfuzzy\control\fuzzyvariable.py:122: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  fig.show()<jupyter_text>Capacity<jupyter_code>capacity = ctrl.Antecedent(np.arange(0, 10, 1), "capacity")
capacity["low"] = fuzz.trapmf(relative_dis.universe, [0, 0, 2, 4])
capacity["medium"] = fuzz.trimf(relative_dis.universe, [2, 4.5, 7])
capacity["high"] = fuzz.trapmf(relative_dis.universe, [5, 7, 9, 9])
capacity.view()<jupyter_output>G:\Anaconda\lib\site-packages\skfuzzy\control\fuzzyvariable.py:122: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  fig.show()<jupyter_text>Consecuentes   Priority<jupyter_code>priority = ctrl.Consequent(np.arange(0, 10, 1), "priority")
priority["low"] = fuzz.trimf(relative_dis.universe, [0, 0, 0.5])
priority["medium"] = fuzz.trimf(relative_dis.universe, [0.25, 0.5, 0.75])
priority["high"] = fuzz.trimf(relative_dis.universe, [0.5, 1, 1])
priority.view()<jupyter_output>G:\Anaconda\lib\site-packages\skfuzzy\control\fuzzyvariable.py:122: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  fig.show()<jupyter_text>Rules<jupyter_code>priority.defuzzify_method = "mom"

rules = []
rules.append(ctrl.Rule(aw_time["low"] | capacity["low"] | relative_dis["low"], priority["high"]))
rules.append(ctrl.Rule(aw_time["medium"] | relative_dis["medium"] | capacity["medium"], priority["medium"]))
rules.append(ctrl.Rule(aw_time["high"] | relative_dis["high"] | capacity["high"], priority["low"]))<jupyter_output><empty_output><jupyter_text>Simulation<jupyter_code>ctrSys = ctrl.ControlSystem(rules)
elevators = ctrl.ControlSystemSimulation(ctrSys)
elevators.input["capacity"] = 2
elevators.input["relative_dis"] = 1
elevators.input["aw_time"] = 1
elevators.compute()
elevators.print_state()
print(f"prioridad: {elevators.output['priority']}")<jupyter_output>=============
 Antecedents 
=============
Antecedent: aw_time                 = 1
  - low                             : 1.0
  - medium                          : 0.0
  - high                            : 0.0
Antecedent: capacity                = 2
  - low                             : 1.0
  - medium                          : 0.0
  - high                            : 0.0
Antecedent: relative_dis            = 1
  - low                             : 0.5
  - medium                          : 0.0
  - high                            : 0.0

=======
 Rules 
=======
RULE #0:
  IF (aw_time[low] OR capacity[low]) OR relative_dis[low] THEN priority[high]
	AND aggregation function : fmin
	OR aggregation function  : fmax

  Aggregation (IF-clause):
  - aw_time[low]                                           : 1.0
  - capacity[low]                                          : 1.0
  - relative_dis[low]                                      : 0.5
      (aw_time[low] OR capacity[low]) OR relative_dis[low] [...]
{'fraction_non_alphanumeric': 0.12018569463548831, 'fraction_numerical': 0.028370013755158185, 'mean_word_length': 3.2740631888317413, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '237425', 'license': 'Apache-2.0', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1957, 'n_words': 466, 'path': 'tp2/Ejercicio2.ipynb', 'repo_name': 'xRUIZxMATIASx/inteligencia-artificial', 'size': '5816'}