# Entidades, agentes, atributos y variables

Aunque el término “atributo” no apareció en este tutorial, es común en los libros de simulación de eventos discretos. En la simulación basada en agentes, en la que se basa AnyLogic, el atributo se representa como una variable que pertenece al agente.&#x20;

Imagine, por ejemplo, que queremos crear un atributo que represente la hora de entrada del cliente que ingresa a la agencia. En este caso, necesitamos, inicialmente, crear un **agente** que represente al cliente. En AnyLogic, la creación de un agente es una tarea de la paleta **Agent**. Haga clic en él y arrastre el icono rojo al área del modelo:

![](https://lh6.googleusercontent.com/I6DtI8FuV4jOLJVbEM_4aA3r88dFK1EEQXaUkhGvCEEEOrdQgQouLBYpzRE8Z4RVV88TsBGhVaPOGQVmbGG6zrBoTowG15KFj96t4weNp1q6FwEL8HwTzLQd0s15H3GxCu8Tr_0u)

AnyLogic abrirá un asistente para crear agentes, poblaciones o tipos de agentes. Con la práctica, descubrirás varias formas de crear agentes, pero el asistente siempre será el más didáctico.

Queremos crear un tipo de agente, llamado **Cliente**, no nos preocupa una población (con un tamaño limitado, por ejemplo), por lo que nuestra elección debe recaer en la 3ª opción **Agent type only**:

* Haga clic en **Agent type only**;
* En **Agent type name**, ponga el nombre Cliente con la primera letra en mayúsculas, ya que es una convención adoptada por los usuarios;
* Haga clic en el botón **Next>**;
* Como no queremos usar animación, seleccione **None** y luego el botón **Finish**.

![](https://lh4.googleusercontent.com/Y3A3UOxkCssoKc6YqT4_f0wkZIkyy6ymJjWwPa39fL9yQQNUPGMbDCENAcAWk7TGOXu8TEACeirHPKNbswvVjkWV9w6CnJETSMb0JUdJPOW7e9P3WC2Fw5NtGumHqwZuIRL0_RkM)

AnyLogic creó un nuevo tipo de agente llamado **Cliente**. Tenga en cuenta que ya ha abierto la pantalla del agente para que pueda modelarse como desee. El agente también aparece en la pestaña **Projects**:

![](https://lh3.googleusercontent.com/i-jzhYKRe-amH_hpHGIL_vePJTbNbRHYf5vTzRFxnEQ8n62xyYi4Q9a-MYPt5G-cUw6a3PKPlIq2T8LFcM1Y2yZ8BZAk9hg2pF0ShWGdaiQEahR2je8VYVPtjLxSxbElCsSEzzP4)

Queremos crear un atributo **tiempoEntrada**, que marcará la hora exacta en que el cliente ingresó al banco. Simplemente cree una variable con el nombre **tiempoEntrada**:

![](https://lh6.googleusercontent.com/3tSHafwfK8Ay-oeWk5JVKT-_bI4xpy4El7B_ty45_PB1qYAsqNDDkbe_1GIRcewQrY1jeZTsbjLARcyYbAOsthm23zy6lMS-ENoqBmXHmLbJUyEqUEtpyNmxwGJzgtzcd2YtdML8)

Ahora, regrese a **Main** e informe al bloque de **llegadas** (que es un bloque de tipo **Source**) que el agente a crear es del tipo **Cliente**, siguiendo los siguientes pasos:

* Seleccione el elemento de **llegadas**;
* En **Properties** abra la barra de(menú) **Agent**;
* En **New agent** sustituya la opción **Cliente**.

![](https://lh6.googleusercontent.com/fTJGWXJfJANMEKBnFj6JhjOTuYeG4pR5t6JYxS1QMvV4-elTCvesws1t4xSykPqXN1V3FSDOZQf_AjA0qH1R_B0bkFvXo3Q2AHrlq_4la3f4dqIEwQbBgWfgdfTWNRzrGVIqFuE4)

Para asignar el valor del tiempo de simulación actual a cada cliente que ingresa a la agencia, AnyLogic tiene la función `time()`. Por lo tanto, asignaremos la hora de entrada directamente en el bloque de **llegadas**:

* Busque la barra de **Actions** en la ventana **Properties** del elemento de **llegadas**;
* En **On exit**, escriba: `agent.tiempoEntrada = time();`

![](https://lh6.googleusercontent.com/NMqwFMrLCsjkxwSWRXgFQBqRRKlpEQpgy5GyUYAQqsGn3ykXFa3EWD_i_nAdS5RdPwIuBhYrOUTXBYngbKBJBBYqwBBfmvVhMAgeTmhUudst0iNdEYokeZfC9tioIHy4m8ERBqeQ)

Notas:

* **agent** es el nombre genérico del agente que pasa por el bloque. Como es de tipo **Cliente**, AnyLogic sabe que tiene la variable (atributo) **tiempoEntrada**;
* Cada bloque de AnyLogic tiene opciones de **Actions** donde puede agregar comandos en el momento en que el agente ingresa al bloque, sale, es destruido, etc;
* Por lo tanto, si desea, por ejemplo, calcular el tiempo que el cliente estuvo en línea en el cajero automático, simplemente agregue el campo de **On exit** al bloque de **queue** la línea de comando:&#x20;

| `agent.tiempoEntrada = time () - agent.tiempoEntrada;` |
| ------------------------------------------------------ |

o

| **`agent.tiempoEntrada - = time ();`** |
| -------------------------------------- |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tutorial.anylogicbrasil.com.br/tutorial-es/entidades-agentes-atributos-and-variaveis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
