Skip to main content

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

Simple install with pip:

pip install lion-sp

The library itself has few 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_direction_deviation: maximum deviation in angle from the straight connection from start to end (default: pi/2)
    • max_angle: 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)
# place some forbidden regions
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

If you use this code in a publication, please cite the following paper:

@article{wiedemann2021optimization,
  title={An Optimization Framework for Power Infrastructure Planning},
  author={Wiedemann, Nina and Adjiashvili, David},
  journal={arXiv preprint arXiv:2101.03388},
  year={2021}
}

Metadata

Release files for lion-sp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lion-sp 0.1.1
File Size Uploaded Provenance
lion-sp-0.1.1.tar.gz 32.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lion-sp 0.1.1
File Interpreter ABI Platform
lion_sp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 81.4 kB

Release files / lion-sp-0.1.1.tar.gz

Download URL lion-sp-0.1.1.tar.gz
Size 32.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b8055fcdcb41559d1c7917f0cf7f826d6e2f54bba0af2a8c265b608f8459f2a5
BLAKE2b-256 checksum
How to use checksums
0614cd46fb841d9eb88dd905c41af7ac5c02e5c1179386e238ed1a4a51d73a58
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / lion_sp-0.1.1-py3-none-any.whl

Download URL lion_sp-0.1.1-py3-none-any.whl
Size 48.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d98d8371c4ebfdbb31f9a11c7f0ee2faade87f6473cb26b8341260da4c8fa35
BLAKE2b-256 checksum
How to use checksums
0870e63010beeb39544dc65691ce7564d04a7f55d36cd6cf74888a37c509248e
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for lion-sp 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page