Commit c9294848 authored by Karol Actun's avatar Karol Actun
Browse files

renaming: tile -> item, particle -> agent; small change to config loading/parsing.

parent 630b5341
This diff is collapsed.
......@@ -22,23 +22,23 @@ def plot_generator(directory):
plot.stdin.write("replot \n")
i += 1
data = pd.read_csv(directory+"/particle.csv")
data = pd.read_csv(directory+"/agent.csv")
i = 1
plot = subprocess.Popen(['gnuplot', '--persist'], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
universal_newlines=True)
plot.stdin.write("set datafile separator ',' \n")
plot.stdin.write('set xlabel "Particle" \n')
plot.stdin.write('set xlabel "Agent" \n')
for bla in data.columns:
if i >= 3 :
plot.stdin.write('set ylabel "%s" \n' % (bla))
plot.stdin.write("set term png giant size 800,600 font 'Helvetica,20' \n")
plot.stdin.write("set outputs '" + directory + "/particle_%s.png' \n" % (bla))
plot.stdin.write("set outputs '" + directory + "/agent_%s.png' \n" % (bla))
plot.stdin.write(
"plot '" + directory + "/particle.csv' using 2:" + str(
"plot '" + directory + "/agent.csv' using 2:" + str(
i) + " title '" + bla + "' with lines axis x1y1 smooth unique \n")
plot.stdin.write("set terminal pdf monochrome font 'Helvetica,10' \n")
plot.stdin.write("set outputs '" + directory + "/particle_%s.pdf' \n" % (bla))
plot.stdin.write("set outputs '" + directory + "/agent_%s.pdf' \n" % (bla))
plot.stdin.write("replot \n")
i += 1
......
......@@ -2,6 +2,8 @@ from PyQt5.QtGui import QColor, QIntValidator
from PyQt5.QtWidgets import (QVBoxLayout, QPushButton, QColorDialog, QRadioButton, QLabel, QTabWidget,
QSlider, QHBoxLayout, QCheckBox, QTabBar, QLineEdit, QGroupBox, QComboBox, QStyle)
from PyQt5.QtCore import Qt
from core.matter import MatterType
from core.vis3d import Visualization
from core.visualization.utils import show_msg, Level
from core.world import World
......@@ -247,22 +249,22 @@ def get_new_matter_color_picker():
# noinspection PyUnresolvedReferences
def get_matter_radios():
p_radio = QRadioButton("particle")
p_radio = QRadioButton("agent")
p_radio.setChecked(False)
t_radio = QRadioButton("tile")
t_radio = QRadioButton("item")
t_radio.setChecked(True)
l_radio = QRadioButton("location")
l_radio.setChecked(False)
def on_toggle():
if p_radio.isChecked():
vis.set_on_cursor_click_matter_type("particle")
vis.set_on_cursor_click_matter_type(MatterType.AGENT)
if t_radio.isChecked():
vis.set_on_cursor_click_matter_type("tile")
vis.set_on_cursor_click_matter_type(MatterType.ITEM)
if l_radio.isChecked():
vis.set_on_cursor_click_matter_type("location")
vis.set_on_cursor_click_matter_type(MatterType.LOCATION)
p_radio.toggled.connect(on_toggle)
t_radio.toggled.connect(on_toggle)
......@@ -388,49 +390,49 @@ def grid_tab():
def matter_tab():
tab = QTabBar()
layout = QVBoxLayout()
layout.addLayout(get_scaler("particle"))
layout.addLayout(get_scaler("tile"))
layout.addLayout(get_scaler("location"))
layout.addLayout(get_scaler(MatterType.AGENT))
layout.addLayout(get_scaler(MatterType.ITEM))
layout.addLayout(get_scaler(MatterType.LOCATION))
layout.addStretch(1)
tab.setLayout(layout)
return tab
def get_scaler(mattertype):
if mattertype == "particle":
current_scaling = vis.get_particle_scaling()
if mattertype == MatterType.AGENT:
current_scaling = vis.get_agent_scaling()
def x_scaler_change(value):
cs = vis.get_particle_scaling()
cs = vis.get_agent_scaling()
new_scaling = (value / 10.0, cs[1], cs[2])
vis.set_particle_scaling(new_scaling)
vis.set_agent_scaling(new_scaling)
def y_scaler_change(value):
cs = vis.get_particle_scaling()
cs = vis.get_agent_scaling()
new_scaling = (cs[0], value / 10.0, cs[2])
vis.set_particle_scaling(new_scaling)
vis.set_agent_scaling(new_scaling)
def z_scaler_change(value):
cs = vis.get_particle_scaling()
cs = vis.get_agent_scaling()
new_scaling = (cs[0], cs[1], value / 10.0)
vis.set_particle_scaling(new_scaling)
elif mattertype == "tile":
current_scaling = vis.get_tile_scaling()
vis.set_agent_scaling(new_scaling)
elif mattertype == MatterType.ITEM:
current_scaling = vis.get_item_scaling()
def x_scaler_change(value):
cs = vis.get_tile_scaling()
cs = vis.get_item_scaling()
new_scaling = (value / 10.0, cs[1], cs[2])
vis.set_tile_scaling(new_scaling)
vis.set_item_scaling(new_scaling)
def y_scaler_change(value):
cs = vis.get_tile_scaling()
cs = vis.get_item_scaling()
new_scaling = (cs[0], value / 10.0, cs[2])
vis.set_tile_scaling(new_scaling)
vis.set_item_scaling(new_scaling)
def z_scaler_change(value):
cs = vis.get_tile_scaling()
cs = vis.get_item_scaling()
new_scaling = (cs[0], cs[1], value / 10.0)
vis.set_tile_scaling(new_scaling)
vis.set_item_scaling(new_scaling)
else:
current_scaling = vis.get_location_scaling()
......
"""
A world is created that has agents formated in a ring structure that is up to 5 hops big
"""
def scenario(world):
world.add_agent(world.grid.get_center())
agent_ring = world.grid.get_n_sphere_border((0, 0, 0), 1)
item_ring = world.grid.get_n_sphere_border((0, 0, 0), 3)
location_ring = world.grid.get_n_sphere_border((0, 0, 0), 5)
for agent in agent_ring:
world.add_agent(agent)
for item in item_ring:
world.add_item(item)
for location in location_ring:
world.add_location(location)
def scenario(world):
world.add_particle(world.grid.get_center())
world.add_agent(world.grid.get_center())
......@@ -6,13 +6,13 @@ def scenario(world):
center = world.grid.get_center()
dirs = world.grid.get_directions_list()
world.add_particle(center)
world.add_particle(get_coordinates_in_direction(center, random.choice(dirs)))
world.add_agent(center)
world.add_agent(get_coordinates_in_direction(center, random.choice(dirs)))
size = 5
ring = world.grid.get_n_sphere_border(center, size)
for c in ring:
world.add_tile(c)
world.add_item(c)
......@@ -5,4 +5,4 @@ import random
def scenario(world):
amount = 5
direction = random.choice(world.grid.get_directions_list())
create_matter_in_line(world, world.grid.get_center(), direction, amount, 'particle')
create_matter_in_line(world, world.grid.get_center(), direction, amount, MatterType.AGENT)
"""
A world is created that has particles formated in a ring structure that is up to 5 hops big
"""
def scenario(world):
world.add_particle(world.grid.get_center())
particle_ring = world.grid.get_n_sphere_border((0, 0, 0), 1)
tile_ring = world.grid.get_n_sphere_border((0, 0, 0), 3)
location_ring = world.grid.get_n_sphere_border((0, 0, 0), 5)
for p in particle_ring:
world.add_particle(p)
for t in tile_ring:
world.add_tile(t)
for l in location_ring:
world.add_location(l)
def scenario(world):
tile_ring = world.grid.get_n_sphere_border((0, 0, 0), 2)
for location in tile_ring:
world.add_tile(location)
item_ring = world.grid.get_n_sphere_border((0, 0, 0), 2)
for agent in item_ring:
world.add_item(agent)
particle_ring = world.grid.get_n_sphere_border((0, 0, 0), 4)
for location in particle_ring:
world.add_particle(location)
agent_ring = world.grid.get_n_sphere_border((0, 0, 0), 4)
for agent in agent_ring:
world.add_agent(agent)
......@@ -6,31 +6,31 @@ def scenario(world):
dirs = world.grid.get_directions_list()
world.add_particle(world.grid.get_center(), color=(1.0, 0.0, 0.0, 1.0))
tile_pos = get_coordinates_in_direction(world.grid.get_center(), dirs[0])
world.add_tile(tile_pos)
loc_pos = get_coordinates_in_direction(tile_pos, dirs[1])
world.add_agent(world.grid.get_center(), color=(1.0, 0.0, 0.0, 1.0))
item_pos = get_coordinates_in_direction(world.grid.get_center(), dirs[0])
world.add_item(item_pos)
loc_pos = get_coordinates_in_direction(item_pos, dirs[1])
world.add_location(loc_pos)
# 1st ring
ring1 = world.grid.get_n_sphere_border(world.grid.get_center(), 1)
for m in ring1:
world.add_particle(m, color=(0.2, 0.2, 0.2, 1.0))
world.add_agent(m, color=(0.2, 0.2, 0.2, 1.0))
# 2nd ring
ring2 = world.grid.get_n_sphere_border(world.grid.get_center(), 2)
for m in ring2:
world.add_particle(m, color=(0.5, 0.5, 0.5, 1.0))
world.add_agent(m, color=(0.5, 0.5, 0.5, 1.0))
tile_pos1 = get_multiple_steps_in_direction(world.grid.get_center(), dirs[0], 4)
tile_pos2 = get_multiple_steps_in_direction(tile_pos1, dirs[1], 2)
tile_pos3 = get_multiple_steps_in_direction(tile_pos2, dirs[2], 2)
tile_pos4 = get_multiple_steps_in_direction(tile_pos3, dirs[3], 2)
item_pos1 = get_multiple_steps_in_direction(world.grid.get_center(), dirs[0], 4)
item_pos2 = get_multiple_steps_in_direction(item_pos1, dirs[1], 2)
item_pos3 = get_multiple_steps_in_direction(item_pos2, dirs[2], 2)
item_pos4 = get_multiple_steps_in_direction(item_pos3, dirs[3], 2)
world.add_tile(tile_pos1)
world.add_tile(tile_pos2)
world.add_tile(tile_pos3)
world.add_tile(tile_pos4)
world.add_item(item_pos1)
world.add_item(item_pos2)
world.add_item(item_pos3)
world.add_item(item_pos4)
"""
A world is created that has two particles, two markers, and two tiles.
A world is created that has two agents, two markers, and two items.
"""
from core.swarm_sim_header import get_multiple_steps_in_direction, get_coordinates_in_direction
......@@ -9,9 +9,9 @@ def scenario(world):
center = world.grid.get_center()
dirs = world.grid.get_directions_list()
world.add_particle(center)
world.add_particle(get_coordinates_in_direction(center, dirs[0]))
world.add_agent(center)
world.add_agent(get_coordinates_in_direction(center, dirs[0]))
world.add_location(get_coordinates_in_direction(center, dirs[1]))
world.add_location(get_multiple_steps_in_direction(center, dirs[1], 2))
world.add_tile(get_coordinates_in_direction(center, dirs[2]))
world.add_tile(get_coordinates_in_direction(center, dirs[3]))
world.add_item(get_coordinates_in_direction(center, dirs[2]))
world.add_item(get_coordinates_in_direction(center, dirs[3]))
"""
This solution is an example for creating and deleting, particles, tiles or locations
This solution is an example for creating and deleting, agents, items or locations
"""
from core.swarm_sim_header import *
......@@ -10,51 +10,51 @@ def solution(world):
center = world.grid.get_center()
if world.get_actual_round() == 1:
for particle in world.get_particle_list():
for agent in world.get_agent_list():
print("World started")
particle.create_tile_in(dirs[0])
particle.create_location_in(dirs[1])
agent.create_item_in(dirs[0])
agent.create_location_in(dirs[1])
if world.get_actual_round() == 2:
if len(world.get_particle_list()) > 0:
world.get_particle_list()[0].create_particle_in(dirs[1])
world.get_particle_list()[0].create_particle_in(dirs[1])
if len(world.get_agent_list()) > 0:
world.get_agent_list()[0].create_agent_in(dirs[1])
world.get_agent_list()[0].create_agent_in(dirs[1])
if world.get_actual_round() == 3:
if len(world.get_particle_list()) > 0:
world.get_particle_list()[0].take_particle_in(dirs[1])
world.get_particle_list()[0].delete_particle_in(dirs[1])
world.get_particle_list()[0].delete_tile_in(dirs[0])
if len(world.get_agent_list()) > 0:
world.get_agent_list()[0].take_agent_in(dirs[1])
world.get_agent_list()[0].delete_agent_in(dirs[1])
world.get_agent_list()[0].delete_item_in(dirs[0])
if world.get_actual_round() == 4:
pos = get_coordinates_in_direction(center, dirs[2])
world.get_particle_list()[0].create_tile_on(pos)
world.get_particle_list()[0].create_location_on(pos)
world.get_agent_list()[0].create_item_on(pos)
world.get_agent_list()[0].create_location_on(pos)
if world.get_actual_round() == 5:
pos = get_coordinates_in_direction(center, dirs[2])
world.get_particle_list()[0].delete_tile_on(pos)
world.get_agent_list()[0].delete_item_on(pos)
if world.get_actual_round() == 6:
pos1 = get_coordinates_in_direction(center, dirs[2])
pos2 = get_coordinates_in_direction(center, dirs[3])
world.get_particle_list()[0].create_particle_on(pos2)
world.get_particle_list()[0].delete_location_on(pos1)
world.get_agent_list()[0].create_agent_on(pos2)
world.get_agent_list()[0].delete_location_on(pos1)
if world.get_actual_round() == 7:
pos2 = get_coordinates_in_direction(center, dirs[3])
world.get_particle_list()[0].delete_particle_on(pos2)
world.get_agent_list()[0].delete_agent_on(pos2)
if world.get_actual_round() == 8:
world.get_particle_list()[0].create_tile()
world.get_particle_list()[0].create_location()
world.get_agent_list()[0].create_item()
world.get_agent_list()[0].create_location()
if world.get_actual_round() == 9:
world.get_particle_list()[0].delete_tile()
world.get_agent_list()[0].delete_item()
if world.get_actual_round() == 12:
world.get_particle_list()[0].create_particle()
world.get_agent_list()[0].create_agent()
if world.get_actual_round() == 15:
world.get_particle_list()[0].delete_particle()
world.get_particle_list()[0].delete_location()
world.get_agent_list()[0].delete_agent()
world.get_agent_list()[0].delete_location()
This diff is collapsed.
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