Posts

Showing posts from February, 2020

Host your own version of a map for free

This is a tutorial on how to use OSRM to host a local version of your map so as to query it as opposed to querying the readily available services on the internet like google maps, mapbox, routific, etc.  Each has its own weaknesses and strengths, the strength points of OSRM are speed, freedom to manipulate the map data and zero costs. First we need to download the map data, The bigger the area, the more time it will take to extract the map data and the more RAM it will occupy when hosted, and this thing is hungry for RِAM. We can extract and host it on a server which we will discuss later, We can download the compressed daily updated map data which can be found on  https://download.geofabrik.de/   , download the osm.pbf file which is a compressed file, you can also click on any of the regions, like Europe or wherever you want, to get a sub region and download it. Or you can also use  https://extract.bbbike.org/    , which can be a bit ...

Learn python programming through algorithms - Binpacking part 2

Image
Bin packing algorithm for regular and irregular shapes Part 2: Constructing the Binary tree (linked list) s is the size, it is a tuple containing the length and the width. c is the coordinate, it is a tuple that will contain its origin point and the origin point won't be the center. Origin point for an inserted shape in red The pointers right and left are used to construct the tree that we will discuss later. occupants is used to hold some complex shapes such that the sorting function takes care of splitting the Node while sorting, thats one method to defeat stuttering as we defer some of the splitting overhead in the inserting stage to the sorting stage. class Node:            def __init__(self, a=[0,0], b=[0,0]):                    self.s = a                    self.c = b                ...

Learn python programming through algorithms - Binpacking

Image
Bin packing algorithm for regular and irregular shape Part 1: theory and data preparation   This is not intended to be just a programming tutorial that has the one “right” route to solving a problem, I will state the philosophy behind choosing something, and by philosophy I mean that everything has a good side and an underside and I will be detailing them both as well as some of the mistakes and weird undocumented python behaviors that I learned from. for example :     Most of my clients ask for fitting the largest items first but it almost always fails to bring good results I will be explaining the theory and giving examples from my code as I go instead of just stating the theories and explaining them in one bulk. So many clients asked me to do a variant of an algorithm to pack items for them into the tightest space possible as an alternative for softwares like Fastcam’s fastcut optimizer or Sketchcut and many others as each had its own limitation/problem. Sa...