Skip to content

Making Connections

isee systems blog

Making Connections

  • About
  • More Connections
Search

New ARRAYRANK Builtin Sorts Array Values

Updated: February 25, 2009February 17, 2009Filed under: STELLA & iThink811 Comments

Version 9.1.2 will introduce the ARRAYRANK feature.  Here is a preview of its capabilities.

The ARRAYRANK built-in can be very powerful for some applications.  It allows you to order the values in an array from smallest to largest or vice-versa.  In this sense, it expands upon what ARRAYMINIDX (find the index of the smallest value) and ARRAYMAXIDX (find the index of the largest value) already do.

To introduce ARRAYRANK, let’s look at a simple model that uses it.  In this model, we explore the efficacy of applying tiered commissions for salespeople in an effort to encourage them to sell more.  Each tier is designed as a reward so the top seller in any given week gets the highest percentage, while those who do not perform will get the lowest.  The tiers are:

Top seller:                    20%
2nd best seller:            15%
3rd best seller:             10%
Everyone else:               5%

Note that the non-tiered system gave everyone 10%.  The model is very simple:

arrayrank-model

As a person’s sales go up, they are paid a higher commission, their morale gets a boost, and they then sell more.  This is a virtuous cycle.  However, as a person’s sales go down, their morale falters, and they sell less.  This is a vicious cycle.  Note that all salespeople start at exactly the same level of morale and, hence, sales.  Observe what happens under the new policy:

arrayrank-graph

It is interesting that within a very short period of time (the simulation runs for one quarter), two people dominate both sales and therefore commissions.  Will this really improve overall sales?  Open the attached model to explore the behavior further (arrayrank-example)

The key variables that make this work are sales ranks, salesperson ranks, and commission.  Their equations, which are applied to all array elements, are:

sales_ranks = ARRAYRANK(sales[*], ARRAYIDX())
salesperson_ranks
= ARRAYRANK(sales_ranks[*], DIMSIZE() - ARRAYIDX() + 1)
commission
= ARRAYVALUE(commissions[*], salesperson_ranks[Salesperson])

ARRAYRANK takes two parameters, the array to rank and which rank is desired.  It evaluates to the index of the element with that ordinal rank from smallest to largest (i.e, in ascending order).  The rank must be between one and the size of the array.  For example,

ARRAYRANK(sales[*], 2)

gives the index of the 2nd smallest element of array sales.  Thus, the formula for sales ranks places the index of the lowest sales figure into its first element, the index of the second lowest sales figure into its second element, and so on up to the index of the highest sales figures in element DIMSIZE().  [Note that ARRAYIDX() in an apply-to-all equation is equal to the numerical index of a given element running from one to DIMSIZE().]

Note, however, that sales ranks does not contain the desired salesperson ranks themselves, which we need to calculate the commissions.  E.g., it does not tell us that the first salesperson is ranked 3rd.  Rather, it contains the indices of the ranked sales figures.  If we examine ARRAYVALUE(sales[*], sales_ranks[1]), we will get the smallest sales figure.  How can we get the salesperson ranks?  Let’s examine this in more detail.

Imagine the sales figures are 2000, 4000, 5000, 3000.  ARRAYRANK on this dataset will return 1, 4, 2, 3.  Using these numbers, we can easily extract the sales figures in ranked order.  But what we really want is the sequence 4, 2, 1, 3.  This sequence tells us that salesperson one had the 4th highest sales, salesperson two had the 2nd highest sales, salesperson three had the highest sales, and salesperson four had the 3rd highest sales.  This allows us to directly extract the commission percentage.  To convert the rankings of sales back to the rankings of the salespersons, we only have to sort the sales rankings.  That is what the equation for salesperson ranks does.

Since we also want the highest, rather than the lowest, sales figure to be ranked one, we do the sort in descending order.  Instead of using ARRAYIDX() for the desired rank, this equation uses DIMSIZE() – ARRAYIDX() + 1, which reverses the rankings.  While ARRAYIDX() counts from one to DIMSIZE() as the array index increases, DIMSIZE() – ARRAYIDX() + 1 counts down from DIMSIZE() to one, reversing the ranks.

Finally, the commission is directly extracted from a table of commissions (stored in an array) using ARRAYVALUE and the salesperson rank.  Note that the array commissions has as many entries as there are salespersons, starts with the highest commission (0.20), and ends with the lowest (0.05).

STELLA & iThink
  • arrays
  • builtins
  • Version 9.1.2

Post navigation

Previous Post:

VSTE 2009 Presentation

Next Post:

A Better Chained Slider

About the Author

Karim Chichakly

Co-President

All posts byKarim ChichaklyWebsite

Hide

Categories

  • Education (4)
  • isee NetSim (3)
  • isee.NET Framework (1)
  • Modeling Tips (32)
  • News & Announcements (15)
  • STELLA & iThink (14)
  • Stories from the Field (5)
  • Systems Thinking (8)
  • Training (6)

Archives

Browse by keyword

2D array archetypes arrays Barry Richmond Bass diffusion builtins calibration Causal Loop CLD command line conferences crisis data diffusion Education environment export game graphical function h1n1 healthcare housing import iThink/STELLA market dynamics MODSIM modules mortgage netsim optimization Physics policy price releases scholarship software spatial Stella storytelling System Dynamics Society Systems Thinking Version 9.1.2 video webinar workshop

Recent Posts

  • COVID-19: Modeling Distributions of Incubation and Recovery Times April 1, 2020
  • Multiobjective Optimization January 9, 2018
  • Optimizing Model Performance December 22, 2017
  • Calibration in Stella® December 15, 2017
  • Drifting Goals March 9, 2016

RSS System Dynamics Forum

Recent Comments

  • best apps review on About
  • digital software on Modeling the Economic Crisis
  • Mishawaka Indiana on What are “Mental Models”?
  • La Paz Indiana on XMILE – An open standard for system dynamics models
  • Bristol Indiana on Modeling the Economic Crisis

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Products
Software (v1.3)
  • Stella Architect
  • Stella Professional
  • Stella Designer
  • Stella Simulator
  • iThink
  • Feature Updates
  • Policies
  • Publishing Options
  • License Agreement
Free Software
  • Stella Online
  • isee Player
  • Stella Architect Trial
Solutions
Consulting
  • Systems Innovation Practice
Common Applications
  • Business
  • Education
  • Research
  • Government
  • Energy
  • Health
  • Agriculture
  • Manufacturing
  • Conservation
Quick Links
About
  • isee systems
  • Systems Thinking
  • Barry Richmond Scholarship
Resources
  • Frequently Asked Questions
  • Product Help
  • Examples
  • Request Support
  • Request Quote
  • Systems in Focus
  • Quick Tips
  • Legacy Tutorials
News and Events
Upcoming Workshops
  • Introduction to Dynamic Modeling
  • Whole Systems Partnership
Newsletter
  • The Connector
Recent Webinars
  • Model Mysteries
Recent Training
  • Systems Thinking Practice
Press Release
  • Stella Architect Release

  Phone: (603) 448-4990   Email: info@iseesystems.com

   Monday - Friday: 9:00 am - 5:00 pm EDT | Saturday - Sunday: Closed
Wheelock Office Park | 31 Old Etna Rd, Suite 7N | Lebanon, NH 03766 | US

isee systems inc. holds registered trademark rights over the following: iThink®, STELLA®, Stella®, isee systems® and claims the following trademarks; isee NetSim™, Stella Live™, Causal Lens™ and Stella Online™.

Terms of Use

© 2017. isee systems inc . All rights reserved.