本文整理汇总了Python中PyXMCDA.getParametersByName方法的典型用法代码示例。如果您正苦于以下问题:Python PyXMCDA.getParametersByName方法的具体用法?Python PyXMCDA.getParametersByName怎么用?Python PyXMCDA.getParametersByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyXMCDA
的用法示例。
在下文中一共展示了PyXMCDA.getParametersByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import getParametersByName [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 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()
#.........这里部分代码省略.........
示例2: main
# 需要导入模块: import PyXMCDA [as 别名]
# 或者: from PyXMCDA import getParametersByName [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
# Initialising a list of dictionaries for the preferences
prefDir = {}
critType = {}
lowerBound = {}
upperBound = {}
levelNumber = {}
thresholds = {}
# Creating a list for error messages
errorList = []
# If some mandatory input files are missing
if not os.path.isfile (in_dir+"/nbCriteria.xml") and not os.path.isfile (in_dir+"/criteriaNames.xml") :
errorList.append("No parameter has been provided. You should provide a number of criteria (using nbCriteria.xml file) or a list of criteria names (using criteriaNames.xml file).")
else :
# User provides a list of criteria names
if os.path.isfile (in_dir+"/criteriaNames.xml") :
# We parse the input file
xmltree_CritNames = PyXMCDA.parseValidate(in_dir+"/criteriaNames.xml")
if xmltree_CritNames == None :
errorList.append ("criteriaNames file can't be validated.")
else :
# We record the criteria names in critNames
critNames = PyXMCDA.getParametersByName (xmltree_CritNames, "criteriaNames")
if not critNames :
errorList.append ("No criterion name has been found in criteriaNames file. Is your file correct ?")
# User provides a number of criteria
else :
# We parse the input file
xmltree_nbCrit = PyXMCDA.parseValidate(in_dir+"/nbCriteria.xml")
if xmltree_nbCrit == None :
errorList.append ("nbCriteria file can't be validated.")
else :
nbCrit = PyXMCDA.getParameterByName (xmltree_nbCrit, "nbCriteria")
# We check the validity of the parameter
if not nbCrit :
errorList.append ("nbCriteria parameter not provided. It should be a strict positive integer.")
if not errorList and not isinstance(nbCrit,int) :
errorList.append ("nbCriteria value should be a strict positive integer.")
if not errorList and nbCrit <= 0 :
errorList.append ("nbCriteria 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+"/criteriaPrefix.xml") :
xmltree_CritPrefix = PyXMCDA.parseValidate(in_dir+"/criteriaPrefix.xml")
if xmltree_CritPrefix == None :
errorList.append ("criteriaPrefix file can't be validated.")
else :
critPrefix = PyXMCDA.getParameterByName (xmltree_CritPrefix, "criteriaPrefix")
# We check the validity of the parameter
if not isinstance(critPrefix,str) :
errorList.append ("criteriaPrefix parameter should be a label")
else :
# If no prefix has been provided, the criteria will be called g1, g2, ...
critPrefix = "g"
if not errorList :
# We create the critNames list
critNames = []
for nb in range(nbCrit) :
critNames.append(critPrefix+str(nb+1))
if not errorList :
# We check if a seed is provided for the random generation
if os.path.isfile (in_dir+"/seed.xml") :
xmltree_seed = PyXMCDA.parseValidate(in_dir+"/seed.xml")
if xmltree_seed == None :
errorList.append ("seed file can't be validated.")
else :
seed = PyXMCDA.getParameterByName (xmltree_seed, "seed")
#.........这里部分代码省略.........