powered by NetLogo

view/download model file: SimpleComplexContagion.nlogo

WHAT IS IT?

This is a model of contagion. There are white nodes that have no opinion, and they may adopt a red or a blue opinion. Once they have adopted the opinion, they do not change their minds.


HOW IT WORKS

The model starts with all nodes having no opinion.

There are two models of contagion.

In the SIMPLE SPREAD model an "infected" node will infect each of its opinion-free neighbors with probability PROB-INFECTION.

In the COMPLEX SPREAD model, each opinion-free node will adopt the opinion of its neigbhors only if at least 2 of its neighbors share that opinion. If there are multiple opinions in the neighborhood


HOW TO USE IT

Click on SELECT-RED and click on the nodes you will seed with the red opinion. Click on SELECT-RED again to stop the selection process. Do the same with SELECT-BLUE.

Then run the model, using either simple or complex contagion. You can slow things down by moving the speed slider up top.


MAKING IT INTO A GAME

Challenge a friend. Have them pick two red nodes, and you pick two blue nodes. Run one of the models. Whose opinion wins out?


CREDITS AND REFERENCES

This model was created by Lada Adamic 2007
Feel free to use it and modify it as you like with or without attribution.


PROCEDURES

; created by Lada Adamic (see copyright below)
; for the purposes of SI708/CSCS608

globals
[
  num-blue
  num-white
  num-red
]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca
  set-default-shape turtles "circle"
  ;; make the initial network of two turtles and an edge
  
  crt 150 [
    set color white
  ]
make-edge turtle 123 turtle 55
make-edge turtle 123 turtle 119
make-edge turtle 123 turtle 85
make-edge turtle 123 turtle 56
make-edge turtle 105 turtle 86
make-edge turtle 105 turtle 89
make-edge turtle 105 turtle 149
make-edge turtle 105 turtle 124
make-edge turtle 105 turtle 78
make-edge turtle 105 turtle 58
make-edge turtle 105 turtle 92
make-edge turtle 105 turtle 1
make-edge turtle 105 turtle 79
make-edge turtle 105 turtle 76
make-edge turtle 105 turtle 125
make-edge turtle 64 turtle 122
make-edge turtle 64 turtle 75
make-edge turtle 64 turtle 70
make-edge turtle 64 turtle 25
make-edge turtle 64 turtle 96
make-edge turtle 64 turtle 22
make-edge turtle 64 turtle 141
make-edge turtle 64 turtle 26
make-edge turtle 64 turtle 77
make-edge turtle 64 turtle 60
make-edge turtle 64 turtle 81
make-edge turtle 64 turtle 76
make-edge turtle 64 turtle 135
make-edge turtle 4 turtle 100
make-edge turtle 4 turtle 112
make-edge turtle 109 turtle 73
make-edge turtle 109 turtle 37
make-edge turtle 109 turtle 35
make-edge turtle 109 turtle 48
make-edge turtle 109 turtle 43
make-edge turtle 39 turtle 38
make-edge turtle 39 turtle 29
make-edge turtle 39 turtle 51
make-edge turtle 39 turtle 30
make-edge turtle 39 turtle 42
make-edge turtle 39 turtle 117
make-edge turtle 39 turtle 120
make-edge turtle 39 turtle 50
make-edge turtle 39 turtle 65
make-edge turtle 39 turtle 36
make-edge turtle 39 turtle 32
make-edge turtle 39 turtle 148
make-edge turtle 39 turtle 31
make-edge turtle 39 turtle 37
make-edge turtle 39 turtle 34
make-edge turtle 39 turtle 45
make-edge turtle 39 turtle 147
make-edge turtle 90 turtle 62
make-edge turtle 90 turtle 122
make-edge turtle 90 turtle 80
make-edge turtle 90 turtle 91
make-edge turtle 100 turtle 138
make-edge turtle 100 turtle 112
make-edge turtle 1 turtle 144
make-edge turtle 1 turtle 103
make-edge turtle 1 turtle 139
make-edge turtle 1 turtle 21
make-edge turtle 1 turtle 58
make-edge turtle 1 turtle 131
make-edge turtle 1 turtle 142
make-edge turtle 1 turtle 143
make-edge turtle 127 turtle 119
make-edge turtle 127 turtle 134
make-edge turtle 127 turtle 126
make-edge turtle 127 turtle 114
make-edge turtle 127 turtle 35
make-edge turtle 127 turtle 93
make-edge turtle 127 turtle 88
make-edge turtle 127 turtle 54
make-edge turtle 47 turtle 140
make-edge turtle 47 turtle 51
make-edge turtle 47 turtle 8
make-edge turtle 47 turtle 67
make-edge turtle 47 turtle 42
make-edge turtle 47 turtle 20
make-edge turtle 47 turtle 145
make-edge turtle 47 turtle 98
make-edge turtle 47 turtle 94
make-edge turtle 47 turtle 50
make-edge turtle 47 turtle 73
make-edge turtle 47 turtle 61
make-edge turtle 47 turtle 11
make-edge turtle 47 turtle 41
make-edge turtle 47 turtle 43
make-edge turtle 47 turtle 148
make-edge turtle 47 turtle 46
make-edge turtle 47 turtle 37
make-edge turtle 47 turtle 31
make-edge turtle 47 turtle 35
make-edge turtle 47 turtle 34
make-edge turtle 47 turtle 118
make-edge turtle 47 turtle 116
make-edge turtle 47 turtle 108
make-edge turtle 47 turtle 48
make-edge turtle 47 turtle 147
make-edge turtle 74 turtle 118
make-edge turtle 74 turtle 41
make-edge turtle 149 turtle 18
make-edge turtle 149 turtle 89
make-edge turtle 149 turtle 2
make-edge turtle 149 turtle 145
make-edge turtle 149 turtle 78
make-edge turtle 149 turtle 124
make-edge turtle 149 turtle 92
make-edge turtle 149 turtle 125
make-edge turtle 89 turtle 124
make-edge turtle 89 turtle 78
make-edge turtle 89 turtle 131
make-edge turtle 89 turtle 95
make-edge turtle 89 turtle 6
make-edge turtle 59 turtle 103
make-edge turtle 66 turtle 19
make-edge turtle 66 turtle 61
make-edge turtle 66 turtle 146
make-edge turtle 66 turtle 147
make-edge turtle 66 turtle 45
make-edge turtle 66 turtle 50
make-edge turtle 53 turtle 107
make-edge turtle 53 turtle 32
make-edge turtle 53 turtle 56
make-edge turtle 20 turtle 73
make-edge turtle 20 turtle 68
make-edge turtle 20 turtle 140
make-edge turtle 20 turtle 11
make-edge turtle 20 turtle 8
make-edge turtle 20 turtle 41
make-edge turtle 20 turtle 42
make-edge turtle 20 turtle 148
make-edge turtle 20 turtle 31
make-edge turtle 20 turtle 102
make-edge turtle 20 turtle 34
make-edge turtle 20 turtle 118
make-edge turtle 20 turtle 50
make-edge turtle 20 turtle 48
make-edge turtle 58 turtle 29
make-edge turtle 58 turtle 86
make-edge turtle 58 turtle 23
make-edge turtle 58 turtle 104
make-edge turtle 58 turtle 21
make-edge turtle 58 turtle 111
make-edge turtle 58 turtle 124
make-edge turtle 58 turtle 142
make-edge turtle 58 turtle 143
make-edge turtle 58 turtle 76
make-edge turtle 58 turtle 132
make-edge turtle 58 turtle 125
make-edge turtle 58 turtle 9
make-edge turtle 58 turtle 14
make-edge turtle 58 turtle 57
make-edge turtle 58 turtle 32
make-edge turtle 58 turtle 2
make-edge turtle 58 turtle 113
make-edge turtle 58 turtle 27
make-edge turtle 58 turtle 72
make-edge turtle 58 turtle 6
make-edge turtle 98 turtle 65
make-edge turtle 98 turtle 140
make-edge turtle 98 turtle 51
make-edge turtle 98 turtle 41
make-edge turtle 98 turtle 42
make-edge turtle 98 turtle 111
make-edge turtle 98 turtle 148
make-edge turtle 98 turtle 40
make-edge turtle 98 turtle 31
make-edge turtle 98 turtle 94
make-edge turtle 98 turtle 44
make-edge turtle 84 turtle 103
make-edge turtle 84 turtle 97
make-edge turtle 84 turtle 9
make-edge turtle 112 turtle 138
make-edge turtle 35 turtle 73
make-edge turtle 35 turtle 134
make-edge turtle 35 turtle 41
make-edge turtle 35 turtle 42
make-edge turtle 35 turtle 43
make-edge turtle 35 turtle 148
make-edge turtle 35 turtle 37
make-edge turtle 35 turtle 34
make-edge turtle 35 turtle 93
make-edge turtle 35 turtle 50
make-edge turtle 35 turtle 48
make-edge turtle 35 turtle 44
make-edge turtle 108 turtle 67
make-edge turtle 108 turtle 50
make-edge turtle 108 turtle 43
make-edge turtle 81 turtle 122
make-edge turtle 81 turtle 75
make-edge turtle 81 turtle 70
make-edge turtle 81 turtle 22
make-edge turtle 81 turtle 141
make-edge turtle 81 turtle 26
make-edge turtle 81 turtle 60
make-edge turtle 81 turtle 76
make-edge turtle 81 turtle 135
make-edge turtle 22 turtle 141
make-edge turtle 22 turtle 135
make-edge turtle 52 turtle 55
make-edge turtle 139 turtle 114
make-edge turtle 139 turtle 126
make-edge turtle 139 turtle 134
make-edge turtle 111 turtle 29
make-edge turtle 111 turtle 140
make-edge turtle 111 turtle 23
make-edge turtle 111 turtle 51
make-edge turtle 111 turtle 49
make-edge turtle 111 turtle 104
make-edge turtle 111 turtle 21
make-edge turtle 111 turtle 124
make-edge turtle 111 turtle 142
make-edge turtle 111 turtle 94
make-edge turtle 111 turtle 143
make-edge turtle 111 turtle 132
make-edge turtle 111 turtle 9
make-edge turtle 111 turtle 57
make-edge turtle 111 turtle 14
make-edge turtle 111 turtle 2
make-edge turtle 111 turtle 16
make-edge turtle 111 turtle 5
make-edge turtle 111 turtle 113
make-edge turtle 111 turtle 31
make-edge turtle 111 turtle 118
make-edge turtle 111 turtle 83
make-edge turtle 33 turtle 118
make-edge turtle 33 turtle 140
make-edge turtle 50 turtle 29
make-edge turtle 50 turtle 140
make-edge turtle 50 turtle 51
make-edge turtle 50 turtle 8
make-edge turtle 50 turtle 67
make-edge turtle 50 turtle 42
make-edge turtle 50 turtle 145
make-edge turtle 50 turtle 117
make-edge turtle 50 turtle 94
make-edge turtle 50 turtle 73
make-edge turtle 50 turtle 28
make-edge turtle 50 turtle 146
make-edge turtle 50 turtle 41
make-edge turtle 50 turtle 43
make-edge turtle 50 turtle 148
make-edge turtle 50 turtle 46
make-edge turtle 50 turtle 37
make-edge turtle 50 turtle 31
make-edge turtle 50 turtle 102
make-edge turtle 50 turtle 34
make-edge turtle 50 turtle 118
make-edge turtle 50 turtle 19
make-edge turtle 50 turtle 147
make-edge turtle 50 turtle 45
make-edge turtle 50 turtle 48
make-edge turtle 50 turtle 44
make-edge turtle 132 turtle 29
make-edge turtle 132 turtle 23
make-edge turtle 132 turtle 51
make-edge turtle 132 turtle 2
make-edge turtle 132 turtle 5
make-edge turtle 132 turtle 21
make-edge turtle 132 turtle 113
make-edge turtle 132 turtle 72
make-edge turtle 132 turtle 9
make-edge turtle 9 turtle 25
make-edge turtle 9 turtle 23
make-edge turtle 9 turtle 104
make-edge turtle 9 turtle 97
make-edge turtle 9 turtle 110
make-edge turtle 9 turtle 103
make-edge turtle 9 turtle 2
make-edge turtle 9 turtle 121
make-edge turtle 9 turtle 5
make-edge turtle 9 turtle 118
make-edge turtle 9 turtle 63
make-edge turtle 9 turtle 72
make-edge turtle 9 turtle 83
make-edge turtle 24 turtle 23
make-edge turtle 24 turtle 69
make-edge turtle 24 turtle 135
make-edge turtle 14 turtle 57
make-edge turtle 14 turtle 23
make-edge turtle 14 turtle 142
make-edge turtle 14 turtle 104
make-edge turtle 14 turtle 83
make-edge turtle 146 turtle 65
make-edge turtle 146 turtle 36
make-edge turtle 146 turtle 28
make-edge turtle 146 turtle 61
make-edge turtle 146 turtle 67
make-edge turtle 146 turtle 46
make-edge turtle 146 turtle 102
make-edge turtle 146 turtle 116
make-edge turtle 146 turtle 19
make-edge turtle 146 turtle 147
make-edge turtle 146 turtle 45
make-edge turtle 0 turtle 144
make-edge turtle 0 turtle 115
make-edge turtle 0 turtle 72
make-edge turtle 0 turtle 5
make-edge turtle 16 turtle 51
make-edge turtle 16 turtle 32
make-edge turtle 16 turtle 41
make-edge turtle 16 turtle 148
make-edge turtle 16 turtle 31
make-edge turtle 16 turtle 34
make-edge turtle 16 turtle 94
make-edge turtle 16 turtle 72
make-edge turtle 16 turtle 44
make-edge turtle 43 turtle 68
make-edge turtle 43 turtle 140
make-edge turtle 43 turtle 51
make-edge turtle 43 turtle 8
make-edge turtle 43 turtle 42
make-edge turtle 43 turtle 145
make-edge turtle 43 turtle 117
make-edge turtle 43 turtle 73
make-edge turtle 43 turtle 11
make-edge turtle 43 turtle 41
make-edge turtle 43 turtle 148
make-edge turtle 43 turtle 37
make-edge turtle 43 turtle 31
make-edge turtle 43 turtle 34
make-edge turtle 43 turtle 102
make-edge turtle 43 turtle 118
make-edge turtle 43 turtle 48
make-edge turtle 43 turtle 44
make-edge turtle 116 turtle 61
make-edge turtle 116 turtle 46
make-edge turtle 116 turtle 37
make-edge turtle 116 turtle 102
make-edge turtle 116 turtle 7
make-edge turtle 116 turtle 94
make-edge turtle 77 turtle 122
make-edge turtle 77 turtle 26
make-edge turtle 77 turtle 70
make-edge turtle 77 turtle 25
make-edge turtle 77 turtle 96
make-edge turtle 77 turtle 97
make-edge turtle 77 turtle 60
make-edge turtle 87 turtle 107
make-edge turtle 87 turtle 133
make-edge turtle 87 turtle 88
make-edge turtle 17 turtle 122
make-edge turtle 49 turtle 122
make-edge turtle 49 turtle 29
make-edge turtle 49 turtle 140
make-edge turtle 49 turtle 51
make-edge turtle 49 turtle 32
make-edge turtle 49 turtle 117
make-edge turtle 49 turtle 118
make-edge turtle 49 turtle 97
make-edge turtle 49 turtle 44
make-edge turtle 104 turtle 57
make-edge turtle 104 turtle 23
make-edge turtle 104 turtle 2
make-edge turtle 104 turtle 5
make-edge turtle 104 turtle 72
make-edge turtle 104 turtle 83
make-edge turtle 145 turtle 68
make-edge turtle 145 turtle 11
make-edge turtle 145 turtle 48
make-edge turtle 120 turtle 117
make-edge turtle 120 turtle 29
make-edge turtle 120 turtle 140
make-edge turtle 120 turtle 147
make-edge turtle 120 turtle 32
make-edge turtle 93 turtle 134
make-edge turtle 93 turtle 88
make-edge turtle 93 turtle 54
make-edge turtle 15 turtle 113
make-edge turtle 15 turtle 34
make-edge turtle 15 turtle 23
make-edge turtle 15 turtle 51
make-edge turtle 15 turtle 94
make-edge turtle 15 turtle 2
make-edge turtle 143 turtle 29
make-edge turtle 143 turtle 142
make-edge turtle 143 turtle 44
make-edge turtle 143 turtle 5
make-edge turtle 60 turtle 122
make-edge turtle 60 turtle 75
make-edge turtle 60 turtle 70
make-edge turtle 60 turtle 25
make-edge turtle 60 turtle 96
make-edge turtle 60 turtle 141
make-edge turtle 60 turtle 26
make-edge turtle 60 turtle 76
make-edge turtle 60 turtle 135
make-edge turtle 125 turtle 86
make-edge turtle 125 turtle 2
make-edge turtle 125 turtle 78
make-edge turtle 125 turtle 124
make-edge turtle 125 turtle 92
make-edge turtle 125 turtle 76
make-edge turtle 133 turtle 119
make-edge turtle 133 turtle 107
make-edge turtle 133 turtle 106
make-edge turtle 133 turtle 88
make-edge turtle 122 turtle 62
make-edge turtle 122 turtle 75
make-edge turtle 122 turtle 25
make-edge turtle 122 turtle 96
make-edge turtle 122 turtle 8
make-edge turtle 122 turtle 141
make-edge turtle 122 turtle 26
make-edge turtle 122 turtle 80
make-edge turtle 122 turtle 76
make-edge turtle 122 turtle 129
make-edge turtle 122 turtle 135
make-edge turtle 122 turtle 70
make-edge turtle 122 turtle 91
make-edge turtle 122 turtle 2
make-edge turtle 71 turtle 131
make-edge turtle 11 turtle 37
make-edge turtle 11 turtle 34
make-edge turtle 32 turtle 38
make-edge turtle 32 turtle 29
make-edge turtle 32 turtle 51
make-edge turtle 32 turtle 30
make-edge turtle 32 turtle 42
make-edge turtle 32 turtle 21
make-edge turtle 32 turtle 117
make-edge turtle 32 turtle 97
make-edge turtle 32 turtle 129
make-edge turtle 32 turtle 36
make-edge turtle 32 turtle 103
make-edge turtle 32 turtle 148
make-edge turtle 32 turtle 5
make-edge turtle 32 turtle 31
make-edge turtle 32 turtle 27
make-edge turtle 32 turtle 118
make-edge turtle 32 turtle 147
make-edge turtle 32 turtle 44
make-edge turtle 2 turtle 86
make-edge turtle 2 turtle 128
make-edge turtle 2 turtle 23
make-edge turtle 2 turtle 30
make-edge turtle 2 turtle 117
make-edge turtle 2 turtle 124
make-edge turtle 2 turtle 78
make-edge turtle 2 turtle 26
make-edge turtle 2 turtle 13
make-edge turtle 2 turtle 135
make-edge turtle 2 turtle 18
make-edge turtle 2 turtle 69
make-edge turtle 2 turtle 99
make-edge turtle 2 turtle 57
make-edge turtle 2 turtle 5
make-edge turtle 2 turtle 121
make-edge turtle 2 turtle 113
make-edge turtle 2 turtle 92
make-edge turtle 2 turtle 95
make-edge turtle 2 turtle 72
make-edge turtle 2 turtle 115
make-edge turtle 2 turtle 6
make-edge turtle 37 turtle 10
make-edge turtle 37 turtle 140
make-edge turtle 37 turtle 51
make-edge turtle 37 turtle 8
make-edge turtle 37 turtle 42
make-edge turtle 37 turtle 117
make-edge turtle 37 turtle 94
make-edge turtle 37 turtle 73
make-edge turtle 37 turtle 41
make-edge turtle 37 turtle 102
make-edge turtle 37 turtle 34
make-edge turtle 37 turtle 48
make-edge turtle 37 turtle 44
make-edge turtle 34 turtle 10
make-edge turtle 34 turtle 140
make-edge turtle 34 turtle 51
make-edge turtle 34 turtle 8
make-edge turtle 34 turtle 42
make-edge turtle 34 turtle 117
make-edge turtle 34 turtle 94
make-edge turtle 34 turtle 73
make-edge turtle 34 turtle 148
make-edge turtle 34 turtle 31
make-edge turtle 34 turtle 118
make-edge turtle 72 turtle 57
make-edge turtle 72 turtle 23
make-edge turtle 72 turtle 5
make-edge turtle 72 turtle 113
make-edge turtle 72 turtle 83
make-edge turtle 45 turtle 29
make-edge turtle 45 turtle 140
make-edge turtle 45 turtle 51
make-edge turtle 45 turtle 67
make-edge turtle 45 turtle 117
make-edge turtle 45 turtle 40
make-edge turtle 45 turtle 7
make-edge turtle 45 turtle 94
make-edge turtle 45 turtle 65
make-edge turtle 45 turtle 61
make-edge turtle 45 turtle 28
make-edge turtle 45 turtle 148
make-edge turtle 45 turtle 113
make-edge turtle 45 turtle 31
make-edge turtle 45 turtle 102
make-edge turtle 45 turtle 147
make-edge turtle 6 turtle 18
make-edge turtle 6 turtle 57
make-edge turtle 6 turtle 99
make-edge turtle 6 turtle 124
make-edge turtle 6 turtle 78
make-edge turtle 6 turtle 92
make-edge turtle 6 turtle 95
make-edge turtle 38 turtle 140
make-edge turtle 38 turtle 51
make-edge turtle 38 turtle 42
make-edge turtle 38 turtle 31
make-edge turtle 38 turtle 117
make-edge turtle 38 turtle 118
make-edge turtle 3 turtle 95
make-edge turtle 3 turtle 130
make-edge turtle 3 turtle 101
make-edge turtle 75 turtle 70
make-edge turtle 75 turtle 25
make-edge turtle 75 turtle 141
make-edge turtle 75 turtle 26
make-edge turtle 75 turtle 76
make-edge turtle 75 turtle 135
make-edge turtle 86 turtle 124
make-edge turtle 96 turtle 26
make-edge turtle 96 turtle 70
make-edge turtle 96 turtle 25
make-edge turtle 128 turtle 23
make-edge turtle 128 turtle 135
make-edge turtle 23 turtle 29
make-edge turtle 23 turtle 137
make-edge turtle 23 turtle 117
make-edge turtle 23 turtle 124
make-edge turtle 23 turtle 142
make-edge turtle 23 turtle 110
make-edge turtle 23 turtle 135
make-edge turtle 23 turtle 69
make-edge turtle 23 turtle 103
make-edge turtle 23 turtle 57
make-edge turtle 23 turtle 113
make-edge turtle 8 turtle 10
make-edge turtle 8 turtle 140
make-edge turtle 8 turtle 51
make-edge turtle 8 turtle 42
make-edge turtle 8 turtle 117
make-edge turtle 8 turtle 94
make-edge turtle 8 turtle 73
make-edge turtle 8 turtle 148
make-edge turtle 8 turtle 31
make-edge turtle 8 turtle 48
make-edge turtle 8 turtle 44
make-edge turtle 67 turtle 73
make-edge turtle 67 turtle 140
make-edge turtle 67 turtle 117
make-edge turtle 67 turtle 102
make-edge turtle 67 turtle 147
make-edge turtle 67 turtle 48
make-edge turtle 42 turtle 29
make-edge turtle 42 turtle 10
make-edge turtle 42 turtle 140
make-edge turtle 42 turtle 51
make-edge turtle 42 turtle 30
make-edge turtle 42 turtle 40
make-edge turtle 42 turtle 117
make-edge turtle 42 turtle 94
make-edge turtle 42 turtle 73
make-edge turtle 42 turtle 65
make-edge turtle 42 turtle 41
make-edge turtle 42 turtle 148
make-edge turtle 42 turtle 31
make-edge turtle 42 turtle 118
make-edge turtle 42 turtle 147
make-edge turtle 42 turtle 48
make-edge turtle 42 turtle 44
make-edge turtle 114 turtle 12
make-edge turtle 114 turtle 134
make-edge turtle 114 turtle 82
make-edge turtle 114 turtle 54
make-edge turtle 26 turtle 25
make-edge turtle 26 turtle 141
make-edge turtle 26 turtle 76
make-edge turtle 26 turtle 110
make-edge turtle 26 turtle 135
make-edge turtle 26 turtle 70
make-edge turtle 26 turtle 69
make-edge turtle 26 turtle 121
make-edge turtle 26 turtle 63
make-edge turtle 97 turtle 103
make-edge turtle 97 turtle 121
make-edge turtle 142 turtle 57
make-edge turtle 142 turtle 21
make-edge turtle 142 turtle 118
make-edge turtle 142 turtle 95
make-edge turtle 76 turtle 70
make-edge turtle 76 turtle 25
make-edge turtle 76 turtle 141
make-edge turtle 76 turtle 124
make-edge turtle 76 turtle 135
make-edge turtle 129 turtle 31
make-edge turtle 129 turtle 140
make-edge turtle 135 turtle 70
make-edge turtle 135 turtle 25
make-edge turtle 135 turtle 141
make-edge turtle 73 turtle 29
make-edge turtle 73 turtle 140
make-edge turtle 73 turtle 51
make-edge turtle 73 turtle 94
make-edge turtle 73 turtle 148
make-edge turtle 73 turtle 31
make-edge turtle 73 turtle 118
make-edge turtle 73 turtle 48
make-edge turtle 73 turtle 44
make-edge turtle 134 turtle 12
make-edge turtle 134 turtle 126
make-edge turtle 134 turtle 82
make-edge turtle 134 turtle 54
make-edge turtle 148 turtle 29
make-edge turtle 148 turtle 10
make-edge turtle 148 turtle 140
make-edge turtle 148 turtle 51
make-edge turtle 148 turtle 30
make-edge turtle 148 turtle 117
make-edge turtle 148 turtle 40
make-edge turtle 148 turtle 94
make-edge turtle 148 turtle 65
make-edge turtle 148 turtle 41
make-edge turtle 148 turtle 31
make-edge turtle 148 turtle 118
make-edge turtle 148 turtle 147
make-edge turtle 148 turtle 44
make-edge turtle 46 turtle 102
make-edge turtle 46 turtle 7
make-edge turtle 121 turtle 25
make-edge turtle 126 turtle 12
make-edge turtle 126 turtle 25
make-edge turtle 31 turtle 10
make-edge turtle 31 turtle 140
make-edge turtle 31 turtle 51
make-edge turtle 31 turtle 30
make-edge turtle 31 turtle 40
make-edge turtle 31 turtle 117
make-edge turtle 31 turtle 94
make-edge turtle 31 turtle 36
make-edge turtle 31 turtle 41
make-edge turtle 31 turtle 118
make-edge turtle 31 turtle 147
make-edge turtle 31 turtle 44
make-edge turtle 92 turtle 18
make-edge turtle 92 turtle 68
make-edge turtle 92 turtle 57
make-edge turtle 92 turtle 124
make-edge turtle 29 turtle 140
make-edge turtle 29 turtle 51
make-edge turtle 29 turtle 30
make-edge turtle 29 turtle 40
make-edge turtle 29 turtle 94
make-edge turtle 29 turtle 36
make-edge turtle 29 turtle 28
make-edge turtle 29 turtle 61
make-edge turtle 29 turtle 57
make-edge turtle 29 turtle 5
make-edge turtle 29 turtle 102
make-edge turtle 29 turtle 118
make-edge turtle 29 turtle 147
make-edge turtle 62 turtle 80
make-edge turtle 62 turtle 91
make-edge turtle 144 turtle 56
make-edge turtle 21 turtle 103
make-edge turtle 21 turtle 51
make-edge turtle 21 turtle 5
make-edge turtle 21 turtle 131
make-edge turtle 21 turtle 94
make-edge turtle 21 turtle 115
make-edge turtle 21 turtle 83
make-edge turtle 80 turtle 91
make-edge turtle 94 turtle 10
make-edge turtle 94 turtle 140
make-edge turtle 94 turtle 51
make-edge turtle 94 turtle 30
make-edge turtle 94 turtle 40
make-edge turtle 94 turtle 117
make-edge turtle 94 turtle 65
make-edge turtle 94 turtle 36
make-edge turtle 94 turtle 61
make-edge turtle 94 turtle 118
make-edge turtle 94 turtle 147
make-edge turtle 94 turtle 44
make-edge turtle 85 turtle 55
make-edge turtle 85 turtle 136
make-edge turtle 85 turtle 119
make-edge turtle 85 turtle 88
make-edge turtle 70 turtle 25
make-edge turtle 70 turtle 141
make-edge turtle 5 turtle 36
make-edge turtle 5 turtle 30
make-edge turtle 5 turtle 115
make-edge turtle 5 turtle 83
make-edge turtle 95 turtle 78
make-edge turtle 95 turtle 79
make-edge turtle 82 turtle 107
make-edge turtle 82 turtle 54
make-edge turtle 63 turtle 110
make-edge turtle 107 turtle 55
make-edge turtle 107 turtle 54
make-edge turtle 107 turtle 88
make-edge turtle 44 turtle 10
make-edge turtle 44 turtle 140
make-edge turtle 44 turtle 51
make-edge turtle 44 turtle 40
make-edge turtle 44 turtle 65
make-edge turtle 44 turtle 61
make-edge turtle 44 turtle 41
make-edge turtle 44 turtle 118
make-edge turtle 44 turtle 48
make-edge turtle 55 turtle 119
make-edge turtle 55 turtle 56
make-edge turtle 140 turtle 10
make-edge turtle 140 turtle 51
make-edge turtle 140 turtle 30
make-edge turtle 140 turtle 117
make-edge turtle 140 turtle 40
make-edge turtle 140 turtle 65
make-edge turtle 140 turtle 36
make-edge turtle 140 turtle 41
make-edge turtle 140 turtle 118
make-edge turtle 140 turtle 147
make-edge turtle 140 turtle 48
make-edge turtle 78 turtle 124
make-edge turtle 78 turtle 131
make-edge turtle 78 turtle 79
make-edge turtle 40 turtle 65
make-edge turtle 40 turtle 51
make-edge turtle 124 turtle 57
make-edge turtle 13 turtle 99
make-edge turtle 65 turtle 61
make-edge turtle 65 turtle 51
make-edge turtle 65 turtle 147
make-edge turtle 18 turtle 68
make-edge turtle 18 turtle 57
make-edge turtle 57 turtle 83
make-edge turtle 48 turtle 51
make-edge turtle 48 turtle 41
make-edge turtle 48 turtle 118
make-edge turtle 147 turtle 51
make-edge turtle 147 turtle 117
make-edge turtle 147 turtle 7
make-edge turtle 147 turtle 36
make-edge turtle 147 turtle 28
make-edge turtle 147 turtle 102
make-edge turtle 147 turtle 19
make-edge turtle 56 turtle 88
make-edge turtle 10 turtle 51
make-edge turtle 10 turtle 41
make-edge turtle 25 turtle 141
make-edge turtle 68 turtle 30
make-edge turtle 51 turtle 30
make-edge turtle 51 turtle 117
make-edge turtle 51 turtle 36
make-edge turtle 51 turtle 61
make-edge turtle 51 turtle 41
make-edge turtle 51 turtle 102
make-edge turtle 51 turtle 118
make-edge turtle 30 turtle 36
make-edge turtle 30 turtle 117
make-edge turtle 117 turtle 36
make-edge turtle 117 turtle 41
make-edge turtle 117 turtle 118
make-edge turtle 7 turtle 102
make-edge turtle 7 turtle 61
make-edge turtle 36 turtle 41
make-edge turtle 61 turtle 102
make-edge turtle 41 turtle 118
make-edge turtle 54 turtle 88
make-edge turtle 112 turtle 62

ask links [set color gray]
repeat 80 [do-layout]
end


;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Runtime Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;


to spread
  let colortospread white
  ;; infection can't take place if every agent has already been infected
  ifelse not any? turtles with [color = white]
    [stop]
   
[
  ask turtles with [ color != white ]
  [
    set colortospread color
    ;; infect neighbors
    ask link-neighbors
    [ 
      if ( random-float 1 <= prob-infection )  ;; infect with probability prob-infection
      [
        if (color = white)  ;; agents can be infected only once
        [
          set color colortospread
          ask link-with myself [set color (colortospread + 2)]
          show-turtle
        ]
      ]
    ]
  ]
  ]
  
  do-plotting
  tick
end


to select-blue
  let current-point nobody
  
  if mouse-down? [
  let x round mouse-xcor
  let y round mouse-ycor
  ;; if we don't have a point yet, pick the closest one
  if current-point = nobody [
    set current-point min-one-of turtles [distancexy x y]
  ]
  ask current-point [
    set color blue
    set size 2
  ]
  ]
end

to select-red
  let current-point nobody
  
  if mouse-down? [
  let x round mouse-xcor
  let y round mouse-ycor
  ;; if we don't have a point yet, pick the closest one
  if current-point = nobody [
    set current-point min-one-of turtles [distancexy x y]
  ]
  ask current-point [
    set color red
    set size 2]
  ]
end

;; in complex contagion, a node will only adopt an opinion
;; if at least two of its neighbors share that opinion
;; it will decide based on the proportion of its neighbors
;; that are either blue or red
to complex-spread
  let colortospread white
  let probblueoverred 0
  ifelse not any? turtles with [color = white] 
    [stop]   
[
  ask turtles with [ color = white ]
  [
    let redneighbors count link-neighbors with [color = red]
    let blueneighbors count link-neighbors with [color = blue]
    ifelse (redneighbors >= 2)
    [ 
      ifelse (blueneighbors < 2) 
      [
          set color red
          show-turtle
      ][
         set probblueoverred (blueneighbors) / (count link-neighbors)
         ifelse ( random-float 1 <= probblueoverred ) [
           set color blue
         ][
           set color red
         ]
      ]
    ]
    [
      if (blueneighbors >= 2) 
      [
        set color blue
        show-turtle
      ]
    ]
  ]
  ]
  
  do-plotting
  tick
end

to clear-opinion
  ask turtles [
    set color white
    set size 1
  ]
  ask links [
    set color gray
   ]
  set num-blue 0
  set num-red 0
end

;;;;;;;;;;;;;;;;;;;;;;;
;;; Edge Operations ;;;
;;;;;;;;;;;;;;;;;;;;;;;

;; connects the two turtles
to make-edge [node1 node2]
  ask node1 [
    ifelse (node1 = node2) 
    [
      show "error: self-loop attempted"
    ]
    [
      create-link-with node2 [ set color green ]
     ]
  ]
end

;;;;;;;;;;;;;;;;
;;; Plotting ;;;
;;;;;;;;;;;;;;;;

to do-plotting
     ;; plot the number of infected individuals at each step
     set-current-plot "Tally"
     set-current-plot-pen "num-blue"
     
     set num-blue count turtles with [color = blue]
     plotxy ticks num-blue
     
      set-current-plot-pen "num-red"
     
     set num-red count turtles with [color = red]
     plotxy ticks num-red
end

;;;;;;;;;;;;;;
;;; Layout ;;;
;;;;;;;;;;;;;;
;; resize-turtles, change back and forth from size based on degree to a size of 1
to resize-nodes
  ifelse not any? turtles with [size > 1]
  [
    ;; a node is a circle with diameter determined by
    ;; the SIZE variable; using SQRT makes the circle's
    ;; area proportional to its degree
    ask turtles [ set size 3 / 4 * ln (count link-neighbors + 0.5)]
  ]
  [
    ask turtles [ set size 1 ]
  ]
end

;; spring layout of infection tree while in tree mode
;; otherwise, layout all nodes and links
to do-layout
  repeat 5 [layout-spring turtles links 0.2 4 4]
  display
end