print(f"Value of the configuration after Hill Climber: " f"{climber.graph.calculate_value()}") # --------------------------- Simulated Annealing -------------------------- # It is very difficult to find a good starting temperature for SA. A rule to # help you find one is to use the maximum change in score that could happen # when mutating your state. In our case, this is 19, because the transmitter # maximum difference in score between the most expensive and the cheapest # transmitter is 19. print("Setting up Simulated Annealing...") simanneal = sa.SimulatedAnnealing(random_graph, transmitters.get_scheme(1), temperature=19) print("Running Simulated Annealing...") simanneal.run(2000, verbose=True) print(f"Value of the configuration after Simulated Annealing: " f"{simanneal.graph.calculate_value()}") # --------------------------- Visualisation -------------------------------- # Turn fast_plot on for a matplotlib plot, which will be faster than Bokeh. # Bokeh will also be too slow for plotting Russia, so turn on when Russia is # selected as input! fast_plot = False vis.visualise(simanneal.graph, f"data/{data_folder}/{data_folder}_regions.shp", fast_plot=fast_plot)
from code.algorithms import randomize from code.classes import graph, transmitters from code.visualisation import visualise as vis if __name__ == '__main__': # Create a graph from our data test_graph = graph.Graph('data/US/states.csv', 'data/US/neighbours.csv') # Create the transmitter cost schemes transmitters = transmitters.CostScheme('data/transmitters.csv') # Perform algorithm that keeps reassigning values until the case is solvedd randomize.random_reassignment(test_graph, transmitters.get_scheme(1)) # Example on how to get the nodes that have neighbours with the same value and print them violating_nodes = test_graph.get_violations() print(len(violating_nodes)) print(test_graph.get_violations()) vis.visualise(test_graph, "data/US/gz_2010_us_040_00_500k.json")
climber = hc.HillClimber(random_graph, transmitters.get_scheme(1)) print("Running Hill Climber...") climber.run(2000, verbose=True) print( f"Value of the configuration after Hill Climber: {climber.graph.calculate_value()}" ) # --------------------------- Simulated Annealing -------------------------- # It is very difficult to find a good starting temperature for SA. A rule to # help you find one is to use the maximum change in score that could happen # when mutating your state. In our case, this is 19, because the transmitter # maximum difference in score between the most expensive and the cheapest # transmitter is 19. print("Setting up Simulated Annealing...") simanneal = sa.SimulatedAnnealing(random_graph, transmitters.get_scheme(1), temperature=19) print("Running Simulated Annealing...") simanneal.run(2000, verbose=True) print( f"Value of the configuration after Simulated Annealing: {simanneal.graph.calculate_value()}" ) # --------------------------- Visualisation -------------------------------- vis.visualise(simanneal.graph, "data/US/gz_2010_us_040_00_500k.json")
swap_answers = prompt(swap_type, style=style) # With Swap if swap_answers["swap"]: greedy_swap = greedy.SwapGreedy(district, 1, 0) result = greedy_swap.run_battery_swap() else: greedy = greedy.Greedy(district, 1, 0) result = greedy.run_battery() # Greedy House else: greedy_swap = greedy.SwapGreedy(district, 1, 0) result = greedy_swap.run_houses_swap() # Clustering algorithms else: clust = cluster.Cluster(district) result = clust.run_cluster() # Table overview of results x.add_column("District", [result["district"].name]) x.add_column("Success", [result["success"]]) x.add_column("Total Cost", [result["district"].total_cost]) x.add_column("Discounted Cost", [result["district"].discounted_cost]) print(x) # Visualisation vis.visualise(result["district"])