本文整理汇总了Python中PyXMCDA.writeFooter方法的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA.writeFooter方法的具体用法?Python PyXMCDA.writeFooter怎么用?Python PyXMCDA.writeFooter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyXMCDA
的用法示例。
在下文中一共展示了PyXMCDA.writeFooter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: output_distillation
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def output_distillation(filename, alternativesID, concept="downwars distillation", atCriterion="Root"):
outfile = open(filename, "w")
if compatibleWith2_0_0 != None:
px.writeHeader(outfile, "2.0.0")
else:
px.writeHeader(outfile)
outfile.write(
"\t<description>\n\t\t<comment>%s on criterion: %s</comment>\n\t</description>\n" % (concept, atCriterion)
)
outfile.write(' <alternativesValues mcdaConcept="%s">\n' % concept)
for id, val in sorted(alternativesID.items(), key=lambda alt: alt[1], reverse=True):
# for id, val in criteria_ids.items():
outfile.write(
"""
<alternativeValue>
<alternativeID>%s</alternativeID>
<value>
<real>%s</real>
</value>
</alternativeValue>"""
% (id, val)
)
outfile.write("\n </alternativesValues>\n")
px.writeFooter(outfile)
outfile.close()
示例2: writeAlternativeComparision
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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: write_xmcda_content
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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()
示例5: writeAlternativeComparisionOnCriterion
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def writeAlternativeComparisionOnCriterion(filename, comparisionMx, criterion, comparisionType=None):
compatibleWith2_0_0 = True
outfile = open(filename, 'w')
if compatibleWith2_0_0 :
px.writeHeader(outfile, '2.0.0')
writeCriterion = None
else:
px.writeHeader(outfile)
writeCriterion = criterion #definicja jakiego kryterium dotyczny dane porównanie dopiero w standardzie 2_2_1
#for key, item in comparisionMx.items() :
outfile.write('\t<alternativesComparisons mcdaConcept="Pairwise comparison">\n')
if comparisionType != None :
outfile.write("\t\t<comparisonType>%s</comparisonType>\n" % comparisionType)
if writeCriterion != None:
outfile.write("\t\t<criterionID>%s</criterionID>\n" % writeCriterion)
outfile.write('\t\t<pairs>\n')
for key1, item1 in comparisionMx[criterion].items():
for key2, item2 in item1.items():
outfile.write("""\t\t\t<pair>
<initial>
<alternativeID>%s</alternativeID>
</initial>
<terminal>
<alternativeID>%s</alternativeID>
</terminal>
<value>
%s
</value>
</pair>\n""" % (key1, key2, correctType(item2)))
outfile.write('\t\t</pairs>\n')
outfile.write('\t</alternativesComparisons>\n')
px.writeFooter(outfile)
outfile.close()
示例6: output_criteria
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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()
示例7: create_messages_file
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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)
示例8: output_criteriaValues
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
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()
示例9: output_criteriaValues
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def output_criteriaValues(filename, weights, mcdaConcept):
outfile = open(filename, "w")
px.writeHeader(outfile)
outfile.write(' <criteriaValues mcdaConcept="%s">' % mcdaConcept)
try:
xmlWeights = [xml_value_real % k for v, k in weights.items()]
except ValueError:
xmlWeights = [xml_value_label % k for v, k in weights.items()]
for id, weight in map(None, weights, xmlWeights):
outfile.write(
"""
<criterionValue>
<criterionID>%s</criterionID>
%s
</criterionValue>
"""
% (id, weight)
)
outfile.write(" </criteriaValues>\n")
px.writeFooter(outfile)
outfile.close()
示例10: writeAlternativeComparision
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def writeAlternativeComparision(filename, intersectionMx, comparisionType=None, criterion=None):
compatibleWith2_0_0 = True
outfile = open(filename, "w")
if compatibleWith2_0_0:
px.writeHeader(outfile, "2.0.0")
criterion = None # definicja jakiego kryterium dotyczny dane porwnanie dopiero w standardzie 2_2_1
else:
px.writeHeader(outfile)
outfile.write('\t<alternativesComparisons mcdaConcept="intersection of upwards and downwards distillation ">\n')
if comparisionType != None:
outfile.write("\t\t<comparisonType>%s</comparisonType>\n" % comparisionType)
if criterion != None:
outfile.write("\t\t<criterionID>%s</criterionID>\n" % criterion)
outfile.write("\t\t<pairs>\n")
for key1, item1 in intersectionMx.items():
for key2, item2 in item1.items():
# if item2 == '?' :
# continue
outfile.write(
"""\t\t\t<pair>
<initial>
<alternativeID>%s</alternativeID>
</initial>
<terminal>
<alternativeID>%s</alternativeID>
</terminal>
<value>
%s
</value>
</pair>\n"""
% (key1, key2, correctType(item2))
)
outfile.write("\t\t</pairs>\n")
outfile.write("\t</alternativesComparisons>\n")
px.writeFooter(outfile)
outfile.close()
示例11: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [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')
#.........这里部分代码省略.........
示例12: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
#.........这里部分代码省略.........
criComparisons = {}
if os.path.isfile (in_dir+"/criteriaComparisons.xml") :
xmltree_criComparisons = PyXMCDA.parseValidate(in_dir+"/criteriaComparisons.xml")
if xmltree_criComparisons == None :
errorList.append ("criteriaComparisons file can't be validated")
else :
criComparisons = PyXMCDA.getCriteriaComparisons (xmltree_criComparisons, criteriaId)
criLB = {}
if os.path.isfile (in_dir+"/criteriaLowerBounds.xml") :
xmltree_criLB = PyXMCDA.parseValidate(in_dir+"/criteriaLowerBounds.xml")
if xmltree_criLB == None :
errorList.append ("criteriaLowerBounds file can't be validated")
else :
criLB = PyXMCDA.getCriterionValue (xmltree_criLB, criteriaId)
criUB = {}
if os.path.isfile (in_dir+"/criteriaUpperBounds.xml") :
xmltree_criUB = PyXMCDA.parseValidate(in_dir+"/criteriaUpperBounds.xml")
if xmltree_criUB == None :
errorList.append ("criteriaUpperBounds file can't be validated")
else :
criUB = PyXMCDA.getCriterionValue (xmltree_criUB, 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 altComparisons :
# errorList.append("No alternatives comparisons found. Is your file correct ?")
if not thresholds :
errorList.append("Problem when retrieving the thresholds. The thresholds need to be constant.")
if not errorList :
p = subprocess.Popen(['ampl'], shell=False, bufsize=0,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
# We write in the pipe the first part of the ampl file
file = open ("amplRoadef2010_model.txt", 'r')
p.stdin.write(file.read())
p.stdin.write("\n")
lib_ampl_reverse.create_ampl_reverse_data (p.stdin, alternativesId, criteriaId, perfTable, altComparisons, thresholds, maxWeight, criComparisons, criLB, criUB)
file = open ("amplRoadef2010_solve.txt", 'r')
p.stdin.write(file.read())
p.stdin.write("\n")
p.stdin.flush()
# Calling CPlex for solving MILP
output,stderr = p.communicate()
status = p.returncode
# We check the correct resolution
if status == 0 and not stderr :
if PyXMCDA.getStringPart(output, "nolicense") == "" :
if PyXMCDA.getStringPart(output, "infeasible") != "infeasible" :
# We create the criteriaWeights file
fileWeights = open(out_dir+"/criteriaWeights.xml", 'w')
PyXMCDA.writeHeader (fileWeights)
fileWeights.write (PyXMCDA.getStringPart(output, "criteriaValues"))
logList.append("Execution ok")
logList.append(PyXMCDA.getStringPart(output, "slackSum"))
logList.append(PyXMCDA.getCleanedStringPart(output, "CPLexInfos"))
PyXMCDA.writeFooter(fileWeights)
fileWeights.close()
else :
errorList.append ("Infeasible problem.")
errorList.append (PyXMCDA.getStringPart(output, "CPLexInfos"))
else :
errorList.append ("No license available.")
errorList.append (PyXMCDA.getStringPart(output, "CPLexInfos"))
else :
errorList.append ("CPlex is unable to solve the problem.")
errorList.append ("CPlex returned status : " + str(status))
errorList.append (stderr)
# Creating log and error file, messages.xml
fileMessages = open(out_dir+"/messages.xml", 'w')
PyXMCDA.writeHeader (fileMessages)
if not errorList :
PyXMCDA.writeLogMessages (fileMessages, logList)
else :
PyXMCDA.writeErrorMessages (fileMessages, errorList)
PyXMCDA.writeFooter(fileMessages)
fileMessages.close()
示例13: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
#.........这里部分代码省略.........
for k1 in Knames:
if not (k1 in RKsum):
missing_eval = True
break
else:
for k2 in Knames:
if not (k2 in RKsum[k1]):
missing_eval = True
break
else:
if not ('i' in RKsum[k1][k2]):
missing_eval = True
break
if not ('p+' in RKsum[k1][k2]):
missing_eval = True
break
if not ('p-' in RKsum[k1][k2]):
missing_eval = True
break
if not ('j' in RKsum[k1][k2]):
missing_eval = True
break
if missing_eval:
errorList.append("Incomplete clusters relations summary.")
if not errorList :
PC = PlotClusters(alternativesId, alternativesRel, Knames, K, RK, RKsum)
try:
PC.PlotKideal(out_dir)
fo = open(out_dir+"/Kideal.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<alternativeValue mcdaConcept="Ideal Relations between Clusters">\n')
fo.write('\t<value>\n')
fo.write('\t\t<image>')
fo.write(base64.b64encode(open(out_dir+"/Kideal.png","rb").read()))
fo.write('</image>\n')
fo.write('\t</value>\n')
fo.write('</alternativeValue>\n')
PyXMCDA.writeFooter(fo)
fo.close()
os.remove(out_dir+'/Kideal.png')
PC.PlotKreal(out_dir)
fo = open(out_dir+"/Kreal.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<alternativeValue mcdaConcept="Real Relations between Clusters">\n')
fo.write('\t<value>\n')
fo.write('\t\t<image>')
fo.write(base64.b64encode(open(out_dir+"/Kreal.png","rb").read()))
fo.write('</image>\n')
fo.write('\t</value>\n')
fo.write('</alternativeValue>\n')
PyXMCDA.writeFooter(fo)
fo.close()
os.remove(out_dir+'/Kreal.png')
PC.PlotKidealsum(out_dir)
fo = open(out_dir+"/Kidealsum.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<alternativeValue mcdaConcept="Summary of Ideal Relations between Clusters">\n')
fo.write('\t<value>\n')
fo.write('\t\t<image>')
fo.write(base64.b64encode(open(out_dir+"/Kidealsum.png","rb").read()))
fo.write('</image>\n')
fo.write('\t</value>\n')
fo.write('</alternativeValue>\n')
PyXMCDA.writeFooter(fo)
fo.close()
os.remove(out_dir+'/Kidealsum.png')
PC.PlotKrealsum(out_dir)
fo = open(out_dir+"/Krealsum.xml",'w')
PyXMCDA.writeHeader(fo)
fo.write('<alternativeValue mcdaConcept="Summary of Real Relations between Clusters">\n')
fo.write('\t<value>\n')
fo.write('\t\t<image>')
fo.write(base64.b64encode(open(out_dir+"/Krealsum.png","rb").read()))
fo.write('</image>\n')
fo.write('\t</value>\n')
fo.write('</alternativeValue>\n')
PyXMCDA.writeFooter(fo)
fo.close()
os.remove(out_dir+'/Krealsum.png')
except Exception as e:
import traceback
traceback.print_exc()
errorList.append("Could not plot clusters.")
# Creating log and error file, messages.xml
fileMessages = open(out_dir+"/messages.xml", 'w')
PyXMCDA.writeHeader (fileMessages)
if not errorList :
PyXMCDA.writeLogMessages (fileMessages, ["Execution ok"])
else :
PyXMCDA.writeErrorMessages (fileMessages, errorList)
PyXMCDA.writeFooter(fileMessages)
fileMessages.close()
示例14: create_log_file
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def create_log_file(out_dir, logs):
msgfile = open(out_dir+"/messages.xml", 'w')
PyXMCDA.writeHeader(msgfile)
PyXMCDA.writeLogMessages(msgfile, logs)
PyXMCDA.writeFooter(msgfile)
msgfile.close()
示例15: create_error_file
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeFooter [as 别名]
def create_error_file(out_dir, errors):
msgfile = open(out_dir+"/messages.xml", 'w')
PyXMCDA.writeHeader(msgfile)
PyXMCDA.writeErrorMessages(msgfile, errors)
PyXMCDA.writeFooter(msgfile)
msgfile.close()