Products into the Market
Model was written in NetLogo 5.2.0
•
Viewed 727 times
•
Downloaded 46 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
extensions [nw] ;;Extends and replaces the old Network Extension bundled in Netlogo breed [people person] ;;Define a new breed people-own [ buyapple? ;; whether or not the person has bought the product Apple buysamsung? ;; whether or not the person has bought the product Samsung randomapplen? ;; other boolean variables to print and check randomsamsungn? friendapplen? friendsamsungn? friendsamsungbutapplen? friendapplebutsamsungn? drawsamsungn? drawapplen? drawsamsungbutapplen? drawapplebutsamsungn? ] to setup ; clear-all ;; if you want that every time you setup you start a new project, uncomment this line create-network ;; go to create-network method seed ;; go to seed method reset-ticks end to allfalse ;; just reset every person ask people [ set buyapple? false set buysamsung? false set randomapplen? false set randomsamsungn? false set friendapplen? false set friendsamsungn? false set friendsamsungbutapplen? false set friendapplebutsamsungn? false set drawsamsungn? false set drawapplen? false set drawsamsungbutapplen? false set drawapplebutsamsungn? false update-color ] seed end ;; seed the population with users who have already been given the product ;; you can either seed randomly or use betweenness centrality ;; if you choose Betweenness you have to add one more samsung sponsor. to seed if seeding-method = "random" [ ;; seeds are putted randomly among people ask n-of sponsorapple people [ set buyapple? true ;; give at n people an apple product set buysamsung? false update-color ;; go to update-color method ] ask n-of sponsorsamsung people [ set buysamsung? true ;; give at n people a samsung product set buyapple? false update-color ;; go to update-color method ] ] if seeding-method = "betweenness" [ ;; Betweenness method is used, n-product are given following the centrality ask max-n-of sponsorsamsung people [ nw:betweenness-centrality ] [ set buysamsung? true ;; give at n people a samsung product set buyapple? false update-color ;; go to update-color method ] ask max-n-of sponsorapple people [ nw:betweenness-centrality ] [ set buyapple? true ;; give at n people an apple product set buysamsung? false update-color ;; go to update-color method ] ] end ;; create the social network to create-network if network-type = "random" [ create-random-network ] if network-type = "preferential-attachment" [ create-preferential-attachment ] end ;; generate an Erdos-Renyi random graph to create-random-network nw:generate-random people links number-of-people 0.004 [ set shape "person" set color yellow set size 1.5 set buyapple? false set buysamsung? false ] end ;; the Barabasi-Albert method of creating a PA graph to create-preferential-attachment nw:generate-preferential-attachment people links number-of-people [ set size 1.5 set shape "person" set color yellow set buyapple? false set buysamsung? false ] end ;; simple loop just check to see if a person hasn't bought then decide if they should adopt to go ifelse forever? [][ ;; if forever button is false the operation will stop when everyone has bought a product if all? people [buyapple? or buysamsung?] [stop] ] if all? people [buyapple?] [stop] ;; Machine stops if apple own the markes if all? people [buysamsung?] [stop] ;; Machine stops if samsung own the market ifelse output?[ ask people [ decide-to-adopt ] ;; Ask to adopt to everyone ] [ ask people [decide-to-adoptnooutput]] ask people [ update-color ] ;; Ask to everyone to update color tick end ;; the decision rule to adopt which is based on the Bass model of diffusion to decide-to-adopt ;; Create strings to print let casualeapple "Buys Apple on his own \n" let casualesamsung "Buys Samsung on his own \n" let amiciapple "Buys Apple because of neighbors \n" let amicisamsung "Buys Samsung because of neighbors \n" let amicisamsungbutapple "Buys Samsung even if has more neighbors with Apple \n" let amiciapplebutsamsung "Buys Apple even if has more neighbors with Samsung \n" let drawsamsung "Buys Samsung even if has same neighbors with Apple and Samsung \n" let drawapple "Buys Apple even if has same neighbors with Apple and Samsung \n" let drawsamsungbutapple "Buys Samsung even if has same neighbors with Apple and Samsung, after tried to buy Apple \n" let drawapplebutsamsung "Buys Apple even if has same neighbors with Apple and Samsung, after tried to buy Samsung \n" ;;Starts a new if sequence for buying algorithm output-print (word "----------START ALGORITHM-----------") let firstrandom random-float 1.0 ifelse firstrandom < 0.02[;random output-print (word "First random number: " firstrandom ". It's minor than 2%. -> Random WAY") let secondrandom random-float 2.0 ifelse secondrandom < 1 [ output-print (word "Second random number: " secondrandom ". It's minor than 1. -> Apple") output-type casualeapple set randomapplen? true set buyapple? true set buysamsung? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ ;;inizio IFELSE RANDOM SAMSUNG output-print (word "Second random number: " secondrandom ". It's greater than 1. -> Samsung") output-type casualesamsung set randomsamsungn? true set buysamsung? true set buyapple? false output-print "----------END OF THE ALGORITHM----------\n\n" ]] [ output-print (word "First random number: " firstrandom ". It's greater than 2%. -> Neighbors Way") ;;inizio NEIGHBORS ifelse any? link-neighbors [ output-print "This person has neighbors." ifelse any? link-neighbors with [ buyapple? = true or buysamsung? = true][ output-print "This person has neighbors with some product." let valoreapple 5 - popularityapple let valoresamsung 5 - popularitysamsung let apple count link-neighbors with [ buyapple? = true ] / count link-neighbors let samsung count link-neighbors with [ buysamsung? = true ] / count link-neighbors ifelse apple > samsung [ output-print (word "More Apple neighbors than Samsung (" apple " vs " samsung ")") let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa [ output-print (word "The random number is minor than the Probability. -> Apple. ("randomnuma " < " probabilitaa")") output-type amiciapple set friendapplen? true set buyapple? true set buysamsung? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is greater than the Probability. -> Try with Samsung. ("randomnuma " > " probabilitaa")") let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[ output-print (word "The random number is minor than the Probability. -> Samsung. ("randomnums " < " probabilitas")") output-type amicisamsungbutapple set friendsamsungbutapplen? true set buysamsung? true set buyapple? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is greater than the Probability. -> Doesn't buy. ("randomnums " > " probabilitas")") ] ] output-print "----------END OF THE ALGORITHM----------\n\n" ] [ ifelse samsung > apple [ output-print (word "More Samsung neighbors than Apple (" apple " vs " samsung ")") let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[ output-print (word "The random number is minor than the Probability. -> Samsung. ("randomnums " < " probabilitas")") output-type amicisamsung set friendsamsungn? true set buysamsung? true set buyapple? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is greater than the Probability. -> Try with Apple. ("randomnums " > " probabilitas")") let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa[ output-print (word "The random number is minor than the Probability. -> Apple. ("randomnuma " < " probabilitaa")") output-type amiciapplebutsamsung set friendapplebutsamsungn? true set buyapple? true set buysamsung? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is greater than the Probability. -> Doesn't buy anything. ("randomnuma " > " probabilitaa")") ] ] output-print "----------END OF THE ALGORITHM----------\n\n" ][;;in teoria va quando è uguale if samsung = apple[ output-print (word "This node has neighbors with the same number of Apple and Samsung (" samsung " contro " apple ")") let randomdraw random-float 1.0 ifelse randomdraw < 0.5 [;;randomdraw < 0.5 output-print (word "Random number generated: " randomdraw ". It's minor than 0.5, so priority to Samsung.") let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[;;ifelse random samsung < probabilita samsung output-print (word "The random number is minor than the Probability. -> Samsung. ("randomnums " < " probabilitas")") output-type drawsamsung set drawsamsungn? true set buysamsung? true set buyapple? false output-print "----------END OF THE ALGORITHM----------\n\n" ][;;ifelse false random samsung < probabilita samsung, tentativo apple output-print (word "The random number is greater than the Probability. -> Try with Apple. ("randomnums " > " probabilitas")") let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa[ output-print (word "The random number is minor than the Probability. -> Apple. ("randomnuma " < " probabilitaa")") output-type drawapplebutsamsung set drawapplebutsamsungn? true set buyapple? true set buysamsung? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is Greater than the Probability. -> Doesn't buy anything. ("randomnuma " > " probabilitaa")") ] ] ] [;; randomdraw > 0.5 output-print (word "The random number generated: " randomdraw ". It's minor than 0.5, so priority to Apple") let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa[;;ifelse random samsung < probabilita samsung output-print (word "The random number is minor than the Probability. -> Apple. ("randomnuma " < " probabilitaa")") output-type drawapple set drawapplen? true set buyapple? true set buysamsung? false output-print "----------END OF THE ALGORITHM----------\n\n" ][ output-print (word "The random number is greater than the Probability. -> Try with Samsung. ("randomnuma " > " probabilitaa")") let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[ output-print (word "The random number is minor than the Probability. -> Samsung. ("randomnums " < " probabilitas")") output-type drawsamsungbutapple set drawsamsungbutapplen? true set buysamsung? true set buyapple? false output-print "----------END OF THE ALGORITHM----------\n\n" ] [ output-print (word "The random number is greater than the Probability. -> Doesn't buy anithing. ("randomnums " > " probabilitas")") ] ] ] ] ] ] ][output-print "This person hasn't neighbor with a product" output-print "----------END OF THE ALGORITHM----------\n\n"] ] [ output-print "This person hasn't neighbor\n\n" output-print "----------END OF THE ALGORITHM----------\n\n"] ] end ;; the decision rule to adopt which is based on the Bass model of diffusion, no output to decide-to-adoptnooutput ;; Create strings to print let casualeapple "Buys Apple on his own \n" let casualesamsung "Buys Samsung on his own \n" let amiciapple "Buys Apple because of neighbors \n" let amicisamsung "Buys Samsung because of neighbors \n" let amicisamsungbutapple "Buys Samsung even if has more neighbors with Apple \n" let amiciapplebutsamsung "Buys Apple even if has more neighbors with Samsung \n" let drawsamsung "Buys Samsung even if has same neighbors with Apple and Samsung \n" let drawapple "Buys Apple even if has same neighbors with Apple and Samsung \n" let drawsamsungbutapple "Buys Samsung even if has same neighbors with Apple and Samsung, after tried to buy Apple \n" let drawapplebutsamsung "Buys Apple even if has same neighbors with Apple and Samsung, after tried to buy Samsung \n" ;;Starts a new if sequence for buying algorithm ;; inizio IFELSE RANDOM APPLE let firstrandom random-float 1.0 ifelse firstrandom < 0.02[;random let secondrandom random-float 2.0 ifelse secondrandom < 1 [ set randomapplen? true set buyapple? true set buysamsung? false ] [ ;;inizio IFELSE RANDOM SAMSUNG set randomsamsungn? true set buysamsung? true set buyapple? false ]] [ ;;inizio NEIGHBORS ifelse any? link-neighbors [ ifelse any? link-neighbors with [ buyapple? = true or buysamsung? = true][ let valoreapple 5 - popularityapple let valoresamsung 5 - popularitysamsung let apple count link-neighbors with [ buyapple? = true ] / count link-neighbors let samsung count link-neighbors with [ buysamsung? = true ] / count link-neighbors ifelse apple > samsung [ let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa [ set friendapplen? true set buyapple? true set buysamsung? false ] [ let probabilitas samsung * 0.5 let randomnums random-float valoresamsung if randomnums < probabilitas[ set friendsamsungbutapplen? true set buysamsung? true set buyapple? false ] ] ] [ ifelse samsung > apple [ let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[ set friendsamsungn? true set buysamsung? true set buyapple? false ] [ let probabilitaa apple * 0.5 let randomnuma random-float valoreapple if randomnuma < probabilitaa[ set friendapplebutsamsungn? true set buyapple? true set buysamsung? false ] ] ][;;quando è uguale if samsung = apple[ let randomdraw random-float 1.0 ifelse randomdraw < 0.5 [;;randomdraw < 0.5 let probabilitas samsung * 0.5 let randomnums random-float valoresamsung ifelse randomnums < probabilitas[;;ifelse random samsung < probabilita samsung set drawsamsungn? true set buysamsung? true set buyapple? false ][ let probabilitaa apple * 0.5 let randomnuma random-float valoreapple if randomnuma < probabilitaa[ set drawapplebutsamsungn? true set buyapple? true set buysamsung? false ] ] ] [;; randomdraw > 0.5 let probabilitaa apple * 0.5 let randomnuma random-float valoreapple ifelse randomnuma < probabilitaa[;;ifelse random samsung < probabilita samsung set drawapplen? true set buyapple? true set buysamsung? false ][ let probabilitas samsung * 0.5 let randomnums random-float valoresamsung if randomnums < probabilitas[ set drawsamsungbutapplen? true set buysamsung? true set buyapple? false ] ] ] ] ] ] ][ ] ] [ ] ] end ;; ;; utility procedures ;; to update-color if buyapple? [ set color white ] if buysamsung? [ set color blue ] if not buyapple? and not buysamsung? [set color yellow] end to layout layout-spring people links 0.1 0.1 1 display end to highlight ifelse mouse-inside? [ do-highlight ] [ undo-highlight ] display end ;; remove any previous highlights to undo-highlight clear-output ask people [ update-color ] ask links [ set color white - 3 ] end to do-highlight let highlight-color red let min-d min [distancexy mouse-xcor mouse-ycor] of people ;; get the node closest to the mouse let the-node one-of people with [any? link-neighbors and distancexy mouse-xcor mouse-ycor = min-d] ;; get the node that was previously the highlight-color let highlighted-node one-of people with [color = highlight-color] if the-node != nobody and the-node != highlighted-node [ ;; highlight the chosen node ask the-node [ undo-highlight set color highlight-color ask my-links [ set color cyan - 1 ] ask link-neighbors [ set color red + 1 ] ] ] end ; Copyright 2015 Fabio Monteneri ; See Info tab for full copyright and license.
There is only one version of this model, created almost 10 years ago by Fabio Monteneri.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Products into the Market.png | preview | Preview for 'Products into the Market' | almost 10 years ago, by Fabio Monteneri | Download |
This model does not have any ancestors.
This model does not have any descendants.