Home

Software

Services

Partners

About

Blog

Forio's Forum

Reporting Totals in a Simulation

In Web Sim Building Tools

I promised to explain some of the new features in Broadcast in a series of articles. My favorite new feature in Forio Broadcast solves a real problem, is simple to apply, and I've started using it everywhere. In a nutshell, you can now easily calculate totals in the user interface. If you've struggled with this as much as I have you'll probably be jumping for joy. For the other 90% of you... Feel free to instead browse this fascinating article on historic video games being designated as cultural artifacts.

One of the strengths of the Forio Broadcast approach to simulation design is the strict separation between model and interface. We've worked hard to keep these two parts apart. Conceptually, they contain two different types of content and are often built by different people. The simulation model contains the mathematical logic driving the simulation. It is written using Forio's equation language or imported from third party modeling software. The simulation interface describes the look and the feel of the simulation. It is built with HTML/Flash files that include Forio Macro Language (FML) statements.

Last year we noticed that arrayed simulation models were containing a number of equations that used solely for reporting. Specifically, to view totals for a highly arrayed simulation variable the modeler needs to include a variable for each possible total.

V Sales[Competitors, Regions, Products] = (some equation)

V Total Sales[Competitors] =
FOREACH(c, Competitors, ARRAYSUM(Sales[c, *, *]))

V Sales by Regions[Competitors, Regions] =
FOREACH(c, Competitors, FOREACH(r, Regions, ARRAYSUM(Sales[c, r, *])))

V Sales by Products[Competitors, Products] =
FOREACH(c, Competitors, FOREACH(p, Products, ARRAYSUM(Sales[c, *, p])))

V Industry Sales = ARRAYSUM(Sales)

And this is even worse if you want to compute market share by a particular segment.

V Market Share by Product[Competitors, Products] =
FOREACH(c, Competitors, FOREACH(p, Products, ARRAYSUM(Sales[c, *, p]/ARRAYSUM(Sales[*, *, p])))

A model in which each variable has 3 or 4 subscripts can easily have hundreds of unnecessary equations cluttering up the model and making it difficult to see the true cause and effect.

Our solution is simple. We've added new syntax to FML that provides an easy way to display the total for a variable. Simply use the standard FML to show a model result, but insert an asterisk (*) in place of one or more array elements.

North American Basketball Sales:
$Values.get("Sales[1, North America, Basketball]")

Total North American Sales:
$Values.get("Sales[1, North America, *]")

Total Sales:
$Values.get("Sales[1, *, *]")

will display something similar to:

North American Basketball Sales: $587,101

Total North American Sales: $1,100,233

Total Sales: $3,662,211

All the standard properties of the $Value reference apply. You can build a table of data over time with the getResultFormatted() method. Or use the Result method to access the unformatted number for use in conditional logic:

#if ($Values.get("Sales[1, North America, *]").Result > 1000000)
Your North American sales are
$Values.get("Sales[1, North America, *]").
Good work!
#end

displays

Your North American sales are $1,100,233. Good work!

It was a little trickier to come up with a straightforward way to display market share for a varying number of segments. In the end, we came up with a general syntax for dividing one Value by another. Again, this can be displayed directly or you can append any of the Value properties.

North American Market Share: $Values.get("Sales[1, North America, *]").divide("Sales[*, North America, *]")

Notice how this works. We've added a new method divide that can be appended to the $Value reference. The result is a new Value which is the first variable divided by the second. If competitor 1's sales are half the total sales for North America, the result for the current time step will be .5.

There's one small problem with the above syntax. The number format for the entire expression is the same as the number format for the first expression. If this is zero decimals, then the market share above will be displayed as "1" or "2". What we need to do is to change the number format when displaying this result. There are two ways to do this. The first is using the $Formatter reference (this has been around for a while). The second is a new simpler means of changing the number format -- passing the format in as an argument to $Values.get().

North American Market Share: $Formatter.number($Values.get("Sales[1, North America, *]").divide("Sales[*, North America, *]").Result,'0%')

North American Market Share: $Values.get("Sales[1, North America, *]").divide("Sales[*, North America, *]",'0%')

Incidentally, this new syntax of including the number format as an argument to $Values works with the get method as well.

We've been using this new syntax on a couple of large simulations recently and it's been a big help in simplifying the model and interface.

As always, we would love to hear feedback from you on this update or our platform in general. Feel free to leave comments below or email us at info@forio.com.

Posted by Will Glass

Leave a Reply

  Subscribe with RSS

Join to receive emails when new articles are posted
Email   


Article Categories

User Created Sims Simulations built by Forio Broadcast users

Staff Articles Articles written by Forio staff

News and Links Simulations, news, and links from around the web

Books Books we like about sims, business, and design

Web Sim Building Tools Resources to help you create sims and websites

Contact Forio

© 2008 Forio Corporation