本文整理汇总了Python中PyXMCDA类的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA类的具体用法?Python PyXMCDA怎么用?Python PyXMCDA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyXMCDA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_input_data
def get_input_data(input_dir):
file_names = (
'alternatives.xml',
'method_parameters.xml',
'outranking.xml',
)
trees = get_trees(input_dir, file_names)
alternatives = px.getAlternativesID(trees['alternatives'])
alternatives.sort()
outranking = get_intersection_distillation(trees['outranking'], alternatives)
if outranking == None:
outranking = px.getAlternativesComparisons(trees['outranking'], alternatives)
eliminate_cycles_method = px.getParameterByName(trees['method_parameters'],
'eliminate_cycles_method')
if eliminate_cycles_method not in ['aggregate', 'cut_weakest']:
raise RuntimeError("Invalid/missing method for cycle elimination.")
cut_threshold = px.getParameterByName(trees['method_parameters'], 'cut_threshold')
check_cut_threshold(cut_threshold)
ret = {
'alternatives': alternatives,
'cut_threshold': cut_threshold,
'eliminate_cycles_method': eliminate_cycles_method,
'outranking': outranking,
}
return ret
示例2: writeAlternativeComparision
def writeAlternativeComparision(self, filename, comparisionMx, comparisionType=None):
outfile = open(filename, 'w')
px.writeHeader(outfile)
for key, item in comparisionMx.items() :
if self.criteria.has_key(key.name):
outfile.write('\t<alternativesComparisons mcdaConcept="Pairwise comparison">\n')
if comparisionType != None :
outfile.write("\t\t<comparisonType>%s</comparisonType>\n" % comparisionType)
outfile.write("\t\t<criterionID>%s</criterionID>\n" % key.name)
outfile.write('\t\t<pairs>\n')
for key1, item1 in item.items():
for key2, item2 in item1.items():
outfile.write("""\t\t\t<pair>
<initial>
<alternativeID>%s</alternativeID>
</initial>
<terminal>
<alternativeID>%s</alternativeID>
</terminal>
<value>
<real>%s</real>
</value>
</pair>\n""" % (key1, key2, item2))
outfile.write('\t\t</pairs>\n')
outfile.write('\t</alternativesComparisons>\n')
else:
pass
px.writeFooter(outfile)
outfile.close()
示例3: output_criteria
def output_criteria(filename, criteria_ids, xml_crit):
oldCriteriaIDs = px.getCriteriaID(xml_crit)
trivial = trivialCopy(xml_crit, oldCriteriaIDs)
# critScale = px.getCriteriaScalesTypes(xml_crit, oldCriteriaIDs)
# critThresholds = px.getConstantThresholds(xml_crit, oldCriteriaIDs)
# critPreference = px.getCriteriaPreferenceDirections(xml_crit, oldCriteriaIDs)
outfile = open(filename, "w")
px.writeHeader(outfile)
outfile.write(" <criteria>\n")
for id in sorted(criteria_ids):
oldID = getOriginalName(id)
if not oldID in oldCriteriaIDs:
pass
# outfile.write('''
# <criterion id="%s" name="%s"/>
#''' % (id,id))
else:
# print trivial
# print oldID
outfile.write(
"""
<criterion id="%s" name="%s">\n%s
</criterion>"""
% (id, id, trivial[oldID])
)
outfile.write(" </criteria>\n")
px.writeFooter(outfile)
outfile.close()
示例4: get_credibility
def get_credibility(*args, **kwargs):
alternatives = px.getAlternativesID(trees['alternatives'])
comparison_with = kwargs.get('comparison_with')
if not comparison_with:
comparison_with = px.getParameterByName(
trees['method_parameters'],
'comparison_with',
)
if comparison_with in ('boundary_profiles', 'central_profiles'):
categories_profiles = _get_categories_profiles(
trees['categories_profiles'],
comparison_with,
)
else:
categories_profiles = None
eliminate_cycles_method = px.getParameterByName(
trees.get('method_parameters'),
'eliminate_cycles_method',
)
tree = trees.get('credibility')
if eliminate_cycles_method == 'cut_weakest' and tree is None:
raise InputDataError(
"'cut_weakest' option requires credibility as an additional "
"input (apart from outranking)."
)
credibility = _get_alternatives_comparisons(
tree,
alternatives,
categories_profiles=categories_profiles,
)
return credibility # NoneType, Vividict
示例5: write_xmcda_content
def write_xmcda_content(filename, content=None):
outfile = open(filename, "w")
px.writeHeader(outfile)
if content != None:
outfile.write(content)
px.writeFooter(outfile)
outfile.close()
示例6: get_input_data
def get_input_data(input_dir):
file_names = (
'alternatives.xml',
'concordance.xml',
'method_parameters.xml',
'discordance_binary.xml',
)
trees = get_trees(input_dir, file_names)
alternatives = px.getAlternativesID(trees['alternatives'])
# we can also get alternatives from 'concordance.xml', therefore 'alternatives.xml'
# can be optional - like here:
# alternatives = list(set([i.text for i in trees['concordance'].findall(".//alternativeID")]))
concordance = px.getAlternativesComparisons(trees['concordance'], alternatives)
discordance_binary = px.getAlternativesComparisons(trees['discordance_binary'], alternatives)
cut_threshold = px.getParameterByName(trees['method_parameters'], 'cut_threshold')
check_cut_threshold(cut_threshold)
ret = {
'alternatives': alternatives,
'concordance': concordance,
'cut_threshold': cut_threshold,
'discordance_binary': discordance_binary,
}
return ret
示例7: get_pref_directions
def get_pref_directions(*args, **kwargs):
criteria = px.getCriteriaID(trees['criteria'])
pref_directions = px.getCriteriaPreferenceDirections(
trees['criteria'],
criteria,
)
return pref_directions # dict
示例8: get_discordance
def get_discordance(*args, **kwargs):
alternatives = px.getAlternativesID(trees['alternatives'])
comparison_with = px.getParameterByName(
trees['method_parameters'],
'comparison_with',
)
if kwargs.get('use_partials') is not None:
use_partials = kwargs.get('use_partials')
else:
parameter = px.getParameterByName(
trees['method_parameters'],
'use_partials',
)
use_partials = True if parameter == 'true' else False
if comparison_with in ('boundary_profiles', 'central_profiles'):
categories_profiles = _get_categories_profiles(
trees['categories_profiles'],
comparison_with,
)
else:
categories_profiles = None
discordance = _get_alternatives_comparisons(
trees['discordance'],
alternatives,
categories_profiles=categories_profiles,
use_partials=use_partials,
)
return discordance # Vividict
示例9: get_input_data
def get_input_data(input_dir):
file_names = (
'alternatives.xml',
'categories.xml',
'categoriesProfiles.xml',
'credibility.xml',
'method_parameters.xml',
)
trees = get_trees(input_dir, file_names)
alternatives = px.getAlternativesID(trees['alternatives'])
categories = px.getCategoriesID(trees['categories'])
categories_rank = px.getCategoriesRank(trees['categories'], categories)
categories_profiles = get_categories_profiles_central(trees['categoriesProfiles'])
credibility = getAlternativesComparisons(trees['credibility'], alternatives,
categories_profiles)
cut_threshold = px.getParameterByName(trees['method_parameters'], 'cut_threshold')
check_cut_threshold(cut_threshold)
ret = {
'alternatives': alternatives,
'categories_rank': categories_rank,
'categories_profiles': categories_profiles,
'credibility': credibility,
'cut_threshold': cut_threshold,
}
return ret
示例10: output_criteria
def output_criteria(filename, criteria_ids):
outfile = open(filename, 'w')
px.writeHeader(outfile)
outfile.write(' <criteria>\n')
for id in criteria_ids:
outfile.write(' <criterion id="%s" />\n' % id)
outfile.write(' </criteria>\n')
px.writeFooter(outfile)
outfile.close()
示例11: create_messages_file
def create_messages_file(log_msg, err_msg, out_dir):
with open(os.path.join(out_dir, 'messages.xml'), 'w') as f:
px.writeHeader(f)
if err_msg:
px.writeErrorMessages(f, err_msg)
elif log_msg:
px.writeLogMessages(f, log_msg)
else:
px.writeErrorMessages(f, ('Neither log nor error messages have been supplied.',))
px.writeFooter(f)
示例12: get_weights
def get_weights(*args, **kwargs):
criteria = px.getCriteriaID(trees['criteria'])
if len(criteria) == 0:
msg = (
"File 'criteria.xml' doesn't contain valid data for this "
"method."
)
raise InputDataError(msg)
weights = px.getCriterionValue(trees['weights'], criteria)
return weights # dict
示例13: makeSelection
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')
示例14: get_interactions
def get_interactions(*args, **kwargs):
criteria = px.getCriteriaID(trees['criteria'])
interactions = _get_criteria_interactions(
trees['interactions'],
criteria,
)
return interactions # dict
示例15: output_criteriaValues
def output_criteriaValues(filename, criteria_ids, mcdaConcept, parents):
outfile = open(filename, 'w')
px.writeHeader(outfile)
outfile.write(' <%s>' % mcdaConcept)
outfile.write('''
<description>
<comment>A hierarchy of criteria</comment>
</description>''')
xmlparents = [ xml_value_label % v for v in criteria_ids ]
outfile.write(make_tree('', parents, criteria_ids))
outfile.write('\n </%s>\n' % mcdaConcept)
px.writeFooter(outfile)
outfile.close()