Skip to content

Commit

Permalink
add task functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperg3 committed Jan 10, 2024
1 parent 70effc7 commit 1177c9f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
11 changes: 4 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ def run_experiment(experiment_title, n_agents, capacity, show_plots, debug, resu
new_route.append((coordinate[0] + min_x, coordinate[1] + min_y))
temp.append(new_route)
open("allocations.json", "w").write(geojson.dumps({"routes": temp}))

Check failure on line 124 in main.py

View workflow job for this annotation

GitHub Actions / test (3.10)

Ruff (SIM115)

main.py:124:9: SIM115 Use context handler for opening files

Check failure on line 124 in main.py

View workflow job for this annotation

GitHub Actions / test (3.10)

Ruff (SIM115)

main.py:124:9: SIM115 Use context handler for opening files
# TODO find a way of adding an agent based on id instead of index in a list
# This has some more work to it as this requires the index querying in cbba to be done based on hash indexing
# exp.add_agent(Agent.agent(id=))

# Save the results in a csv file
(
Expand Down Expand Up @@ -176,13 +173,13 @@ def run_experiment(experiment_title, n_agents, capacity, show_plots, debug, resu
)
else:
ds = "AC300"
n_agents = 3
capacity = 15000
n_agents = 5
capacity = 1500
main(
dataset_name=ds,
experiment_title=ds + "_" + str(n_agents) + "agents_" + str(capacity) + "capacity",
n_agents=n_agents,
capacity=capacity,
show_plots=True,
debug=True,
show_plots=False,
debug=False,
)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel", "pep517"]
build-backend = "setuptools.build_meta"

[project]
name = "trajallocpy"
version = "0.0.1"
version = "0.0.2"
description = "TrajAllocPy is a Python library that provides functionality for trajectory task Allocaition using Consensus based bundle algorithm"
readme = "README.md"
authors = [
Expand Down
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from setuptools import setup

setup(
name="trajallocpy",
version="0.0.2",
description="TrajAllocPy is a Python library that provides functionality for trajectory task Allocation using Consensus based bundle algorithm",
long_description="",
long_description_content_type="text/markdown",
author="Kasper Rømer Grøntved",
author_email="kaspergrontved@gmail.com",
url="",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
packages=[],
python_requires=">=3.10",
install_requires=[],
extras_require={"test": ["pytest"]},
)
8 changes: 8 additions & 0 deletions trajallocpy/ACBBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def __init__(
self.removal_threshold = 5 # TODO find a good value for this when ros is implemented
self.message_history = []

def __repr__(self) -> str:
return f"Agent {self.id} \n path {self.path} \n bundle {self.bundle} \n y(winning bids) {self.y} \n z(winning agents) {self.z} \n t(timestamps) {self.t} \n"

def add_tasks(self, tasks):
# add the tasks to self.tasks dictionary
for task in tasks:
self.tasks[task.id] = task

def __str__(self) -> str:
return f"Agent {self.id} \n path {self.path} \n bundle {self.bundle} \n y(winning bids) {self.y} \n z(winning agents) {self.z} \n t(timestamps) {self.t} \n"

Expand Down
3 changes: 3 additions & 0 deletions trajallocpy/CBBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def __init__(
self.removal_list = np.zeros(self.task_num, dtype=np.int8)
self.removal_threshold = 15

def add_tasks(self, tasks):
self.tasks.extend(tasks)

def getPathTasks(self) -> List[TrajectoryTask]:
return self.tasks[self.path]

Expand Down
7 changes: 7 additions & 0 deletions trajallocpy/Experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def evaluateSolution(self):
max_path_cost,
)

def add_tasks(self, tasks):
# TODO make sure that the tasks are within the search area

# TODO make sure that the tasks not already in the list
for robot in self.robot_list:
robot.add_tasks(tasks)

def solve(self, profiling_enabled=False, debug=False):
if profiling_enabled:
print("Profiling enabled!")
Expand Down
2 changes: 1 addition & 1 deletion trajallocpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import trajallocpy.Agent
import trajallocpy.Task
from trajallocpy import ACBBA, CBBA, Agent, CoverageProblem, Task
from trajallocpy import ACBBA, CBBA, Agent, CoverageProblem, Experiment, Task

0 comments on commit 1177c9f

Please # to comment.