示例#1
0
    def FromAltCrtTable(altCrtMat, crtName):
        epsilon = 1e-307

        crtNames = altCrtMat.CriterionNames()
        altNames = altCrtMat.AlternativeNames()

        crtIdx = crtNames.index(crtName)
        if crtName not in crtNames:
            return None

        cmpTbl = AltCmpTable(crtName, altNames)
        cmpMat = Matrix((len(altNames), len(altNames)))
        valList = [
            altCrtMat.AltCrtValue(altNames.index(altName), crtIdx)
            for altName in altNames
        ]

        for rowIdx in range(len(altNames)):
            for colIdx in range(rowIdx, len(altNames)):
                cmpMat[rowIdx][colIdx] = (valList[rowIdx] + epsilon) / (
                    valList[colIdx] + epsilon)
                cmpMat[colIdx][rowIdx] = 1.0 / (cmpMat[rowIdx][colIdx] +
                                                epsilon)

        cmpTbl.SetComparisonMatrix(cmpMat.arr2d_)
        cmpTbl.CalculateProperties()

        return cmpTbl
示例#2
0
	def _LoadFromDomTree(self, domRoot):
		root  = domRoot.getElementsByTagName(self.altcrtRootTag)[0]
		criteriaNamesNode = root.getElementsByTagName(self.criterionNamesTag)[0]
		
		#解析评价指标名称
		self.crtNames_ = [self._GetText(criterionNameNode.childNodes) 
			for criterionNameNode in criteriaNamesNode.getElementsByTagName(self.criterionNameTag)]
		evalCount = len(self.crtNames_)
		
		#解析评价目标-评价指标矩阵
		altMatrixNode = root.getElementsByTagName(self.matrixTag)[0]
		altNodes = altMatrixNode.getElementsByTagName(self.altTag)
		altCount = len(altNodes)
		
		self.priorities_ = [0.0 for i in range(altCount)]
		self.mat_ = Matrix((altCount, evalCount))
		self.altNames_ = ["" for i in range(altCount)]
		
		#读取矩阵
		i_row = 0
		for altNode in altNodes:
			self.altNames_[i_row] = altNode.getAttribute(self.altNameAttrTag)
			#读取alternative对应每个criteria的值
			for altcrtFactorNode in altNode.getElementsByTagName(self.altcrtFactorTag):
				factor = float(self._GetText(altcrtFactorNode.childNodes))
				altcrtFactorName = altcrtFactorNode.getAttribute(self.altcrtFactorNameAttrTag)
				i_col = self.crtNames_.index(altcrtFactorName)
				self.mat_[i_row][i_col] = factor
			i_row += 1
示例#3
0
	def __init__(self):
		self.altNames_ = []
		self.crtNames_ = []
		self.mat_ = Matrix((0, 0))
		self.priorities_ = []
		self.criteria_ = []
		self.rank2idxDict_ = {}
		self.idx2rankDict_ = {}
		return
示例#4
0
	def RemoveItem(self, itemName):
		try: idx = self.items_.index(itemName)
		except: return
		
		oldSize = len(self.items_)
		newSize = oldSize - 1
		self.items_.remove(itemName)
		if newSize == 0: return
		
		oldSubMatLT = self.mat_.GetSub(0, 0, (idx, idx))
		oldSubMatRT = self.mat_.GetSub(0, idx+1, (idx, oldSize-idx-1))
		oldSubMatLB = self.mat_.GetSub(idx+1, 0, (oldSize-idx-1, idx))
		oldSubMatRB = self.mat_.GetSub(idx+1, idx+1, (oldSize-idx-1, oldSize-idx-1))
		
		self.mat_ = Matrix((newSize, newSize))
		
		self.mat_.SetSub(0, 0, oldSubMatLT)
		self.mat_.SetSub(0, idx, oldSubMatRT)
		self.mat_.SetSub(idx, 0, oldSubMatLB)
		self.mat_.SetSub(idx, idx, oldSubMatRB)
示例#5
0
	def __init__(self, items, RIDict = None):
		"""
		描述:初始化函数。
		参数:
			items:AHP矩阵的要素名称列表
			RIList: 随即一致性指标列表字典
		"""
		self.items_ = items
		matSize = len(items)
		self.mat_ = Matrix((matSize, matSize))
		
		self.propNames_  = ['MaxEigenvalue', 'CI', 'RI', 'CR', 'Consistancy']
		
		self.RIDict_ = RIDict
		if self.RIDict_ == None:
			RIList = [
				0.00, 0.00, 0.58, 0.90, 1.12, #5个一组
				1.24, 1.32, 1.41, 1.46, 1.49,
				1.52, 1.54, 1.56, 1.58, 1.59
				]
			self.RIDict_ = dict([(i+1, RIList[i]) for i in range(len(RIList))])
			
		self._InitializeProperties()
		return
示例#6
0
	def AddItem(self, itemName):
		self.items_.append(itemName)
		oldMat = self.mat_
		self.mat_ = Matrix((len(self.items_), len(self.items_)))
		self.mat_.SetSub(0, 0, oldMat)
		return