diff --git a/Dockerfile b/Dockerfile index 403b5dcb4..b3a86d787 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ WORKDIR /app COPY requirements /app/requirements # py dev tooling -RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && pip3 install --no-cache-dir --upgrade setuptools && pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt +RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && pip3 install --no-cache-dir --upgrade setuptools && pip3 install highspy && pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt # Copy code and meta/config data COPY setup.* .flaskenv wsgi.py /app/ diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 31e7af3b2..b1b72be2f 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -27,8 +27,7 @@ Infrastructure / Support * Add support for profiling Flask API calls using ``pyinstrument`` (if installed). Can be enabled by setting the environment variable ``FLEXMEASURES_PROFILE_REQUESTS`` to ``True`` [see `PR #722 `_] * The endpoint `[POST] /health/ready `_ returns the status of the Redis connection, if configured [see `PR #699 `_] * Document the `device_scheduler` linear program [see `PR #764 `_]. - -/api/v3_0/health/ready +* Add support for `HiGHS `_ solver [see `PR #766 `_]. v0.14.2 | July 25, 2023 ============================ diff --git a/documentation/configuration.rst b/documentation/configuration.rst index 899a06d98..635737c82 100644 --- a/documentation/configuration.rst +++ b/documentation/configuration.rst @@ -55,7 +55,7 @@ Default: ``False`` FLEXMEASURES_LP_SOLVER ^^^^^^^^^^^^^^^^^^^^^^ -The command to run the scheduling solver. This is the executable command which FlexMeasures calls via the `pyomo library `_. Other values might be ``cplex`` or ``glpk``. Consult `their documentation `_ to learn more. +The command to run the scheduling solver. This is the executable command which FlexMeasures calls via the `pyomo library `_. Other values might be ``cplex``, ``glpk`` or ``appsi_highs`` for `HiGHS `_. Consult `their documentation `_ to learn more. Default: ``"cbc"`` diff --git a/documentation/dev/introduction.rst b/documentation/dev/introduction.rst index f055f72b3..2c9623d35 100644 --- a/documentation/dev/introduction.rst +++ b/documentation/dev/introduction.rst @@ -54,6 +54,11 @@ Go into the ``flexmeasures`` folder and install all dependencies including the o $ apt-get install coinor-cbc +Alternatively, HiGHS solver can be installed with pip: + +.. code-block:: bash + + $ pip install highspy Configuration ^^^^^^^^^^^^^^^^^^^^ diff --git a/documentation/host/deployment.rst b/documentation/host/deployment.rst index de1972a81..41f335498 100644 --- a/documentation/host/deployment.rst +++ b/documentation/host/deployment.rst @@ -48,10 +48,10 @@ Keep in mind that FlexMeasures is based on `Flask `_ mixed integer linear optimization solver. -It is used through `Pyomo `_\ , so in principle supporting a `different solver `_ would be possible. +To compute schedules, FlexMeasures uses the `CBC `_ (FlexMeasures solver by default) or `HiGHS `_ mixed integer linear optimization solver. +Solvers are used through `Pyomo `_\ , so in principle supporting a `different solver `_ would be possible. -Cbc needs to be present on the server where FlexMeasures runs, under the ``cbc`` command. +CBC needs to be present on the server where FlexMeasures runs, under the ``cbc`` command. You can install it on Debian like this: @@ -66,3 +66,10 @@ pass a directory for the installation. In case you want to install a later version, adapt the version in the script. +HiGHS can be installed using pip: + +.. code-block:: bash + + $ pip install highspy + + diff --git a/documentation/tut/installation.rst b/documentation/tut/installation.rst index ab3ef1c35..249e5e456 100644 --- a/documentation/tut/installation.rst +++ b/documentation/tut/installation.rst @@ -226,9 +226,12 @@ For FlexMeasures to be able to send email to users (e.g. for resetting passwords Install an LP solver ^^^^^^^^^^^^^^^^^^^^ -For planning balancing actions, the FlexMeasures platform uses a linear program solver. Currently that is the Cbc solver. See :ref:`solver-config` if you want to change to a different solver. +For planning balancing actions, the FlexMeasures platform uses a linear program solver. Currently that is the CBC or HiGHS solvers. See :ref:`solver-config` if you want to change to a different solver. -Installing Cbc can be done on Unix via: +CBC +***** + +Installing CBC can be done on Unix via: .. code-block:: bash @@ -239,7 +242,18 @@ Installing Cbc can be done on Unix via: We provide a script for installing from source (without requiring ``sudo`` rights) in the `ci` folder. -More information (e.g. for installing on Windows) on `the Cbc website `_. +More information (e.g. for installing on Windows) on `the CBC website `_. + +HiGHS +****** + +HiGHS is a modern LP solver that aims at solving large problems. It can be installed using pip: + +.. code-block:: bash + + $ pip install highspy + +More information (e.g. for installing on Windows) on `the HiGHS website `_. Install and configure Redis diff --git a/flexmeasures/data/models/planning/linear_optimization.py b/flexmeasures/data/models/planning/linear_optimization.py index f0d79f866..cba7fde88 100644 --- a/flexmeasures/data/models/planning/linear_optimization.py +++ b/flexmeasures/data/models/planning/linear_optimization.py @@ -339,10 +339,16 @@ def cost_function(m): model.costs = Objective(rule=cost_function, sense=minimize) # Solve + + # load_solutions=False to avoid a RuntimeError exception in appsi solvers when solving an infeasible problem. results = SolverFactory(current_app.config.get("FLEXMEASURES_LP_SOLVER")).solve( - model + model, load_solutions=False ) + # load the results only if a feasible solution has been found + if len(results.solution) > 0: + model.solutions.load_from(results) + planned_costs = value(model.costs) planned_power_per_device = [] for d in model.d: diff --git a/requirements/app.in b/requirements/app.in index 2809f4ec9..936d0c39f 100644 --- a/requirements/app.in +++ b/requirements/app.in @@ -67,4 +67,4 @@ Flask-SQLAlchemy>=2.4.3,<3 # flask should be after all the flask plugins, because setup might find they ARE flask # <2.3: https://github.com/Parallels/rq-dashboard/issues/417 and https://github.com/FlexMeasures/flexmeasures/issues/754 and flask-login 0.6.1 not compatible flask>=1.0, <=2.1.2 -werkzeug<=2.1 +werkzeug<=2.1 \ No newline at end of file