Skip to main content

LInear Optimization Networks - shortest path algorithms

Project description

build codecov License: GPL v3

LInear Optimization Networks (LION)

             ,%%%%%%%%,
           ,%%/\%%%%/\%%
          ,%%%\c "" J/%%%
 %.       %%%%/ o  o \%%%
 `%%.     %%%%    _  |%%%
  `%%     `%%%%(__Y__)%%'
  //       ;%%%%`\-/%%%'
 ((       /  `%%%%%%%'
  \\    .'          |
   \\  /       \  | |
    \\/         ) | |
     \         /_ | |__
     (___________)))))))

This package implements variants of shortest path algorithms to compute minimal angle shortest paths and k diverse shortest paths through a cost / resistance array.

Possible applications include

  • Computer vision tasks
  • Route finding in robotics
  • Infrastructure planning

Installation

The library itself has few major dependencies (see setup.py).

  • numba (for fast compiled algorithms)
  • numpy
  • scipy

Installation from git:

Create a virtual environment and activate it:

python3 -m venv env
source env/bin/activate

Install the repository in editable mode:

git clone https://github.com/NinaWie/lion
cd lion
pip install -e .

Instructions

All main functions are available in algorithms. Usage is examplified in test_api.

Input:

  • instance: 2D numpy array of real float or integer values which are the costs
  • configuration dictionary with
    • start_inds: start coordinates, e.g. [0,0]
    • dest_inds: target coordinates, e.g. [20,20]
    • angle_weight: Float between 0 and 1, 0: angles don't matter, 1: only angles are minimized, costs are not taken into account
    • forbidden_val: value indicating that a cell is forbidden / outside of the project region (can be int, np.nan, np.inf ... )
    • point_dist_min: minimum cell distance of neighboring points (default 3)
    • point_dist_max: minimum cell distance of neighboring points (default 5)
    • angle_weight: how important is the angle (default 0)
    • edge_weight: importantance of costs between points compared to the cost at the points (default=0, i.e. only the points count)
    • max_angle: maximum deviation in angle from the straight connection from start to end (default: pi/2)
    • max_angle_lg: maximum angle of adacent edges (default: pi, i.e. no restriction)
    • angle_cost_function: 'linear' and 'discrete' are implemented. See code
    • memory_limit: default is 1 trillion, if the number of edges is higher, an iterative approximation procedure (''pipeline'') is used
    • pipeline: List of decreasing positive integers, ending with 1 The pipeline in an iterative approach defines the downsampling factors for each step. By default, it is set automatically based on the memory limit. It can however be set manually as well, e.g. [3,1] means downsample by factor of 3, compute optimal path, reduce region of interest to a corridor around optimal path (corridor width is computed automatically based on the memory_limit) then downsample by factor of 1 (aka full resolution). There is no support for setting the corridor width manually because it does not make sense to make it smaller than it could be
    • between_points_allowed: If True, then forbidden areas can still be between points (only relevant for point routing) If False, then it is not allowed that a forbidden area is between two points of the path
    • diversity_threshold:
      • FOR KSP.ksp: Minimum diversity of next path from previous paths in cell distance. E.g. if thresh = 200, each path will be at least 200 cells away at one point from each other path. If None, it is set by default to 1/20 of the instance size
      • FOR KSP.min_set_intersection: maximum intersection of the new path with all previous points Must be between 0 and 1. E.g. if 0.2, then at most 20% of cells are shared between one path and the other paths

Example usage

np.random.seed(0)
instance = np.random.rand(100,100)
# set some forbidden values
instance[instance>0.9] = np.inf
# define config dictionary
cfg = {
  "start_inds": [0,2],
  "dest_inds": [96, 93],
  "angle_weight": 0.5,
  "forbidden_val": np.inf
}

# Compute the least cost route:
opt_route = optimal_route(instance, cfg)
# >>> optimal_route.shape
# (120, 2) --> x and y coordinates of 120 cells on the route

# compute k diverse routes:
multiple_routes = ksp_routes(instance, cfg, 5)
# >>> len(multiple_routes)
# 5
# >>> np.all(np.array(multiple_routes[0]) == np.array(opt_route)))
# True --> 1st route is the optimal one, other routes are diverse alternatives 

# define minimum and maximum distance between points
cfg["point_dist_min"] = 5
cfg["point_dist_max"] = 7

opt_points = optimal_points(instance, cfg)
# >>> len(opt_points)
# 26 --> only 26 because they can be more than 1 apart
# >>> np.linalg.norm(np.array(opt_points[0]) - np.array(opt_points[1]))
# 5.83095189 --> Euclidean distance between cells is between 5 and 7

multiple_points = ksp_points(instance, cfg, 5)
# >>> len(multiple_points)
# 5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lion-sp-0.1.0.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lion_sp-0.1.0-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

Details for the file lion-sp-0.1.0.tar.gz.

File metadata

  • Download URL: lion-sp-0.1.0.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for lion-sp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22d182f40a96ad81e9f6471e19a5d32bcd2501f69f8636be509dd53e771bd841
MD5 45bcd3f7236a533d9fffbb7b47b2abaf
BLAKE2b-256 892e19d3e87c5cc2f24a8d8dff834214e15e838ea9c5b29435ed6adaa78904fb

See more details on using hashes here.

File details

Details for the file lion_sp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lion_sp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for lion_sp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d18013f5b67f847ece662d97b01d519d153b3c2404314b7c2f19af21ebe01c3
MD5 f8e1ecfedfbafb00a321604800fbd082
BLAKE2b-256 4b451050336dfdbf4a32441e35d4544e6a60e885b4b87e5f5510f36ac52a5071

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page