Вопрос

I'm trying to calculate the percentage chance that an event occurs. I've attempted to implement this by creating two globals ("success" and "total"). Whenever the the event occurs the "success" and "total" variables increment and when the event doesn't occur (another occurs instead) only "total" is incremented.

So to get the percentage chance this happens I need to divide the "success" variable by the "total" and multiply by 100. I also want to display this value in a monitor on the user interface so I've created another variable "percentage" to assign the calculation to so that it can be declared in the monitor.

I've created a procedure called calculation and called it in the go procedure, however I'm not sure of the correct syntax to get what I need working. I've added some pseudo code as I believe it should work

to calculate
 set percentage (count success)/(count total)
end
Это было полезно?

Решение

You're really close. count counts the number of agents in an agent set. Since success and total are just numbers, you don't want that. The basic expression you're looking for is 100 * success / total. Next, there's actually no need for the percentage global variable. Instead, you can just make a reporter:

to-report percent-success
  report 100 * success / total
end

Then, in the monitor's "reporter" field, you'd just put percent-success. This field can actually even take reporter expressions, so you could put 100 * success / total straight in there, though using the reporter procedure above is a bit cleaner. Also, you're probably going to want to set the "Decimal places" field to something smaller.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top