Ex­plor­ing Soft­ware: Mod­el­ling the Short­age of Change Us­ing Net­l­ogo

Last month we ex­plored Net­l­ogo, the multi-agent pro­gram­ming en­vi­ron­ment which sim­u­lates nat­u­ral and so­cial phe­nom­ena. In this ar­ti­cle, the au­thor skil­fully uses an ex­ist­ing real-world sit­u­a­tion, namely, the short­age of change due to de­mon­eti­sa­tion, to set

OpenSource For You - - Contents - Anil Seth

We have all re­cently ex­pe­ri­enced the short­age of cash or change. Since my ex­pec­ta­tions of the cash avail­abil­ity sit­u­a­tion post de­mon­eti­sa­tion did not turn out to be cor­rect, I wanted to see if a sim­ple model could be cre­ated in Net­l­ogo, to model the short­age of change.

The model

The sim­ple model I chose was as fol­lows:

Our world con­sists of shops, shop­pers, coins and notes. Each note is equal to note-value coins.

There are a fixed num­ber of shops, N_shops, at fixed lo­ca­tions.

Each shop starts with start­ing-change coins.

There are a fixed num­ber of shop­pers, N_shop­pers, who move a step on each tick.

Each per­son starts with no coins but an in­fi­nite num­ber of notes.

If a per­son lands at a shop, (s)he makes a pur­chase of a ran­dom value be­tween 0 and note-value ex­clud­ing the end points.

Each per­son pays with coins if (s)he has enough and does not hold onto them.

Each shop re­turns the change if it has enough, even if the sale is for a small amount.

If nei­ther the shop nor the shop­per has an ad­e­quate num­ber of coins, the sale fails.

You can vary the val­ues of N_shops, N_shop­pers, start­ing-change and note-value to study the rate of failed sales.

The code

The in­ter­face screen is shown in Fig­ure 1. This in­cludes the val­ues you can set for the num­ber of shops and the num­ber of shop­pers in this world. You also con­fig­ure the amount of change each shop has and the num­ber of coins that add up to the value of a note.

You need to de­fine ‘tur­tles’ called shops and shop­pers, and var­i­ous vari­ables for the model. The global vari­ables keep track of the to­tal value of sales, the num­ber of sales and the num­ber of sales that failed be­cause there was no change.

breed [shops shop] breed [shop­pers shop­per] shops-own [shop-coins] shop­pers-own [coins] glob­als [sale no-change count-sales]

The set-up code sets up the shops at non-over­lap­ping lo­ca­tions. Each shop is a square. The shop­pers are cre­ated at ran­dom lo­ca­tions and shaped as dots.

to setup clear-all set sale 0 setup-shops setup-shop­pers re­set-ticks end

to setup-shops

ask n-of N_shops patches [sprout-shops 1 [ set shape "square" set colour grey set pcolor yel­low set shop-coins start­ing-change set no-change 0 set count-sales 0


] end

to setup-shop­pers cre­ate-shop­pers N_shop­pers [ setxy ran­dom-xcor ran­dom-ycor set color blue set shape "dot" set coins 0

] end

The mod­el­ling code runs for 500 ticks. Each shop­per is asked to move for­ward a step and check if there is any shop in that lo­ca­tion. If there is a shop, a sale is at­tempted. The value of each sale is se­lected at ran­dom by a num­ber that ranges be­tween 1 and the note value. If a shop­per has enough coins, (s)he pays with the coins. If (s)he does not have enough coins, (s)he pays with a note and the shop re­turns the change if it has enough coins. The sale fails if that is not pos­si­ble.

to go if ticks >= 500 [ stop ] ask shops [ set color grey ] ask shop­pers [ for­ward 1 if any? shops-here [



] tick end

to make-sale let value max (list 1 ran­dom note-value) ifelse coins >= value

[ set coins coins - value ask shops-here

[ set shop-coins shop-coins + value set color green

] set count-sales count-sales + 1 set sale sale + value


[ ask shops-here

[ ifelse shop-coins >= (note-value - value)

[ set shop-coins shop-coins - (note-value - value) ask my­self [ set coins coins + (note-value - value)] set sale sale + value set count-sales count-sales + 1 set color cyan


[ set no-change no-change + 1

set color red



] end

Dur­ing the run­ning of the model, the in­ter­face shows the fail­ure rate and the rev­enue per sale at­tempted.

Run­ning the model

The ob­jec­tive is to code. But you can ver­ify that some of our in­tu­itive per­cep­tions are rea­son­able. You may choose the num­ber of coins in a note to be 20 (mod­elled on ` 2000/` 100). Let’s sup­pose there are 100 shops and 500 shop­pers, and the shops start out with change of a 100 coins each. We ex­pect that the fail­ure rate will be low. It sta­bilises at about 5 per cent with an av­er­age earn­ing per visit of nine coins. Now let’s sup­pose that the start­ing change of each shop is 20 coins. How badly would the sales be af­fected? In our model, the fail­ure rate reaches over 60 per cent and the av­er­age earn­ings per visit drop to about 3.5 coins.

You can ex­plore and play around with the model.

The key­word ‘ask’ is the crit­i­cal con­struct which al­lows you to code for a spe­cific breed of tur­tles or patches (the lo­ca­tion/co­or­di­nates in our world).

The ‘trick­i­est’ code is the cre­ation of N shops lo­cated ran­domly. In this case, you ask any N patches to ‘sprout’ a shop (ask n of N patches ….).

This is a very use­ful fea­ture if you need to have only a ran­dom sub­set of tur­tles to do some­thing.

The key take­away is that sur­pris­ingly lit­tle code is needed to start ex­plor­ing com­plex phe­nom­ena and un­der­stand the sta­tis­ti­cal im­pli­ca­tions of even sim­ple in­ter­ac­tions.

By: Dr Anil Seth The au­thor has earned the right to do what in­ter­ests him. You can find him on­line at http://sethanil.com and http://sethanil. blogspot.com, and reach him via email at [email protected]

Fig­ure 1: In­ter­face for the de­mon­eti­sa­tion model

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.