PyTOPS - A Python Based Tool For TOPSIS
PyTOPS - A Python Based Tool For TOPSIS
SoftwareX
journal homepage: www.elsevier.com/locate/softx
graphical abstract
article info a b s t r a c t
Article history: The Technique for Order Preference by Similarity to Ideal Solution (TOPSIS) method determines the
Received 10 October 2018 best solution from a set of alternatives with certain attributes. The best alternative is chosen based
Received in revised form 12 February 2019 on its Euclidean distance from the ideal solution. TOPSIS is widely used in various multi-attribute
Accepted 12 February 2019
decision making problems such as supply chain logistics, marketing management, environmental
Keywords: management or chemical engineering. Despite the extensive use of this method, there is no free and
Python open-source software (FOSS) for TOPSIS with comprehensive post-analysis extensions. Therefore, this
TOPSIS paper describes a Python-3 based tool PyTOPS for TOPSIS with the Berkeley Software Distribution
(BSD)-3-Clause license.
© 2019 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY license
(http://creativecommons.org/licenses/by/4.0/).
https://doi.org/10.1016/j.softx.2019.02.004
2352-7110/© 2019 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).
218 V. Yadav, S. Karmakar, P.P. Kalbar et al. / SoftwareX 9 (2019) 217–222
Code metadata
Current code version v0.1
Permanent link to code/repository used for this code version https://github.com/ElsevierSoftwareX/SOFTX_2018_196
Legal Code License BSD-3-Clause
Code versioning system used none
Software code languages, tools, and services used Python3, PyQt5
Compilation requirements, operating environments & dependencies numpy, sklearn, collections, math, xlrd, random, sys, QtCore, QtGui, QtWidgets
If available Link to developer documentation/manual http://www.cese.iitb.ac.in/people/facinfo.php?id=skarmakar (Password:
pytops2018)
Support email for questions [email protected]
Software metadata
Current software version v0.1
Permanent link to executables of this version uploaded with manuscript
Legal Software License BSD-3-Clause
Computing platforms/Operating Systems Linux, Microsoft Windows
Installation requirements & dependencies numpy, sklearn, collections, math, xlrd, random, sys, PyQt5 (for linux only)
If available, link to user manual - if formally published include a http://www.cese.iitb.ac.in/people/facinfo.php?id=skarmakar (Password:
reference to the publication in the reference list pytops2018)
Support email for questions [email protected]
such as probability of rank reversibility, the mean and standard for spreadsheets and can be exported using many free software
deviation of relative closeness to the ideal solutions. The mean such as LibreOffice Calc and Google Sheets. The data of these files
and standard deviation of the relative closeness concerning each are extracted using xlrd library. The weights to attributes are
alternative provide the liberty to belittle some alternative with given by decision makers based on the relative importance and
an intervention of human understanding. The influence of some are generally subjective in nature. This subjectivity is always
attributes with their given weights can also be examined with associated with inherent uncertainty. To address this issue, the
multiple simulations using PyTOPS. These advanced applications degree of variation component is added with double spin box.
will facilitate many researchers and decision makers to utilize This double spin box has a variation up to 1.00 (1.00 means
enhanced computational capability for studying TOPSIS method. decision maker is willing to have a variation of 100% in provided
Many software packages have been developed for solving weights). To analyze the influence of this variation multiple sim-
MADM problems using TOPSIS such as DECERNS [14], Triptych: ulations may be carried out in the next component using a spin
TOPSIS [15], SANNA [16], Topsis Solver 2012 [17] and TechSe- box. Number of simulations can be increased to one million.
lect [18]. DECERNS is a web-based and desktop decision support Outputs block contains four components: (i) rank with varying
system for MADM models with a wide range of applications weights; (ii) probability of rank reversal; (iii) mean of relative
in scientific and practical problems [19]. However, it does not closeness to ideal solution; and (iv) standard deviation of relative
have any post analysis functionality and is distributed with a closeness to the ideal solution. After uploading all necessary files
proprietary commercial license. The Triptych package for TOPSIS and other information in Inputs block, next step is to run the
analysis is developed and distributed by Statistical Design Insti- script with RUN pushbutton. RUN button fills remaining text
tute with proprietary commercial license. This software requires boxes of Outputs block. The first component gives respective
Microsoft Excel and limits the number of attributes and alterna- ranks of alternatives with the chosen weights from the user
tives to 200. SANNA and Topsis Solver 2012 also need Microsoft defines variation in weights (see component 4 of Inputs). This text
Excel to function and limits the number of attributes and alter- box first prints the weights and subsequently prints the ranks in a
natives to 50 and 20, respectively. TechSelect is a scenario-based
loop configuration. MADM approaches have a prominent problem
decision support tool with TOPSIS nested on Microsoft Excel.
of rank reversal i.e., change in the rank ordering of preferable
Evidently, the available software are either commercial or depend
alternatives. For the quantification of this problem, the probabil-
on some other commercial package such as Microsoft Excel and
ity of rank reversal for all the alternatives in two-column format
have limitations in terms of the attributes and alternatives in
is printed in the second component. This probability palpably
the decision matrix. The goal of PyTOPS is to provide a FOSS
reflects the robustness of alternatives ranks. The third and fourth
equivalent for TOPSIS with a large decision matrix (thousands of
components print mean and standard deviation of relative close-
attributes and alternatives) and up to a million simulations for
ness to the ideal solution in the respective text boxes for every
post-analysis.
alternative. The mean and standard deviations values bestow an
opportunity to the decision maker for choosing an inferior, but
2. Software description
best with human perceptibility, alternative. All printed values in
each text boxes of all components can be saved by using save
The standard steps for the TOPSIS method are (i) formation
of normalized decision matrix; (ii) weighted normalized decision tool button with txt extension. The overall structure of PyTOPS is
matrix formation; (iii) ideal and negative-ideal solution deter- given in Fig. 2.
mination; (iv) separation measure calculation; (v) calculation of
relative closeness to ideal solutions; and (vi) ranking of prefer- 2.2. Sample code snippets analysis
ence order. The normalization of the decision matrix is carried out
using inbuilt sklearn.preprocessing package followed by a matrix Source code of PyTOPS are written in Python3. The codes may
multiplication with the weights to construct weighted normal- be further modified for developing a tool for fuzzy TOPSIS meth-
ized decision matrix. Ideal and negative ideal solutions are iden- ods. Existing functions such as normalize of sklearn.preprocessing
tified based on predetermined cost and benefit attributes. Sepa- and xlrd are operational only for deterministic values (see the
ration measure and relative closeness are calculated by defining snippet below). The possible modification in these utility func-
specific functions respectively. Alternatives are then ranked based tions will allow decision makers to choose a preferable alternative
on relative closeness to the ideal solution using various inbuilt under fuzzy uncertainty.
functions of numpy package. The subsequent sections explain
these functionalities in detail.
workbook = x l r d . open_workbook ( ’ decision_matrix . xlsx ’ )
2.1. Software architecture and functionalities sheet1 = workbook . sheet_by_index ( 0 )
_matrix = [ ]
As can be seen in Fig. 1, PyTOPS has two blocks: Inputs and f o r row in range ( sheet1 . nrows ) :
Outputs. The Inputs block lists five components: (i) attribute type; _row = [ ]
(ii) upload decision matrix; (iii) upload weights; (iv) degree of f o r c o l in range ( sheet1 . n co ls ) :
variation in weights; and (v) number of simulations. The input _row . append ( sheet1 . c e l l _ v a l u e ( row , c o l ) )
attribute type component identifies cost and benefit based on the _matrix . append ( _row )
binary values (0 for benefit and 1 for cost) given by the user. A = np . matrix ( _matrix )
These binary values are then appended to the columns of deci- from s k l e a r n . preprocessing import normalize
sion matrix. This practice ushers defined functions to recognize B = normalize (A , norm= ’ l2 ’ , a x i s =0)
attributes of different types, which are used in the determination
of the ideal and negative-ideal solutions. OrderedDict subclass
is used to remember the attribute type (given in list form) for 3. Illustrative example
further operations. Components two and three have pushbuttons
for uploading decision matrix and attribute weights with xlsx The working of PyTOPS is illustrated using Example 1, which
extensions, respectively. xlsx is the most common file extension a commonly practiced simple numerical problem.
220 V. Yadav, S. Karmakar, P.P. Kalbar et al. / SoftwareX 9 (2019) 217–222
Fig. 2. Unified modeling language diagram to show the structure of PyTOPS; where DMat is decision matrix, Std deviation is standard deviation and DM is decision
maker; Inputs and Outputs are same as given in Fig. 1.
Example 1. A manager of an international firm is trying to for this evaluation. (S)he also assign certain weights for each of
these attributes as shown in Table 1.
evaluate the requirement of a new facility for the replacement
As can be seen in Table 1, all of the attributes in Example 1
of current structure with A1 , A2 , A3 and A4 as alternatives. (S)he
are benefit type. Therefore, the first step is to provide 0, 0, 0
considers three attributes i.e. durability, reliability and capability in the first component (i.e. Input attribute type) of Inputs block.
V. Yadav, S. Karmakar, P.P. Kalbar et al. / SoftwareX 9 (2019) 217–222 221
Fig. 3. (a) Probability of rank reversal for top ranks; and (b) Mean and standard deviation of closeness to the ideal solution for the top ranks of alternatives (i.e., A2 ,
A3 and A4 ).
Table 1 with the probability of their reversal. Moreover, it also gives the
Alternatives and attributes for Example 1 [20].
mean and standard deviation of the relative closeness in multiple
Durability Reliability Capability
simulations, which is an important reckon for municipal officials.
Weights 0.3 0.4 0.3 The use of PyTOPS is not restricted to academicians and may
A1 5 4 8
A2 7 8 6 be used by any decision maker in industries and governments
A3 8 6 8 under BSD license as MADM problems extensively encounters in
A4 7 6 4 these domains. The examples of many MADM problems in indus-
tries and governments can be found in literature (for example,
see [25,26]). PyTOPS may also be used in educational institutes in
The decision matrix and assigned weights are then uploaded operation research courses as it has a very user-friendly graphical
using respective push buttons (see supplementary information interface. Additionally, the present software may be of interest
for xlsx files). PyTOPS ranks the alternatives as A2 > A3 > A4 > to decision makers who works with real large data sets with
A1 . These results are intuitive as A2 has the highest score in the thousands of alternatives and attributes.
Reliability attribute, which is the highest weighted attribute. For
the demonstration purpose, a variation of 25%, 40% and 50% in
the assigned weights have been considered. In all these variations 5. Conclusions
one thousand simulations are performed. Fig. 3 (a) depicts the
probability of rank reversibility under the given variations of This paper presents a Python based tool PyTOPS for the MADM
weights (i.e., 25%, 40% and 50%) graphically. Fig. 3(b) gives means method TOPSIS with a wide range of post-analysis extensions
and standard deviations of the closeness to the ideal solution of such as probability of rank reversibility, the mean and standard
top alternatives (i.e., A2 , A3 and A4 ). deviation of relative closeness to the ideal solution. All the func-
tionalities of PyTOPS are explained using a numerical example
4. Impact and all necessary files to solve the example problem are provided
as supplementary material. The use of state of the art packages
Most of the MADM methods principally depend on the sub- bestows a high efficiency which makes PyTOPS a suitable tool
jective judgments of decision makers [21]. TOPSIS method also for large datasets and concurrently reduces the processing time.
requires weights associated with attributes as subjective informa-
Users from diverse backgrounds are invited to use PyTOPS and
tion [22]. This subjectivity brings uncertainty into the outcomes.
to provide feedback, which will be taken forward to improve the
PyTOPS provides liberty for decision makers to analyze how un-
functionality in later versions. Apart from routine maintenance
certainty of outcomes is apportioned to the subjectivity of input
and bug fixation, future study on PyTOPS will incorporate fuzzy
weights by allowing multiple simulations with uniformly dis-
tributed values around the given information. Definiteness of uncertainty of decision models as explained in Section 2.2.
preferred alternatives can be examined using this functionality
without creating new scenarios. This functionality also focuses on Acknowledgments
the robustness testing of the decision model e.g., if the best alter-
native changes with a very minute perturbation in weight, then
decision makers may question the robustness of the model. On The authors would like to thank the Editor-in-Chief and anony-
the other hand, models are considered robust if a comparatively mous Reviewers for providing extremely insightful comments,
larger perturbation of weights does not change the rank of al- which has improved the quality of this manuscript. VY thanks
ternatives. Conclusively, PyTOPS has the capability for robustness Ministry of Human Resource and Development, Government of
examination and uncertainty analysis of decision models. India for providing his Ph.D. fellowship and IIT Bombay for com-
PyTOPS has been used to solve a two stage multi-attribute de- putational support. VY also acknowledges Mr. Ranjeet Kumar
cision making model for selecting appropriate locations of waste Singh and Mr. Pratiman Patel for their help.
transfer stations in the city of Nashik (India) reported in [23,
24]. This model chooses best locations of municipal solid waste
management facilities in the urban centers based on the at- Conflict of interest
tributes identified by all level of stake holders. PyTOPS provides
the rank to all the possible combinations of these facilities along The authors declare that there is no conflict of interest.
222 V. Yadav, S. Karmakar, P.P. Kalbar et al. / SoftwareX 9 (2019) 217–222