10
10
"""
11
11
12
12
import math
13
+ import random
14
+
15
+ import numpy as np
13
16
14
17
from mesa import Model
15
18
from mesa .datacollection import DataCollector
16
19
from mesa .examples .advanced .wolf_sheep .agents import GrassPatch , Sheep , Wolf
17
20
from mesa .experimental .cell_space import OrthogonalVonNeumannGrid
18
- from mesa .experimental .devs import ABMSimulator
19
21
from mesa .experimental .cell_space .property_layer import PropertyLayer
20
- import numpy as np
21
- import random
22
+ from mesa .experimental .devs import ABMSimulator
22
23
23
24
24
25
class WolfSheep (Model ):
@@ -74,7 +75,10 @@ def __init__(
74
75
75
76
# Create grid using experimental cell space
76
77
self .grid = OrthogonalVonNeumannGrid (
77
- (self .height , self .width ), # use tuple instead of list, otherwise it would fail the dimension check in add_property_layer
78
+ (
79
+ self .height ,
80
+ self .width ,
81
+ ), # use tuple instead of list, otherwise it would fail the dimension check in add_property_layer
78
82
torus = True ,
79
83
capacity = math .inf ,
80
84
random = self .random ,
@@ -92,10 +96,13 @@ def __init__(
92
96
93
97
self .datacollector = DataCollector (model_reporters )
94
98
95
- cliff_arr = [[False ]* self .width for i in range (self .height )]
96
-
97
- cliff_coord = set ([(random .randrange (self .height ), random .randrange (self .width )) for i in range ((width * height )// 3 )] ) # set is used because the random number gen might return the same coordinate
98
- for i ,j in cliff_coord :
99
+ cliff_arr = [[False ] * self .width for i in range (self .height )]
100
+
101
+ cliff_coord = {
102
+ (random .randrange (self .height ), random .randrange (self .width ))
103
+ for i in range ((width * height ) // 3 )
104
+ } # set is used because the random number gen might return the same coordinate
105
+ for i , j in cliff_coord :
99
106
cliff_arr [i ][j ] = True
100
107
101
108
cliff_arr = np .array (cliff_arr )
@@ -104,7 +111,10 @@ def __init__(
104
111
105
112
possibleCells = []
106
113
for cell in self .grid .all_cells .cells :
107
- if (cell .coordinate [0 ], cell .coordinate [1 ]) not in cliff_coord : # so we don't create wolf or sheep on cliff cells
114
+ if (
115
+ cell .coordinate [0 ],
116
+ cell .coordinate [1 ],
117
+ ) not in cliff_coord : # so we don't create wolf or sheep on cliff cells
108
118
possibleCells .append (cell )
109
119
110
120
# Create sheep:
0 commit comments