当前位置: 首页>>代码示例>>Python>>正文


Python PyXMCDA.writeErrorMessages方法代码示例

本文整理汇总了Python中PyXMCDA.writeErrorMessages方法的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA.writeErrorMessages方法的具体用法?Python PyXMCDA.writeErrorMessages怎么用?Python PyXMCDA.writeErrorMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyXMCDA的用法示例。


在下文中一共展示了PyXMCDA.writeErrorMessages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_messages_file

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [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)
开发者ID:sbigaret,项目名称:electre_diviz,代码行数:12,代码来源:common.py

示例2: create_error_file

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:8,代码来源:infetribm.py

示例3: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
            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)
            
                L = ['i','p+','p-','j']
            
                fo = open(out_dir+"/clustersRelationsDetailed.xml",'w')
                PyXMCDA.writeHeader(fo)
                fo.write('<categoriesComparisons>\n')
                fo.write('\t<pairs>\n')
                for i in Knames:
                    for j in Knames:
                        fo.write('\t\t<pair>\n')
                        fo.write('\t\t\t<initial>\n')
                        fo.write('\t\t\t\t<categoryID>'+i+'</categoryID>\n')
                        fo.write('\t\t\t</initial>\n')
                        fo.write('\t\t\t<terminal>\n')
                        fo.write('\t\t\t\t<categoryID>'+j+'</categoryID>\n')
                        fo.write('\t\t\t</terminal>\n')
                        fo.write('\t\t\t<values>\n')
                        for l in L:
                            fo.write('\t\t\t\t<value id="'+ l +'">\n')
                            fo.write('\t\t\t\t\t<real>'+str(RKsum[i][j][l])+'</real>\n')
                            fo.write('\t\t\t\t</value>\n')
                        fo.write('\t\t\t</values>\n')
                        fo.write('\t\t</pair>\n')
                fo.write('\t</pairs>\n')
                fo.write('</categoriesComparisons>\n')
                PyXMCDA.writeFooter(fo)
                fo.close()
                
            
        # 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()
开发者ID:aolteanu,项目名称:ws-Mcc,代码行数:104,代码来源:mccClustersRelationSummary.py

示例4: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
				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
				else :
					if criteriaRL.has_key(crit) and criteriaRL[crit] != None :
						criteriaUB[crit] = len(criteriaRL[crit])
					else :
						criteriaUB[crit] = 10
				
		# We construct the performance Tableau
		Tab = {}
		for crit in criteriaId :
			Tab[crit] = {}
			
			if critNormalSD.has_key(crit) :
				sd = critNormalSD[crit]
				if critAverage.has_key(crit) :
					average = critAverage[crit]
				else :
					average = (criteriaLB[crit] + criteriaUB[crit])/2.0
				for alt in alternativesId :			
					temp = criteriaLB[crit] -1
					while temp < criteriaLB[crit] or temp > criteriaUB[crit] :
						temp = random.gauss (average,sd)
					Tab[crit][alt] = temp
					if criteriaTypes[crit] == "qualitative" :
						Tab[crit][alt] = int(Tab[crit][alt])
					
			elif critTriangSD.has_key (crit) :
				for alt in alternativesId :
					# TO BE CHANGED !!!
					Tab[crit][alt] = random.randint (criteriaLB[crit], criteriaUB[crit])
			
			else :
				for alt in alternativesId :
					if criteriaTypes[crit] == "quantitative" :
						Tab[crit][alt] = float(random.randint (criteriaLB[crit]*100, criteriaUB[crit]*100))/100.0
					else :
						Tab[crit][alt] = random.randint (criteriaLB[crit], criteriaUB[crit])
		
		# We construct the performanceTable.xml file
		filePerfTable = open(out_dir+"/performanceTable.xml", 'w')
		PyXMCDA.writeHeader (filePerfTable)
		
		filePerfTable.write ("<performanceTable>\n")
		
		for alt in alternativesId :
			filePerfTable.write ("\t<alternativePerformances>\n\t\t<alternativeID>" + alt + "</alternativeID>\n")
			
			for crit in criteriaId :
				if criteriaTypes[crit] == "quantitative" :
					filePerfTable.write ("\t\t<performance>\n\t\t\t<criterionID>" + crit + "</criterionID>\n\t\t\t<value><real>"+ str(Tab[crit][alt]) + "</real></value>\n\t\t</performance>\n")
				else :
					filePerfTable.write ("\t\t<performance>\n\t\t\t<criterionID>" + crit + "</criterionID>\n\t\t\t<value><integer>"+ str(Tab[crit][alt]) + "</integer></value>\n\t\t</performance>\n")
			
			filePerfTable.write ("\t</alternativePerformances>\n")
		
		filePerfTable.write ("</performanceTable>\n")
		
		PyXMCDA.writeFooter(filePerfTable)
		filePerfTable.close()
	
	# 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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:randomPerformanceTable.py

示例5: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
		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] == []:
					# Tous les surc stables et negatifs, on force la categorie la plus basse
					affectations[alt] = [rankCategories[lowestRank]]

		else:
			errorList.append("Optimistic rule is not taken into account yet")
	
	if not errorList :	
					
		# Creating alternativesAffectations file
		fileAffectations = open(out_dir+"/alternativesAffectations.xml",'w')
		PyXMCDA.writeHeader(fileAffectations)
		
		# We write some information about the generated file
		fileAffectations.write ("\t<projectReference>\n\t\t<title>Stable alternatives affectation</title>\n\t\t<version>"+VERSION+"</version>\n\t\t<author>ws_PyXMCDA suite (TV)</author>\n\t</projectReference>\n\n")
		
		fileAffectations.write("\t<alternativesAffectations>\n")
		
		for alt in alternativesId:
			fileAffectations.write("\t\t<alternativeAffectation>\n\t\t\t<alternativeID>"+alt+"</alternativeID>\n\t\t\t<categoriesSet>\n")
			
			for cat in affectations[alt]:
				fileAffectations.write("\t\t\t\t<element><categoryID>"+cat+"</categoryID></element>\n")

			fileAffectations.write("\t\t\t</categoriesSet>\n\t\t</alternativeAffectation>\n")
		
		fileAffectations.write("\t</alternativesAffectations>\n")
		PyXMCDA.writeFooter(fileAffectations)
		fileAffectations.close()
	
	
	# Creating log and error file, messages.xml
	fileMessages = open(out_dir+"/messages.xml", 'w')
	PyXMCDA.writeHeader (fileMessages)
	
	if not errorList :
		logList.append("Execution ok")
		PyXMCDA.writeLogMessages (fileMessages, logList)
	else :
		PyXMCDA.writeErrorMessages (fileMessages, errorList)
		
	PyXMCDA.writeFooter(fileMessages)
	fileMessages.close()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:stableSorting.py

示例6: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
	(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.")
		
		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 check if a criterion weight is defined for all the active criteria
		for crit in criteriaId :
			if not weights.has_key(crit) :
				errorList.append("There is no defined weight for criterion "+crit+".")
		
		
	if not errorList :
		
		# We compute the weighted sum for all the active alternatives
		fileAltValues = open(out_dir+"/alternativesValues.xml", 'w')
		PyXMCDA.writeHeader (fileAltValues)
		
		fileAltValues.write ("<alternativesValues>\n")
		
		for alt in alternativesId :
		
			fileAltValues.write("<alternativeValue><alternativeID>"+alt+"</alternativeID><value>")
			sum = 0.0
			errorAlt = False
	
			for crit in criteriaId :
				
				try :
					sum = sum + weights[crit] * perfTable[alt][crit]
				except :
					errorList.append("No evaluation found for alternative "+alt+" on criterion "+crit+" in the performance table.")
					errorAlt = True
		
			if not errorAlt :	
				fileAltValues.write ("<real>"+str(sum)+"</real></value></alternativeValue>\n")
			else :
				fileAltValues.write ("<NA>not available</NA></value></alternativeValue>\n")
			
		fileAltValues.write ("</alternativesValues>")
		
		PyXMCDA.writeFooter(fileAltValues)
		fileAltValues.close()
	
	# 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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:weightedSum.py

示例7: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
                                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)
                
            clustersRel = PyXMCDA.getCategoriesComparisonsValues(xmltree_clustersRelations, Knames)
            
            if not clustersRel :
                errorList.append("Problems with clusters relations.")
                
            RK = {}
            for cid1 in Knames:
                RK[cid1] = {}
                for cid2 in Knames:
                    if cid1 == cid2:
                        RK[cid1][cid2] = 'i'
                    else:
                        RK[cid1][cid2] = ''
            missing_eval = False
            for cid1 in Knames:
                for cid2 in Knames:
                    if cid1 != cid2:
                        found = False
                        if cid1 in clustersRel:
                            if cid2 in clustersRel[cid1]:
                                found = True
                                RK[cid1][cid2] = clustersRel[cid1][cid2]
                                if clustersRel[cid1][cid2] == 'p+':
                                    RK[cid2][cid1] = 'p-'
                                elif clustersRel[cid1][cid2] == 'p-':
                                    RK[cid2][cid1] = 'p+'
                                else:
                                    RK[cid2][cid1] = clustersRel[cid1][cid2]
                        if not found and cid2 in clustersRel:
                            if cid1 in clustersRel[cid2]:
                                found = True
                                RK[cid2][cid1] = clustersRel[cid2][cid1]
                                if clustersRel[cid2][cid1] == 'p+':
                                    RK[cid1][cid2] = 'p-'
                                elif clustersRel[cid2][cid1] == 'p-':
                                    RK[cid1][cid2] = 'p+'
                                else:
                                    RK[cid1][cid2] = clustersRel[cid2][cid1]
                        if not found:
                            missing_eval = True
                            break
            if missing_eval:
                errorList.append("Incomplete clusters relations. Each pair needs an evaluation.")


        if not errorList :
            E = MccEval(alternativesId, alternativesRel, Knames, K, RK)
            o_nr,o_r,o_t,o_q = E.GetPerformances()
            
            logList.append("%.2f %% (%d/%d) relations in accordance to the Non-Relational Clustering problematic"%(200*o_nr/len(alternativesId)/(len(alternativesId) - 1),o_nr,len(alternativesId)*(len(alternativesId) - 1)/2))
            logList.append("%.2f %% (%d/%d) relations in accordance to the Relational Clustering problematic"%(200*o_r/len(alternativesId)/(len(alternativesId) - 1),o_r,len(alternativesId)*(len(alternativesId) - 1)/2))
            logList.append("%d cycles detected"%(o_t))
            logList.append("%d relations in discordance to the {p+,p-}-exclusivity property"%(o_q))                    

        if not errorList :
	    # Output results, results.xml
            output = open(out_dir+"/results.xml", 'w')
            PyXMCDA.writeHeader (output)
            PyXMCDA.writeLogMessages (output, logList)
	    PyXMCDA.writeFooter(output)
            output.close()

        # 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()
开发者ID:aolteanu,项目名称:ws-Mcc,代码行数:104,代码来源:mccEvaluateClusters.py

示例8: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
			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
		fileThresholds.write("<criteriaValues mcdaConcept='indLowerBounds'>\n")
		for crit in criteriaId:
			if thresholdsBounds[crit]["ind"].has_key("min"):
				fileThresholds.write("<criterionValue><criterionID>"+crit+"</criterionID><value><real>"+str(thresholdsBounds[crit]["ind"]["min"])+"</real></value></criterionValue>\n")
		fileThresholds.write("</criteriaValues>\n\n")
		
		# Writing the indUpperBounds
		fileThresholds.write("<criteriaValues mcdaConcept='indUpperBounds'>\n")
		for crit in criteriaId:
			if thresholdsBounds[crit]["ind"].has_key("max"):
				fileThresholds.write("<criterionValue><criterionID>"+crit+"</criterionID><value><real>"+str(thresholdsBounds[crit]["ind"]["max"])+"</real></value></criterionValue>\n")
		fileThresholds.write("</criteriaValues>\n\n")
		
		# Writing the indLowerBounds
		fileThresholds.write("<criteriaValues mcdaConcept='prefLowerBounds'>\n")
		for crit in criteriaId:
			if thresholdsBounds[crit]["pre"].has_key("min"):
				fileThresholds.write("<criterionValue><criterionID>"+crit+"</criterionID><value><real>"+str(thresholdsBounds[crit]["pre"]["min"])+"</real></value></criterionValue>\n")
		fileThresholds.write("</criteriaValues>\n\n")
		
		# Writing the preUpperBounds
		fileThresholds.write("<criteriaValues mcdaConcept='prefUpperBounds'>\n")
		for crit in criteriaId:
			if thresholdsBounds[crit]["pre"].has_key("max"):
				fileThresholds.write("<criterionValue><criterionID>"+crit+"</criterionID><value><real>"+str(thresholdsBounds[crit]["pre"]["max"])+"</real></value></criterionValue>\n")
		fileThresholds.write("</criteriaValues>\n\n")
		
		PyXMCDA.writeFooter(fileThresholds)
		fileThresholds.close()
			
	# Creating log and error file, messages.xml
	fileMessages = open(out_dir+"/messages.xml", 'w')
	PyXMCDA.writeHeader (fileMessages)
	
	if not errorList:
		logList.append("Execution ok")
		PyXMCDA.writeLogMessages (fileMessages, logList)
	else:
		PyXMCDA.writeErrorMessages (fileMessages, errorList)
		
	PyXMCDA.writeFooter(fileMessages)
	fileMessages.close()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:thresholdsSensitivityAnalysis.py

示例9: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
		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 :
		
		# We recover the criteria preference directions
		criteriaDir = PyXMCDA.getCriteriaPreferenceDirections (xmltree_criteria, criteriaId)
	
		# We compute the alternative comparisons values
		fileAltValues = open(out_dir+"/alternativesComparisons.xml", 'w')
		PyXMCDA.writeHeader (fileAltValues)
		
		fileAltValues.write ("\t<alternativesComparisons>\n\t\t<pairs>\n")
		
		ElemOut = PyXMCDA.getRubisElementaryOutranking (alternativesId, criteriaId, perfTable, thresholds)
		
		for alt1 in alternativesId :
			for alt2 in alternativesId :
			
				fileAltValues.write("\t\t\t<pair>\n\t\t\t\t<initial><alternativeID>"+alt1+"</alternativeID></initial>\n\t\t\t\t<terminal><alternativeID>"+alt2+"</alternativeID></terminal>\n")
				
				# Verifier s'il manque des valeurs !!! try expect
				#fileAltValues.write ("\t\t\t\t<value><NA>not available</NA></value>\n\t\t\t</pair>\n")
				sum = 0.0
				
				for crit in criteriaId :
					
					sum += ElemOut[alt1][alt2][crit] * weights[crit]
					
				sum = sum/sumWeights
				
				# La valeur est entre 0 et 1, on la met dans le bon intervalle
				sum = (maxValDomain - minValDomain)*sum + minValDomain
				
				fileAltValues.write ("\t\t\t\t<value><real>"+str(sum)+"</real></value>\n\t\t\t</pair>\n")
					
			
		fileAltValues.write ("\t\t</pairs>\n\t</alternativesComparisons>\n")
			
		PyXMCDA.writeFooter(fileAltValues)
		fileAltValues.close()
	
	# 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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:RubisConcordanceRelation.py

示例10: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
    # 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+"/alternativesComparisons.xml"):
            errorList.append("alternativesComparisons.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_alternativesComparisons = PyXMCDA.parseValidate(in_dir+"/alternativesComparisons.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_alternativesComparisons == None :
            errorList.append("alternativesComparisons.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.getAlternativesComparisons (xmltree_alternativesComparisons, alternativesId)
            bipolar = PyXMCDA.getParameterByName(xmltree_methodParameters, "bipolar")
            cutlvl = PyXMCDA.getParameterByName(xmltree_methodParameters, "cutlvl")

            if not alternativesId :
                errorList.append("No active alternatives found.")
            if not alternativesRel :
                errorList.append("Problems between relation and alternatives.")
            if not bipolar:
                errorList.append("No bipolar parameter found.")
            if not cutlvl:
                errorList.append("No cutlvl parameter 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
            if missing_eval:
                errorList.append("Not all alternatives from alternatives.xml contain evaluations in alternativesComparisons.xml. Possible inputs from different sources.")

        if not errorList :
            
            PR = PreferenceRelation(alternativesId, alternativesRel, bipolar, cutlvl)
            R = PR.ExtractR()
            L = ['i','p+','p-','j']
            
            fo = open(out_dir+"/preferenceRelation.xml",'w')
            PyXMCDA.writeHeader(fo)
            fo.write('<alternativesComparisons>\n')
            fo.write('\t<pairs>\n')
            for o in alternativesId:
                for p in alternativesId:
                    fo.write('\t\t<pair>\n')
                    fo.write('\t\t\t<initial>\n')
                    fo.write('\t\t\t\t<alternativeID>'+o+'</alternativeID>\n')
                    fo.write('\t\t\t</initial>\n')
                    fo.write('\t\t\t<terminal>\n')
                    fo.write('\t\t\t\t<alternativeID>'+p+'</alternativeID>\n')
                    fo.write('\t\t\t</terminal>\n')
                    fo.write('\t\t\t<values>\n')
                    for i in range(4):
                        fo.write('\t\t\t\t<value id="'+ L[i] +'">\n')
                        fo.write('\t\t\t\t\t<real>'+str(R[o][p][i])+'</real>\n')
                        fo.write('\t\t\t\t</value>\n')
                    fo.write('\t\t\t</values>\n')
                    fo.write('\t\t</pair>\n')
            fo.write('\t</pairs>\n')
            fo.write('</alternativesComparisons>\n')
            PyXMCDA.writeFooter(fo)
            fo.close()                
            
        # 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()
开发者ID:aolteanu,项目名称:ws-Mcc,代码行数:104,代码来源:mccPreferenceRelation.py

示例11: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........
        # We recover the criteria preference directions
        # criteriaDir = PyXMCDA.getCriteriaPreferenceDirections (xmltree_criteria, criteriaId)
        # Plus necessaire

        # We compute the alternative comparisons values
        fileAltValues = open(out_dir + "/alternativesComparisons.xml", "w")
        PyXMCDA.writeHeader(fileAltValues)

        # We write some information about the generated file
        fileAltValues.write(
            "\t<projectReference>\n\t\t<title>Rubis outranking relation</title>\n\t\t<version>"
            + VERSION
            + "</version>\n\t\t<author>ws_PyXMCDA suite (TV)</author>\n\t</projectReference>\n\n"
        )

        fileAltValues.write("\t<alternativesComparisons>\n\t\t<pairs>\n")

        # ATTENTION Solution rustine
        # On retourne ici le tableau de perf pour les criteres a minimiser
        # Devra etre fait par le getRubisElementaryOutranking
        criteriaDir = PyXMCDA.getCriteriaPreferenceDirections(xmltree_criteria, criteriaId)
        for crit in criteriaId:
            if criteriaDir[crit] == "min":
                for alt in alternativesId:
                    perfTable[alt][crit] = -perfTable[alt][crit]

        ElemOut = PyXMCDA.getRubisElementaryOutranking(alternativesId, criteriaId, perfTable, thresholds)

        tabVetos = PyXMCDA.getVetos(alternativesId, criteriaId, perfTable, thresholds)

        for alt1 in alternativesId:
            for alt2 in alternativesId:

                fileAltValues.write(
                    "\t\t\t<pair>\n\t\t\t\t<initial><alternativeID>"
                    + alt1
                    + "</alternativeID></initial>\n\t\t\t\t<terminal><alternativeID>"
                    + alt2
                    + "</alternativeID></terminal>\n"
                )

                # Verifier s'il manque des valeurs !!! try expect
                # fileAltValues.write ("\t\t\t\t<value><NA>not available</NA></value>\n\t\t\t</pair>\n")
                sum = 0.0
                isVeto = 0
                isWeakVeto = 0

                for crit in criteriaId:

                    sum += ElemOut[alt1][alt2][crit] * weights[crit]

                    # On verifie si un veto est leve
                    if (
                        tabVetos.has_key(alt1)
                        and tabVetos[alt1].has_key(alt2)
                        and tabVetos[alt1][alt2].has_key(crit)
                        and tabVetos[alt1][alt2][crit] == 1
                    ):
                        isVeto = 1

                        # On verifie si un veto faible est leve
                    if (
                        tabVetos.has_key(alt1)
                        and tabVetos[alt1].has_key(alt2)
                        and tabVetos[alt1][alt2].has_key(crit)
                        and tabVetos[alt1][alt2][crit] == 0.5
                    ):
                        isWeakVeto = 1

                sum = sum / sumWeights

                if isVeto == 1:
                    # On utilise le veto classique, qui met la valeur minimale
                    sum = 0.0
                elif isWeakVeto == 1 and sum > 0.5:
                    # Un veto faible est leve
                    sum = 0.5

                    # La valeur est entre 0 et 1, on la met dans le bon intervalle
                sum = (maxValDomain - minValDomain) * sum + minValDomain

                fileAltValues.write("\t\t\t\t<value><real>" + str(sum) + "</real></value>\n\t\t\t</pair>\n")

        fileAltValues.write("\t\t</pairs>\n\t</alternativesComparisons>\n")

        PyXMCDA.writeFooter(fileAltValues)
        fileAltValues.close()

        # 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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:RubisOutrankingRelation.py

示例12: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........

    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')
                fo.write('\t<pairs>\n')
                for i in range(len(K)):
                    for j in range(len(K)):                        
                        fo.write('\t\t<pair>\n')
                        fo.write('\t\t\t<initial>\n')
                        fo.write('\t\t\t\t<categoryID>'+'K'+str(i+1)+'</categoryID>\n')
                        fo.write('\t\t\t</initial>\n')
                        fo.write('\t\t\t<terminal>\n')
                        fo.write('\t\t\t\t<categoryID>'+'K'+str(j+1)+'</categoryID>\n')
                        fo.write('\t\t\t</terminal>\n')
                        fo.write('\t\t\t<value>\n')
                        fo.write('\t\t\t\t<label>'+RK[i][j]+'</label>\n')
                        fo.write('\t\t\t</value>\n')
                        fo.write('\t\t</pair>\n')
                fo.write('\t</pairs>\n')
                fo.write('</categoriesComparisons>')
                PyXMCDA.writeFooter(fo)
                fo.close()                
            
        # 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()
开发者ID:aolteanu,项目名称:ws-Mcc,代码行数:104,代码来源:mccClusters.py

示例13: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [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 os.path.isfile (in_dir+"/alternatives.xml"):
        errorList.append("alternatives.xml is missing")
    if not os.path.isfile (in_dir+"/relation.xml"):
        errorList.append("relation.xml is missing")
    if not os.path.isfile (in_dir+"/parameters.xml"):
        errorList.append("parameters.xml is missing")

    if not errorList:
        # We parse all the mandatory input files
        xmltree_alternatives = PyXMCDA.parseValidate(in_dir+"/alternatives.xml")
        xmltree_relation = PyXMCDA.parseValidate(in_dir+"/relation.xml")
        xmltree_parameters = PyXMCDA.parseValidate(in_dir+"/parameters.xml")
        
        # We check if all madatory input files are valid
        if xmltree_alternatives == None :
            errorList.append("alternatives.xml can't be validated.")
        if xmltree_relation == None :
            errorList.append("relation.xml can't be validated.")
        if xmltree_parameters == None :
            errorList.append("parameters.xml can't be validated.")
            
        if not errorList :

            alternativesId = PyXMCDA.getAlternativesID(xmltree_alternatives)
            alternativesRel = PyXMCDA.getAlternativesComparisons (xmltree_relation, alternativesId)
            relationMin = PyXMCDA.getParameterByName (xmltree_parameters, "min")
            relationMax = PyXMCDA.getParameterByName (xmltree_parameters, "max")
            relationCut = PyXMCDA.getParameterByName (xmltree_parameters, "cut")
            relationBipolar = PyXMCDA.getParameterByName (xmltree_parameters, "bipolar")

            if not alternativesId :
                errorList.append("No active alternatives found.")
            if not alternativesRel :
                errorList.append("Problems between relation and alternatives.")
            if relationMin is None:
                errorList.append("No \'min\' method parameter found")
            if relationMax is None:
                errorList.append("No \'max\' method parameter found")
            if relationCut is None:
                errorList.append("No \'cut\' method parameter found")
            if relationBipolar is None:
                errorList.append("No \'bipolar\' method parameter found")

        if not errorList :
            
            alg = algMccP(alternativesId, alternativesRel, relationMin, relationMax, relationCut, relationBipolar)
            results = alg.Run()
            
            fo = open(out_dir+"/output.xml",'w')
            PyXMCDA.writeHeader(fo)
            fo.write('<alternativesAffectations>\n')
            for o in results:
                fo.write('\t<alternativeAffectation>\n\t\t<alternativeID>'+o+'</alternativeID>\n\t\t\t<categoryID>'+results[o]+'</categoryID>\n\t</alternativeAffectation>\n')
            fo.write('</alternativesAffectations>')
            PyXMCDA.writeFooter(fo)
            fo.close()
            
        # 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()
开发者ID:paterijk,项目名称:MccP,代码行数:88,代码来源:MccP.py

示例14: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [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()
开发者ID:aolteanu,项目名称:ws-Mcc,代码行数:104,代码来源:mccPlotClusters.py

示例15: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import writeErrorMessages [as 别名]

#.........这里部分代码省略.........

    # Creating a list for error messages
    errorList = []

    # If some mandatory input files are missing
    if not os.path.isfile(in_dir + "/nbAlternatives.xml") and not os.path.isfile(in_dir + "/alternativesNames.xml"):
        errorList.append(
            "No parameter has been provided. You should provide a number of alternatives (using nbAlternatives.xml file) or a list of alternatives names (using alternativesNames.xml file)."
        )

    else:

        # User provide a list of alternatives names
        if os.path.isfile(in_dir + "/alternativesNames.xml"):

            # We parse the input file
            xmltree_AltNames = PyXMCDA.parseValidate(in_dir + "/alternativesNames.xml")
            if xmltree_AltNames == None:
                errorList.append("alternativesNames file can't be validated.")

            else:
                # We record the alternatives names in altNames
                altNames = PyXMCDA.getParametersByName(xmltree_AltNames, "alternativesNames")

                if not altNames:
                    errorList.append(
                        "No alternative name has been found in alternativesNames file. Is your file correct ?"
                    )

                    # user provide a number of alternatives
        else:

            # We parse the input file
            xmltree_nbAlt = PyXMCDA.parseValidate(in_dir + "/nbAlternatives.xml")
            if xmltree_nbAlt == None:
                errorList.append("nbAlternatives file can't be validated.")

            else:

                nbAlt = PyXMCDA.getParameterByName(xmltree_nbAlt, "nbAlternatives")

                # We check the validity of the parameter
                if not nbAlt:
                    errorList.append("nbAlternatives parameter not provided. It should be a strict positive integer.")
                if not errorList and not isinstance(nbAlt, int):
                    errorList.append("nbAlternatives value should be a strict positive integer.")
                if not errorList and nbAlt <= 0:
                    errorList.append("nbAlternatives value should be a scrict positive integer.")

                    # We check if a prefix parameter has been provided
                if not errorList:
                    if os.path.isfile(in_dir + "/alternativesPrefix.xml"):
                        xmltree_AltPrefix = PyXMCDA.parseValidate(in_dir + "/alternativesPrefix.xml")
                        if xmltree_AltPrefix == None:
                            errorList.append("alternativesPrefix file can't be validated.")
                        else:
                            altPrefix = PyXMCDA.getParameterByName(xmltree_AltPrefix, "alternativesPrefix")

                            # We check the validity of the parameter
                            if not isinstance(altPrefix, str):
                                errorList.append("alternativesPrefix parameter should be a label")

                    else:
                        # If no prefix has been provided, the alternatives will be called a1, a2, ...
                        altPrefix = "a"

                if not errorList:

                    # We create the altNames list
                    altNames = []
                    for nb in range(nbAlt):
                        altNames.append(altPrefix + str(nb + 1))

    if not errorList:

        # We create the alternatives.xml file
        fileAlt = open(out_dir + "/alternatives.xml", "w")
        PyXMCDA.writeHeader(fileAlt)
        fileAlt.write("<alternatives>\n")

        for alt in altNames:
            fileAlt.write("\t<alternative id='" + alt + "'>\n\t\t<active>true</active>\n\t</alternative>\n")

        fileAlt.write("</alternatives>\n")

        PyXMCDA.writeFooter(fileAlt)
        fileAlt.close()

        # 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()
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:randomAlternatives.py


注:本文中的PyXMCDA.writeErrorMessages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。