如何结合AND命令IF ELSE条件并达到最大值?

问题描述 投票:0回答:1

我的乌龟是公司,他们有一只乌龟,它们是自动化的公司级别。在设置时,此参数是介于0和1之间的随机值。

随后,它与研发投资成比例地增加。它应该上升到0.99,因为达到99%的完全自动化。这就是为什么我增加了一个条件,即公司层面的IFELSE自动化低于1且仍然低于1,以防R&D投资发生,SET与研发投资成比例增长。否则设置为上一轮的水平,因为公司应该停止投资然后将研发投资设置为零。

breed [ firms firm ]


firms-own [   
  firm-level-of-automation    ;; efficiency in automation on the firm level
  r&d-investment   ;; particular share of the total income which is used to invest in R&D
   income   ;; defined value
]

to setup
 ask firms [ 
    set firm-level-of-automation 0 + random-float 1 if firm-level-of-automation > 1 [ set firm-level-of-automation 1 ]   ;; initially random between >0 and <1
    set r&d-investment income * 0.04 ]   ;; R&D investment is a particular share of a firm's income
end

to go  
  tick   
  ask firms [
    ifelse ( firm-level-of-automation < 1 ) AND ( firm-level-of-automation + ( r&d-investment * 0.02 ) < 1 ) [   ;; IF automation on the firm level is below 1 AND still below 1 in case R&D investment would happen
      set firm-level-of-automation firm-level-of-automation + ( r&d-investment * 0.02 ) ]   ;; initially random between >0 and <1 but increases proportionally according to R&D investment
    [ set firm-level-of-automation 0.99 ]
end

到目前为止,我所拥有的代码并没有使公司级别的自动化跳转到0.99。知道最后的研发投资以填补空白会更好。

random netlogo agent-based-modeling economics
1个回答
1
投票

主要的问题是,你没有初始化income的值,而你的Ifelse没问题。如果你不这样做,r&d-investment没有价值,可以通过firm-level-of-automation声明添加到Ifelse。请查看下面的修订代码。添加的行被评论。

breed [ firms firm ]


firms-own [   
  firm-level-of-automation    ;; efficiency in automation on the firm level
  r&d-investment   ;; particular share of the total income which is used to invest in R&D
   income   ;; defined value
]

to setup
  ca ;; ADDED

  create-firms 10 [set color red setxy random-xcor random-ycor set size 2] ;;ADDED, for illustration


 ask firms [ 
    set firm-level-of-automation 0 + random-float 1 if firm-level-of-automation > 1 [ set firm-level-of-automation 1 ]   ;; initially random between >0 and <1
    set income 100  ;; ADDED, needed to be initilaized, otherwise r&d-investment  would remain r&d-investment 0. The value 100 is choosen arbitrarily. 
    set r&d-investment income * 0.04  ;; R&D investment is a particular share of a firm's income

  ]   
  reset-ticks ;; ADDED, otherwise tick counter will not start
end

to go  

  ask firms [
    ifelse ( firm-level-of-automation < 1 ) AND ( firm-level-of-automation + ( r&d-investment * 0.02 ) < 1 ) [   ;; IF automation on the firm level is below 1 AND still below 1 in case R&D investment would happen
      set firm-level-of-automation firm-level-of-automation + ( r&d-investment * 0.02 ) ]   ;; initially random between >0 and <1 but increases proportionally according to R&D investment
    [ set firm-level-of-automation 0.99 ]
  ]

  tick ;; ADDED 
end

这对你有用吗?

© www.soinside.com 2019 - 2024. All rights reserved.