2014-11-21 5 views
2

NetLogo 코드를 디버그하려고합니다. 이웃의 확률로부터 목록을 만들고 'reduce'를 사용하여 목록의 모든 값을 함께 곱하려고합니다. 늘어나는만큼 내가 달리 말할 수있는이 실행중인 경우를 제외하고 런타임 오류가 아래와 같습니다.reduce를 사용하여 NetLogo의 목록 곱하기

또한 'let P reduce [? 1 *? 2] prob-list'를 사용하여 시도했지만 동일한 오류가 발생합니다.

참고 Prob_water_water_breaking, Prob_solute_solute_breaking은 '글로벌'로 정의되며 설정에서 특정 품종에 할당됩니다.

* expected input to be a number but got the list [0.3 0.3 0.3] instead. 
error while solute 2 running * 
    called by procedure ALL-PROBABILITIES 
    called by procedure GO 
    called by Button 'go' 

이 어떤 도움이 아주 많이 주시면 감사하겠습니다, 정말 고마워요 :

to-report all-probabilities 
    let prob-list (list ([Prob_water_water_breaking ] of turtles-on neighbors4) 
     ([Prob_solute_solute_breaking ] of turtles-on neighbors4) 
    let P reduce * prob-list ;;this is the line that's causing the error 
    report P 
    end 

이것은 런트시 오류입니다!

답변

2

아! 나는 reduce과 관련된 질문을 좋아합니다. 그러나 귀하의 경우에 문제가있는 라인이다 :

let prob-list (list ([Prob_water_water_breaking ] of turtles-on neighbors4) 
     ([Prob_solute_solute_breaking ] of turtles-on neighbors4) 

당신에게 (그리고 reduce) 숫자의 단일 목록을 기대하고 있지만, prob-list 실제로 목록 숫자의 목록입니다 of 호출 할 때마다 생산 목록이 있으며이 목록은 각각 list으로 작성한 목록의 항목이됩니다. 당신이 함께 귀하의 목록을 연결하는 원하기 때문에

, 당신은 sentence 대신 list 사용할 수 있습니다

let prob-list (sentence ([Prob_water_water_breaking ] of turtles-on neighbors4) 
     ([Prob_solute_solute_breaking ] of turtles-on neighbors4)) 

또 다른 (그리고 아마도 더 나은) 방법을 설명하며, 이러한 문제를 방지하기 위해 of 내부의 첫 번째 곱셈을 수행하는 것입니다 :

let prob-list [ Prob_water_water_breaking * Prob_solute_solute_breaking ] 
    of turtles-on neighbors4 
+0

감사합니다. Nicolas! 그게 문제를 해결했습니다! 도와 주셔서 정말 고맙습니다. –

관련 문제