Commit 6324a170 authored by Karol Actun's avatar Karol Actun
Browse files

merge with master

parents ceaf7b0c 05a8706a
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/docs/source/_templates" />
</list>
</option>
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
......@@ -4,12 +4,14 @@
seedvalue = 12
## Maximum round number in swarm-world, 0 = infinite
max_round = 0
max_round = 100
## 1 = Call of particles in randmom order
## 0 = Call of particles in added order in scenario
## 1/True = Call of particles in randmom order
## 0/False = Call of particles in added order in scenario
particle_random_order = True
## 1/True = Call of particles in randmom order after each round
## 0/False = Call of particles in randmom order only once at the start of the simulator
particle_random_order_always = False
## Viewing window size in pixels
window_size_x = 1920
window_size_y = 1080
......@@ -42,24 +44,24 @@ gui = default_gui
;grid_size = 100
# end of Triangular grid configs
;
;# cubic grid default configs:
;grid_class = CubicGrid
;particle_model_file = 3d_particle_low_poly.obj
;tile_model_file = 3d_cube_tile.obj
;location_model_file = 3d_location.obj
;grid_size = 10
;# end of cubic grid configs
# cubic grid default configs:
grid_class = CubicGrid
particle_model_file = 3d_particle_low_poly.obj
tile_model_file = 3d_cube_tile.obj
location_model_file = 3d_location.obj
grid_size = 10
# end of cubic grid configs
# ccp grid default configs:
grid_class = CCPGrid
particle_model_file = 3d_particle.obj
tile_model_file = 3d_ccp_tile.obj
location_model_file = 3d_location_2.obj
grid_size = 10
# end of ccp grid configs
;# ccp grid default configs:
;grid_class = CCPGrid
;particle_model_file = 3d_particle.obj
;tile_model_file = 3d_ccp_tile.obj
;location_model_file = 3d_location_2.obj
;grid_size = 10
;# end of ccp grid configs
;
# matter default colors (rgba)
particle_color = (0.8, 0.3, 0.3, 1.0)
......@@ -76,7 +78,7 @@ cursor_color = (0.5, 0.5, 0.5, 0.5)
center_color = (1.0, 0.0, 0.0, 0.5)
# background (rgb)
background_color = (0.8, 0.8, 0.8)
background_color = (1.0, 1.0, 1.0)
# color of grid lines (rgba)
line_color = (0.0, 0.0, 0.0, 1.0)
# length/scaling of the grid lines (max should be 1,1,1)
......@@ -130,6 +132,33 @@ particle_mm_size = 2
tile_mm_size = 2
[File]
##Examples##
#marking (rasenmäher) in 3D
scenario = marking_3d_scenario
solution = marking_3d_local
##Moving
#scenario = lonely_particle
#scenario = n_particle_in_line
#solution = random_walk
#solution = triangular_round_walk
#solution = random_walk_with_take_and_drop
## Creating and Deleting
#scenario = lonely_particle
#solution = create_delete
## Take and Drop
#scenario=two_particles_tiles_locations
#solution= take_drop_aims
## Read and Write
#scenario = two_particles_tiles_markers
#solution = read_write
#scenario = test_interfaces
#solution = test_all_the_interfaces
>>>>>>> origin
......@@ -159,7 +159,7 @@ class Grid(ABC):
current_ns = ns
result.update(ns)
for i in range(radius):
for _ in range(radius):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_coordinates_not_in_set(n, result)
......@@ -187,7 +187,7 @@ class Grid(ABC):
seen.update(ns)
seen.add(coordinates)
for i in range(radius-1):
for _ in range(radius-1):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_coordinates_not_in_set(n, seen)
......
......@@ -12,6 +12,7 @@ class ConfigData:
self.seed_value = config.getint("Simulator", "seedvalue")
self.max_round = config.getint("Simulator", "max_round")
self.particle_random_order = config.getboolean("Simulator", "particle_random_order")
self.particle_random_order_always = config.getboolean("Simulator", "particle_random_order_always")
self.window_size_x = config.getint("Simulator", "window_size_x")
self.window_size_y = config.getint("Simulator", "window_size_y")
......
......@@ -89,18 +89,18 @@ class Particle(matter.Matter):
"""
direction_coord = get_coordinates_in_direction(self.coordinates, direction)
direction, direction_coord = self.check_within_border(direction, direction_coord)
if self.world.grid.are_valid_coordinates(direction_coord):
if direction_coord not in self.world.particle_map_coordinates:
if self.coordinates in self.world.particle_map_coordinates:
del self.world.particle_map_coordinates[self.coordinates]
self.coordinates = direction_coord
self.world.particle_map_coordinates[self.coordinates] = self
self.world.vis.particle_changed(self)
logging.info("particle %s successfully moved to %s", str(self.get_id()), direction)
self.world.csv_round.update_metrics(steps=1)
self.csv_particle_writer.write_particle(steps=1)
self.check_for_carried_tile_or_particle()
return True
if self.world.grid.are_valid_coordinates(direction_coord) \
and direction_coord not in self.world.particle_map_coordinates:
if self.coordinates in self.world.particle_map_coordinates:
del self.world.particle_map_coordinates[self.coordinates]
self.coordinates = direction_coord
self.world.particle_map_coordinates[self.coordinates] = self
self.world.vis.particle_changed(self)
logging.info("particle %s successfully moved to %s", str(self.get_id()), direction)
self.world.csv_round.update_metrics(steps=1)
self.csv_particle_writer.write_particle(steps=1)
self.check_for_carried_tile_or_particle()
return True
return False
......@@ -133,18 +133,18 @@ class Particle(matter.Matter):
else:
tmp_memory = target.read_whole_memory()
if tmp_memory is not None:
if not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
if target.type == "particle":
self.world.csv_round.update_metrics(particle_read=1)
self.csv_particle_writer.write_particle(particle_read=1)
elif target.type == "tile":
self.world.csv_round.update_metrics(tile_read=1)
self.csv_particle_writer.write_particle(tile_read=1)
elif target.type == "location":
self.world.csv_round.update_metrics(location_read=1)
self.csv_particle_writer.write_particle(location_read=1)
return tmp_memory
if tmp_memory is not None \
and not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
if target.type == "particle":
self.world.csv_round.update_metrics(particle_read=1)
self.csv_particle_writer.write_particle(particle_read=1)
elif target.type == "tile":
self.world.csv_round.update_metrics(tile_read=1)
self.csv_particle_writer.write_particle(tile_read=1)
elif target.type == "location":
self.world.csv_round.update_metrics(location_read=1)
self.csv_particle_writer.write_particle(location_read=1)
return tmp_memory
return None
def matter_in(self, direction):
......
......@@ -159,7 +159,6 @@ class GridProgram(Program):
eprint("WARNING: invalid offset data! "
"Amount of coordinate components not dividable by 3 (not in xyz format?)!")
self.amount = int(self.amount)
pass
def set_line_scaling(self, scaling):
"""
......
......@@ -80,7 +80,6 @@ class OffsetColorProgram(Program):
eprint("WARNING: invalid offset data! "
"Amount of coordinate components not dividable by 3 (not in xyz format?)!")
self.amount = int(self.amount)
pass
def update_colors(self, data):
"""
......
......@@ -3,6 +3,6 @@ import random
def scenario(world):
amount = 10
amount = 5
direction = random.choice(world.grid.get_directions_list())
create_matter_in_line(world, world.grid.get_center(), direction, amount, 'location')
create_matter_in_line(world, world.grid.get_center(), direction, amount, 'particle')
......@@ -329,6 +329,9 @@ def solution(world):
global visited
global unvisited_queue
if world.config_data.max_round == world.get_actual_round():
print("last round! (if not yet finished = max_round to small)")
done_particles = 0
search_algorithm = 0
......
......@@ -346,6 +346,9 @@ def move(world, particle, next_location):
def solution(world):
if world.config_data.max_round == world.get_actual_round():
print("last round! (if not yet finished = max_round to small)")
# communication variables
start_communication_round = 30
communication_frequency = 15
......
......@@ -320,6 +320,9 @@ def move(world, particle, next_location):
def solution(world):
if world.config_data.max_round == world.get_actual_round():
print("last round! (if not yet finished = max_round to small)")
# 0 = BFS, 1 = DFS, 2 = MIXED
search_algorithm = 2
......
......@@ -7,4 +7,5 @@ def solution(world):
if world.get_actual_round() % 1 == 0:
for particle in world.get_particle_list():
print(world.get_actual_round()," Particle No.", particle.number)
particle.move_to(random.choice(dirs))
......@@ -92,6 +92,8 @@ def create_direction_for_data(config_data):
def run_solution(swarm_sim_world):
if swarm_sim_world.config_data.particle_random_order_always:
random.shuffle(swarm_sim_world.particles)
mod = importlib.import_module('solution.' + swarm_sim_world.config_data.solution)
mod.solution(swarm_sim_world)
swarm_sim_world.csv_round.next_line(swarm_sim_world.get_actual_round())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment