Algorithms for TW
Project description
TW Complex
Repo with algorithms to divide ally villages into front and back in TW.
Underneath it is a problem of dividing a set of 2D points A according to the min_radius
and max_radius
distances from a set of other 2D points B, which can be solved most simply by counting the distances from each point in the first set A to all points in the second set B one by one.
Instalation
pip install tw_complex
Basic usage
from tw_complex import CDistBrute
import numpy as np
# The code for Example 1 below
points1 = np.random.rand(10000, 2) + [2, 0]
points2 = np.random.rand(15000, 2)
min_radius = 1.4
max_radius = 2
precise_front, precise_back = CDistBrute(
ally_villages=points1,
enemy_villages=points2,
min_radius=min_radius,
max_radius=max_radius,
).result()
Examples (before -> after)
Example 1
Ally: 10000 points
Enemy: 15000 points
min_radius: 1.4
max_radius: 2
Example 2
Ally: 2500 points
Enemy: 6000 points
min_radius: 4
max_radius: 10
Example 3
Ally: 20000 points
Enemy: 20000 points
min_radius: 20
max_radius: 60
Example 4
Ally: 20000 points
Enemy: 20000 points
min_radius: 10
max_radius: 120
Running locally
You will need to have poetry installed.
git clone https://github.com/rafsaf/tw-complex.git
cd tw-complex
poetry install
Code lives in tw-complex
folder, and you may also test algorithms running in main folder
# In main folder
# eg. ~/Desktop/tw-complex
pytest
For CDistAndKNN it looks like
# tests/test_cdist.py
from tw_complex import CDistAndKNN
import tests.utils as utils
def test_CDistAndKNN():
utils.run_all_tests(CDistAndKNN, "CDistAndKNN", _precision=0.8, draw=True)
# Go with `draw=False` if you do not want to use pyplot to show diagrams
Some hardcoded tests are located in tests/utils.py
, it uses brute force for calculating exact result, then compare it to given algorithm using basic maths. You can even compare it to brute force itself (eg. using diffrent _precision
). For new test there should be another file in tests/test_name_of_file_in_tw_complex_folder.py
with pretty much the same content as above.
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
Built Distribution
File details
Details for the file tw-complex-1.0.0.tar.gz
.
File metadata
- Download URL: tw-complex-1.0.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1852f2b6eeb0c79385a7697e1047da8faf468c1c407397af9ebed613873b23bf |
|
MD5 | 65b246e9fb4be27056c5f86c0b33ac84 |
|
BLAKE2b-256 | c30f9d0ac165ab61c0b0b13985a06be3bb1133108434726c099fa37246eb5e4f |
File details
Details for the file tw_complex-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: tw_complex-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9fc8dff552dcf1d7d0366b61e0e74a0ef91f63464f1af051bea2924bb3079be |
|
MD5 | f454a920ae952f4ac1d85441bf944413 |
|
BLAKE2b-256 | 0143ac6b80608b127bdecc88de6cc5e43ff9d054b4afc4a09f00c1bb6e752fe8 |