@@ -122,7 +122,7 @@ def return_topsis_res(self, scores=[]):
122122 """Display results in CLI"""
123123 res = ""
124124 if self .results ["optimum_id" ] is None :
125- res += "Alternatives cannot be ranked if weights are null.\n "
125+ res += "Alternatives cannot be ranked if weights are null or considered alternatives identical on chosen requirements .\n "
126126 res += "However, blockchains have been filtered according to your requirements.\n "
127127 res += "Suitable alternatives: \n "
128128 for a in self .results ["considered" ]:
@@ -141,20 +141,41 @@ def return_topsis_res(self, scores=[]):
141141 best_altr ["name" ] + " (" + best_altr ["infoAttributes" ]["consensusAlgorithm" ] + ")\n " )
142142 res += "Scores: %s \n " % scores
143143
144- return res
144+ return {
145+ "success" : True ,
146+ "msg" : res
147+ }
145148
146149 def solve (self ):
147150 """Executes the 2-step solving process : filter unsuitable alternatives, then run TOPSIS to find the best alternative"""
148151
149152 self .filter_unsuitable_alternatives ()
150- self .gen_alternatives_values_array ()
151-
152- if (sum (abs (x ) for x in self .weights ) > 0 ):
153- decision = topsis (self .alternatives_values , self .weights , self .costs )
154- decision .calc ()
155153
156- self .results ['optimum_id' ] = decision .optimum_choice
157-
158- return self .return_topsis_res (decision .C )
159-
160- return self .return_topsis_res ()
154+ if len (self .results ["considered" ]) == 1 :
155+ return {
156+ "success" : True ,
157+ "msg" : "Only one alternative is compatible with your input: " + self .results ["considered" ][0 ]
158+ }
159+ elif len (self .results ["considered" ]) > 1 :
160+ try :
161+ self .gen_alternatives_values_array ()
162+
163+ if (sum (abs (x ) for x in self .weights ) > 0 ):
164+ decision = topsis (self .alternatives_values , self .weights , self .costs )
165+ decision .calc ()
166+
167+ self .results ['optimum_id' ] = decision .optimum_choice
168+
169+ return self .return_topsis_res (decision .C )
170+
171+ return self .return_topsis_res ()
172+ except :
173+ return {
174+ "error" : True ,
175+ "msg" : "An unexpected error happened. Please copy your generated YAML file and send it to one of the researcher in charge of the project. Thanks!"
176+ }
177+ else :
178+ return {
179+ "success" : True ,
180+ "msg" : "No alternative compatible with this input. Please change your requirements and retry."
181+ }
0 commit comments