Skip to content

Commit

Permalink
end simus tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
leliel12 committed Jun 22, 2018
1 parent df03f45 commit 8ae1521
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 57 deletions.
1 change: 1 addition & 0 deletions doc/source/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Contents:
:maxdepth: 1

quickstart.ipynb
simus.ipynb


.. seealso::
Expand Down
251 changes: 194 additions & 57 deletions doc/source/tutorial/simus.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -55,50 +54,12 @@
"uno.\n",
"The data are provided in the next table:\n",
"\n",
"<table>\n",
" <thead>\n",
" <th>Criteria</th>\n",
" <th>Project 1</th>\n",
" <th>Project 2</th>\n",
" <th>Project 3</th>\n",
" <th>Right side value</th>\n",
" <th>Optimal Sense</th>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>jobs</th>\n",
" <td>250</td>\n",
" <td>130</td>\n",
" <td>350</td>\n",
" <td>-</td>\n",
" <td>Maximize</td>\n",
" </tr>\n",
" <tr>\n",
" <th>green</th>\n",
" <td>120</td>\n",
" <td>200</td>\n",
" <td>340</td>\n",
" <td>500</td>\n",
" <td>Maximize</td>\n",
" </tr>\n",
" <tr>\n",
" <th>fin</th>\n",
" <td>20</td>\n",
" <td>40</td>\n",
" <td>15</td>\n",
" <td>-</td>\n",
" <td>Maximize</td>\n",
" </tr>\n",
" <tr>\n",
" <th>env</th>\n",
" <td>800</td>\n",
" <td>1000</td>\n",
" <td>600</td>\n",
" <td>-</td>\n",
" <td>Maximize</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"|Criteria|Project 1|Project 2|Project 3|Right side value|Optimal Sense|\n",
"|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |\n",
"|jobs|250|130|350|-|Maximize|\n",
"|green|120|200|340|500|Maximize|\n",
"|fin|20|40|15|-|Maximize|\n",
"|env|800|1000|600|-|Maximize|\n",
"\n",
"\n",
"### Data input\n",
Expand All @@ -112,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -137,7 +98,7 @@
" Prj 3 350 340 15 600"
]
},
"execution_count": 20,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -172,32 +133,55 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# import the class\n",
"from skcriteria.madm.simus import SIMUS"
"from skcriteria.madm.simus import SIMUS\n",
"\n",
"# create the new simus and\n",
"dm = SIMUS()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"dec = SIMUS()"
"By default the call `SIMUS()` create a solver that internally uses the [PuLP](https://pythonhosted.org/PuLP/) solver to solve the linear programs. Other availables solvers are:\n",
"\n",
"- `SUMUS(solver='glpk')` for the [GNU Linear programming toolkit](https://en.wikipedia.org/wiki/GNU_Linear_Programming_Kit)\n",
"- `SUMUS(solver='gurobi')` to use [Gurobi Optimizer](https://en.wikipedia.org/wiki/Gurobi)\n",
"- `SUMUS(solver='cplex')` for [IBM ILOG CPLEX Optimization Studio](https://en.wikipedia.org/wiki/CPLEX)\n",
"\n",
"<div class=\"alert alert-info\">\n",
"**Note:** The check the full list of available optimizers are stored in `skcriteria.utils.lp.SOLVERS`.\n",
"</div>\n",
"\n",
"Also the `njobs` parameters determines how many cores the user want to use to run the linear programs. For example\n",
"`SIMUS(njobs=2)` uses up to two cores. (By default all CPUs are used).\n",
"\n",
"Also the last (and most important) parameter is `rank_by` (default is 1): determines which of the two ranks methods executed by SIMUS is the one that determines the final ranking. If the experiment is consistent, the two methos *must* detemines the *same* ranking (Please check the [paper](https://revistas.unc.edu.ar/index.php/epio/article/viewFile/16533/16348) for more details)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Solve the problem\n",
"\n",
"This is achived by calling the method `decide()` of the decision maker object (`dm`)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div id='dec-7fb97f6c-7508-11e8-8d16-d85de264446f'><p><b>SIMUS (mnorm=none, wnorm=none) - Solution:</b></p><table>\n",
"<div id='dec-e627bdd2-75ca-11e8-8d16-d85de264446f'><p><b>SIMUS (mnorm=none, wnorm=none) - Solution:</b></p><table>\n",
"<thead>\n",
"<tr><th style=\"text-align: center;\"> ALT./CRIT. </th><th style=\"text-align: center;\"> jobs (max) </th><th style=\"text-align: center;\"> green (max) </th><th style=\"text-align: center;\"> fin (min) </th><th style=\"text-align: center;\"> env (max) </th><th style=\"text-align: center;\"> Rank </th></tr>\n",
"</thead>\n",
Expand All @@ -217,13 +201,166 @@
" Prj 3 350 340 15 600 1"
]
},
"execution_count": 26,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# store the decision inside the dec variable\n",
"dec = dm.decide(data, b=[None, 500, None, None])\n",
"\n",
"# let's see the decision\n",
"dec"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you check the last column the raking is:\n",
"\n",
"1. Project 3\n",
"- Project 2\n",
"- Project 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Analysis\n",
"\n",
"Most of the \"intermediate\" data of the SIMUS method are stored in the `e_` field of the decision object `dec`."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Extra(rank_by, solver, stages, stage_results, points1, points2, tita_j_p, tita_j_d, doms, dom_by_crit)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dec.e_"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"for example the attribute `stages` stores all the Linear programs executed by SIMUS:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[no-name:\n",
" MAXIMIZE\n",
" 250*x0 + 130*x1 + 350*x2 + 0\n",
" SUBJECT TO\n",
" _C1: 120 x0 + 200 x1 + 340 x2 <= 500\n",
" \n",
" _C2: 20 x0 + 40 x1 + 15 x2 >= 15\n",
" \n",
" _C3: 800 x0 + 1000 x1 + 600 x2 <= 1000\n",
" \n",
" VARIABLES\n",
" x0 Continuous\n",
" x1 Continuous\n",
" x2 Continuous, no-name:\n",
" MAXIMIZE\n",
" 120*x0 + 200*x1 + 340*x2 + 0\n",
" SUBJECT TO\n",
" _C1: 250 x0 + 130 x1 + 350 x2 <= 350\n",
" \n",
" _C2: 20 x0 + 40 x1 + 15 x2 >= 15\n",
" \n",
" _C3: 800 x0 + 1000 x1 + 600 x2 <= 1000\n",
" \n",
" VARIABLES\n",
" x0 Continuous\n",
" x1 Continuous\n",
" x2 Continuous, no-name:\n",
" MINIMIZE\n",
" 20*x0 + 40*x1 + 15*x2 + 0\n",
" SUBJECT TO\n",
" _C1: 250 x0 + 130 x1 + 350 x2 <= 350\n",
" \n",
" _C2: 120 x0 + 200 x1 + 340 x2 <= 500\n",
" \n",
" _C3: 800 x0 + 1000 x1 + 600 x2 <= 1000\n",
" \n",
" VARIABLES\n",
" x0 Continuous\n",
" x1 Continuous\n",
" x2 Continuous, no-name:\n",
" MAXIMIZE\n",
" 800*x0 + 1000*x1 + 600*x2 + 0\n",
" SUBJECT TO\n",
" _C1: 250 x0 + 130 x1 + 350 x2 <= 350\n",
" \n",
" _C2: 120 x0 + 200 x1 + 340 x2 <= 500\n",
" \n",
" _C3: 20 x0 + 40 x1 + 15 x2 >= 15\n",
" \n",
" VARIABLES\n",
" x0 Continuous\n",
" x1 Continuous\n",
" x2 Continuous]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dec._e.stages"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The attribute `stages_results` stores the *eficients restults normalized matrix* "
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.125 , 0. , 0.875 ],\n",
" [0. , 0.38888889, 0.61111111],\n",
" [0. , 0. , 0. ],\n",
" [0.05681818, 0.94318182, 0. ]])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dec.decide(data, b=[None, 500, None, None])"
"dec.e_.stage_results"
]
},
{
Expand Down

0 comments on commit 8ae1521

Please sign in to comment.