summaryrefslogtreecommitdiff
path: root/README
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-11-25 17:56:21 +0100
committeryctct <yctct@yctct.com>2026-11-25 17:56:21 +0100
commit489b223db74f468032c1eeb6ca18ee6a4da3bc33 (patch)
treea360664813443859ebfc0dcce79dec7fddf93c9f /README
Add files, first commit
Diffstat (limited to 'README')
-rw-r--r--README209
1 files changed, 209 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..7d9a109
--- /dev/null
+++ b/README
@@ -0,0 +1,209 @@
+## Description
+
+This a Multi-Agent Path Finding (MAPF) algorithm.
+
+An exercise I did at school to learn about MAPF.
+
+The aim is to route agents through nodes from 'start' to 'goal'.
+
+Nodes can be of type NORMAL, RESTRICTED, PRIORITY or BLOCKED.
+
+See 'Algorithm explanation' for more details.
+
+## Algorithm explanation
+
+- the program first computes the shortest path using Djikstra algorithm
+- then, starts sending agents through the shortest-path
+- if an agent cannot move to its next node, then the program recomputes a
+ shortest-path for that specific agent
+- if no shortest path is possible, the program skips to next agent
+
+### RESTRICTED node
+
+If a node is RESTRICTED:
+
+- the agent checks whether connection between two nodes has capacity and
+ whether the RESTRICTED node is `reserved`
+- if so:
+ - the agent reserves the RESTRICTED node and moves to the connection
+ between two nodes
+ - on the following turn, the agent moves to the RESTRICTED node and
+ unreserve the node
+
+### PRIORITY node
+
+The algorithm that computes the shortest path counts each PRIORITY node, and
+choose the path with the highest number of PRIORITY node at the end.
+
+### BLOCKED node
+
+BLOCKED node are skipped when computing the shortest path.
+
+## Instructions
+
+Create a virtual environment:
+
+ $ make env
+
+Install dependencies:
+
+ $ make install
+
+Run the program:
+
+ $ make run MAP=path/to/map
+
+also:
+
+ $ ./main.py path/to/map
+
+Clean:
+
+ $ make clean
+
+Debug:
+
+ $ make debug MAP=path/to/map
+
+Lint:
+
+ $ make lint
+
+and:
+
+ $ make lint-strict
+
+### About passing arguments to 'make run'
+
+Right now I use the variable $ARG.
+
+Another option is to use $(filter-out $@,$(MAKECMDGOALS)). What is this?
+
+The make file uses 'MAKECMDGOALS' to pass arguments to the program.
+
+However, 'MAKECMDGOALS' prepends the argument with the target. In our case that
+is 'run', which we don't want.
+
+So we want to filter the target, 'run', out.
+
+To do so we use 'filter-out', i.e. $(filter-out pattern, list)
+
+In Make the target is represented by the variable '$@'.
+
+So to remove the target we can write: $(filter-out $@,$(MAKECMDGOALS))
+
+Source: https://www.gnu.org/software/make/manual/html_node/Goals.html
+
+### About ctags in Vim
+
+If you want to use ctags with Vim, you can create a tag table file with:
+
+ $ make tags
+
+## Visual representation
+
+ ``` D1-waypoint1 D1-waypoint2 D2-waypoint1 D1-goal D2-waypoint2 D2-goal
+```
+
+The syntax is `D<drone_id>-<zone>|<connection>`, with color when provided.
+
+## Explanation of the network zone files
+
+### Input Format
+
+- The first line defines the number of drones (agents) using `nb_drones`:
+
+ ``` nb_drones: <number> ```
+
+- Zones are defined one per line using the following type prefixes:
+
+ ``` start_hub: <name> <x> <y> [metadata] end_hub: <name> <x> <y> [metadata]
+hub: <name> <x> <y> [metadata] ```
+
+ - `start_hub` marks the starting zone.
+ - `end_hub` marks the end zone.
+ - `hub` defines a regular zone.
+ - The connection syntax forbids dashes (`-`) in zone names.
+
+### Zone Metadata
+
+All metadata is optional and enclosed in square brackets (`[...]`). Metadata
+has the following default values:
+
+- `zone=<type>` — Default: `normal`
+- `color=<value>` — Default: `none`
+- `max_drones=<number>` — Default: `1`. The maximum number of drones that can
+ occupy the zone simultaneously.
+
+Tags inside brackets can appear in any order.
+
+### Zone Types
+
+- `normal` — Standard zone with a movement cost of 1 turn. This is the default.
+- `blocked` — Inaccessible zone. Drones must not enter or pass through this
+ zone. Any path using it is invalid.
+- `restricted` — Sensitive or dangerous zone. Movement to this zone costs 2
+ turns.
+- `priority` — Preferred zone. Movement to this zone costs 1 turn but should be
+ prioritized during pathfinding.
+
+### Colors
+
+- Colors are optional and can be used for visual representation, such as
+ terminal output or graphical displays.
+- Any valid single-word string can be used as a color value, for example:
+ - `red`
+ - `blue`
+ - `gray`
+- There is no fixed list of allowed colors.
+- When colors are specified, the implementation should provide visual feedback
+ through colored terminal output or a graphical representation.
+
+### Connections
+
+Connections are defined using the following syntax:
+
+``` connection: <name1>-<name2> [metadata] ```
+
+- Connections define a bidirectional edge between two zones.
+- The connection syntax forbids dashes (`-`) in zone names.
+- Optional metadata can be specified in square brackets (`[...]`):
+
+ - `max_link_capacity=<number>` — Default: `1`. The maximum number of drones
+ that can traverse the connection simultaneously.
+
+### Comments
+
+Comments start with `#` and are ignored:
+
+## Resources
+
+- the Wikipedia pages of Dijkstra and multi-agent pathfinding (MAPF)
+- on silencing prints in Make file:
+ https://www.gnu.org/software/make/manual/make.html#Echoing
+- on naming methods:
+ https://peps.python.org/pep-0008/#descriptive-naming-styles
+- on hashable objects: https://docs.python.org/3/glossary.html#term-hashable
+- on color syntax, escape char etc:
+ https://en.wikipedia.org/wiki/ANSI_escape_code
+- on 256-color: https://tintin.mudhalla.net/info/256color/
+- Xterm 256-color palette with
+ code://upload.wikimedia.org/wikipedia/commons/f/f5/Xterm-256color.svg
+
+## To improve
+
+- rewrite models.py without Pydantics (no dependencies)
+- move `colors` to their own class and file
+- optimize program for high number of drones
+
+### Misc.
+
+Command to get the list of colors from all maps:
+
+ grep -oiP 'color=\K[a-z]+' maps/**/*.txt | sort | uniq
+
+- -o, don't print the line, only the match
+- -i ignore case
+- \K look ahead, keep 'color=' but don't print it, -P (perl necessary)
+- [a-z]+ match or more lower case otherwise stop
+- sort to prepare for uniq