> For the complete documentation index, see [llms.txt](https://doc.verteego.com/verteego-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.verteego.com/verteego-doc/pipelines/optimization-pipelines/getting-started.md).

# Getting started

My first Optimization

## **Overview**

**In order to generate optimisations with Verteego, you will need to:**&#x20;

* Create datasets
* Create a configuration file
* Create a pipeline run.

{% hint style="info" %}
See the [Concepts page](https://doc.verteego.com/concepts.html) for a description of the general concepts used below (Datasource, Dataset, Pipeline, etc.).
{% endhint %}

Here, we will look at three examples of optimization, which represent the **three main categories of optimization** addressed by the Verteego platform:

1. Optimisation of a variable
2. Scenario selection
3. Optimisation of a variable and selection of scenarios

**For each of these 3 cases, you will need to :**

* **Create the pipeline :**

  In Pipelines Tab, click on “New” in order to create a pipeline of type optimisation :&#x20;

<figure><img src="https://4291965094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJkYuqsCIBAOnonwt3TXF%2Fuploads%2FTfr04vTJrApetVXqgKM5%2FUntitled.png?alt=media&amp;token=ec5e5dff-c6d4-4bda-9271-302600626760" alt="" width="239"><figcaption></figcaption></figure>

* **Add the relevant datasets :**

  In Data Tab → Datasets, click on New to create a dataset. If your datasets are CSV files of less than 50 MB, you can go directly to the Data>Datasets section and add a dataset (select the 'Upload File' data source, and click on 'Choose file' to upload your file). If however your dataset is in the Cloud, we support a number of [Connectors](https://doc.verteego.com/connectors.html) which you can use to create a datasource (Data>Datasources), and then create datasets from this source.

<figure><img src="https://4291965094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJkYuqsCIBAOnonwt3TXF%2Fuploads%2FNoh1qKzf8cRihlR4UYu5%2FUntitled%20(1).png?alt=media&amp;token=107dd920-af4e-45bb-add7-4392d81609ed" alt="" width="234"><figcaption></figcaption></figure>

* **Set up the configuration file**
* **Launch a pipeline\_run**

## 1. Optimisation of a variable

First, you need to create a pipeline on the platform. In the Pipelines section, create a new Optimization pipeline.

Let's say we want to optimise daily car rental prices for different rental periods.

**Data overview:**

In our example, we have **3 vehicles** (vehicle A, vehicle B and vehicle C), **3 rental periods** (1D, 7D, 14D), the **price of the competition** and the **price of the competition plus 30%**.

| Vehicle   | Duration | Competition\_price | Competition\_upper\_bound\_price |
| --------- | -------- | ------------------ | -------------------------------- |
| Vehicle A | 1J       | 38                 | 49                               |
| Vehicle A | 7J       | 37                 | 48                               |
| Vehicle A | 14J      | 34                 | 44                               |
| Vehicle B | 1J       | 39                 | 51                               |
| Vehicle B | 7J       | 36                 | 47                               |
| Vehicle B | 14J      | 33                 | 43                               |
| Vehicle C | 1J       | 41                 | 53                               |
| Vehicle C | 7J       | 38                 | 49                               |
| Vehicle C | 14J      | 37                 | 48                               |

Then, you need to create the system. The system contains the keys that uniquely identify the variables (Vehicle, Duration) and the columns that are useful for optimisation (Competition\_price, Competition\_upper\_bound\_price).

You need to upload your system dataset on the platform:&#x20;

{% file src="/files/I9qFuaPZAzUm0OpYZqJr" %}

Once your system dataset has been uploaded and validated on the platform, you need to create the configuration file.

**Configuration:**

### v1 - Launching our first pipeline run

#### Creating the first configuration

You need to set up the initial configuration of your optimisation pipeline.

**Goal:**

In our example, we want to **maximise the price of the vehicles**, and ensure that these prices are **higher than the competition's prices** and **lower than the competition's prices plus 30%.**

**Variables:**

First of all, you need to fill in everything relating to the **variables** :

* *variables* : the name of the **variable to optimise**. In this example, we want to optimize the price.
* *variable\_types* : **type of the variable to optimise**. Could be int, float, bool. In this example, we want integer prices.
* *variable\_keys* : **keys that uniquely identify the variables**. In this example, the price is indexed by a vehicle and a duration.

Then you need to determine the **objective** of the optimisation. There are two ways of computing the objective: the sum of a column or the weighted sum of two columns. You need to specify :

* *objective\_method* : **max or min**, whether you want to maximize or minimize the objective. In this example, we want to maximize the price.
* *weighted\_objective\_columns* : **column(s) used as the optimisation objective**. In this example, it is the price.

**Constraints:**

Afterwards, you need to define the set of **constraints** :

* *lower\_bound\_on\_price :* This constraint means that our price variable must be greater than 0.
* *competition\_lower\_bound* : This constraint means that our price variable must be greater than the competition price. Here we use a binary constraint, because we are constraining our variable (price) against another column (Competition\_price).
* *competition\_upper\_bound* : This constraint means that our price variable must be lesser than the competition price plus 30% (Competition\_upper\_bound\_price).

For example, a very simple initial configuration might be as follows:

```yaml
variables:
- name: price
variable_types: int
variable_keys:
- Vehicle
- Duration
objective_method: max
weighted_objective_columns:
- price

constraints:

  lower_bound_on_price:
    constraint_type: unary
    column: price
    operator: greater
    bound: 0
    
  competition_lower_bound:
    constraint_type: binary
    left_column: price
    operator: greater
    right_column: Competition_price
    delta: 0
    relax: false

  competition_upper_bound:
    constraint_type: binary
    left_column: price
    operator: lesser
    right_column: Competition_upper_bound_price
    delta: 0
    relax: false
```

You are now ready to launch a pipeline run.

Then, click on the pipeline you have just created. This redirects you to the pipeline runs page. You can create a new run by clicking on "New", and specifying which dataset is used as input to the optimisation.

#### Analyzing the results

You can click on Pipeline>Predictions, then on the prediction of your pipeline. In the top-right, you can then choose to download the prediction file (as a CSV), or export it to an existing DataSource.

In our example, we obtain the following results:

| Vehicle   | Duration | Competition\_price | Competition\_upper\_bound\_price | price |
| --------- | -------- | ------------------ | -------------------------------- | ----- |
| Vehicle A | 1J       | 38                 | 49                               | 49    |
| Vehicle A | 7J       | 37                 | 48                               | 48    |
| Vehicle A | 14J      | 34                 | 44                               | 44    |
| Vehicle B | 1J       | 39                 | 51                               | 51    |
| Vehicle B | 7J       | 36                 | 47                               | 47    |
| Vehicle B | 14J      | 33                 | 43                               | 43    |
| Vehicle C | 1J       | 41                 | 53                               | 53    |
| Vehicle C | 7J       | 38                 | 49                               | 49    |
| Vehicle C | 14J      | 37                 | 48                               | 48    |

The results are consistent with our configuration: the price of vehicles is maximised, while respecting the min and max bounds.

However, for 7J duration, vehicle A is more expensive than vehicle B. This is not possible in our case, as we want the prices of the vehicles to increase (the price of vehicle A must be lower than the price of vehicle B, which must be lower than the price of vehicle C).

Let’s add a new constraint in the following section.

### v2 - Adding more constraints

#### Adding a new constraint

We want to add an additional constraint to our example, to order the prices of vehicles A, B and C for each rental period (Duration). We want that the car prices must be at least €1 apart in the following order: Vehicle A, B, C.

To do this, we define the category\_constraint :

For each rental period :&#x20;

$$
Price(VehicleA) \leq Price(Vehicle B) - 1 \leq Price(Vehicle C) - 1
$$

Indeed, order constraints can be written mathematically as follows:$variable(lesserorder) <= variable(greaterorder) \* factor + delta$

$$
variable(lesser\_order) \leq variable(greater\_order) \times factor + delta
$$

The configuration then looks like this:

```yaml
variables:
- name: price
variable_types: int
variable_keys:
- Vehicle
- Duration
objective_method: max
weighted_objective_columns:
- price

constraints:

  lower_bound_on_price:
    constraint_type: unary
    column: price
    operator: greater
    bound: 0
    
  competition_lower_bound:
    constraint_type: binary
    left_column: price
    operator: greater
    right_column: Competition_price
    delta: 0
    relax: false

  competition_upper_bound:
    constraint_type: binary
    left_column: price
    operator: lesser
    right_column: Competition_upper_bound_price
    delta: 0
    relax: false

  category_constraint:
    constraint_type: order
    variable_column: price
    order_by: Vehicle
    ordering:
    - Vehicle A
    - Vehicle B
    - Vehicle C
    operator: asc
    delta: -1
    relax: false
    factor: 1
    group_by:
    - Duration
```

#### Analyzing the results

We obtain the following results :

| Vehicle   | Duration | Competition\_price | Competition\_upper\_bound\_price | price |
| --------- | -------- | ------------------ | -------------------------------- | ----- |
| Vehicle A | 1J       | 38                 | 49                               | 49    |
| Vehicle A | 7J       | 37                 | 48                               | 46    |
| Vehicle A | 14J      | 34                 | 44                               | 42    |
| Vehicle B | 1J       | 39                 | 51                               | 51    |
| Vehicle B | 7J       | 36                 | 47                               | 47    |
| Vehicle B | 14J      | 33                 | 43                               | 43    |
| Vehicle C | 1J       | 41                 | 53                               | 53    |
| Vehicle C | 7J       | 38                 | 49                               | 49    |
| Vehicle C | 14J      | 37                 | 48                               | 48    |

The results here are more consistent : Depending on the rental period, the prices of vehicles A, B and C increase in this order.

## 2. Scenario selection

First, you need to create a pipeline on the platform. In the Pipelines section, create a new Optimization pipeline.

Let's say we want to optimise the promotions applied to a shop's products. We need to determine the optimal discount percentage for each of our products, between 10% and 50% off.

First, the Verteego platform simulated **all possible scenarios:** for each of our products and each percentage reduction, the platform predicted the quantities sold (Forecasting module).

| item\_id          | item\_level\_1 | item\_level\_2            | item\_level\_3 | promo\_meca | reduction\_percent | item\_reduced\_price | item\_cost | quantity\_sold | revenue  | margin  |
| ----------------- | -------------- | ------------------------- | -------------- | ----------- | ------------------ | -------------------- | ---------- | -------------- | -------- | ------- |
| 5 901 234 124 021 | Alimentation   | Lait et produits laitiers | MIKO           | MECA\_01    | 0.1                | 5.49                 | 3.66       | 1537           | 8438.13  | 2812.71 |
| 5 901 234 124 021 | Alimentation   | Lait et produits laitiers | MIKO           | MECA\_02    | 0.2                | 4.88                 | 3.66       | 2714           | 13244.32 | 3311.08 |
| 5 901 234 124 021 | Alimentation   | Lait et produits laitiers | MIKO           | MECA\_03    | 0.3                | 4.27                 | 3.66       | 3095           | 13215.65 | 1887.95 |

Now we can use these scenarios to choose the best promotion mechanics to apply to our products (Optimization module).&#x20;

In our example, we have 12 products and 5 promotion mechanisms, so the system has 60 rows.

You need to upload your system dataset on the platform :&#x20;

{% file src="/files/AqSJ5dUOzNf9ST5SxNy9" %}

Once your system dataset has been uploaded and validated on the platform, you need to create the configuration file.

### v1 - Launching our first pipeline run

#### Creating the first configuration

You need to set up the initial configuration of your optimisation pipeline.

As explained in the previous section, you need to fill in everything relating to the **variables** :

* *variables* : In this example, we want to optimize the variable select\_best\_promo\_meca. We want this variable to be equal to 0 or 1, in order to select the right scenarios. The rows where the variable is equal to 1 will be the rows selected by the optimisation.
* *variable\_types* : In this example, we want integer or bool.
* *variable\_keys* : In this example, the variable best\_promo\_meca is indexed by a product and a promotional mechanism.

Then you need to determine the **objective** of the optimisation :

* *objective\_method* : In this example, we want to maximize the margin.
* *weighted\_objective\_columns* : column(s) used as the optimisation objective. In this example, it is the margin and the variable select\_best\_promo\_meca. Indeed, the objective can be written as :

$$
max \sum select\_best\_promo\_meca \times margin
$$

Afterwards, you need to define the set of **constraints** :

* unique: This constraint means that a product can only have one promotional mechanism. For each product, the sum of the variable best\_promo\_meca must be equal to 1. Given that the type of this variable is int or bool, this means that select\_best\_promo\_meca can be equal to 0 or 1.

For example, a very simple initial configuration might be as follows:

```yaml
variables:
- name: select_best_promo_meca
variable_keys:
- item_id
- promo_meca
variable_types: int
objective_method: max
weighted_objective_columns:
- select_best_promo_meca
- margin
constraints:
  unique:
    constraint_type: aggregation
    keys:
    - item_id
    left_column: select_best_promo_meca
    left_method: sum
    operator: equal
    right_column: 1
    right_method: min
```

You are now ready to launch a pipeline run.

#### Analyzing the results

In our example, we obtain the following results:

| item\_id          | item\_level\_1 | item\_level\_2            | item\_level\_3          | promo\_meca | reduction\_percent | item\_reduced\_price | item\_cost | quantity\_sold | revenue  | margin   | select\_best\_promo\_meca |
| ----------------- | -------------- | ------------------------- | ----------------------- | ----------- | ------------------ | -------------------- | ---------- | -------------- | -------- | -------- | ------------------------- |
| 5 901 234 124 021 | Alimentation   | Lait et produits laitiers | MIKO                    | MECA\_02    | 0.2                | 4.88                 | 3.66       | 2714           | 13244.32 | 3311.08  | 1                         |
| 5 901 234 124 022 | Alimentation   | Lait et produits laitiers | LA FROMAGERIE DU QUERCY | MECA\_01    | 0.1                | 14.94                | 11.2       | 1393           | 20811.42 | 5209.82  | 1                         |
| 5 901 234 124 028 | Alimentation   | Lait et produits laitiers | ARGEL                   | MECA\_01    | 0.1                | 10.35                | 10.18      | 786            | 8135.1   | 133.62   | 1                         |
| 5 901 234 124 043 | Alimentation   | Lait et produits laitiers | MONOPRIX GOURMET        | MECA\_01    | 0.1                | 10.35                | 8.1        | 2424           | 25088.4  | 5454.0   | 1                         |
| 5 901 234 124 047 | Alimentation   | Lait et produits laitiers | PILPA                   | MECA\_02    | 0.2                | 15.12                | 7.57       | 2508           | 37920.96 | 18935.4  | 1                         |
| 5 901 234 124 053 | Alimentation   | Lait et produits laitiers | CARRE DES PINS          | MECA\_01    | 0.1                | 17.28                | 12.3       | 2465           | 42595.2  | 12275.7  | 1                         |
| 5 901 234 124 020 | Alimentation   | Fruits et légumes         | NOTRE JARDIN            | MECA\_02    | 0.2                | 9.28                 | 8.6        | 4616           | 42836.48 | 3138.88  | 1                         |
| 5 901 234 124 040 | Alimentation   | Fruits et légumes         | MONOPRIX BIO            | MECA\_01    | 0.1                | 14.31                | 12.09      | 4578           | 65511.18 | 10163.16 | 1                         |
| 5 901 234 124 042 | Alimentation   | Fruits et légumes         | SANS MARQUE             | MECA\_01    | 0.1                | 13.32                | 9.78       | 4677           | 62297.64 | 16556.58 | 1                         |
| 5 901 234 124 066 | Alimentation   | Fruits et légumes         | BINS DE FRAICHEUR       | MECA\_02    | 0.2                | 4.08                 | 2.8        | 4635           | 18910.8  | 5932.8   | 1                         |
| 5 901 234 124 153 | Alimentation   | Fruits et légumes         | LES HERBES DE MON PERE  | MECA\_01    | 0.1                | 9.81                 | 5.5        | 4675           | 45861.75 | 20149.25 | 1                         |
| 5 901 234 124 191 | Alimentation   | Fruits et légumes         | BIO VILLAGE             | MECA\_02    | 0.2                | 13.6                 | 8.9        | 5741           | 78077.6  | 26982.7  | 1                         |

In this case, the optimization has selected the right promotional mechanism to maximise the margin. The output is 12 rows, 1 for each product, with the associated promotional mechanism.

Now let's add some constraints.

### v2 - Adding more constraints

#### Adding a new constraint

Let’s say we want to have at least 2 promotional mechanics at 40% off.

To do so, we add an aggregation constraint nb\_meca\_04.

```yaml
variables:
- name: select_best_promo_meca
variable_keys:
- item_id
- promo_meca
variable_types: int
objective_method: max
weighted_objective_columns:
- select_best_promo_meca
- margin
constraints:
  unique:
    constraint_type: aggregation
    keys:
    - item_id
    left_column: select_best_promo_meca
    left_method: sum
    operator: equal
    right_column: 1
    right_method: min
    
  nb_meca_04:
    constraint_type: aggregation
    left_column: select_best_promo_meca
    left_method: sum
    left_where:
      promo_meca:
      - MECA_04
    operator: greater
    right_column: 2
    right_method: min
```

#### Analyzing the results

We obtain the following results:

| item\_id          | item\_level\_1 | item\_level\_2            | item\_level\_3          | promo\_meca | reduction\_percent | item\_reduced\_price | item\_cost | quantity\_sold | revenue  | margin      | select\_best\_promo\_meca |
| ----------------- | -------------- | ------------------------- | ----------------------- | ----------- | ------------------ | -------------------- | ---------- | -------------- | -------- | ----------- | ------------------------- |
| 5 901 234 124 021 | Alimentation   | Lait et produits laitiers | MIKO                    | MECA\_04    | 0.4                | 3.66                 | 3.66       | 3200           | 11712.0  | -3.2685e-11 | 1                         |
| 5 901 234 124 022 | Alimentation   | Lait et produits laitiers | LA FROMAGERIE DU QUERCY | MECA\_01    | 0.1                | 14.94                | 11.2       | 1393           | 20811.42 | 5209.82     | 1                         |
| 5 901 234 124 028 | Alimentation   | Lait et produits laitiers | ARGEL                   | MECA\_01    | 0.1                | 10.35                | 10.18      | 786            | 8135.1   | 133.62      | 1                         |
| 5 901 234 124 043 | Alimentation   | Lait et produits laitiers | MONOPRIX GOURMET        | MECA\_01    | 0.1                | 10.35                | 8.1        | 2424           | 25088.4  | 5454.0      | 1                         |
| 5 901 234 124 047 | Alimentation   | Lait et produits laitiers | PILPA                   | MECA\_02    | 0.2                | 15.12                | 7.57       | 2508           | 37920.96 | 18935.4     | 1                         |
| 5 901 234 124 053 | Alimentation   | Lait et produits laitiers | CARRE DES PINS          | MECA\_01    | 0.1                | 17.28                | 12.3       | 2465           | 42595.2  | 12275.7     | 1                         |
| 5 901 234 124 020 | Alimentation   | Fruits et légumes         | NOTRE JARDIN            | MECA\_02    | 0.2                | 9.28                 | 8.6        | 4616           | 42836.48 | 3138.88     | 1                         |
| 5 901 234 124 040 | Alimentation   | Fruits et légumes         | MONOPRIX BIO            | MECA\_01    | 0.1                | 14.31                | 12.09      | 4578           | 65511.18 | 10163.16    | 1                         |
| 5 901 234 124 042 | Alimentation   | Fruits et légumes         | SANS MARQUE             | MECA\_01    | 0.1                | 13.32                | 9.78       | 4677           | 62297.64 | 16556.58    | 1                         |
| 5 901 234 124 066 | Alimentation   | Fruits et légumes         | BINS DE FRAICHEUR       | MECA\_04    | 0.4                | 3.06                 | 2.8        | 6315           | 19323.9  | 1641.9      | 1                         |
| 5 901 234 124 153 | Alimentation   | Fruits et légumes         | LES HERBES DE MON PERE  | MECA\_01    | 0.1                | 9.81                 | 5.5        | 4675           | 45861.75 | 20149.25    | 1                         |
| 5 901 234 124 191 | Alimentation   | Fruits et légumes         | BIO VILLAGE             | MECA\_02    | 0.2                | 13.6                 | 8.9        | 5741           | 78077.6  | 26982.7     | 1                         |
