npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

country-routing-algorithm

v2.0.1

Published

Graph based algorithm for traversing and finding the shortest path between two countries

Downloads

15

Readme

Country Routing Algorithm

AKA: POOR MAN's ROUTING Algorithm. Because you can't really afford APIs

NPM package: https://www.npmjs.com/package/country-routing-algorithm

Not much of a README right now, just fiddle with page-scripts.js and see the result on your console.

TODO List

  • [ ] Prevented/pruned redundancies count on routingResult
  • [X] ~~Issues #8 and #9~~
  • [X] ~~calculate the total distance to be traversed:~~
    • [X] ~~Yeah we return the path/route but the distance ? It's the whole point of this~~
  • [X] ~~Handle max moves exceeded~~
    • [X] ~~It should pick among traversed countries which is the closest to the final destination. Then return a routing to that closest country~~
    • Btw there is possibly something wrong with the traversed countries array. When i was experimenting with something else, i noticed both duplicate and different distance values. Not sure if this issue still persists.
  • [ ] visualize
  • Tests
    • [X] ~~Initial, basic tests~~
    • [ ] Advanced tests about total distance
    • [X] ~~Standard pruning~~
    • [X] ~~Pruning involving origin country (Like Finland->Germany test case)~~
    • [ ] FoundPath order (reversed) and countries should be identical when origin and destination countries switch (Issue #11). Prepare unit tests for this.
  • [X] ~~Class and instance based solution for RoutingResult#foundPath entries~~
  • [X] ~~Class and instance based solution for RoutingResult#traversedCountries~~
  • [X] ~~Afghanistan to Antarctica edge case. Algorithm should prune down the path if it cycles back to one of the origin country's neighbors.~~ [Pruning]
  • [X] ~~Afghanistan->Åland Islands. It should prune down the visit to China since it cycles back to Russia eventually. [Pruning]~~
  • [ ] Rollback count for RoutingResult (I guess I was talking about the NoOtherBorderException ?)
  • [ ] Abstraction for GraphController (to-be-renamed), in order to achieve independence of graph library.
  • [ ] Deviance rate calculation through google maps api

Resources:

Data

  • Countries db, including lat-long of center
  • Pivot table for bordering countries

Supplementary and library

  • https://github.com/amejiarosario/dsa.js-data-structures-algorithms-javascript
  • https://github.com/felipernb/algorithms.js
  • https://github.com/avoidwork/tiny-graph
  • ~~Includes visualization: https://github.com/strathausen/dracula~~
  • this is such an overkill: cytoscape.js
  • ~~https://github.com/avoidwork/tiny-graph simple yet promising~~
  • https://github.com/anvaka/ngraph.graph. Problem with undirected edges smh
  • Graphology.js Let's stick to this for now, functions are a bit awful but...
  • cytoscape didn't like it much

Method:

  • Undirected graph will be applied

    • Countries gonna be represented by nodes
    • Edges will represent distance between center lat-long of the countries at each end
  • Distance calculation between countries will be made using country's center lat-long point and applying euclidean distance formula.

  • This algorithm will be used to find possible path(s) to destination country:

    • While current country and destination country does not share borders:
      1. Among bordering countries of the current country: get the one with the smaller distance to the destination country. (Named C1)
      2. Move to that country, C1
      3. If no bordering country is present (excluding the visited ones), or no country is closer to the destination country: start reverting. Trace back steps and try different paths.
  • Technical note: it returns isClosest:true if the target cannot be reached through land (e.g: Malta)

Notes

  • Distinction between graphology dependencies
    • Unit tests use node version of graphology, so you need to npm install to run unit tests
    • Meanwhile the demo/index.html and page-script.js use classic javascript file version of graphology.

Credits

Resources and libraries