;In this version sellers and buyers are assumed to have Cash attribute. Seller's and Buyer's Cash will accumulate overtime as a result of the trading process. ;The number of daily supply and demand within the system is assumed to be constant ;This model used three types of agents. breed [ markets market ] ;Acts as facilitators in the interaction between the sellers and the buyers. breed [ sellers seller] ;Acts as commodities providers breed [ buyers buyer] ;Acts as commodities consumers globals [ ;List of global variables list-market ;Global vector consists of identities of all involving market total-init-stock-dist-score ;The sum of init-distribution-score of all sellers total-init-demand-dist-score ;The sum of init-distribution-score of all buyers remaining-stock ;The stock surplus or deficit after the first distribution remaining-demand ;The demand surplus or deficit after the first distribution total-sales ;the amount of commodities sold in the given day total-transaction ;the value of total transaction in the given day avg-price ;the average market price in the given day list-restocking-seller ;vector of seller who restocking their stock, in unsorted order list-restocking-seller-rp ;vector reservation price of restocking seller, in unsorted order list-restocking-seller-sort ;vector of seller who restocking their stock, sorted based on ext reservation price, from the highest to the lowest list-restocking-seller-rp-sort ;vector reservation price of restocking seller, sorted based on ext reservation price, from the highest to the lowest ext-agreed-price ;the mid point of the seller & the buyer reservation price and external market reservation price total-max-ext-demand ;total demand from the external market that can be handled by all buyer num-day experiment avg-price-experiment ;vector that store the average prices from one experiment avg-price-all-experiment ;vector that store the average prices from all experiment avg-price-day-experiment ;vector that store the average prices from all day in experiment j avg-price-day-all-experiment ;vector that store the average prices in day i from all experiment mean-avg-price ;the mean of avg price in day i from all experiments med-avg-price ;the median of avg price in day i from all experiments min-avg-price ;the minimum of avg price in day i from all experiments min-min-avg-price ;the minimum from all minimum average price from all day max-avg-price ;the maximum of avg price in day i from all experiments max-max-avg-price ;the minimum from all minimum average price from all day Q1-avg-price Q3-avg-price total-sales-experiment ;vector that store the total price from one experiment total-sales-all-experiment ;vector that store the total price from all experiment min-min-total-sales ;the minimum from all minimum average price from all day max-max-total-sales ;the maximum from all maximum average price from all day total-sales-day-all-experiment ;vector that store the total sales in day i from all experiment total-sales-day-experiment ;vector that store the total sales from all day in experiment j mean-total-sales ;the mean of total sales in day i from all experiments med-total-sales ;the median of total sales in day i from all experiments Q1-total-sales Q3-total-sales min-total-sales ;the minimum of total sales in day i from all experiments max-total-sales ;the minimum of total sales in day i from all experiments max-buyer-cash-all-experiment ;the maximum value of buyer cash from all experiment, will be used to calculate the highest class boundary max-seller-cash-all-experiment ;the maximum value of seller cash from all experiment, will be used to calculate the highest class boundary min-buyer-cash-all-experiment ;the maximum value of buyer cash from all experiment, will be used to calculate the lowest class boundary min-seller-cash-all-experiment ;the maximum value of seller cash from all experiment, will be used to calculate the lowest class boundary up-buyer-calss-1 ;upper class 1 boundary for buyer cash up-buyer-calss-2 ;upper class 2 boundary for buyer cash up-buyer-calss-3 ;upper class 3 boundary for buyer cash up-buyer-calss-4 ;upper class 4 boundary for buyer cash up-buyer-calss-5 ;upper class 5 boundary for buyer cash up-seller-calss-1 ;upper class 1 boundary for seller cash up-seller-calss-2 ;upper class 2 boundary for seller cash up-seller-calss-3 ;upper class 3 boundary for seller cash up-seller-calss-4 ;upper class 4 boundary for seller cash up-seller-calss-5 ;upper class 5 boundary for seller cash class-range-buyer-cash ;range of buyer cash range class-range-seller-cash ;range of selle cash range freq-class1-buyer ;frequency in calss 1 of buyer cash in one experiment freq-class2-buyer ;frequency in calss 2 of buyer cash in one experiment freq-class3-buyer ;frequency in calss 3 of buyer cash in one experiment freq-class4-buyer ;frequency in calss 4 of buyer cash in one experiment freq-class5-buyer ;frequency in calss 5 of buyer cash in one experiment freq-class1-buyer-all-experiment ;frequency in calss 1 of buyer cash from all experiment freq-class2-buyer-all-experiment ;frequency in calss 2 of buyer cash from all experiment freq-class3-buyer-all-experiment ;frequency in calss 3 of buyer cash from all experiment freq-class4-buyer-all-experiment ;frequency in calss 4 of buyer cash from all experiment freq-class5-buyer-all-experiment ;frequency in calss 5 of buyer cash from all experiment freq-class1-seller-all-experiment ;frequency in calss 1 of seller cash from all experiment freq-class2-seller-all-experiment ;frequency in calss 2 of seller cash from all experiment freq-class3-seller-all-experiment ;frequency in calss 3 of seller cash from all experiment freq-class4-seller-all-experiment ;frequency in calss 4 of seller cash from all experiment freq-class5-seller-all-experiment ;frequency in calss 5 of seller cash from all experiment freq-class1-seller ;frequency in calss 1 of seller cash in one experiment freq-class2-seller ;frequency in calss 2 of seller cash in one experiment freq-class3-seller ;frequency in calss 3 of seller cash in one experiment freq-class4-seller ;frequency in calss 4 of seller cash in one experiment freq-class5-seller ;frequency in calss 5 of seller cash in one experiment total-seller-init-cash total-buyer-init-cash average-seller-daily-profit average-buyer-daily-profit ] markets-own [ ;List of market attributes list-seller ;Vector consists of all sellers connected to each market list-buyer ;Vector consists of all buyers connected to each market list-part-seller ;Vector consists of sellers who will participate in current day trading, in unsorted order list-part-seller-stock ;Vector consists of the value of stock owned by sellers that participate in current day trading, in unsorted order list-part-seller-rp ;Vector consists of the value of reservation price owned by sellers that participate in current day trading, in unsorted order list-part-seller-sort ;Vector consists of sellers who will participate in current day trading, sorted based on reservation price, from the lowest to the highest list-part-seller-stock-sort ;Vector consists of the value of stock owned by sellers that participate in current day trading, sorted based on reservation price, from the lowest to the highest list-part-seller-rp-sort ;Vector consists of the value of reservation price owned by sellers that participate in current day trading, sorted based on reservation price, from the lowest to the highest list-part-buyer ;Vector consists of buyers who will participate in current day trading, in unsorted order list-part-buyer-demand ;Vector consists of the value of demand owned by buyers that participate in current day trading, in unsorted order list-part-buyer-rp ;Vector consists of the value of reservation price owned by buyers that participate in current day trading, in unsorted order list-part-buyer-cash ;Vector consists of the value of cash owned by buyers that participate in current day trading, in unsorted order list-part-buyer-sort ;Vector consists of buyers who participating in current day trading, sorted based on reservation price, from the highest to the lowest list-part-buyer-demand-sort ;Vector consists of buyer's demand who participating in current day trading, sorted based on reservation price, from the highest to the lowest list-part-buyer-rp-sort ;Vector consists of buyer's reservation price who participating in current day trading, sorted based on reservation price, from the highest to the lowest list-part-buyer-cash-sort ;Vector consists of buyer's cash who participating in current day trading, sorted based on reservation price, from the highest to the lowest seller-stock ;Stock of transacting seller seller-rp ;Reservation price of transacting seller buyer-demand ;Demand of transacting buyer buyer-rp ;reservation price of transacting buyer buyer-cash ;cash of transacting buyer agreed-price ;the mid point of seller's and buyer's reservation price ] sellers-own [ ;List of sellers attributes res-price ;The lowest price at which a seller still willing to sell his/her commodity to the buyer stock ;The number of commodities owned by a seller in each day init-distribution-score ;Score that will determine the proportion of each seller's stock in stock initiation procedure cash ;The amount of money owned by the seller ext-res-price ;Sellers reservation price when transacting with external market in order to get new stock req-stock ;The maximum number of new stock that can be bought by the seller to refill their stock transaction ;the number of commodities sold in each day ] buyers-own [ ;List of buyers attributes res-price ;The highest price at which a buyer still willing to buy demand ;The number of commodities wanted by a buyer in each day init-distribution-score ;Score that will determine the proportion of each buyer's demand in demand initiation procedure cash ;The amount of money owned by the buyer available-market ;Vector consists of markets at which there are sellers that offer their commodity rp-in-market ;Vector consists of the lowest seller's reservation price in the available markets transaction ;the number of commodities bought in each day ext-res-price ;buyers reservation price when transacting with external stock-to-resell ;the number of commodities that can be resell by a buyer, represents the demand that can be met max-ext-demand ;the maximum demand from the external market that can be handle by a buyer, considering their cash and ext-res-price (represents cost) ] to setup ;This procedure aims to generate the agents and to initiate their attributes. clear-all generate-agents init-agent-network init-agent-rp init-seller-supply init-buyer-demand init-agent-cash set total-seller-init-cash sum [cash] of sellers set total-buyer-init-cash sum [cash] of buyers set experiment 0 set avg-price-all-experiment [] set total-sales-all-experiment [] set max-buyer-cash-all-experiment 0 set max-seller-cash-all-experiment 0 set min-buyer-cash-all-experiment 1000000000 set min-seller-cash-all-experiment 1000000000 end to begin while [experiment < num-experiment][ set num-day 0 set avg-price-experiment [] set total-sales-experiment [] while [num-day < 30][ set total-sales 0 set total-transaction 0 agent-reset-transaction-and-ext-res-price market-list-participating-seller market-sort-list-participating-seller market-make-trade ifelse total-sales > 0 [set avg-price total-transaction / total-sales][set avg-price 0] agent-calculate-ext-rest-price seller-redistribute-supply buyer-redistribute-demand set avg-price-experiment lput avg-price avg-price-experiment set total-sales-experiment lput total-sales total-sales-experiment set num-day num-day + 1 ] set avg-price-all-experiment lput avg-price-experiment avg-price-all-experiment set total-sales-all-experiment lput total-sales-experiment total-sales-all-experiment set-cash-data-range save-cash-data ;procedure to save the value of agent's cash to text set experiment experiment + 1 ] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;set average-seller-daily-profit ( sum [cash] of sellers - total-seller-init-cash ) / ( 30 * num-seller) ;set average-buyer-daily-profit (sum [cash] of buyers - total-buyer-init-cash ) / ( 30 * num-buyer) calculate-class-boundaries calculate-buyer-cash-frequency calculate-seller-cash-frequency update-plot file-delete "buyer-cash.txt" file-delete "seller-cash.txt" end to generate-agents ;This procedure aims to genarate agents according to the input sliders ask n-of num-market patches [ sprout-markets 1] ask markets [ set shape "square" set color yellow] ;The market agent is indicated by yellow square ask n-of num-seller patches [sprout-sellers 1] ask sellers [ set shape "circle" set color red] ;The seller agent is indicated by red circle ask n-of num-buyer patches [sprout-buyers 1] ask buyers [set shape "circle" set color blue] ;The buyer agent is inidicated by blue circle end to init-agent-network ;This procedure aims to initiate agents network set list-market [] ask markets [ set list-market lput self list-market ;The market listed list-market vector set list-seller [] ;List-seller vector first initiated as vector with zero element set list-buyer [] ;List-buyer vector first initiated as vector with zero element ] ;Each Seller is listed to list-seller vector owned by one of the market. ;It is assumed that seller will interact locally, i.e. each of them is only connected to one market. ;When the number of market agent is > 1, each seller is randomly connected to one market agent. ask sellers [ let i random count markets ask market i [ set list-seller lput myself list-seller] ] ;!!!Bugs: When the number of seller is small enaough there is probability that this procedure produce markets with empty list-seller vector ;Each Buyer is listed to list-buyer vector owned by one of the market ;The buyer is assumed to be able to interact globally, i.e. they may have conection to more than one market. ;When the number of market agent is > 1, buyer can be assumed to have access to all markets, or ;can be assumed to have access to several market only (in this condition a buyer have 50% probability to have connection to a market) If (buyer-access = "all markets")[ ask buyers [ let i 0 while [i < count markets ][ ask market i [ set list-buyer lput myself list-buyer] set i i + 1 ] ] ] If (buyer-access = "some markets")[ ask markets [ let i num-market + num-seller while [ i < num-market + num-seller + num-buyer][ if random 2 = 1 [ set list-buyer lput buyer i list-buyer ] set i i + 1 ] ] ] ;!!!Bugs: When the number of buyer is small enaough there is probability that this procedure produce markets with empty list-buyer vector end to init-agent-rp ;This procedure aims to initiate sellers and buyers reservation price ask sellers [ set res-price init-min-seller-rp + random ( init-max-seller-rp - init-min-seller-rp ) ] ask buyers [ set res-price init-min-buyer-rp + random ( init-max-buyer-rp - init-min-buyer-rp ) ] end to init-seller-supply ;This procedure aims to initiate sellers supply. In this simulation, seller's supply can be initiated equally, or randomly ;When initiated equally each seller will start with almost same number of supply If (init-stock-distribution ="equally")[ ask sellers [ set stock floor (total-daily-supply / num-seller) ] set remaining-stock total-daily-supply - sum [stock] of sellers ask n-of remaining-stock sellers [ set stock stock + 1] ] ;While when initiated randomly each seller will start with various number of supply but, none of them will have zero stock If (init-stock-distribution ="randomly")[ ask sellers [ set init-distribution-score 1 + random 100 ] ;Each seller generate a random number from 1 - 100 to determine the proportion of their stock set total-init-stock-dist-score sum [init-distribution-score] of sellers ask sellers [ set stock ceiling ((init-distribution-score / total-init-stock-dist-score) * total-daily-supply)] ;Will produce total init stock that is greater than total daily supply set remaining-stock total-daily-supply - sum [stock] of sellers ;negative remaining stock inidicate the number stock that must be excluded from the initiation while [remaining-stock < 0][ ;until the surplus become zero, deduct one stock from random seller whose stock > 1 ask (one-of sellers with [stock > 1])[ set stock stock - 1] set remaining-stock remaining-stock + 1 ] ] end to init-buyer-demand ;This procedure aims to initiate buyers demand. In this simulation, demand's supply can be initiated equally, or randomly ;When initiated equally each buyer will start with almost same number of demand If (init-demand-distribution ="equally")[ ask buyers [ set demand floor (total-daily-demand / num-buyer) ] set remaining-demand total-daily-demand - sum [demand] of buyers ask n-of remaining-demand buyers [ set demand demand + 1] ] ;While when initiated randomly each buyer will start with various number of demand but, none of them will have zero demand If (init-demand-distribution ="randomly")[ ask buyers [ set init-distribution-score 1 + random 100 ] ;Each buyer generate a random number from 1 - 100 to determine the proportion of their demand set total-init-demand-dist-score sum [init-distribution-score] of buyers ask buyers [ set demand ceiling ((init-distribution-score / total-init-demand-dist-score) * total-daily-demand)] ;Will produce total init demand that is greater than total daily demand set remaining-demand total-daily-demand - sum [demand] of buyers ;negative remaining demand inidicate the number demand that must be excluded from the initiation while [remaining-demand < 0][ ;until the surplus become zero, deduct one stock from random seller whose stock > 1 ask (one-of buyers with [demand > 1])[ set demand demand - 1] set remaining-demand remaining-demand + 1 ] ] end to init-agent-cash ;Buyer's cash is initiated so that they can afford all of their demand under their initial reservation price ask buyers [ set cash res-price * demand ] ;Seller's cash is initiated as zero, assuming they invest all of their money in the commodities that being sold ask sellers [ set cash 0 ] end to market-list-participating-seller ;The indetity, the stock and reservation price of sellers that participate in the current day trading are listed by the market ;All sellers with stock > 0 are assumed to participate in the trading in the given day ask markets [ set list-part-seller [] set list-part-seller-stock [] set list-part-seller-rp [] let i 0 while [i < length list-seller][ ;If in the current day seller i have commodities to sale (stock > 0) ;The the given seller's identity, stock and res-price are listed by the market if [stock] of item i list-seller > 0 [ set list-part-seller lput item i list-seller list-part-seller set list-part-seller-stock lput [stock] of item i list-seller list-part-seller-stock set list-part-seller-rp lput [res-price] of item i list-seller list-part-seller-rp ] set i i + 1 ] ] end to market-sort-list-participating-seller ;Asumming that buyers will always try to find seller with the lowest price, all participating sellers are then sorted based on their reservation price, from the lowest to the highest ask markets [ set list-part-seller-sort [] set list-part-seller-stock-sort [] set list-part-seller-rp-sort [] ;As long as there is elements in list-part-seller vector, the market will search for seller with the lowest reservation price ;Smallest available index in the sorted vector is the given to the seller's identity, stock and reservation price ;The given seller, and its attributes are then removed from the unsorted vectors while [length list-part-seller > 0][ let i position ( min list-part-seller-rp) list-part-seller-rp set list-part-seller-sort lput item i list-part-seller list-part-seller-sort set list-part-seller-stock-sort lput item i list-part-seller-stock list-part-seller-stock-sort set list-part-seller-rp-sort lput item i list-part-seller-rp list-part-seller-rp-sort set list-part-seller remove-item i list-part-seller set list-part-seller-stock remove-item i list-part-seller-stock set list-part-seller-rp remove-item i list-part-seller-rp ] ] end to market-make-trade ;This procedure is executed as long as there are still any seller any buyers that participating in trading while [sum [length list-part-seller-sort] of markets > 0][ ;indicate that there is sellers in the market ;The buyers create vector to store information from the markets ask buyers [ set available-market [] ;Buyer set available-market & rp-in-market vectors empty to receive information from the markets set rp-in-market [] ] ;The market create vector consists of the attributes of buyers that will participate in the trading ask markets [ set list-part-buyer [] set list-part-buyer-demand [] set list-part-buyer-rp [] set list-part-buyer-cash [] ] ;Market sent price information to buyers within its network ask markets with [length list-part-seller-sort > 0][ let i 0 while [ i < length list-buyer ][ if random 100 < information [ ;With probability of information, the buyer will recieve information from the market ask item i list-buyer [ if ([item 0 list-part-seller-rp-sort] of myself <= res-price) and demand > 0 and cash > 0 [ ;If the given buyer's demand > 0 and the received price information is lower than buyer's reservation price set available-market lput myself available-market ;The buyer will then add the information about the market and the price offered in that market in their memory set rp-in-market lput [item 0 list-part-seller-rp-sort] of myself rp-in-market ] ] ] set i i + 1 ] ] ;Buyer choose market that offer the lowest price ask buyers with [length available-market > 0][ let j position (min rp-in-market) rp-in-market ask item j available-market [ set list-part-buyer lput myself list-part-buyer set list-part-buyer-demand lput [demand] of myself list-part-buyer-demand set list-part-buyer-rp lput [res-price] of myself list-part-buyer-rp set list-part-buyer-cash lput [cash] of myself list-part-buyer-cash ] ] ;Market check wheter there are any buyer that participate in the trading ;If there are no buyer that participate in the trading, then the iteration is terminated if sum [length list-part-buyer] of markets <= 0[ ask markets [ set list-part-seller-sort [] ] ] ;Assuming that each seller always try to sell to the buyer with the highest offer, ;market will then sort the buyer based on their reservation price, from the highest to the lowest ask markets [ set list-part-buyer-sort [] set list-part-buyer-demand-sort [] set list-part-buyer-rp-sort [] set list-part-buyer-cash-sort [] while [length list-part-buyer > 0][ let k position (max list-part-buyer-rp) list-part-buyer-rp set list-part-buyer-sort lput item k list-part-buyer list-part-buyer-sort set list-part-buyer-demand-sort lput item k list-part-buyer-demand list-part-buyer-demand-sort set list-part-buyer-rp-sort lput item k list-part-buyer-rp list-part-buyer-rp-sort set list-part-buyer-cash-sort lput item k list-part-buyer-cash list-part-buyer-cash-sort set list-part-buyer remove-item k list-part-buyer set list-part-buyer-demand remove-item k list-part-buyer-demand set list-part-buyer-rp remove-item k list-part-buyer-rp set list-part-buyer-cash remove-item k list-part-buyer-cash ] ] ;The market pair seller with the buyers starting from the buyer with the highest reservation price ask markets with [length list-part-buyer-sort > 0][ set seller-stock item 0 list-part-seller-stock-sort set seller-rp item 0 list-part-seller-rp-sort let l 0 ;index of buyers in list-part-buyer-sort while [(seller-stock > 0) and (l < length list-part-buyer-sort)][ set buyer-demand item l list-part-buyer-demand-sort set buyer-rp item l list-part-buyer-rp-sort set buyer-cash item l list-part-buyer-cash-sort set agreed-price (seller-rp + buyer-rp) / 2 ifelse (seller-stock <= min (list (buyer-demand) (buyer-cash / agreed-price)) ) [ set total-sales total-sales + seller-stock set total-transaction total-transaction + (agreed-price * seller-stock) ask item 0 list-part-seller-sort [ set stock stock - [seller-stock] of myself ;the seller's stock become zero set transaction transaction + [seller-stock] of myself set cash cash + ([seller-stock] of myself * [agreed-price] of myself) ;the seller's cash increased by the transaction value between the buyer and seller set ext-res-price ext-res-price + ([agreed-price] of myself * [seller-stock] of myself) ] ask item l list-part-buyer-sort [ set demand demand - [seller-stock] of myself ;the buyer's demand is decreased by the number of seller stock set transaction transaction + [seller-stock] of myself set stock-to-resell stock-to-resell + [seller-stock] of myself set cash cash - ([seller-stock] of myself * [agreed-price] of myself) ;the buyer's cash is decreased by transaction value between the buyer and seller set ext-res-price ext-res-price + ( [seller-stock] of myself * [agreed-price] of myself ) ] set buyer-demand buyer-demand - seller-stock set seller-stock 0 set list-part-buyer-demand-sort replace-item l list-part-buyer-demand-sort buyer-demand set list-part-seller-stock-sort replace-item 0 list-part-seller-stock-sort seller-stock ][ set total-sales total-sales + min (list (buyer-demand) (buyer-cash / agreed-price)) set total-transaction total-transaction + (agreed-price * min (list (buyer-demand) (buyer-cash / agreed-price))) ask item l list-part-buyer-sort [ set demand demand - [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself ;the buyers's demand become zero set transaction transaction + [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself set stock-to-resell stock-to-resell + [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself set cash cash - ([min (list (buyer-demand) (buyer-cash / agreed-price))] of myself * [agreed-price] of myself) ;the buyers's cash decreased by the transaction value between the buyer and seller set ext-res-price ext-res-price + [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself * [agreed-price] of myself ] ask item 0 list-part-seller-sort [ set stock stock - [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself ;the seller's stock is decreased by the number of buyer demand set transaction transaction + [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself set cash cash + ([min (list (buyer-demand) (buyer-cash / agreed-price))] of myself * [agreed-price] of myself) ;the seller's cash is increased by transaction value between the buyer and seller set ext-res-price ext-res-price + ([agreed-price] of myself * [min (list (buyer-demand) (buyer-cash / agreed-price))] of myself) ] set seller-stock seller-stock - min (list (buyer-demand) (buyer-cash / agreed-price)) set buyer-demand buyer-demand - min (list (buyer-demand) (buyer-cash / agreed-price)) set list-part-buyer-demand-sort replace-item l list-part-buyer-demand-sort min (list (buyer-demand) (buyer-cash / agreed-price)) set list-part-seller-stock-sort replace-item 0 list-part-seller-stock-sort seller-stock ] set l l + 1 ] if seller-stock = 0 [ set list-part-seller-sort remove-item 0 list-part-seller-sort set list-part-seller-stock-sort remove-item 0 list-part-seller-stock-sort set list-part-seller-rp-sort remove-item 0 list-part-seller-rp-sort ] ] ] end to seller-redistribute-supply ;This procedure aims to restock the sellers so that the total stock in the next iteration is equal to the initial daily supply set remaining-stock total-daily-supply - sum [stock] of sellers set list-restocking-seller [] set list-restocking-seller-rp [] ;seller who have cash in their hand are listed ask sellers with [cash > 0] [ set list-restocking-seller lput self list-restocking-seller set list-restocking-seller-rp lput [ext-res-price] of self list-restocking-seller-rp ] ;the external market sort the restocking seller based on their reservation price from the highest to the lowest set list-restocking-seller-sort [] set list-restocking-seller-rp-sort [] while [length list-restocking-seller > 0][ let i position ( max list-restocking-seller-rp) list-restocking-seller-rp set list-restocking-seller-sort lput item i list-restocking-seller list-restocking-seller-sort set list-restocking-seller-rp-sort lput item i list-restocking-seller-rp list-restocking-seller-rp-sort set list-restocking-seller remove-item i list-restocking-seller set list-restocking-seller-rp remove-item i list-restocking-seller-rp ] ;the seller start to restocking until the remaining stock become zero, strating from seller with highest ext-rp ;similar with the interaction between seller and the buyer, the price they need to pay is the mid point between their ext res price and the external market reservation price let i 0 while [ remaining-stock > 0][ ask item i list-restocking-seller-sort [ set ext-agreed-price seller-external-market-rp + (( ext-res-price - seller-external-market-rp ) / 2) set req-stock floor (cash / ext-agreed-price) ifelse ( remaining-stock <= req-stock ) [ set stock stock + remaining-stock set cash cash - ( ext-agreed-price * remaining-stock ) set remaining-stock 0 set res-price ext-agreed-price ;the reservation price that will be offered to the buyers in the next day is set based on the price they pay to the external market ][ set stock stock + req-stock set cash cash - ( ext-agreed-price * req-stock ) set remaining-stock remaining-stock - req-stock set res-price ext-agreed-price ] ] set i i + 1 ] end to agent-reset-transaction-and-ext-res-price ask sellers [ set transaction 0 set ext-res-price 0 ] ask buyers [ set transaction 0 set ext-res-price 0 set stock-to-resell 0 ] end to agent-calculate-ext-rest-price ask sellers [ ifelse (transaction > 0) [ set ext-res-price ext-res-price / transaction] [ set ext-res-price res-price] ] ask buyers [ ifelse (transaction > 0) [ set ext-res-price ext-res-price / transaction] [ set ext-res-price res-price] ] end to buyer-redistribute-demand ;Buyer will first sell the stock to resell to the external market ask buyers [ set ext-agreed-price ext-res-price + ((buyer-external-market-rp - ext-res-price) / 2) set cash cash + (ext-agreed-price * stock-to-resell) set stock-to-resell 0 set max-ext-demand floor ( cash / ext-res-price ) set res-price ext-agreed-price ] ;In redistributing the demand the unmet demand in the previous procedure is not taken into account ;Similar to the previous procedure, buyer with the lowest ext-agreed-price has more chance to get demand ;Buyer with bigger cash is considered to be more capable in meeting demand from the external market ;The maximum external demand that can be handle by a buyer is equal to cash / ext-res-price ;Because the total demand in the system is constant, then the demand acquired by each buyer is assumed to be proportional with the maximum external demand they can handle set total-max-ext-demand sum [max-ext-demand] of buyers ask buyers [ set demand floor ((max-ext-demand / total-max-ext-demand) * total-daily-demand) ] ;if there is demand that still undistributed, then this demand is assign to random buyer set remaining-demand total-daily-demand - sum [demand] of buyers if remaining-demand > 0 [ ask n-of remaining-demand buyers [ set demand demand + 1 ] ] end to update-plot update-avg-price-plot update-total-sales-plot update-buyer-cash-histogram update-seller-cash-histogram end to update-avg-price-plot set-current-plot "Average Price Box Plot" set-current-plot-pen "median" plot-pen-up set-current-plot-pen "minimum" plot-pen-up set min-min-avg-price 10 set-current-plot-pen "maximum" plot-pen-up set max-max-avg-price 0 set-current-plot-pen "Q1" plot-pen-up set-current-plot-pen "Q3" plot-pen-up set-current-plot-pen "outer-line" plot-pen-up set num-day 0 while [num-day < 30][ set experiment 0 set avg-price-day-all-experiment [] while [ experiment < num-experiment][ set avg-price-day-experiment [] set avg-price-day-experiment item experiment avg-price-all-experiment set avg-price-day-all-experiment lput (item num-day avg-price-day-experiment) avg-price-day-all-experiment set experiment experiment + 1 ] set avg-price-day-all-experiment sort avg-price-day-all-experiment ;plot mean of average price in day i set mean-avg-price mean avg-price-day-all-experiment set-current-plot "Average Price" set-current-plot-pen "mean" plotxy num-day mean-avg-price ;plot median of average price in day i ifelse (length avg-price-day-all-experiment mod 2 = 0)[ set med-avg-price ((item (length avg-price-day-all-experiment / 2) avg-price-day-all-experiment ) + (item ((length avg-price-day-all-experiment / 2) - 1) avg-price-day-all-experiment )) / 2 ][ set med-avg-price item ((floor ((length avg-price-day-all-experiment) / 2))) avg-price-day-all-experiment ] set-current-plot "Average Price Box Plot" set-current-plot-pen "median" plotxy num-day - 0.2 med-avg-price plot-pen-down plotxy num-day + 0.2 med-avg-price plot-pen-up ;plot Q1 and Q3 of average price in day i ifelse (length avg-price-day-all-experiment mod 4 = 0)[ set Q1-avg-price ((item (length avg-price-day-all-experiment / 4) avg-price-day-all-experiment ) + (item ((length avg-price-day-all-experiment / 4) - 1) avg-price-day-all-experiment )) / 2 set Q3-avg-price ((item ((length avg-price-day-all-experiment / 4) * 3) avg-price-day-all-experiment ) + (item (((length avg-price-day-all-experiment / 4) * 3) - 1) avg-price-day-all-experiment )) / 2 ][ set Q1-avg-price item ((floor ((length avg-price-day-all-experiment) / 4))) avg-price-day-all-experiment set Q3-avg-price item ((floor (((length avg-price-day-all-experiment) * 3) / 4))) avg-price-day-all-experiment ] set-current-plot-pen "Q1" plotxy num-day - 0.2 Q1-avg-price plot-pen-down plotxy num-day + 0.2 Q1-avg-price plot-pen-up set-current-plot-pen "Q3" plotxy num-day - 0.2 Q3-avg-price plot-pen-down plotxy num-day + 0.2 Q3-avg-price plot-pen-up ;plot minimum average price in day i set min-avg-price min avg-price-day-all-experiment set-current-plot-pen "minimum" plotxy num-day - 0.2 min-avg-price plot-pen-down plotxy num-day + 0.2 min-avg-price plot-pen-up if (min-min-avg-price > min-avg-price) [ set min-min-avg-price min-avg-price] ;;plot maximum average price in day i set max-avg-price max avg-price-day-all-experiment set-current-plot-pen "maximum" plotxy num-day - 0.2 max-avg-price plot-pen-down plotxy num-day + 0.2 max-avg-price plot-pen-up if (max-max-avg-price < max-avg-price) [ set max-max-avg-price max-avg-price] set-current-plot-pen "outer-line" plotxy num-day - 0.2 Q1-avg-price plot-pen-down plotxy num-day - 0.2 Q3-avg-price plot-pen-up plotxy num-day min-avg-price plot-pen-down plotxy num-day Q1-avg-price plot-pen-up plotxy num-day Q3-avg-price plot-pen-down plotxy num-day max-avg-price plot-pen-up plotxy num-day + 0.2 Q1-avg-price plot-pen-down plotxy num-day + 0.2 Q3-avg-price plot-pen-up set num-day num-day + 1 ] set-current-plot "Average Price" set-plot-y-range (precision min-min-avg-price 2 ) (precision max-max-avg-price 2) set-current-plot "Average Price Box Plot" set-plot-y-range (precision min-min-avg-price 2 ) (precision max-max-avg-price 2) set-plot-x-range 0 30 end to update-total-sales-plot set-current-plot "Total Sales Box Plot" set-current-plot-pen "median" plot-pen-up set-current-plot-pen "minimum" plot-pen-up set min-min-avg-price 100 set-current-plot-pen "maximum" plot-pen-up set max-max-avg-price 0 set-current-plot-pen "Q1" plot-pen-up set-current-plot-pen "Q3" plot-pen-up set-current-plot-pen "outer-line" plot-pen-up set num-day 0 while [num-day < 30][ set experiment 0 set total-sales-day-all-experiment [] while [ experiment < num-experiment][ set total-sales-day-experiment [] set total-sales-day-experiment item experiment total-sales-all-experiment set total-sales-day-all-experiment lput (item num-day total-sales-day-experiment) total-sales-day-all-experiment set experiment experiment + 1 ] set total-sales-day-all-experiment sort total-sales-day-all-experiment ;plot mean of total sales in day i set mean-total-sales mean total-sales-day-all-experiment set-current-plot "Total Sales" set-current-plot-pen "mean" plotxy num-day mean-total-sales ;plot median of total sales in day i ifelse (length total-sales-day-all-experiment mod 2 = 0)[ set med-total-sales ((item (length total-sales-day-all-experiment / 2) total-sales-day-all-experiment ) + (item ((length total-sales-day-all-experiment / 2) - 1) total-sales-day-all-experiment )) / 2 ][ set med-total-sales item ((floor ((length total-sales-day-all-experiment) / 2))) total-sales-day-all-experiment ] set-current-plot "Total Sales Box Plot" set-current-plot-pen "median" plotxy num-day - 0.2 med-total-sales plot-pen-down plotxy num-day + 0.2 med-total-sales plot-pen-up ;plot Q1 and Q3 of total sales in day i ifelse (length total-sales-day-all-experiment mod 4 = 0)[ set Q1-total-sales ((item (length total-sales-day-all-experiment / 4) total-sales-day-all-experiment ) + (item ((length total-sales-day-all-experiment / 4) - 1) total-sales-day-all-experiment )) / 2 set Q3-total-sales ((item ((length total-sales-day-all-experiment / 4) * 3) total-sales-day-all-experiment ) + (item (((length total-sales-day-all-experiment / 4) * 3) - 1) total-sales-day-all-experiment )) / 2 ][ set Q1-total-sales item ((floor ((length total-sales-day-all-experiment) / 4))) total-sales-day-all-experiment set Q3-total-sales item ((floor (((length total-sales-day-all-experiment) * 3) / 4))) total-sales-day-all-experiment ] set-current-plot-pen "Q1" plotxy num-day - 0.2 Q1-total-sales plot-pen-down plotxy num-day + 0.2 Q1-total-sales plot-pen-up set-current-plot-pen "Q3" plotxy num-day - 0.2 Q3-total-sales plot-pen-down plotxy num-day + 0.2 Q3-total-sales plot-pen-up ;plot minimum total sales in day i set min-total-sales min total-sales-day-all-experiment set-current-plot-pen "minimum" plotxy num-day - 0.2 min-total-sales plot-pen-down plotxy num-day + 0.2 min-total-sales plot-pen-up if (min-min-total-sales > min-total-sales) [ set min-min-total-sales min-total-sales] ;;plot maximum total-sales in day i set max-total-sales max total-sales-day-all-experiment set-current-plot-pen "maximum" plotxy num-day - 0.2 max-total-sales plot-pen-down plotxy num-day + 0.2 max-total-sales plot-pen-up if (max-max-total-sales < max-total-sales) [ set max-max-total-sales max-total-sales] set-current-plot-pen "outer-line" plotxy num-day - 0.2 Q1-total-sales plot-pen-down plotxy num-day - 0.2 Q3-total-sales plot-pen-up plotxy num-day min-total-sales plot-pen-down plotxy num-day Q1-total-sales plot-pen-up plotxy num-day Q3-total-sales plot-pen-down plotxy num-day max-total-sales plot-pen-up plotxy num-day + 0.2 Q1-total-sales plot-pen-down plotxy num-day + 0.2 Q3-total-sales plot-pen-up set num-day num-day + 1 ] set-current-plot "Total Sales" set-plot-y-range min-min-total-sales ( max-max-total-sales * 1.01) set-current-plot "Total Sales Box Plot" set-plot-y-range min-min-total-sales ( max-max-total-sales * 1.01) set-plot-x-range 0 30 end to set-cash-data-range If (max-buyer-cash-all-experiment < max [cash] of buyers) [ set max-buyer-cash-all-experiment max [cash] of buyers] If (max-seller-cash-all-experiment < max [cash] of sellers) [set max-seller-cash-all-experiment max [cash] of sellers] If (min [cash] of buyers < min-buyer-cash-all-experiment) [set min-buyer-cash-all-experiment min [cash] of buyers] If (min [cash] of sellers < min-seller-cash-all-experiment) [set min-seller-cash-all-experiment min [cash] of sellers] end to save-cash-data ;seller menyimpan data cash pada file file-open "seller-cash.txt" ask sellers [ file-write cash] file-close ;buyer menyimpan data cash pada file file-open "buyer-cash.txt" ask buyers [file-write cash] file-close end to calculate-class-boundaries ;calculate class boundaries for buyer cash set class-range-buyer-cash (max-buyer-cash-all-experiment - min-buyer-cash-all-experiment) / 5 set up-buyer-calss-1 min-buyer-cash-all-experiment + class-range-buyer-cash set up-buyer-calss-2 up-buyer-calss-1 + class-range-buyer-cash set up-buyer-calss-3 up-buyer-calss-2 + class-range-buyer-cash set up-buyer-calss-4 up-buyer-calss-3 + class-range-buyer-cash set up-buyer-calss-5 up-buyer-calss-4 + class-range-buyer-cash ;calculate class boundaries for seller cash set class-range-seller-cash (max-seller-cash-all-experiment - min-seller-cash-all-experiment) / 5 set up-seller-calss-1 min-seller-cash-all-experiment + class-range-seller-cash set up-seller-calss-2 up-seller-calss-1 + class-range-seller-cash set up-seller-calss-3 up-seller-calss-2 + class-range-seller-cash set up-seller-calss-4 up-seller-calss-3 + class-range-seller-cash set up-seller-calss-5 up-seller-calss-4 + class-range-seller-cash end to calculate-buyer-cash-frequency set experiment 0 set freq-class1-buyer-all-experiment [] set freq-class2-buyer-all-experiment [] set freq-class3-buyer-all-experiment [] set freq-class4-buyer-all-experiment [] set freq-class5-buyer-all-experiment [] file-open "buyer-cash.txt" while [experiment < num-experiment][ set freq-class1-buyer 0 set freq-class2-buyer 0 set freq-class3-buyer 0 set freq-class4-buyer 0 set freq-class5-buyer 0 let i 1 ;number of buyer in each experiment while [ i <= num-buyer][ let agent-cash file-read if (agent-cash >= min-buyer-cash-all-experiment) and (agent-cash < up-buyer-calss-1) [ set freq-class1-buyer freq-class1-buyer + 1] if (agent-cash >= up-buyer-calss-1) and (agent-cash < up-buyer-calss-2) [ set freq-class2-buyer freq-class2-buyer + 1] if (agent-cash >= up-buyer-calss-2) and (agent-cash < up-buyer-calss-3) [ set freq-class3-buyer freq-class3-buyer + 1] if (agent-cash >= up-buyer-calss-3) and (agent-cash < up-buyer-calss-4) [ set freq-class4-buyer freq-class4-buyer + 1] if (agent-cash >= up-buyer-calss-4) and (agent-cash <= up-buyer-calss-5) [ set freq-class5-buyer freq-class5-buyer + 1] set i i + 1 ] set freq-class1-buyer-all-experiment lput freq-class1-buyer freq-class1-buyer-all-experiment set freq-class2-buyer-all-experiment lput freq-class2-buyer freq-class2-buyer-all-experiment set freq-class3-buyer-all-experiment lput freq-class3-buyer freq-class3-buyer-all-experiment set freq-class4-buyer-all-experiment lput freq-class4-buyer freq-class4-buyer-all-experiment set freq-class5-buyer-all-experiment lput freq-class5-buyer freq-class5-buyer-all-experiment set experiment experiment + 1 ] file-close end to calculate-seller-cash-frequency set experiment 0 set freq-class1-seller-all-experiment [] set freq-class2-seller-all-experiment [] set freq-class3-seller-all-experiment [] set freq-class4-seller-all-experiment [] set freq-class5-seller-all-experiment [] file-open "seller-cash.txt" while [experiment < num-experiment][ set freq-class1-seller 0 set freq-class2-seller 0 set freq-class3-seller 0 set freq-class4-seller 0 set freq-class5-seller 0 let i 1 ;number of seller in each experiment while [ i <= num-seller][ let agent-cash file-read if (agent-cash >= min-seller-cash-all-experiment) and (agent-cash < up-seller-calss-1) [ set freq-class1-seller freq-class1-seller + 1] if (agent-cash >= up-seller-calss-1) and (agent-cash < up-seller-calss-2) [ set freq-class2-seller freq-class2-seller + 1] if (agent-cash >= up-seller-calss-2) and (agent-cash < up-seller-calss-3) [ set freq-class3-seller freq-class3-seller + 1] if (agent-cash >= up-seller-calss-3) and (agent-cash < up-seller-calss-4) [ set freq-class4-seller freq-class4-seller + 1] if (agent-cash >= up-seller-calss-4) and (agent-cash <= up-seller-calss-5) [ set freq-class5-seller freq-class5-seller + 1] set i i + 1 ] set freq-class1-seller-all-experiment lput freq-class1-seller freq-class1-seller-all-experiment set freq-class2-seller-all-experiment lput freq-class2-seller freq-class2-seller-all-experiment set freq-class3-seller-all-experiment lput freq-class3-seller freq-class3-seller-all-experiment set freq-class4-seller-all-experiment lput freq-class4-seller freq-class4-seller-all-experiment set freq-class5-seller-all-experiment lput freq-class5-seller freq-class5-seller-all-experiment set experiment experiment + 1 ] file-close end to update-buyer-cash-histogram set-current-plot "Buyer Wealth Distribution" set-plot-x-range min-buyer-cash-all-experiment max-buyer-cash-all-experiment set-current-plot-pen "mean" plotxy min-buyer-cash-all-experiment 0 plotxy min-buyer-cash-all-experiment mean freq-class1-buyer-all-experiment plotxy up-buyer-calss-1 mean freq-class1-buyer-all-experiment plotxy up-buyer-calss-1 0 plotxy up-buyer-calss-1 mean freq-class2-buyer-all-experiment plotxy up-buyer-calss-2 mean freq-class2-buyer-all-experiment plotxy up-buyer-calss-2 0 plotxy up-buyer-calss-2 mean freq-class3-buyer-all-experiment plotxy up-buyer-calss-3 mean freq-class3-buyer-all-experiment plotxy up-buyer-calss-3 0 plotxy up-buyer-calss-3 mean freq-class4-buyer-all-experiment plotxy up-buyer-calss-4 mean freq-class4-buyer-all-experiment plotxy up-buyer-calss-4 0 plotxy up-buyer-calss-4 mean freq-class5-buyer-all-experiment plotxy up-buyer-calss-5 mean freq-class5-buyer-all-experiment plotxy up-buyer-calss-5 0 ;plot maximum set-current-plot-pen "max" plot-pen-up plotxy min-buyer-cash-all-experiment max freq-class1-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-1 max freq-class1-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-1 max freq-class2-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-2 max freq-class2-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-2 max freq-class3-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-3 max freq-class3-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-3 max freq-class4-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-4 max freq-class4-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-4 max freq-class5-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-5 max freq-class5-buyer-all-experiment ;plot minimum set-current-plot-pen "min" plot-pen-up plotxy min-buyer-cash-all-experiment min freq-class1-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-1 min freq-class1-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-1 min freq-class2-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-2 min freq-class2-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-2 min freq-class3-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-3 min freq-class3-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-3 min freq-class4-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-4 min freq-class4-buyer-all-experiment plot-pen-up plotxy up-buyer-calss-4 min freq-class5-buyer-all-experiment plot-pen-down plotxy up-buyer-calss-5 min freq-class5-buyer-all-experiment ;plot mid line set-current-plot-pen "mid" plot-pen-up plotxy (min-buyer-cash-all-experiment + up-buyer-calss-1 ) / 2 min freq-class1-buyer-all-experiment plot-pen-down plotxy (min-buyer-cash-all-experiment + up-buyer-calss-1 ) / 2 max freq-class1-buyer-all-experiment plot-pen-up plotxy (up-buyer-calss-1 + up-buyer-calss-2) / 2 min freq-class2-buyer-all-experiment plot-pen-down plotxy (up-buyer-calss-1 + up-buyer-calss-2) / 2 max freq-class2-buyer-all-experiment plot-pen-up plotxy (up-buyer-calss-2 + up-buyer-calss-3) / 2 min freq-class3-buyer-all-experiment plot-pen-down plotxy (up-buyer-calss-2 + up-buyer-calss-3) / 2 max freq-class3-buyer-all-experiment plot-pen-up plotxy (up-buyer-calss-3 + up-buyer-calss-4) / 2 min freq-class4-buyer-all-experiment plot-pen-down plotxy (up-buyer-calss-3 + up-buyer-calss-4) / 2 max freq-class4-buyer-all-experiment plot-pen-up plotxy (up-buyer-calss-4 + up-buyer-calss-5) / 2 min freq-class5-buyer-all-experiment plot-pen-down plotxy (up-buyer-calss-4 + up-buyer-calss-5) / 2 max freq-class5-buyer-all-experiment plot-pen-up end to update-seller-cash-histogram set-current-plot "Sellers Wealth Distribution" set-plot-x-range min-seller-cash-all-experiment max-seller-cash-all-experiment set-current-plot-pen "mean" plotxy min-seller-cash-all-experiment 0 plotxy min-seller-cash-all-experiment mean freq-class1-seller-all-experiment plotxy up-seller-calss-1 mean freq-class1-seller-all-experiment plotxy up-seller-calss-1 0 plotxy up-seller-calss-1 mean freq-class2-seller-all-experiment plotxy up-seller-calss-2 mean freq-class2-seller-all-experiment plotxy up-seller-calss-2 0 plotxy up-seller-calss-2 mean freq-class3-seller-all-experiment plotxy up-seller-calss-3 mean freq-class3-seller-all-experiment plotxy up-seller-calss-3 0 plotxy up-seller-calss-3 mean freq-class4-seller-all-experiment plotxy up-seller-calss-4 mean freq-class4-seller-all-experiment plotxy up-seller-calss-4 0 plotxy up-seller-calss-4 mean freq-class5-seller-all-experiment plotxy up-seller-calss-5 mean freq-class5-seller-all-experiment plotxy up-seller-calss-5 0 ;plot maximum set-current-plot-pen "max" plot-pen-up plotxy min-seller-cash-all-experiment max freq-class1-seller-all-experiment plot-pen-down plotxy up-seller-calss-1 max freq-class1-seller-all-experiment plot-pen-up plotxy up-seller-calss-1 max freq-class2-seller-all-experiment plot-pen-down plotxy up-seller-calss-2 max freq-class2-seller-all-experiment plot-pen-up plotxy up-seller-calss-2 max freq-class3-seller-all-experiment plot-pen-down plotxy up-seller-calss-3 max freq-class3-seller-all-experiment plot-pen-up plotxy up-seller-calss-3 max freq-class4-seller-all-experiment plot-pen-down plotxy up-seller-calss-4 max freq-class4-seller-all-experiment plot-pen-up plotxy up-seller-calss-4 max freq-class5-seller-all-experiment plot-pen-down plotxy up-seller-calss-5 max freq-class5-seller-all-experiment ;plot minimum set-current-plot-pen "min" plot-pen-up plotxy min-seller-cash-all-experiment min freq-class1-seller-all-experiment plot-pen-down plotxy up-seller-calss-1 min freq-class1-seller-all-experiment plot-pen-up plotxy up-seller-calss-1 min freq-class2-seller-all-experiment plot-pen-down plotxy up-seller-calss-2 min freq-class2-seller-all-experiment plot-pen-up plotxy up-seller-calss-2 min freq-class3-seller-all-experiment plot-pen-down plotxy up-seller-calss-3 min freq-class3-seller-all-experiment plot-pen-up plotxy up-seller-calss-3 min freq-class4-seller-all-experiment plot-pen-down plotxy up-seller-calss-4 min freq-class4-seller-all-experiment plot-pen-up plotxy up-seller-calss-4 min freq-class5-seller-all-experiment plot-pen-down plotxy up-seller-calss-5 min freq-class5-seller-all-experiment ;plot mid line set-current-plot-pen "mid" plot-pen-up plotxy (min-seller-cash-all-experiment + up-seller-calss-1 ) / 2 min freq-class1-seller-all-experiment plot-pen-down plotxy (min-seller-cash-all-experiment + up-seller-calss-1 ) / 2 max freq-class1-seller-all-experiment plot-pen-up plotxy (up-seller-calss-1 + up-seller-calss-2) / 2 min freq-class2-seller-all-experiment plot-pen-down plotxy (up-seller-calss-1 + up-seller-calss-2) / 2 max freq-class2-seller-all-experiment plot-pen-up plotxy (up-seller-calss-2 + up-seller-calss-3) / 2 min freq-class3-seller-all-experiment plot-pen-down plotxy (up-seller-calss-2 + up-seller-calss-3) / 2 max freq-class3-seller-all-experiment plot-pen-up plotxy (up-seller-calss-3 + up-seller-calss-4) / 2 min freq-class4-seller-all-experiment plot-pen-down plotxy (up-seller-calss-3 + up-seller-calss-4) / 2 max freq-class4-seller-all-experiment plot-pen-up plotxy (up-seller-calss-4 + up-seller-calss-5) / 2 min freq-class5-seller-all-experiment plot-pen-down plotxy (up-seller-calss-4 + up-seller-calss-5) / 2 max freq-class5-seller-all-experiment plot-pen-up end @#$#@#$#@ GRAPHICS-WINDOW 843 19 1282 479 16 16 13.0 1 10 1 1 1 0 1 1 1 -16 16 -16 16 0 0 1 ticks 30.0 SLIDER 211 21 383 54 num-market num-market 0 20 5 1 1 NIL HORIZONTAL SLIDER 211 53 383 86 num-seller num-seller 0 500 100 1 1 NIL HORIZONTAL SLIDER 211 86 383 119 num-buyer num-buyer 0 500 100 1 1 NIL HORIZONTAL BUTTON 779 77 842 110 NIL setup NIL 1 T OBSERVER NIL NIL NIL NIL 1 CHOOSER 211 119 349 164 buyer-access buyer-access "all markets" "some markets" 1 SLIDER 385 20 557 53 init-min-seller-rp init-min-seller-rp 1 20 4 1 1 NIL HORIZONTAL SLIDER 385 53 557 86 init-max-seller-rp init-max-seller-rp 1 20 8 1 1 NIL HORIZONTAL SLIDER 385 86 557 119 init-min-buyer-rp init-min-buyer-rp 1 20 9 1 1 NIL HORIZONTAL SLIDER 385 119 557 152 init-max-buyer-rp init-max-buyer-rp 0 20 13 1 1 NIL HORIZONTAL CHOOSER 386 151 542 196 init-stock-distribution init-stock-distribution "equally" "randomly" 0 CHOOSER 386 196 541 241 init-demand-distribution init-demand-distribution "equally" "randomly" 0 SLIDER 559 86 742 119 total-daily-supply total-daily-supply 0 10000 1000 100 1 NIL HORIZONTAL SLIDER 559 119 743 152 total-daily-demand total-daily-demand 0 10000 1000 100 1 NIL HORIZONTAL BUTTON 779 110 842 143 NIL begin NIL 1 T OBSERVER NIL NIL NIL NIL 1 SLIDER 211 164 383 197 information information 0 100 100 50 1 % HORIZONTAL MONITOR 211 198 276 243 NIL avg-price 2 1 11 MONITOR 212 836 283 881 NIL total-sales 17 1 11 SLIDER 558 20 743 53 seller-external-market-rp seller-external-market-rp 0 10 1 1 1 NIL HORIZONTAL SLIDER 558 52 743 85 buyer-external-market-rp buyer-external-market-rp 0 20 16 1 1 NIL HORIZONTAL PLOT 212 544 522 837 Total Sales NIL NIL 0.0 30.0 0.0 10.0 true false "" "" PENS "mean" 1.0 0 -955883 true "" "" PLOT 211 242 521 536 Average Price NIL NIL 0.0 30.0 0.0 8.0 true false "" "" PENS "mean" 1.0 0 -2674135 true "" "" PLOT 1158 543 1468 836 Sellers Wealth Distribution NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "mean" 1.0 1 -14070903 true "" "" "max" 1.0 0 -2674135 true "" "" "min" 1.0 0 -2674135 true "" "" "mid" 1.0 0 -2674135 true "" "" PLOT 848 543 1158 836 Buyer Wealth Distribution NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "mean" 1.0 0 -5825686 true "" "" "max" 1.0 0 -14439633 true "" "" "min" 1.0 0 -14439633 true "" "" "mid" 1.0 0 -14439633 true "" "" INPUTBOX 749 18 842 78 num-experiment 30 1 0 Number PLOT 521 242 830 536 Average Price Box Plot NIL NIL 0.0 30.0 0.0 10.0 true false "" "" PENS "median" 1.0 0 -2674135 true "" "" "minimum" 1.0 0 -2674135 true "" "" "maximum" 1.0 0 -2674135 true "" "" "Q1" 1.0 0 -2674135 true "" "" "Q3" 1.0 0 -2674135 true "" "" "outer-line" 1.0 0 -2674135 true "" "" PLOT 522 544 830 837 Total Sales Box Plot NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "median" 1.0 0 -955883 true "" "" "minimum" 1.0 0 -955883 true "" "" "maximum" 1.0 0 -955883 true "" "" "Q1" 1.0 0 -955883 true "" "" "Q3" 1.0 0 -955883 true "" "" "outer-line" 1.0 0 -955883 true "" "" @#$#@#$#@ ## WHAT IS IT? (a general understanding of what the model is trying to show or explain) ## HOW IT WORKS (what rules the agents use to create the overall behavior of the model) ## HOW TO USE IT (how to use the model, including a description of each of the items in the Interface tab) ## THINGS TO NOTICE (suggested things for the user to notice while running the model) ## THINGS TO TRY (suggested things for the user to try to do (move sliders, switches, etc.) with the model) ## EXTENDING THE MODEL (suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.) ## NETLOGO FEATURES (interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features) ## RELATED MODELS (models in the NetLogo Models Library and elsewhere which are of related interest) ## CREDITS AND REFERENCES (a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links) @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 sheep false 15 Circle -1 true true 203 65 88 Circle -1 true true 70 65 162 Circle -1 true true 150 105 120 Polygon -7500403 true false 218 120 240 165 255 165 278 120 Circle -7500403 true false 214 72 67 Rectangle -1 true true 164 223 179 298 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 Circle -1 true true 3 83 150 Rectangle -1 true true 65 221 80 296 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 Polygon -7500403 true false 276 85 285 105 302 99 294 83 Polygon -7500403 true false 219 85 210 105 193 99 201 83 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 wolf false 0 Polygon -16777216 true false 253 133 245 131 245 133 Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 5.0.5 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@