{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Gantt Chart\n\nIn this example, we illustrate the use of the Gantt chart plot\non the Sobieski's SSBJ problem.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from __future__ import division, unicode_literals\n\nfrom matplotlib import pyplot as plt\n\nfrom gemseo.api import configure_logger, create_discipline, create_scenario\nfrom gemseo.core.discipline import MDODiscipline\nfrom gemseo.post.core.gantt_chart import create_gantt_chart\nfrom gemseo.problems.sobieski.core import SobieskiProblem\n\nconfigure_logger()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Create disciplines\nThen, we instantiate the disciplines of the Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "disciplines = create_discipline(\n    [\n        \"SobieskiPropulsion\",\n        \"SobieskiAerodynamics\",\n        \"SobieskiStructure\",\n        \"SobieskiMission\",\n    ]\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "design_space = SobieskiProblem().read_design_space()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "scenario = create_scenario(\n    disciplines,\n    formulation=\"MDF\",\n    objective_name=\"y_4\",\n    maximize_objective=True,\n    design_space=design_space,\n)\n\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n    scenario.add_constraint(constraint, \"ineq\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Activate time stamps\nIn order to record all time stamps recording, we have to call this method\nbefore the execution of the scenarios\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "MDODiscipline.activate_time_stamps()\n\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Post-process scenario\nLastly, we plot the Gantt chart.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "create_gantt_chart(show=False, save=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()\n\n# Finally, we deactivate the time stamps for other executions\nMDODiscipline.deactivate_time_stamps()"
      ]
    }
  ],
  "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.8.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}