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


Python PyXMCDA.getRubisElementaryOutranking方法代码示例

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


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

示例1: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import getRubisElementaryOutranking [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

示例2: main

# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import getRubisElementaryOutranking [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
#.........这里部分代码省略.........
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:103,代码来源:thresholdsSensitivityAnalysis.py

示例3: main

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

#.........这里部分代码省略.........
            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)
        # 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
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:70,代码来源:RubisOutrankingRelation.py

示例4: create_ampl_reverse_data

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

#.........这里部分代码省略.........
	file.write("\n")
	for crit in criLB.keys() :
		file.write("s.t. ct_LB_"+crit+"{i in cr_"+crit+"} : sum {k in WEIGHTUNIT} Accumulator[i,k] >= "+str(criLB[crit])+";\n")
	
	
	#Les contraintes du style g_i < upper_bound_i
	file.write("\n")
	for crit in criUB.keys() :
		file.write("s.t. ct_UB_"+crit+"{i in cr_"+crit+"} : sum {k in WEIGHTUNIT} Accumulator[i,k] <= "+str(criUB[crit])+";\n")

	file.write ("\n\n\ndata;\n\n")
	file.write ("set CRITERIA := ")
	for c in critId :
		file.write (c+" ")
	file.write(";\n\nset ALLPAIRS :=\n")
	for a1 in altId :
		for a2 in altId :
			file.write (a1+a2+" ")
		file.write ("\n")
	file.write (";\n\n")

	pairs2 = []
	pairsm2 = []
	pairs1 = []
	pairsm1 = []
	
	tabVeto = PyXMCDA.getVetos (altId, critId, perfTable, thresholds)
	
	for init in altComparisons.keys() :
		for term in altComparisons[init].keys() :
			
			if tabVeto.has_key(init) and tabVeto[init].has_key(term) and not tabVeto[init][term] is None :
				# Veto situation
				continue
				
			if init != term :
				val = altComparisons[init][term]
	
				if val == 2 :
					pairs2.append (""+init+term)
				elif val == -2 :
					pairsm2.append (""+init+term)
				elif val == 1 :
					pairs1.append (""+init+term)
				elif val == -1 :
					pairsm1.append (""+init+term)
		
	file.write ("set ROBUSTPREFPAIRS :=\n")
	
	count = 0
	for pair in pairs2 :
		count = count + 1
		file.write (pair+" ")
		if count == 10 :
			count = 0
			file.write ("\n")
	file.write (";\n\nset ROBUSTnotPREFPAIRS :=\n")
	count = 0
	for pair in pairsm2 :
		count = count + 1
		file.write (pair+" ")
		if count == 10 :
			count = 0
			file.write ("\n")
	file.write (";\n\nset SIMPLEPREFPAIRS :=\n")
	count = 0
	for pair in pairs1 :
		count = count + 1
		file.write (pair+" ")
		if count == 10 :
			count = 0
			file.write ("\n")
	file.write (";\n\nset SIMPLEnotPREFPAIRS :=\n")
	count = 0
	for pair in pairsm1 :
		count = count + 1
		file.write (pair+" ")
		if count == 10 :
			count = 0
			file.write ("\n")
	
	file.write(";\n\n")
		
	
	file.write ("\nparam maxWeight := "+str(maxWeight))
	file.write (";\nparam S : ")
	for c in critId :
		file.write (c+" ")
	file.write (":=\n")
	
	ElemOut = PyXMCDA.getRubisElementaryOutranking (altId, critId, perfTable, thresholds)
	
	for alt1 in altId :
		for alt2 in altId :
			file.write (str(alt1)+str(alt2)+" ")
			for crit in critId :
				file.write (str(ElemOut[alt1][alt2][crit])+" ")						
			
			file.write ("\n")
	file.write(";\n")
开发者ID:quiewbee,项目名称:ws-PyXMCDA,代码行数:104,代码来源:lib_ampl_reverse.py


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