matrx-software / matrx

Human-Agent Teaming Rapid Experimentation Software
https://www.matrx-software.com
MIT License
10 stars 3 forks source link

Custom pathplanner that takes preferences into account #319

Closed thaije closed 2 years ago

thaije commented 2 years ago

Is your feature request related to a problem? Please describe. A pathplanner that could avoid specific areas has been requested, e.g. because it makes the user walk slower over specific tiles. At the moment, the A star pathplanner has been hardcoded and is not easily switchable to an alternative pathplanner, without changing the MATRX core code.

Describe the solution you would like

Describe alternatives you have considered Extending the existing A star algorithm to include the weighted pathplanning as an option, however it also requires a different function for calculating the occupation map, so that is difficult and not really future proof.

Additional context As part of a TNO project, V2205.

thaije commented 2 years ago

See https://github.com/matrx-software/matrx/commit/fa15b1eac1d2ed942afeaccf20409096c7bf4095

thaije commented 2 years ago

Using the weighted pathplanner

self.navigator = Navigator(agent_id=self.agent_id, action_set=self.action_set, algorithm=Navigator.WEIGHTED_A_STAR_ALGORITHM, algorithm_settings={"traversability_penalty_multiplier": 10})


For an example of an entire agent using the new pathplanner see this file: https://github.com/matrx-software/matrx/blob/319_custom_pathplanner(s)/matrx/agents/agent_types/patrolling_agent.py 

## Tweaking the weighted pathplanner 
By increasing `traversability_penalty_multiplier` in the `algorithm_settings` above, the algorithm will try to avoid objects more aggresively with a `traversability_penalty`. 

You can calculate this as follows: 
For an agent that uses the pathplanner, normally 1 step sideways or upwards has a 'cost' of 1. However, if there is a object on route with a `traversability_penalty=0.5` and the `{traversability_penalty_multiplier": 10}`, then walking over that object has a cost of `0.5*10=5`, thus equal to walking over 5 normal tiles. 

In this way, the agent will avoid to walk over this object. However, if the alternative is more than 5 normal tiles longer, it will opt t o walk over the slow tile instead. 

# Creating a custom pathplanner
It is also possible to create a new pathplanner, e.g. with a different pathplanner algorithm, or one that completely ignores the `is_traversable` such as maybe a drone would do. To do so:

- Change the navigator settings in your agent's initialize function as so: 
```python
self.navigator = Navigator(agent_id=self.agent_id, action_set=self.action_set,  algorithm="name_of_your_pathplanner",, custom_algorithm_class=YourCustomPathPlannerClass, traversability_map_func=your_custom_traversability_map_function, algorithm_settings={"settings_specific_to_your_pathplanner": True})