0

我正在使用 R 的 ahp 包(cran.r-project.org/web/packages/ahp)。我用备选方案和标准构建了一个新文档 .ahp

Version: 2.0

#########################
# Alternatives Section
#

Alternatives: &alternatives
# Here, we list all the alternatives, together with their attributes. 

  A:
    hectareas: 1.88
    ninos: 1
    adultos: 12
  B:
    hectareas: 21.06
    ninos: 14
    adultos: 19


#
# End of Alternatives Section
#####################################

#####################################
# Goal Section
#


Goal:
# The goal spans a tree of criteria and the alternatives
  name: Zona Verde
  description: >
    This is a classic single decision maker problem.
  author: unknown
  preferences:
    # preferences are typically defined pairwise
    # 1 means: A is equal to B
    # 9 means: A is highly preferrable to B
    # 1/9 means: B is highly preferrable to A
    pairwise:
      - [hectareas, ninos, 3]
      - [hectareas, adultos, 7]
      - [ninos, adultos, 3]
  children: 
    hectareas:
      preferences:
        pairwise:
          - [A, B, 9]
        children: *alternatives
    ninos: 
      preferences:
        pairwise:
          - [A, B, 1/3]
        children: *alternatives
    adultos: 
      preferences: 
        pairwise:
          - [A, B, 1/4]
        children: *alternatives
#
# End of Goal Section
#####################################

另一个文件是 ahp.R by te libray and analysis

library(ahp)
#list example files provided by the package
list.files(system.file("extdata", package="ahp"))
#zonas verdes example
ahpFile <- system.file("extdata", "zonasverdes.ahp", package="ahp")
zonasverdesAhp <- Load(ahpFile)
Calculate(zonasverdesAhp)
Analyze(zonasverdesAhp)
AnalyzeTable(zonasverdesAhp)

当我运行代码分析AHP结果时出现这个错误:

Error in value[[3L]](cond) : 
  Could not load ahp model. Exception caught when converting into a data.tree: Error in preferences[[type]]: attempt to select less than one element in get1index

不知道是不是缩进的代码有错误,或者是某些函数有错误。

谢谢

4

1 回答 1

0

这是一个关于缩进的问题。在 ahpfile 的第 49、54 和 59 行,您需要减少缩进。像这样:

<code>
  children:
    hectareas:
      preferences:
        pairwise:
          - [A, B, 9]
      children: *alternatives
    ninos:
      preferences:
        pairwise:
          - [A, B, 1/3]
      children: *alternatives
    adultos:
      preferences:
        pairwise:
          - [A, B, 1/4]
      children: *alternatives
</code>
于 2018-06-02T01:20:24.660 回答