LinkSmart® Optimization Framework : Getting started


Checking the API

Once you have installed the Optimization Framework and it is running, you can check its API by calling the following command in a browser:


http://raspberry_ip_address:8080/v1/ui


As a result you are to going to see the API interface of the OFW. It should look like as here.


Registering inputs

Inputs can be understood as being the "Parameters" in the optimization model, in which the inputs of the optimization model will be received.


  1. POST request to register the inputs to OFW

You should start using the POST request.

In the case OFW is going to receive data via MQTT use POST /data_source/mqt. You can find examples of how to do it here.

In the case OFW is going to receive data via HTTP use POST /data_source/file. You can find examples of to do it here.

Once you send this command, you are going to receive an id, which will identify the OFW object you are creating.


WARNING:

Copy this id or save it into memory for the nex steps. You cannot do anything else, if you lose this id.


2. PUT request to add extra inputs

If you forgot to register something with the POST request. Or you just need to add another input because your system expanded. Use then the PUT request to easily create new registries for these new inputs.

The PUT request allows also the use of MQTT input data together with HTTP input data. In this case, if you registered some inputs with MQTT you can add extra inputs using HTPP or viceversa.

You just need the id you received while you used the POST request.

In case of using MQTT, you can find examples of how to do it here.

In case of using HTTP, you can find examples of how to do it here.


3. Deleting input registries

If you want to delete registries that you entered for any reason, use the DELETE request.

In case of using MQTT, you can find examples of how to do it here.

In case of using HTTP, you can find examples of how to do it here.

Registering control outputs

Outputs can be understood as being the "Variables" in the optimization model, in which the results of the optimization will be stored.

The outputs are either setpoints that a driver or other software mechanism can use for accomplishing a control task or files that can be accessed through HTTP requests.

1. PUT request to add extra MQTT outputs

If you want to register an output or different outputs of the optimization problem to be published in an MQTT Topic, use the PUT request of the /control endpoint.

You just need the id you received while you used the POST request.

You can find examples of how to do it here.


2. Deleting MQTT output registries

If you want to delete registries that you entered for any reason, use the DELETE request.

You just need the id you received while you used the POST request.

You can find examples of how to do it here.


3. Obtaining results through HTTP

If you want to obtain all results from the optimization through HTTP, use the GET /control/file/{id}

{id} is the id you received while you sent the POST request.

You can find examples of how to do it here.

Starting/Stopping the OFW

If you want to start the OFW, you need to enter some optimization parameters:

  • Optimization horizon: Defined time window to be used by the optimization
  • Model name: Name of the optimization model to be loaded
  • Repetitions: Number of repetitions that the software will solve the optimization problem
  • Time step: Frequency of calculating the optimization problem
  • Solver: Name of the solver to be chosen for solving the opitmization problem. At the moment there are three solvers present:
    • GLPK: Linear problems
    • Ipopt: Quadratic problems
    • Bonmin: Non linear problems

Don't forget to use the id for starting the optimization.

You can find examples of how to do it here.

For stopping OFW, you just need the id.

You can find examples of how to do it here.

Introducing custom optimization models

1. Obtaining the names of the optimization models saved into the internal repository

If you want to obtain the names of the optimization models saved into the OFW's repository, use the GET /models

You can find examples of how to do it here.


2. Introducing a custom optimization model

If you want to introduce a new custom optimization model into the OFW's repository, use the PUT /models/upload/{name}

where:

  • {name}: Custom name of the optimization model. This is the new that you have to choose later, while starting the OFW.


OFW is based on abstract models written in Pyomo. For this reason you can use all your abstract models written in pyomo and convert them in an online optimal control.

In the model you specify:

  • Paremeters:  Parameters names have to coincide with the input registry names in /data_source
  • Variables: Variables names have to coincide with the output registry names in /control. (If you don't want to have an output, you don't have to register anything. You can just read the results)
  • Constrains
  • Optimization objectives

You can find examples of how to do it here.