以下程序的倒数第八行:
FUNCTION plant_growth, n_months, initial_plants, pick_strategy
N = LONARR(n_months + 1)
M = LONARR(n_months + 1)
N[0] = initial_plants
M[0] = 0
FOR t=0, n_months-1 DO BEGIN
IF t ge 2 THEN M[t] = N[t-2] + M[t-1] - pick_strategy[t]
N[t+1] = N[t] + M[t]
ENDFOR
RETURN, N
END
PRO monte_carlo_simulation, n_months, initial_plants
n_months = 8
initial_plants = 1000
n_simulations = 27933
seed = 0L
best_strategy = LONARR(n_months)
max_final_month_plants = 0
FOR i=0, n_simulations-1 DO BEGIN
pick_strategy = LONARR(n_months)
FOR j=0, n_months-1 DO BEGIN
pick_strategy[j] = FLOOR(RANDOMU(seed)*initial_plants)
ENDFOR
N = plant_growth(n_months, initial_plants, pick_strategy)
final_month_plants = N[n_months]
IF final_month_plants gt max_final_month_plants THEN BEGIN
best_strategy = pick_strategy
max_final_month_plants = final_month_plants
ENDIF
ENDFOR
PRINT, '最优策略是:', best_strategy
PRINT, '最后一月的最大母本数量是:', max_final_month_plants
END
为什么把【gt】替换为【>】后,编译通过,也有结果,但结果不一样?
>
是最大运算符,gt
是“大于”逻辑运算符。例如:
IDL> print, 3 > 5 ; 5 is the maximum of 3 and 5
5
IDL> print, 3 gt 5 ; 3 is not greater than 5, so return false (0)
0