def setup(args): """Set up the config object used to interact with the GUI""" # chaparral,denseForest,lake,canyon,burning,burnt = neighbours config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "Forest Fire" config.dimensions = 2 config.states = \ ( CHAPARRAL, DENSE_FORREST, LAKE, CANYON, BURNING, BURNT, START_BURN, END_BURN ) # ------------ ------------------------------------------------------------- config.state_colors = \ [ (0.6,0.6,0), #chaparral (0,0.4,0), #dense forrest (0,0.5,1), #lake (0.5,0.5,0.5), #canyon (1,0,0), #burning (0.25,0.25,0.25), #burnt (1,0.7,0), #starting to burn (0.8,0,0.2) #ending burn ] config.grid_dims = (grid_size, grid_size) config.num_generations = 1000 config.set_initial_grid(initial_grid) config.wrap = False # -------------------------------------------------------------------- # the GUI calls this to pass the user defined config # into the main system with an extra argument # do not change if len(args) == 2: config.save() sys.exit() return config
def test_minimal_2d_vars_fill(self): ca_config = CAConfig(self.filepath2d) prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertIsInstance(ca_config, CAConfig) self.assertEqual(ca_config.states, (0,1,2)) #values from file ca_config.fill_in_defaults() #values from defaults expected_gens = 100 expected_dims = (200, 200) expected_grid = np.zeros(expected_dims) expected_nhood = np.ones((3,3)) self.assertEqual(ca_config.num_generations, expected_gens) self.assertEqual(ca_config.grid_dims, expected_dims) self.assertTrue(np.array_equal(ca_config.initial_grid, expected_grid)) self.assertTrue(np.array_equal(ca_config.nhood_arr, expected_nhood))
def setup(args): """Set up the config object used to interact with the GUI""" config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "Fire spread CaA" config.dimensions = 2 config.states = (0, 1, 2, 3, 4, 5, 6) # STATES: # 0 Background # 1 Water # 2 Canyon # 3 Forest # 4 Village # 5 Fire # 6 Burnt out # config.num_generations = 100 # ------------------------------------------------------------------------- # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(0.5, 0.9, 0.1), (0, 0, 1), (0.4, 0.4, 0.4), (0.4, 0.6, 0.37), (1, 1, 1), (1, 0, 0), (0, 0, 0)] config.grid_dims = (50 * coef, 50 * coef) config.initial_grid = np.zeros(config.grid_dims) config.initial_grid[5 * coef:8 * coef, 5 * coef:8 * coef] = 5 config.initial_grid[10 * coef:15 * coef, 5 * coef:15 * coef] = 1 config.initial_grid[5 * coef:35 * coef, 32 * coef:35 * coef] = 2 config.initial_grid[30 * coef:41 * coef, 15 * coef:25 * coef] = 3 config.initial_grid[48 * coef:50 * coef, :3 * coef] = 4 config.wrap = False config.num_generations = 200 * coef #set_grid_dims(dims = (200, 200)) #set_initial_grid(grid) #config.inital_grid[1,1] = 1 # ---------------------------------------------------------------------- # the GUI calls this to pass the user defined config # into the main system with an extra argument # do not change if len(args) == 2: config.save() sys.exit() return config
def setup(args): """Set up the config object used to interact with the GUI""" # chaparral,denseForest,lake,canyon,burning,burnt = neighbours config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "Forest Fire" config.dimensions = 2 config.states = \ ( CHAPARRAL, DENSE_FORREST, LAKE, CANYON, BURNING, BURNT, START_BURN, END_BURN
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "fire" config.dimensions = 2 config.states = (0, 1, 2, 3, 4, 5, 6) # 0 no fire (yellow) # 1 on fire (red) # 2 burned (dark red) # 3 lake (blue) # 4 forest (green) # 5 canyon (grey) # 6 fuel (brown) # 7 burned canyon (black) # 8 burned forest (dark green) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.num_generations = 500 # 1 GENERATION = 2 HOURS config.grid_dims = (200, 200) config.state_colors = [(0.9, 0.7, 0.1), (1, 0, 0), (0, 0, 0), (0, 0.5, 1), (0, 0.5, 0.3), (0.6, 0.6, 0.6), (0.4, 0.1, 0.1)] config.initial_grid = np.zeros(config.grid_dims) # zero grid halfr, halfc = config.grid_dims[0] // 2, config.grid_dims[ 1] // 2 # calc central square indices config.initial_grid[halfr:halfr + 5, halfc:halfc + 5] = 0 # fill square with state 0 config.initial_grid[40:60, 20:60] = 3 # fill square with state 3 config.initial_grid[120:160, 60:100] = 4 # fill square with state 4 config.initial_grid[20:140, 130:140] = 5 # fill square with state 5 #config.initial_grid[0:3,0:3] = 6 # fill square with state 6 config.initial_grid[0:3, 197:200] = 6 # fill square with state 6 config.wrap = False # Stops fire spreading over grid edges # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def test_1d_fill(self): ca_config = CAConfig(self.filepath1d) prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertIsInstance(ca_config, CAConfig) #values from file ca_config.fill_in_defaults() #values from defaults expected_rulenum = 0 expected_gens = 100 expected_dims = (expected_gens + 1, expected_gens*2 + 1) expected_grid = np.zeros(expected_dims) expected_nhood = np.array([1,1,1]) self.assertEqual(ca_config.rule_num, expected_rulenum) self.assertEqual(ca_config.num_generations, expected_gens) self.assertEqual(ca_config.grid_dims, expected_dims) self.assertTrue(np.array_equal(ca_config.initial_grid, expected_grid)) self.assertTrue(np.array_equal(ca_config.nhood_arr, expected_nhood))
def setup(args): config_path = args[0] config = utils.load(config_path) config.dimensions = 2 config.title = "Forest Fires (Nick)" # States: burnt, unburn, burning... config.states = range(6) config.state_colors = [(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0)] config.num_generations = 5 config.grid_dims = (10, 10) if len(args) == 2: config.save() sys.exit() return config
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "Wolframs 1D CA" config.dimensions = 1 config.states = (0, 1) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.wrap = True # config.state_colors = [(0,0,0),(1,1,1)] # config.num_generations = 100 # config.grid_dims = (200,200) # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): """Set up the config object used to interact with the GUI""" config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "2D test" config.dimensions = 2 config.num_generations = 500 # STATES # 0: chaparral (set as background) # 1: fire # 2: burned area # 3: dense forest # 4: lake # 5: canyon config.states = (0, 1, 2, 3, 4, 5) #terrain = (burn time, ignition time) #chaparral = (288,1); #canyon = (144,0.5); #dense_forest = (8064,3); #burns for 28 days #lake = (0,0); # ------------------------------------------------------------------------- # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(1, 1, 0), (1, 0.2, 0.2), (0, 0, 0), (0, 0.5, 0), (0, 1, 1), (0.5, 0.5, 0.5)] config.grid_dims = (200, 200) config.wrap = False #should solve the problem with fire starting at all 4 corners # ---------------------------------------------------------------------- # the GUI calls this to pass the user defined config # into the main system with an extra argument # do not change if len(args) == 2: config.save() sys.exit() return config
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "Conway's game of life" config.dimensions = 2 config.states = (0, 1, 2, 3, 4, 5, 6, 7) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(0.749, 0.741, 0.003),(0.921, 0.211, 0.098),(0.498, 0.482, 0.529), (0.984, 0.721, 0.274), (0.309, 0.388, 0.160), (0.733, 0.223, 0.368), (0.223, 0.454, 0.733), (0,0,0)] config.num_generations = 2000 config.grid_dims = (200,200) # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "FireStorm" config.dimensions = 2 config.states = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(1, 1, 0), (0, 1, 0), (0.752, 0.752, 0.752), (0, 0, 1), (0, 0, 0), (1, 0, 0), (1, 1, 1), (0.874, 0.615, 0.027), (0.137, 0.325, 0.227), (0.4, 0.4, 0.4), (135 / 255, 62 / 255, 59 / 255)] config.grid_dims = (100, 100) # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "FIRE SPREAD" config.dimensions = 2 config.states = (0, 1) config.wrap = False # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(0.196, 0.804, 0.196),(1.000, 0.000, 0.000)] config.num_generations = 10 config.grid_dims = (50,50) # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "Conway's game of life" config.dimensions = 2 config.states = (0, 1) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- # green = (180/255,238/255,180/255) # fire = (178/255,34/255,34/255) # config.state_colors = [green,fire]#[(180,238,180),(178,34,34)] # config.num_generations = 150 # config.grid_dims = (100,200) # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): """Set up the config object used to interact with the GUI""" config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "NAME" config.dimensions = 2 config.states = STATES # ------------------------------------------------------------------------- # ---- Override the defaults below (these may be changed at anytime) ---- # config.state_colors = [(0,0,0),(1,1,1)] # config.grid_dims = (200, 200) # --------------------------------------------------------------------- # the GUI calls this to pass the user defined config # into the main system with an extra argument # do not change if len(args) == 2: config.save() sys.exit() return config
def transition_func(grid, neighbourstates, neighbourcounts, numValues, waterDrop, initNumValues): args = sys.argv[1:] config_path = args[0] configF = utils.load(config_path) wind_direction = configF.wind_dir #Find cells specified for a water drop, and if correct no of iterations have occured swap them to water wetChap = (waterDrop == 0) & (grid != 6) & (grid != 3) & (initNumValues == 0.2) wetForest = (waterDrop == 0) & (grid != 6) & (grid != 3) & (initNumValues == 2.1) wetCan = (waterDrop == 0) & (grid != 6) & (grid != 3) & (initNumValues == 1.4) numValues[wetChap] -= 0.5 numValues[wetForest] -= 0.2 numValues[wetCan] -= 0.4 grid[wetChap] = 7 grid[wetForest] = 8 grid[wetCan] = 9 #on fire neighbour count dead_neighbours = neighbourcounts[5] + neighbourcounts[6] # Chaparral = state == 0, forest = state == 1, canyon = state == 2, lake = state == 3, town = state == 4 # fire = state == 5, burnt = state == 6 # wet chap = 7, wet forest = 8, wet canyon = 9 # Setting thresholds up chapFireThreshold = 0.5 canFireThreshold = 1.45 forFireThreshold = 6 # adding up depending on burning neighboars add_one_neighbour = (dead_neighbours == 1) & (grid != 3) & (grid != 6) & (grid != 5) add_two_neighbour = (dead_neighbours == 2) & (grid != 3) & (grid != 6) & (grid != 5) add_more_neighbour = (dead_neighbours >= 3) & (grid != 3) & (grid != 6) & (grid != 5) one_neighbour_random = np.random.uniform(0.01, 0.05, (100, 100)) two_neighbour_random = np.random.uniform(0.05, 0.07, (100, 100)) more_neighbour_random = np.random.uniform(0.08, 0.1, (100, 100)) numValues[add_one_neighbour] += one_neighbour_random[add_one_neighbour] numValues[add_two_neighbour] += two_neighbour_random[add_two_neighbour] numValues[add_more_neighbour] += more_neighbour_random[add_more_neighbour] #adding wind into the equation numValues = wind(wind_direction, numValues, neighbourstates, grid) # Checking values and setting states chap_cells = (grid == 0) forest_cells = (grid == 1) can_cells = (grid == 2) on_fire = (grid == 5) switch_chap_to_fire = (dead_neighbours > 0) & (numValues >= chapFireThreshold) & (grid == 0) switch_forest_to_fire = (dead_neighbours > 0) & (numValues >= forFireThreshold) & (grid == 1) switch_can_to_fire = (dead_neighbours > 0) & (numValues >= canFireThreshold) & (grid == 2) switch_wet_chap_to_fire = (dead_neighbours > 0) & ( numValues >= forFireThreshold) & (grid == 7) switch_wet_forest_to_fire = (dead_neighbours > 0) & ( numValues >= forFireThreshold) & (grid == 8) switch_wet_can_to_fire = (dead_neighbours > 0) & ( numValues >= forFireThreshold) & (grid == 9) switch_chap_to_burnt = (dead_neighbours > 0) & (numValues <= 0) & (grid == 5) switch_forest_to_burnt = (dead_neighbours > 0) & (numValues <= 0) & (grid == 5) switch_can_to_burnt = (dead_neighbours > 0) & (numValues <= 0) & (grid == 5) itMult = 8 itHours = itMult * 24 chap_random = np.random.random_integers(itMult * 6, itHours * 5, (100, 100)) can_random = np.random.random_integers(itMult * 6, itMult * 18, (100, 100)) forest_random = np.random.random_integers(itHours * 15, itHours * 31, (100, 100)) numValues[switch_chap_to_fire] += chap_random[switch_chap_to_fire] numValues[switch_can_to_fire] += can_random[switch_can_to_fire] numValues[switch_forest_to_fire] += forest_random[switch_forest_to_fire] numValues[switch_wet_chap_to_fire] += chap_random[switch_wet_chap_to_fire] numValues[switch_wet_forest_to_fire] += forest_random[ switch_wet_forest_to_fire] numValues[switch_wet_can_to_fire] += can_random[switch_wet_can_to_fire] numValues[on_fire] -= 1 grid[switch_chap_to_fire] = 5 grid[switch_forest_to_fire] = 5 grid[switch_can_to_fire] = 5 grid[switch_wet_chap_to_fire] = 5 grid[switch_wet_forest_to_fire] = 5 grid[switch_wet_can_to_fire] = 5 grid[switch_chap_to_burnt] = 6 grid[switch_forest_to_burnt] = 6 grid[switch_can_to_burnt] = 6 waterDrop -= 1 return grid
def setup(args): config_path = args[0] config = utils.load(config_path) # ---THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED--- config.title = "Forest Fire Simulation" config.dimensions = 2 config.states = (0, 1, 2, 3, 4, 5, 6) # ------------------------------------------------------------------------ # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(0, 1, 0), (1, 0, 0), (0.133, 0.55, 0.133), (0.7, 0.4, 0), (0, 0, 1), (0, 0, 0), (0.66, 0.66, 0.66)] config.num_generations = 1500 if config.grid_dims is None: if config.dimensions == 2: config.grid_dims = (100, 100) if config.initial_grid is None: fillstate = config.states[0] if config.states is not None else 0 newGrid = np.zeros(config.grid_dims, dtype=type(fillstate)) for row in range(config.grid_dims[0]): for col in range(config.grid_dims[1]): if ((row >= (config.grid_dims[0] / 5) and row <= ((3 * config.grid_dims[0]) / 10)) and (col >= (config.grid_dims[1] / 10) and col <= ((3 * config.grid_dims[1]) / 10))): newGrid[row][col] = 4 continue if ((row >= config.grid_dims[0] / 10 and row <= (7 * config.grid_dims[0]) / 10) and (col >= ((13 * config.grid_dims[1]) / 20) and col <= (7 * config.grid_dims[1]) / 10)): newGrid[row][col] = 3 continue if ((row >= (3 * config.grid_dims[0]) / 5 and row <= (4 * config.grid_dims[0]) / 5) and (col >= (3 * config.grid_dims[1]) / 10 and col <= (config.grid_dims[1] / 2))): newGrid[row][col] = 2 continue if ((row > (195 * config.grid_dims[0]) / 200 and row <= config.grid_dims[0]) and (col >= ((0 * config.grid_dims[1])) and col < (config.grid_dims[1]) / 20)): newGrid[row][col] = 6 continue newGrid[row][col] = 0 config.initial_grid = newGrid config.wrap = False # ---------------------------------------------------------------------- if len(args) == 2: config.save() sys.exit() return config
def setup(args): """Set up the config object used to interact with the GUI""" config_path = args[0] config = utils.load(config_path) # -- THE CA MUST BE RELOADED IN THE GUI IF ANY OF THE BELOW ARE CHANGED -- config.title = "2D test" config.dimensions = 2 config.num_generations = 800 # STATES # 0: chaparral (set as background) # 1: fire # 2: burned area # 3: dense forest # 4: lake # 5: canyon # 6: town # 7: fire breaks config.states = (0, 1, 2, 3, 4, 5, 6, 7) #terrain = (ignition_time, burn_time) #chaparral = (2,43); #canyon = (1,2); #dense_forest = (6,403); #burns for month (approximated to 28 days) #lake = (0,0); #town # ------------------------------------------------------------------------- # ---- Override the defaults below (these may be changed at anytime) ---- config.state_colors = [(1, 1, 0), (1, 0.2, 0.2), (0, 0, 0), (0, 0.5, 0), (0, 1, 1), (0.5, 0.5, 0.5), (0, 0.1, 1), (0.4, 0.4, 0.2)] config.grid_dims = (200, 200) config.initial_grid = np.full((200, 200), 0) """for x in range (15,19): for y in range (160,200): config.initial_grid[y][x] = 4""" for x in range(70, 120): for y in range(120, 160): config.initial_grid[y][x] = 3 for x in range(20, 70): for y in range(40, 70): config.initial_grid[y][x] = 4 for x in range(140, 160): for y in range(15, 140): config.initial_grid[y][x] = 5 for x in range(0, 15): for y in range(190, 200): config.initial_grid[y][x] = 6 #set the fire to automatically starting #represents fire at the power plant #config.initial_grid[0][0] = 1 #represents a fire starting at the incinerator config.initial_grid[0][199] = 1 #When dealing with south winds #config.initial_grid[1][0] = 1 #config.initial_grid[1][199] = 1 #config.initial_grid[2][0] = 1 #config.initial_grid[2][199] = 1 config.wrap = False #should solve the problem with fire starting at all 4 corners # ---------------------------------------------------------------------- # the GUI calls this to pass the user defined config # into the main system with an extra argument # do not change if len(args) == 2: config.save() sys.exit() return config