{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solving the river pollution problem using NIMBUS\n", "\n", "Welcome to this notebook demonstrating the DESDEO interactive multi-objective optimisation framework.\n", "\n", "In this notebook we will consider a toy problem dealing with water quality management, and the pollution produced by a fishery. We want to maximise the water quality as measured in two locations: the fishery and a downstream city (the measurements are based on dissolved oxygen concentration). Additionally, we want to maximise the ROI (Return On Investment) of the fishery. Simultaneously we want to minimise the additional tax which residents of the city must pay.\n", "\n", "To run this example, you need to run each individual code block (the ones saying `In [ ]:` to their left) by clicking on each one and then clicking \"Run\". Please refer to the [background section of the documentation](http://desdeo.readthedocs.io/en/latest/background/index.html) for information about NIMBUS.\n", "\n", "## Imports\n", "\n", "This first code snippet simply imports the parts of DESDEO we need for this notebook. We import optimisation methods, NIMBUS and the RiverPollution problem definition from the desdeo module, and visualisation and preference selection tools and widgets from the desdeo_vis module." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from desdeo.method.NIMBUS import NIMBUS\n", "from desdeo.optimization import SciPyDE\n", "from desdeo.problem.toy import RiverPollution\n", "\n", "from desdeo_vis.widget import NimbusPrefWidget, ParplotWidget" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initial iteration and preference selection\n", "\n", "First we initialise the RiverPollution problem and the NIMBUS solution method. Then we get an initial result. We can plot solutions at any time using `ParplotWidget`. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "problem = RiverPollution()\n", "method = NIMBUS(problem, SciPyDE)\n", "results = method.init_iteration()\n", "\n", "ParplotWidget(results.objective_vars, problem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we will give our first preference based on NIMBUS. We construct a `NimbusPrefWidget`, save it to a variable and display it. You can now specify your preferences using the displayed widget. If you're not sure how to use it, read [the documentation on classification in NIMBUS](http://desdeo.readthedocs.io/en/latest/background/classification-in-nimbus.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pref = NimbusPrefWidget(results.objective_vars, problem)\n", "pref" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solutions based on preference\n", "\n", "We can now generate a new set of results based on this preference. Note that this will raise an `InvalidNimbusPreferencesException` if you run it while the above preferences are invalid." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results2_all = method.next_iteration(preference=pref.nimbus_clf(method))\n", "\n", "ParplotWidget(results2_all.objective_vars, problem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We might choose to generate less extra solutions..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results2_less = method.next_iteration(preference=pref.nimbus_clf(method), num_scalars=2)\n", "\n", "ParplotWidget(results2_less.objective_vars, problem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also choose a subset of scalarization functions from NIM, ACH, GUESS, STOM. These are the NIMBUS scalarization function and the NIMBUS version of the achievement, guess and satisficing trade-off functions respectively." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results2_spec = method.next_iteration(preference=pref.nimbus_clf(method), scalars=['NIM', 'GUESS', 'STOM'])\n", "\n", "ParplotWidget(results2_spec.objective_vars, problem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generating intermediate solutions\n", "\n", "If none of these solutions exactly satisfy us, we can generate and view solutions between two solutions we've generated so far. Here we generate 4 solutions between the solutions generated by the NIMBUS and GUESS scalarisation functions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results3 = method.between(results2_spec.objective_vars[0], results2_spec.objective_vars[1], 4)\n", "\n", "ParplotWidget(results3.objective_vars, problem)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5rc1" } }, "nbformat": 4, "nbformat_minor": 2 }