本文整理汇总了Python中PyXMCDA.getProfilesCategories方法的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA.getProfilesCategories方法的具体用法?Python PyXMCDA.getProfilesCategories怎么用?Python PyXMCDA.getProfilesCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyXMCDA
的用法示例。
在下文中一共展示了PyXMCDA.getProfilesCategories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import getProfilesCategories [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv
parser = OptionParser()
parser.add_option("-i", "--in", dest="in_dir")
parser.add_option("-o", "--out", dest="out_dir")
(options, args) = parser.parse_args(argv[1:])
in_dir = options.in_dir
out_dir = options.out_dir
# Creating lists for error and log messages
errorList = []
logList = []
# If some mandatory input files are missing
if not os.path.isfile (in_dir+"/alternatives.xml") or not os.path.isfile (in_dir+"/categories.xml") or not os.path.isfile (in_dir+"/categoriesProfiles.xml") or not os.path.isfile (in_dir+"/stabilityRelation.xml"):
errorList.append("Some input files are missing")
else :
if os.path.isfile (in_dir+"/sortingMode.xml") :
xmltree_mode = PyXMCDA.parseValidate(in_dir+"/sortingMode.xml")
if xmltree_mode == None :
errorList.append ("sortingMode file cannot be validated.")
else :
mode = PyXMCDA.getParameterByName (xmltree_mode, "sortingMode")
if not (mode == "pessimistic" or mode == "optimistic"):
errorList.append ("Value of parameter sortingMode should be 'pessimistic' or 'optimistic'.")
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_categories = PyXMCDA.parseValidate(in_dir+"/categories.xml")
xmltree_profiles = PyXMCDA.parseValidate(in_dir+"/categoriesProfiles.xml")
xmltree_altStability = PyXMCDA.parseValidate(in_dir+"/stabilityRelation.xml")
if xmltree_alternatives == None :
errorList.append("The alternatives file cannot be validated.")
if xmltree_categories == None :
errorList.append("The categories file cannot be validated.")
if xmltree_profiles == None :
errorList.append("The categoriesProfiles file cannot be validated.")
if xmltree_altStability == None :
errorList.append("The alternatives comparisons file cannot be validated.")
if not errorList :
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives, "ACTIVEREAL")
allalt = PyXMCDA.getAlternativesID(xmltree_alternatives, "ACTIVE")
categoriesId = PyXMCDA.getCategoriesID(xmltree_categories)
categoriesRank = PyXMCDA.getCategoriesRank(xmltree_categories, categoriesId)
altStability = PyXMCDA.getAlternativesComparisons (xmltree_altStability, allalt)
if not alternativesId:
errorList.append("No alternatives found.")
if not categoriesId:
errorList.append("No categories found.")
if not altStability :
errorList.append("No alternatives comparisons found.")
if not errorList :
catPro = PyXMCDA.getCategoriesProfiles(xmltree_profiles, categoriesId)
proCat = PyXMCDA.getProfilesCategories(xmltree_profiles, categoriesId)
profilesId = proCat.keys()
# On retourne la liste pour trier selon les rangs
rankCategories = {}
for i, j in categoriesRank.iteritems():
rankCategories[j] = i
ranks = rankCategories.keys()[:]
ranks.sort()
lowestRank = ranks.pop()
# Un tableau pour conserver les affectations
affectations = {}
if mode == "pessimistic":
# Electre tri pessimistic rule
for alt in alternativesId:
affectations[alt] = []
for rank in ranks:
profile = catPro[rankCategories[rank]]["lower"]
if altStability[alt][profile] >= -1 and altStability[alt][profile] <= 1:
# Surclassement instable, on ajoute les categories sup et inf
if affectations[alt].count(proCat[profile]["lower"]) == 0:
affectations[alt].append(proCat[profile]["lower"])
if affectations[alt].count(proCat[profile]["upper"]) == 0:
affectations[alt].append(proCat[profile]["upper"])
if altStability[alt][profile] > 1:
# Surclassement stable, on ajoute que sup et on arrete
if affectations[alt].count(proCat[profile]["upper"]) == 0:
affectations[alt].append(proCat[profile]["upper"])
break
if affectations[alt] == []:
#.........这里部分代码省略.........