本文整理汇总了Python中PyXMCDA.parseValidate方法的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA.parseValidate方法的具体用法?Python PyXMCDA.parseValidate怎么用?Python PyXMCDA.parseValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyXMCDA
的用法示例。
在下文中一共展示了PyXMCDA.parseValidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeDistilation
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def makeDistilation(
in_selected, in_alternatives, in_credibility, out_descending, out_ascending, out_medianPreorder, out_final
):
xml_alternatives = px.parseValidate(in_alternatives)
xml_selected = px.parseValidate(in_selected)
xml_alternatives = px.parseValidate(in_alternatives)
xml_credibility = px.parseValidate(in_credibility)
if xml_selected == None:
raise ValueError, "Invalid selected file"
if xml_alternatives == None:
raise ValueError, "Invalid alternative file"
if xml_credibility == None:
raise ValueError, "Invalid credibility file"
onCriterion = px.getParameterByName(xml_selected, "selectedCriterion")
alternativesID = px.getAlternativesID(xml_alternatives)
alternativesComparisions = getAlternativesComparisonsAtCriteria(xml_credibility, alternativesID)
if not alternativesComparisions.has_key(onCriterion):
raise ValueError, "Invalid selected criterion"
distillation = Distillation(alternativesID, alternativesComparisions[onCriterion])
output_distillation(out_ascending, distillation.downwards(), "downward distillation", onCriterion)
output_distillation(out_descending, distillation.upwards(), "upward distillation", onCriterion)
output_distillation(out_medianPreorder, distillation.medianPreorder(), "median Preorder", onCriterion)
writeAlternativeComparision(out_final, distillation.intersectionUpDowns, "outranks", onCriterion)
示例2: makeSelection
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def makeSelection(in_selected, in_outranking, out_outranking):
xml_outranking = px.parseValidate(in_outranking)
xml_selected = px.parseValidate(in_selected)
if xml_selected == None:
raise ValueError, "Invalid selected file"
if xml_outranking == None:
raise ValueError, "Invalid xml_outranking file"
onCriterion = px.getParameterByName(xml_selected, 'selectedCriterion')
alternativesComparisions = getAlternativesComparisonsAtCriteria(xml_outranking)
if not alternativesComparisions.has_key(onCriterion):
raise ValueError, 'Invalid selected criterion'
writeAlternativeComparisionOnCriterion(out_outranking, alternativesComparisions, onCriterion, 'outranks')
示例3: get_trees
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def get_trees(input_dir, file_names):
trees = {}
for f in file_names:
file_name = os.path.join(input_dir, f)
if not os.path.isfile(file_name):
raise RuntimeError("Problem with input file: '{}'.".format(f))
tree = None
tree = px.parseValidate(file_name)
if tree is None:
raise RuntimeError("Validation error with file: '{}'.".format(f))
trees.update({os.path.splitext(f)[0]: tree})
return trees
示例4: parse_xmcda_files
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def parse_xmcda_files(in_weights, in_hierarchy, in_concorlevel, in_criteria, in_alternatives, in_performances):
xml_crit = px.parseValidate(in_criteria)
xml_alt = px.parseValidate(in_alternatives)
xml_pt = px.parseValidate(in_performances)
xml_weight = px.parseValidate(in_weights)
xml_hierarchy = px.parseValidate(in_hierarchy)
xml_concordance = px.parseValidate(in_concorlevel)
if xml_crit == None:
raise ValueError, ["Invalid criteria file"]
if xml_alt == None:
raise ValueError, ["Invalid alternative file"]
if xml_pt == None:
raise ValueError, ["Invalid performance table file"]
if xml_weight == None:
raise ValueError, ["Invalid weight file"]
if xml_hierarchy == None:
raise ValueError, ["Invalid assignment file"]
if xml_concordance == None:
raise ValueError, ["Invalid concordance file"]
try:
alternatives_ids = px.getAlternativesID(xml_alt)
criteria_ids = px.getCriteriaID(xml_crit)
performance_table = px.getPerformanceTable(xml_pt, alternatives_ids, criteria_ids)
criteriaWeight = px.getCriterionValue(xml_weight, criteria_ids, 'Importance')
preferenceDirections = px.getCriteriaPreferenceDirections(xml_crit, criteria_ids)
hierarchyArray = get_hierarchy_array(xml_hierarchy)
criteria_thresholds = px.getConstantThresholds(xml_crit, criteria_ids)
concordanceCutLev = get_criterion_concordance_cutting_level_value(xml_concordance, 'Concordance')
except:
raise ValueError, ["Failed to parse one or more file"]
return
return alternatives_ids, criteria_ids, performance_table, criteriaWeight, preferenceDirections, hierarchyArray, criteria_thresholds, concordanceCutLev
示例5: get_fixed_parameters
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def get_fixed_parameters(in_dir, alt_id, crit_id, pt, cat_id, cat_rank, pref_dir):
weights = None
lbda = None
cat_profiles = None
pt_refalts = None
xml_weights = PyXMCDA.parseValidate(in_dir+"/crit_weights.xml")
xml_lbda = PyXMCDA.parseValidate(in_dir+"/lambda.xml")
xml_catprofiles = PyXMCDA.parseValidate(in_dir+"/cat_profiles.xml")
xml_refalts = PyXMCDA.parseValidate(in_dir+"/reference_alts.xml")
if xml_weights != None and xml_lbda != None:
if xml_weights == None or xml_lbda == None:
error_list.append("You must give both weights and lambda")
try:
weights = PyXMCDA.getCriterionValue(xml_weights, crit_id)
weights_sum = sum(weights.values())
for key, value in weights.iteritems():
weights[key] = value/weights_sum
lbda = xmcda.get_lambda(xml_lbda)
except:
error_list.append("Unable to get fixed weights or lambda")
if xml_catprofiles != None and xml_refalts != None:
if xml_catprofiles == None or xml_refalts == None:
error_list.append("You must give both categories profiles and performance table of reference alternatives")
try:
cat_profiles = xmcda.get_categories_profiles(xml_catprofiles)
pt_refalts = PyXMCDA.getPerformanceTable(xml_refalts, cat_id, crit_id)
except:
error_list.append("Unable to get fixed profiles")
if weights != None and lbda != None and pt_refalts != None:
error_list.append("No parameters to infer")
return (weights, lbda, cat_profiles, pt_refalts)
示例6: check_criteria_hierarchy
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def check_criteria_hierarchy(
in_weights, in_hierarchy, in_concorlevel, in_criteria, out_criteria, out_weights, out_hierarchy, out_concorlevel
):
weights_xmltree = px.parseValidate(in_weights)
hierarchy_xmtree = px.parseValidate(in_hierarchy)
concordance_xmltree = px.parseValidate(in_concorlevel)
criteria_xmltree = px.parseValidate(in_criteria)
if weights_xmltree == None:
raise ValueError, "Invalid weights file"
if hierarchy_xmtree == None:
raise ValueError, "Invalid hierarchy file"
if concordance_xmltree == None:
raise ValueError, "Invalid concordance level file"
if criteria_xmltree == None:
raise ValueError, "Invalid criterioa file"
hierarchyArray = check_hierarchy(hierarchy_xmtree, out_hierarchy)
check_weights(weights_xmltree, hierarchyArray, out_weights)
check_concordance(concordance_xmltree, hierarchyArray, out_concorlevel)
output_criteria(out_criteria, [(v) for v, k in hierarchyArray.items()], criteria_xmltree)
return None
示例7: parse_xmcda_files
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def parse_xmcda_files(in_dir):
xml_crit = PyXMCDA.parseValidate(in_dir+"/criteria.xml")
xml_alt = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xml_pt = PyXMCDA.parseValidate(in_dir+"/perfs_table.xml")
xml_assign = PyXMCDA.parseValidate(in_dir+"/assign.xml")
xml_cat = PyXMCDA.parseValidate(in_dir+"/categories.xml")
if xml_crit == None:
error_list.append("Invalid criteria file")
return
if xml_alt == None:
error_list.append("Invalid alternative file")
return
if xml_pt == None:
error_list.append("Invalid performance table file")
return
if xml_assign == None:
error_list.append("Invalid assignment file")
return
if xml_cat == None:
error_list.append("Invalid categories file")
return
try:
alt_id = PyXMCDA.getAlternativesID(xml_alt)
crit_id = PyXMCDA.getCriteriaID(xml_crit)
pt = PyXMCDA.getPerformanceTable(xml_pt, alt_id, crit_id)
cat_id = PyXMCDA.getCategoriesID(xml_cat)
cat_rank = PyXMCDA.getCategoriesRank(xml_cat, cat_id)
assign = PyXMCDA.getAlternativesAffectations(xml_assign)
pref_dir = PyXMCDA.getCriteriaPreferenceDirections(xml_crit, crit_id)
except:
error_list.append("Failed to parse one or more file")
return
return (alt_id, crit_id, pt, cat_id, cat_rank, assign, pref_dir)
示例8: _get_trees
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [as 别名]
def _get_trees(input_dir, filenames):
trees = {}
for f, is_optional in filenames:
file_name = os.path.join(input_dir, f)
if not os.path.isfile(file_name):
if is_optional:
continue
else:
raise RuntimeError("Problem with the input file: '{}'.".format(f))
tree = None
tree = px.parseValidate(file_name)
if tree is None:
raise RuntimeError("Validation error with the file: '{}'.".format(f))
tree_name = os.path.splitext(f)[0]
# although we use 'classes' and 'classes_profiles' in the names of
# the input files and in the documentation, we want to use them as
# 'categories' (and 'categories_profiles') internally
if "classes" in tree_name:
tree_name = tree_name.replace("classes", "categories")
trees.update({tree_name: tree})
return trees
示例9: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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 a list for error messages
errorList = []
if not in_dir:
errorList.append("option --in is missing")
if not out_dir:
errorList.append("option --out is missing")
if not errorList:
if not os.path.isfile (in_dir+"/alternatives.xml"):
errorList.append("alternatives.xml is missing")
if not os.path.isfile (in_dir+"/preferenceRelation.xml"):
errorList.append("preferenceRelation.xml is missing")
if not os.path.isfile (in_dir+"/methodParameters.xml"):
errorList.append("methodParameters.xml is missing")
if not errorList:
# We parse all the mandatory input files
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_preferenceRelation = PyXMCDA.parseValidate(in_dir+"/preferenceRelation.xml")
xmltree_methodParameters = PyXMCDA.parseValidate(in_dir+"/methodParameters.xml")
# We check if all mandatory input files are valid
if xmltree_alternatives == None :
errorList.append("alternatives.xml can't be validated.")
if xmltree_preferenceRelation == None :
errorList.append("preferenceRelation.xml can't be validated.")
if xmltree_methodParameters == None :
errorList.append("methodParameters.xml can't be validated.")
if not errorList :
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
alternativesRel = PyXMCDA.getAlternativesComparisonsValues(xmltree_preferenceRelation, alternativesId)
method_type = PyXMCDA.getParameterByName(xmltree_methodParameters, "type")
if not alternativesId :
errorList.append("No active alternatives found.")
if not alternativesRel :
errorList.append("Problems between relation and alternatives.")
if not method_type:
errorList.append("No method type found.")
missing_eval = False
for o in alternativesId:
if not (o in alternativesRel):
missing_eval = True
break
else:
for p in alternativesId:
if not (p in alternativesRel[o]):
missing_eval = True
break
else:
if not ('i' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p+' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p-' in alternativesRel[o][p]):
missing_eval = True
break
if not ('j' in alternativesRel[o][p]):
missing_eval = True
break
if missing_eval:
errorList.append("Not all alternatives from alternatives.xml contain evaluations in preferenceRelation.xml, or evaluations are incomplete. Possible inputs from different sources")
if not errorList :
alg = Mcc(alternativesId, alternativesRel, method_type)
K, RK = alg.Run()
fo = open(out_dir+"/alternativesAffectations.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<alternativesAffectations>\n')
for i in range(len(K)):
for o in K[i]:
fo.write('\t<alternativeAffectation>\n\t\t<alternativeID>'+o+'</alternativeID>\n\t\t<categoryID>'+'K'+str(i+1)+'</categoryID>\n\t</alternativeAffectation>\n')
fo.write('</alternativesAffectations>')
PyXMCDA.writeFooter(fo)
fo.close()
fo = open(out_dir+"/clustersRelations.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<categoriesComparisons>\n')
#.........这里部分代码省略.........
示例10: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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 a list for error messages
errorList = []
if not in_dir:
errorList.append("option --in is missing")
if not out_dir:
errorList.append("option --out is missing")
if not errorList:
if not os.path.isfile (in_dir+"/alternatives.xml"):
errorList.append("alternatives.xml is missing")
if not os.path.isfile (in_dir+"/preferenceRelation.xml"):
errorList.append("preferenceRelation.xml is missing")
if not os.path.isfile (in_dir+"/alternativesAffectations.xml"):
errorList.append("alternativesAffectations.xml is missing")
if not os.path.isfile (in_dir+"/clustersRelations.xml"):
errorList.append("clustersRelations.xml is missing")
if not os.path.isfile (in_dir+"/clustersRelationsDetailed.xml"):
errorList.append("clustersRelationsDetailed.xml is missing")
if not errorList:
# We parse all the mandatory input files
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_preferenceRelation = PyXMCDA.parseValidate(in_dir+"/preferenceRelation.xml")
xmltree_alternativesAffectations = PyXMCDA.parseValidate(in_dir+"/alternativesAffectations.xml")
xmltree_clustersRelations = PyXMCDA.parseValidate(in_dir+"/clustersRelations.xml")
xmltree_clustersRelationsDetailed = PyXMCDA.parseValidate(in_dir+"/clustersRelationsDetailed.xml")
# We check if all mandatory input files are valid
if xmltree_alternatives == None :
errorList.append("alternatives.xml can't be validated.")
if xmltree_preferenceRelation == None :
errorList.append("preferenceRelation.xml can't be validated.")
if xmltree_alternativesAffectations == None :
errorList.append("alternativesAffectations.xml can't be validated.")
if xmltree_clustersRelations == None :
errorList.append("clustersRelations.xml can't be validated.")
if xmltree_clustersRelationsDetailed == None :
errorList.append("clustersRelationsDetailed.xml can't be validated.")
if not errorList :
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
alternativesRel = PyXMCDA.getAlternativesComparisonsValues(xmltree_preferenceRelation, alternativesId)
if not alternativesId :
errorList.append("No active alternatives found.")
if not alternativesRel :
errorList.append("Problems between relation and alternatives.")
missing_eval = False
for o in alternativesId:
if not (o in alternativesRel):
missing_eval = True
break
else:
for p in alternativesId:
if not (p in alternativesRel[o]):
missing_eval = True
break
else:
if not ('i' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p+' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p-' in alternativesRel[o][p]):
missing_eval = True
break
if not ('j' in alternativesRel[o][p]):
missing_eval = True
break
if missing_eval:
errorList.append("Not all alternatives from alternatives.xml contain evaluations in preferenceRelation.xml, or evaluations are incomplete. Possible inputs from different sources")
alternativesAffectations = PyXMCDA.getAlternativesAffectations(xmltree_alternativesAffectations)
Knames = []
for o in alternativesId:
clusterId = alternativesAffectations[o]
if not (clusterId in Knames):
Knames.append(clusterId)
if Knames == []:
errorList.append("No clusters found.")
#.........这里部分代码省略.........
示例11: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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 a list for error messages
errorList = []
if not in_dir:
errorList.append("option --in is missing")
if not out_dir:
errorList.append("option --out is missing")
if not errorList:
if not os.path.isfile (in_dir+"/alternatives.xml"):
errorList.append("alternatives.xml is missing")
if not os.path.isfile (in_dir+"/preferenceRelation.xml"):
errorList.append("preferenceRelation.xml is missing")
if not os.path.isfile (in_dir+"/alternativesAffectations.xml"):
errorList.append("alternativesAffectations.xml is missing")
if not errorList:
# We parse all the mandatory input files
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_preferenceRelation = PyXMCDA.parseValidate(in_dir+"/preferenceRelation.xml")
xmltree_alternativesAffectations = PyXMCDA.parseValidate(in_dir+"/alternativesAffectations.xml")
# We check if all mandatory input files are valid
if xmltree_alternatives == None :
errorList.append("alternatives.xml can't be validated.")
if xmltree_preferenceRelation == None :
errorList.append("preferenceRelation.xml can't be validated.")
if xmltree_alternativesAffectations == None :
errorList.append("alternativesAffectations.xml can't be validated.")
if not errorList :
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
alternativesRel = PyXMCDA.getAlternativesComparisonsValues(xmltree_preferenceRelation, alternativesId)
if not alternativesId :
errorList.append("No active alternatives found.")
if not alternativesRel :
errorList.append("Problems between relation and alternatives.")
missing_eval = False
for o in alternativesId:
if not (o in alternativesRel):
missing_eval = True
break
else:
for p in alternativesId:
if not (p in alternativesRel[o]):
missing_eval = True
break
else:
if not ('i' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p+' in alternativesRel[o][p]):
missing_eval = True
break
if not ('p-' in alternativesRel[o][p]):
missing_eval = True
break
if not ('j' in alternativesRel[o][p]):
missing_eval = True
break
if missing_eval:
errorList.append("Not all alternatives from alternatives.xml contain evaluations in preferenceRelation.xml, or evaluations are incomplete. Possible inputs from different sources")
alternativesAffectations = PyXMCDA.getAlternativesAffectations(xmltree_alternativesAffectations)
Knames = []
for o in alternativesId:
clusterId = alternativesAffectations[o]
if not (clusterId in Knames):
Knames.append(clusterId)
if Knames == []:
errorList.append("No clusters found.")
K = {}
for clusterId in Knames:
K[clusterId] = []
for o in alternativesId:
K[alternativesAffectations[o]].append(o)
if not errorList :
CRS = ClustersRelationSummary(alternativesId, alternativesRel)
RKsum = CRS.RKSummary(K)
#.........这里部分代码省略.........
示例12: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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 a list for error messages
errorList = []
# If some mandatory input files are missing
if (
not os.path.isfile(in_dir + "/alternatives.xml")
or not os.path.isfile(in_dir + "/criteria.xml")
or not os.path.isfile(in_dir + "/criteriaWeights.xml")
or not os.path.isfile(in_dir + "/performanceTable.xml")
):
errorList.append("Some input files are missing")
else:
# We parse all the mandatory input files
xmltree_alternatives = PyXMCDA.parseValidate(in_dir + "/alternatives.xml")
xmltree_criteria = PyXMCDA.parseValidate(in_dir + "/criteria.xml")
xmltree_weights = PyXMCDA.parseValidate(in_dir + "/criteriaWeights.xml")
xmltree_perfTable = PyXMCDA.parseValidate(in_dir + "/performanceTable.xml")
# We check if all madatory input files are valid
if xmltree_alternatives == None:
errorList.append("The alternatives file can't be validated.")
if xmltree_criteria == None:
errorList.append("The criteria file can't be validated.")
if xmltree_perfTable == None:
errorList.append("The performance table file can't be validated.")
if xmltree_weights == None:
errorList.append("The criteria weights file can't be validated.")
# By default, the valuation domain is fixed to [0,1]
minValDomain = 0
maxValDomain = 1
# If a valuation domain input file has been provided
if os.path.isfile(in_dir + "/valuationDomain.xml"):
xmltree_valuation = PyXMCDA.parseValidate(in_dir + "/valuationDomain.xml")
if xmltree_valuation == None:
errorList.append("valuationDomain file can't be validated.")
else:
minValDomain = PyXMCDA.getParameterByName(xmltree_valuation, "min", "valuationDomain")
maxValDomain = PyXMCDA.getParameterByName(xmltree_valuation, "max", "valuationDomain")
# We check the validity of the parameters
if not isinstance(minValDomain, float) and not isinstance(minValDomain, int):
errorList.append("min value should be an integer or a real")
if not isinstance(maxValDomain, float) and not isinstance(maxValDomain, int):
errorList.append("max value should be an integer or a real")
if not errorList:
if minValDomain >= maxValDomain:
errorList.append("The max value should be strictly greater than the min value")
if not errorList:
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
criteriaId = PyXMCDA.getCriteriaID(xmltree_criteria)
perfTable = PyXMCDA.getPerformanceTable(xmltree_perfTable, alternativesId, criteriaId)
thresholds = PyXMCDA.getConstantThresholds(xmltree_criteria, criteriaId)
weights = PyXMCDA.getCriterionValue(xmltree_weights, criteriaId)
if not alternativesId:
errorList.append("No alternatives found. Is your alternatives file correct ?")
if not criteriaId:
errorList.append("No criteria found. Is your criteria file correct ?")
if not perfTable:
errorList.append("No performance table found. Is your performance table file correct ?")
if not weights:
errorList.append("No weights found. Is your weights file correct ?")
if not errorList:
# We compute the weight sum (only the weights associated to active criteria)
sumWeights = 0.0
for crit in criteriaId:
try:
sumWeights = sumWeights + weights[crit]
except:
errorList.append("There is no defined weight for criterion " + crit + ".")
if not errorList:
#.........这里部分代码省略.........
示例13: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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] == []:
#.........这里部分代码省略.........
示例14: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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
critAverage = {}
critNormalSD = {}
critTriangSD = {}
# Creating a list for error messages
errorList = []
# If some mandatory input files are missing
if not os.path.isfile (in_dir+"/alternatives.xml") or not os.path.isfile (in_dir+"/criteria.xml") :
errorList.append("Some input files are missing")
else :
# We parse all the mandatory input files
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_criteria = PyXMCDA.parseValidate(in_dir+"/criteria.xml")
# We check if all madatory input files are valid
if xmltree_alternatives == None :
errorList.append("The alternatives file can't be validated.")
if xmltree_criteria == None :
errorList.append("The criteria file can't be validated.")
if not errorList :
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
criteriaId = PyXMCDA.getCriteriaID(xmltree_criteria)
if not alternativesId :
errorList.append("No alternatives found. Is your alternatives file correct ?")
if not criteriaId :
errorList.append("No criteria found. Is your criteria file correct ?")
if not errorList :
# We check if parameters for criteria distribution profile have been provided
if os.path.isfile (in_dir+"/criteriaProfiles.xml") :
xmltree_CritProfile = PyXMCDA.parseValidate(in_dir+"/criteriaProfiles.xml")
if xmltree_CritProfile == None :
errorList.append ("criteriaProfiles file can't be validated.")
else :
critAverage = PyXMCDA.getNamedParametersByName (xmltree_CritProfile, "distributionAverage")
critNormalSD = PyXMCDA.getNamedParametersByName (xmltree_CritProfile, "normalDistributionStandardDeviation")
critTriangSD = PyXMCDA.getNamedParametersByName (xmltree_CritProfile, "triangularDistributionStandardDeviation")
# ...
if not errorList :
# We check if a seed is provided for the random generation
if os.path.isfile (in_dir+"/seed.xml") :
xmltree_seed = PyXMCDA.parseValidate(in_dir+"/seed.xml")
if xmltree_seed == None :
errorList.append ("seed file can't be validated.")
else :
seed = PyXMCDA.getParameterByName (xmltree_seed, "seed")
if not isinstance(seed,int) :
errorList.append ("seed value should be a strictly positive integer")
else :
if seed <= 0 :
errorList.append ("seed should be a strictly positive integer")
else:
# We initialize the random generator
random.seed(seed)
if not errorList :
for i in range(20):
print random.random()
# We recover criteria scale information
criteriaTypes = PyXMCDA.getCriteriaScalesTypes (xmltree_criteria, criteriaId)
criteriaDir = PyXMCDA.getCriteriaPreferenceDirections (xmltree_criteria, criteriaId)
criteriaUB = PyXMCDA.getCriteriaUpperBounds (xmltree_criteria, criteriaId)
criteriaLB = PyXMCDA.getCriteriaLowerBounds (xmltree_criteria, criteriaId)
criteriaRL = PyXMCDA.getCriteriaRankedLabel (xmltree_criteria, criteriaId)
# We add some default lower and upper bounds
for crit in criteriaId :
if not criteriaLB.has_key (crit) or criteriaLB[crit] == None :
if criteriaTypes[crit] == "quantitative" :
criteriaLB[crit] = 0.0
else :
criteriaLB[crit] = 1
if not criteriaUB.has_key (crit) or criteriaUB[crit] == None :
if criteriaTypes[crit] == "quantitative" :
criteriaUB[crit] = 100.0
#.........这里部分代码省略.........
示例15: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import parseValidate [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+"/criteria.xml") or not os.path.isfile (in_dir+"/performanceTable.xml"):
errorList.append("Some input files are missing")
else:
xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
xmltree_criteria = PyXMCDA.parseValidate(in_dir+"/criteria.xml")
xmltree_perfTable = PyXMCDA.parseValidate(in_dir+"/performanceTable.xml")
if xmltree_alternatives == None:
errorList.append("The alternatives file can't be validated.")
if xmltree_criteria == None:
errorList.append("The criteria file can't be validated.")
if xmltree_perfTable == None:
errorList.append("The performance table file can't be validated.")
if not errorList:
alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
criteriaId = PyXMCDA.getCriteriaID(xmltree_criteria)
perfTable = PyXMCDA.getPerformanceTable(xmltree_perfTable, alternativesId, criteriaId)
thresholds = PyXMCDA.getConstantThresholds (xmltree_criteria, criteriaId)
if not alternativesId:
errorList.append("No alternatives found. Is your alternatives file correct ?")
if not criteriaId:
errorList.append("No criteria found. Is your criteria file correct ?")
if not perfTable:
errorList.append("No performance table found. Is your performance table file correct ?")
if not errorList:
ElemOut = PyXMCDA.getRubisElementaryOutranking (alternativesId, criteriaId, perfTable, thresholds)
# Adding thresholds equals to 0 when they are not defined
for crit in criteriaId:
if not thresholds.has_key(crit):
thresholds[crit] = {}
if not thresholds[crit].has_key("indifference"):
thresholds[crit]["indifference"] = 0
if not thresholds[crit].has_key("preference"):
thresholds[crit]["preference"] = 0
# Creating the table for min and max thresholds
thresholdsBounds = {}
for crit in criteriaId:
thresholdsBounds[crit] = {}
thresholdsBounds[crit]["ind"] = {}
thresholdsBounds[crit]["ind"]["min"] = 0.0
thresholdsBounds[crit]["pre"] = {}
thresholdsBounds[crit]["pre"]["min"] = 0.0
for alt1 in alternativesId:
for alt2 in alternativesId:
if alt1 != alt2:
if perfTable[alt1][crit] < perfTable[alt2][crit]:
if ElemOut[alt1][alt2][crit] == 1:
if perfTable[alt2][crit] - perfTable[alt1][crit] > thresholdsBounds[crit]["ind"]["min"]:
thresholdsBounds[crit]["ind"]["min"] = perfTable[alt2][crit] - perfTable[alt1][crit]
if perfTable[alt2][crit] - perfTable[alt1][crit] > thresholdsBounds[crit]["pre"]["min"]:
thresholdsBounds[crit]["pre"]["min"] = perfTable[alt2][crit] - perfTable[alt1][crit]
elif ElemOut[alt1][alt2][crit] == 0.5:
if perfTable[alt2][crit] - perfTable[alt1][crit] > thresholdsBounds[crit]["pre"]["min"]:
thresholdsBounds[crit]["pre"]["min"] = perfTable[alt2][crit] - perfTable[alt1][crit]
if not thresholdsBounds[crit]["ind"].has_key("max") or perfTable[alt2][crit] - perfTable[alt1][crit] < thresholdsBounds[crit]["ind"]["max"]:
thresholdsBounds[crit]["ind"]["max"] = perfTable[alt2][crit] - perfTable[alt1][crit]
else:
if not thresholdsBounds[crit]["ind"].has_key("max") or perfTable[alt2][crit] - perfTable[alt1][crit] < thresholdsBounds[crit]["ind"]["max"]:
thresholdsBounds[crit]["ind"]["max"] = perfTable[alt2][crit] - perfTable[alt1][crit]
if not thresholdsBounds[crit]["pre"].has_key("max") or perfTable[alt2][crit] - perfTable[alt1][crit] < thresholdsBounds[crit]["pre"]["max"]:
thresholdsBounds[crit]["pre"]["max"] = perfTable[alt2][crit] - perfTable[alt1][crit]
# Creating criteriaThresholdsBounds file
fileThresholds = open(out_dir+"/criteriaThresholdsBounds.xml",'w')
PyXMCDA.writeHeader(fileThresholds)
# We write some information about the generated file
fileThresholds.write ("\t<projectReference>\n\t\t<title>Thresholds Sensitivity Analysis (TSA)</title>\n\t\t<version>"+VERSION+"</version>\n\t\t<author>ws_PyXMCDA suite (TV)</author>\n\t</projectReference>\n\n")
# Writing the indLowerBounds
#.........这里部分代码省略.........