Commit ffc59465 authored by Ahmad Reza's avatar Ahmad Reza
Browse files

Changed the location name to marker.

parent 1e3b4742
<?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.6.2 (/usr/bin/python3.6)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/swarm-sim.iml" filepath="$PROJECT_DIR$/.idea/swarm-sim.iml" />
</modules>
</component>
</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$" />
<orderEntry type="inheritedJdk" />
<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
......@@ -35,7 +35,7 @@ mm_limitation = 0
## mm size in quantity
## Works only with mm_limitation flag set on 1
location_mm_size = 2
marker_mm_size = 2
particle_mm_size = 2
tile_mm_size = 2
......@@ -57,11 +57,11 @@ solution = create_delete
#solution= take_drop_aims
## Read and Write
#scenario = two_particles_tiles_locations
#scenario = two_particles_tiles_markers
#solution = read_write
## Scanning for matters
#scenario = particles_tiles_locations_ring
#scenario = particles_tiles_markers_ring
#solution= scanning_for_all_aims
## All interfaces
......
This diff is collapsed.
"""The location module provides the interface to the locations. A location is any point on
"""The marker module provides the interface to the markers. A marker is any point on
the coordinate system of the simulators sim"""
......@@ -31,10 +31,10 @@ color_map = {
class Matter():
"""In the classe location all the methods for the characterstic of a location is included"""
"""In the classe marker all the methods for the characterstic of a marker is included"""
def __init__(self, sim, x, y, color=black, alpha=1, type=None, mm_limit=False, mm_size=0):
"""Initializing the location constructor"""
"""Initializing the marker constructor"""
self.coords = (x, y)
self.color = color_map[color]
self.__id = str(uuid.uuid4())
......@@ -97,7 +97,7 @@ class Matter():
def read_whole_memory(self):
"""
Reads all locations own memory based on a give keywoard
Reads all markers own memory based on a give keywoard
:param key: Keywoard
:return: The founded memory; None: When nothing is written based on the keywoard
......@@ -152,16 +152,16 @@ class Matter():
def get_id(self):
"""
Gets the location id
:return: Location id
Gets the marker id
:return: marker id
"""
return self.__id
def set_color(self, color):
"""
Sets the location color
Sets the marker color
:param color: Location color
:param color: marker color
:return: None
"""
if type (color) == int:
......@@ -173,9 +173,9 @@ class Matter():
def get_color(self):
"""
Sets the location color
Sets the marker color
:param color: Location color
:param color: marker color
:return: None
"""
for color, code in color_map.items(): # for name, age in dictionary.iteritems(): (for Python 2.x)
......
This diff is collapsed.
"""The sim module provides the interface of the simulation sim. In the simulation sim
all the data of the particles, tiles, and locations are stored.
all the data of the particles, tiles, and markers are stored.
It also have the the coordination system and stated the maximum of the x and y coordinate.
.. todo:: What happens if the maximum y or x axis is passed? Either the start from the other side or turns back.
......@@ -10,7 +10,7 @@ import importlib
import random
import math
import logging
from lib import csv_generator, particle, tile, location, vis
from lib import csv_generator, particle, tile, marker, vis
from lib.gnuplot_generator import generate_gnuplot
......@@ -80,14 +80,14 @@ class Sim:
self.__tile_deleted=False
self.new_tile_flag = False
self.tile_mm_size=config_data.tile_mm_size
self.locations_num=0
self.locations = []
self.locations_created = []
self.location_map_coords = {}
self.location_map_id = {}
self.locations_rm = []
self.location_mm_size=config_data.location_mm_size
self.__location_deleted = False
self.markers_num=0
self.markers = []
self.markers_created = []
self.marker_map_coords = {}
self.marker_map_id = {}
self.markers_rm = []
self.marker_mm_size=config_data.marker_mm_size
self.__marker_deleted = False
self.new_tile=None
self.__size_x = config_data.size_x
self.__size_y = config_data.size_y
......@@ -249,37 +249,37 @@ class Sim:
"""
return self.tile_map_id
def get_location_num(self):
def get_marker_num(self):
"""
Returns the actual number of locations in the sim
Returns the actual number of markers in the sim
:return: The actual number of locations
:return: The actual number of markers
"""
return self.locations_num
return self.markers_num
def get_location_list(self):
def get_marker_list(self):
"""
Returns the actual number of locations in the sim
Returns the actual number of markers in the sim
:return: The actual number of locations
:return: The actual number of markers
"""
return self.locations
return self.markers
def get_location_map_coords(self):
def get_marker_map_coords(self):
"""
Get a dictionary with all locations mapped with their actual coordinates
Get a dictionary with all markers mapped with their actual coordinates
:return: a dictionary with locations and their coordinates
:return: a dictionary with markers and their coordinates
"""
return self.location_map_coords
return self.marker_map_coords
def get_location_map_id(self):
def get_marker_map_id(self):
"""
Get a dictionary with all locations mapped with their own ids
Get a dictionary with all markers mapped with their own ids
:return: a dictionary with locations and their own ids
:return: a dictionary with markers and their own ids
"""
return self.location_map_id
return self.marker_map_id
def get_coords_in_dir(self, coords, dir):
......@@ -311,8 +311,8 @@ class Sim:
def get_particle_deleted(self):
return self.__particle_deleted
def get_location_deleted(self):
return self.__location_deleted
def get_marker_deleted(self):
return self.__marker_deleted
def set_tile_deleted(self):
self.__tile_deleted = False
......@@ -320,8 +320,8 @@ class Sim:
def set_particle_deleted(self):
self.__particle_deleted=False
def set_location_deleted(self):
self.__location_deleted = False
def set_marker_deleted(self):
self.__marker_deleted = False
def check_coords(self, coords_x, coords_y):
"""
......@@ -545,7 +545,7 @@ class Sim:
return False
def add_location(self, x, y, color=black, alpha=1):
def add_marker(self, x, y, color=black, alpha=1):
"""
Add a tile to the sim database
......@@ -557,77 +557,77 @@ class Sim:
if alpha < 0 or alpha >1:
alpha = 1
if self.check_coords(x, y) == True:
if (x, y) not in self.location_map_coords:
self.new_location = location.Location(self, x, y, color, alpha, self.mm_limitation, self.location_mm_size)
self.locations.append(self.new_location)
self.location_map_coords[self.new_location.coords] = self.new_location
self.location_map_id[self.new_location.get_id()] = self.new_location
self.csv_round_writer.update_locations_num(len(self.locations))
logging.info("Created location with id %s on coords %s", str(self.new_location.get_id()), str(self.new_location.coords))
self.new_location.created = True
self.new_location.touch()
return self.new_location
if (x, y) not in self.marker_map_coords:
self.new_marker = marker.marker(self, x, y, color, alpha, self.mm_limitation, self.marker_mm_size)
self.markers.append(self.new_marker)
self.marker_map_coords[self.new_marker.coords] = self.new_marker
self.marker_map_id[self.new_marker.get_id()] = self.new_marker
self.csv_round_writer.update_markers_num(len(self.markers))
logging.info("Created marker with id %s on coords %s", str(self.new_marker.get_id()), str(self.new_marker.coords))
self.new_marker.created = True
self.new_marker.touch()
return self.new_marker
else:
logging.info("on x %f and y %f coordinates is a location already", x, y)
logging.info("on x %f and y %f coordinates is a marker already", x, y)
return False
else:
logging.info("for x %f and y %f not possible to draw ", x, y)
return False
def remove_location(self, id):
def remove_marker(self, id):
"""
Removes a tile with a given tile_id from to the sim database
:param id: The locations id that should be removec
:param id: The markers id that should be removec
:return: True: Successful removed; False: Unsuccessful
"""
if id in self.location_map_id:
rm_location = self.location_map_id[id]
rm_location.touch()
if rm_location in self.locations:
self.locations.remove(rm_location)
if id in self.marker_map_id:
rm_marker = self.marker_map_id[id]
rm_marker.touch()
if rm_marker in self.markers:
self.markers.remove(rm_marker)
self.locations_rm.append(rm_location)
logging.info("Deleted location with location id %s on %s", str(id), str(rm_location.coords))
self.markers_rm.append(rm_marker)
logging.info("Deleted marker with marker id %s on %s", str(id), str(rm_marker.coords))
try:
del self.location_map_coords[rm_location.coords]
del self.marker_map_coords[rm_marker.coords]
except KeyError:
pass
try:
del self.location_map_id[id]
del self.marker_map_id[id]
except KeyError:
pass
self.csv_round_writer.update_locations_num(len(self.locations))
self.csv_round_writer.update_metrics( location_deleted=1)
self.__location_deleted = True
self.csv_round_writer.update_markers_num(len(self.markers))
self.csv_round_writer.update_metrics( marker_deleted=1)
self.__marker_deleted = True
return True
else:
return False
def remove_location_on(self, coords):
def remove_marker_on(self, coords):
"""
Removes a location on a give coordinat from to the sim database
Removes a marker on a give coordinat from to the sim database
:param coords: A tupel that includes the x and y coorindates
:return: True: Successful removed; False: Unsuccessful
"""
if coords in self.location_map_coords:
self.locations.remove(self.location_map_coords[coords])
self.locations_rm.append(self.location_map_coords[coords])
if coords in self.marker_map_coords:
self.markers.remove(self.marker_map_coords[coords])
self.markers_rm.append(self.marker_map_coords[coords])
try: # cher: added so the program does not crashed if it does not find any entries in the map
del self.location_map_id[self.location_map_coords[coords].get_id()]
del self.marker_map_id[self.marker_map_coords[coords].get_id()]
except KeyError:
pass
try: # cher: added so the program does not crashed if it does not find any entries in the map
del self.location_map_coords[coords]
del self.marker_map_coords[coords]
except KeyError:
pass
self.csv_round_writer.update_locations_num(len(self.locations))
self.csv_round_writer.update_metrics( location_deleted=1)
self.__location_deleted = True
self.csv_round_writer.update_markers_num(len(self.markers))
self.csv_round_writer.update_metrics( marker_deleted=1)
self.__marker_deleted = True
return True
else:
return False
\ No newline at end of file
......@@ -15,10 +15,10 @@ write=1
class Tile(matter.Matter):
"""In the classe location all the methods for the characterstic of a location is included"""
"""In the classe marker all the methods for the characterstic of a marker is included"""
def __init__(self, sim, x, y, color=gray, alpha=1, mm_limit=0, mm_size=0):
"""Initializing the location constructor"""
"""Initializing the marker constructor"""
super().__init__( sim, x, y, color, alpha=1, type="tile", mm_limit=mm_limit, mm_size=mm_size)
self.__isCarried = False
self.created = False
......
......@@ -38,7 +38,7 @@ rounds_per_second = 10
# tile_alpha = 0.6
particle_alpha = 1
location_alpha = 1
marker_alpha = 1
......@@ -118,7 +118,7 @@ class VisWindow(pyglet.window.Window):
self.sim = sim
self.init_tile_vertex_list()
self.init_particle_vertex_list()
self.init_location_vertex_list()
self.init_marker_vertex_list()
self.view = View()
self.particleTexture = pyglet.image.load('lib/images/particle.png').get_mipmapped_texture()
......@@ -206,7 +206,7 @@ class VisWindow(pyglet.window.Window):
def draw(self):
self.update_tiles()
self.update_particles()
self.update_locations()
self.update_markers()
glLoadIdentity()
glOrtho(self.view.left, self.view.right, self.view.bottom, self.view.top, 1, -1)
......@@ -222,7 +222,7 @@ class VisWindow(pyglet.window.Window):
if len(self.sim.tiles) != 0:
self.tile_vertex_list.draw(GL_QUADS)
self.particle_vertex_list.draw(GL_QUADS)
self.location_vertex_list.draw(GL_QUADS)
self.marker_vertex_list.draw(GL_QUADS)
self.flip()
......@@ -375,46 +375,46 @@ class VisWindow(pyglet.window.Window):
self.particle_vertex_list.colors[16 * i: 16 * i + 16] = (particle.color + [particle.get_alpha()]) * 4
def init_location_vertex_list(self):
self.location_vertex_list = self.location_vertex_list = pyglet.graphics.vertex_list \
(4 * len(self.sim.locations), 'v2f', 't2f', 'c4f')
self.update_locations(True)
def init_marker_vertex_list(self):
self.marker_vertex_list = self.marker_vertex_list = pyglet.graphics.vertex_list \
(4 * len(self.sim.markers), 'v2f', 't2f', 'c4f')
self.update_markers(True)
def update_locations(self, update_all=True):
if (len(self.sim.locations) != 0):
if self.sim.get_location_deleted():
self.location_vertex_list.resize(4 * len(self.sim.locations))
self.sim.set_location_deleted()
def update_markers(self, update_all=True):
if (len(self.sim.markers) != 0):
if self.sim.get_marker_deleted():
self.marker_vertex_list.resize(4 * len(self.sim.markers))
self.sim.set_marker_deleted()
update_all = True
for i, location in enumerate(self.sim.locations):
if location.created:
self.location_vertex_list.resize(4 * len(self.sim.locations))
for i, marker in enumerate(self.sim.markers):
if marker.created:
self.marker_vertex_list.resize(4 * len(self.sim.markers))
# self.tile_vertex_list.resize(4 * len(self.sim.tiles), 8 * len(self.sim.tiles))
location.created = False
if update_all or location.modified:
self.update_location(i, location)
location.modified = False
marker.created = False
if update_all or marker.modified:
self.update_marker(i, marker)
marker.modified = False
else:
pass
def update_location(self, i, location):
def update_marker(self, i, marker):
weird = 256 / 220
pos = coords_to_sim(location.coords)
pos = coords_to_sim(marker.coords)
x = pos[0]
y = pos[1]
self.location_vertex_list.vertices[8 * i: 8 * i + 8] = [x - weird, y - weird, x + weird, y - weird, x + weird,
self.marker_vertex_list.vertices[8 * i: 8 * i + 8] = [x - weird, y - weird, x + weird, y - weird, x + weird,
y + weird, x - weird, y + weird]
texLeft = 7/8
texRight = 1 #8/8
texBottom = 0/8
texTop = 1/8
self.location_vertex_list.tex_coords[8 * i: 8 * i + 8] = [texLeft, texBottom, texRight, texBottom,
self.marker_vertex_list.tex_coords[8 * i: 8 * i + 8] = [texLeft, texBottom, texRight, texBottom,
texRight, texTop, texLeft, texTop]
self.location_vertex_list.colors[16 * i: 16 * i + 16] = (location.color + [location.get_alpha()]) * 4
self.marker_vertex_list.colors[16 * i: 16 * i + 16] = (marker.color + [marker.get_alpha()]) * 4
def run(self):
p = 0
......
......@@ -35,7 +35,7 @@ class ConfigData():
self.mm_limitation = config.getboolean("Matter", "mm_limitation")
self.particle_mm_size = config.getint("Matter", "particle_mm_size")
self.tile_mm_size = config.getint("Matter", "tile_mm_size")
self.location_mm_size = config.getint("Matter", "location_mm_size")
self.marker_mm_size = config.getint("Matter", "marker_mm_size")
self.dir_name = None
def swarm_sim( argv ):
......
"""
A sim is created that has two particles, two locations, and two tiles.
A sim is created that has two particles, two markers, and two tiles.
"""
def scenario(sim):
......
......@@ -29,23 +29,23 @@ def scenario(sim):
sim.add_tile(-1.000000, -2.000000, color=2)
# 3rd ring
sim.add_location(3.000000, 0.000000, color=3)
sim.add_location(-3.000000, 0.000000, color=3)
sim.add_location(2.500000, 1.000000, color=3)
sim.add_location(2.500000, -1.000000, color=3)
sim.add_location(-2.500000, 1.000000, color=3)
sim.add_location(-2.500000, -1.000000, color=3)
sim.add_location(2.000000, 2.000000, color=3)
sim.add_location(2.000000, -2.000000, color=3)
sim.add_location(-2.000000, 2.000000, color=3)
sim.add_location(-2.000000, -2.000000, color=3)
sim.add_location(1.500000, 3.000000, color=3)
sim.add_location(1.500000, -3.000000, color=3)
sim.add_location(0.500000, 3.000000, color=3)
sim.add_location(0.500000, -3.000000, color=3)
sim.add_location(-0.500000, 3.000000, color=3)
sim.add_location(-0.500000, -3.000000, color=3)
sim.add_location(-1.500000, 3.000000, color=3)
sim.add_location(-1.500000, -3.000000, color=3)
sim.add_marker(3.000000, 0.000000, color=3)
sim.add_marker(-3.000000, 0.000000, color=3)
sim.add_marker(2.500000, 1.000000, color=3)
sim.add_marker(2.500000, -1.000000, color=3)
sim.add_marker(-2.500000, 1.000000, color=3)
sim.add_marker(-2.500000, -1.000000, color=3)
sim.add_marker(2.000000, 2.000000, color=3)
sim.add_marker(2.000000, -2.000000, color=3)
sim.add_marker(-2.000000, 2.000000, color=3)
sim.add_marker(-2.000000, -2.000000, color=3)
sim.add_marker(1.500000, 3.000000, color=3)
sim.add_marker(1.500000, -3.000000, color=3)
sim.add_marker(0.500000, 3.000000, color=3)
sim.add_marker(0.500000, -3.000000, color=3)
sim.add_marker(-0.500000, 3.000000, color=3)
sim.add_marker(-0.500000, -3.000000, color=3)
sim.add_marker(-1.500000, 3.000000, color=3)
sim.add_marker(-1.500000, -3.000000, color=3)
......@@ -4,7 +4,7 @@ A sim is created that has particles formated in a ring structure that is up to 5
def scenario(sim):
sim.add_particle(0, 0, color=3)
sim.add_tile(1.0, 0.0)
sim.add_location(3.0, 2.0)
sim.add_marker(3.0, 2.0)
# 1st ring
sim.add_particle(1.000000, 0.000000, color=1)
......
"""
A sim is created that has two particles, two locations, and two tiles.
A sim is created that has two particles, two markers, and two tiles.
"""
def scenario(sim):
sim.add_particle(0, 0)
sim.add_particle(1, 0)
sim.add_location(0.5, 1)
sim.add_marker(0.5, 1)
sim.add_tile(-1, 0)
sim.add_tile(1, 0)
"""
This solution is an example for creating and deleting, particles, tiles or locations
This solution is an example for creating and deleting, particles, tiles or markers
"""
import logging
......@@ -21,10 +21,10 @@ def solution(sim):
for particle in sim.get_particle_list():
print("Sim started")
particle.create_tile_in(E)
particle.create_location_in(W)
particle.create_marker_in(W)
if sim.get_actual_round() == 2:
if len(sim.get_particle_list()) > 0:
# sim.get_particle_list()[0].delete_location_in(W)
# sim.get_particle_list()[0].delete_marker_in(W)
sim.get_particle_list()[0].create_particle_in(W)
sim.get_particle_list()[0].create_particle_in(W)
if sim.get_actual_round() == 3:
......@@ -34,17 +34,17 @@ def solution(sim):
sim.get_particle_list()[0].delete_tile_in(E)
if sim.get_actual_round() == 4:
sim.get_particle_list()[0].create_tile_on(1,0)
sim.get_particle_list()[0].create_location_on(1, 0)
sim.get_particle_list()[0].create_marker_on(1, 0)
if sim.get_actual_round() == 5:
sim.get_particle_list()[0].delete_tile_on(1,0)
if sim.get_actual_round() == 6:
sim.get_particle_list()[0].create_particle_on(-1, 0)
sim.get_particle_list()[0].delete_location_on(1, 0)
sim.get_particle_list()[0].delete_marker_on(1, 0)
if sim.get_actual_round() == 7:
sim.get_particle_list()[0].delete_particle_on(-1, 0)
if sim.get_actual_round() == 8:
sim.get_particle_list()[0].create_tile()
sim.get_particle_list()[0].create_location()
sim.get_particle_list()[0].create_marker()
if sim.get_actual_round() == 9:
sim.get_particle_list()[0].delete_tile()
......@@ -52,4 +52,4 @@ def solution(sim):