Distances precalculation for Optaplanner with Quarkus - quarkus

I want to solve the VRP problem (with some addition) with Optaplanner. In the documentation, it's often said, that it's a good thing to precalculate the distances between locations and then use a map for each location to get distanceTo(location).
I use Optaplanner with Quarkus and I am wondering when and how to precalculate these traveling times +how to assign obtained travelDistanceMap to a specific location. I'd like to use Google maps for doing it.

In optaweb-vehicle-routing, we use GraphHopper embedded, but to scale out it's better use either OSRM or a bulk distance matrix API like that of Google Maps or GraphHopper Enterprise.
See this video https://youtu.be/rEeAML74oWo

Related

Algorithm for generating a subway transit map

I would like to draw a transit map which is not based on any real map.
Unlike conventional maps, transit maps are usually not geographically accurate—instead they use straight lines and fixed angles, and often illustrate a fixed distance between stations, compressing those in the outer area of the system and expanding those close to the center.
This map would be massive, not infinite but if a line ran horizontally across it could ideally have 40,075 stations. I want it to look just like any local transit map (I'm basing myself on the Montreal metro map) but much bigger obviously, which means I don't care about what a metro system of this scale should look like or how useless a map this size would be.
I think the hardest part will be to generate where the stations will be, then drawing stylized lines between those stations should be relatively easy using something like Processing.
So, do you have any idea how to generate a giant transit map???
So far, the research
Nathan Hellinga's Processing.py subway map generator resembles what I'm looking for and looks great but the algorithm wouldn't scale well to a very large grid.
Jannis Redmann's generating transit map theory is really interesting but bases itself on real world data. Maybe it could be used with generated data but how do you generate that data then?
My idea, a random walker
Basically, roll some dice and based on a predefined set of rules: go forward, place a station, turn... and repeat countless times until the map is filled. I'm not yet sure what the probabilities would be, it would take some trial and error.
Results of another question I asked on Worldbuilding
Fractal generators loos really promising! But how do I make it look like a transit map? I think it relates to the slime (see below) so I'll look more into it.
Graphviz, an open-source tool that converts DOT script files into graphical images. I think that has the same problem as Jannis Redmann's, I still need an algorithm to generate data.
Slime is a really interesting idea! I would have to do some more research on how to reproduce these patterns but it's an interesting place to start.

How compare two images and check whether both images are having same object or not in OpenCV python or JavaCV

I am working on a feature matching project and i am using OpenCV Python as the tool for developed the application.
According to the project requirement, my database have images of some objects like glass, ball,etc ....with their descriptions. User can send images to the back end of the application and back end is responsible for matching the sent image with images which are exist in the database and send the image description to the user.
I had done some research on the above scenario. Unfortunately still i could not find a algorithm for matching two images and identifying both are matching or not.
If any body have that kind of algorithm please send me.(I have to use OpenCV python or JavaCV)
Thank you
This is a very common problem in Computer Vision nowadays. A simple solution is really simple. But there are many, many variants for more sophisticated solutions.
Simple Solution
Feature Detector and Descriptor based.
The idea here being that you get a bunch of keypoints and their descriptors (search for SIFT/SURF/ORB). You can then find matches easily with tools provided in OpenCV. You would match the keypoints in your query image against all keypoints in the training dataset. Because of typical outliers, you would like to add a robust matching technique, like RanSaC. All of this is part of OpenCV.
Bag-of-Word model
If you want just the image that is as much the same as your query image, you can use Nearest-Neighbour search. Be aware that OpenCV comes with the much faster Approximated-Nearest-Neighbour (ANN) algorithm. Or you can use the BruteForceMatcher.
Advanced Solution
If you have many images (many==1 Million), you can look at Locality-Sensitive-Hashing (see Dean et al, 100,000 Object Categories).
If you do use Bag-of-Visual-Words, then you should probably build an Inverted Index.
Have a look at Fisher Vectors for improved accuracy as compared to BOW.
Suggestion
Start by using Bag-Of-Visual-Words. There are tutorials on how to train the dictionary for this
model.
Training:
Extract Local features (just pick SIFT, you can easily change this as OpenCV is very modular) from a subset of your training images. First detect features and then extract them. There are many tutorials on the web about this.
Train Dictionary. Helpful documentation with a reference to a sample implementation in Python (opencv_source_code/samples/python2/find_obj.py)!
Compute Histogram for each training image. (Also in the BOW documentation from previous step)
Put your image descriptors from the step above into a FLANN-Based-matcher.
Querying:
Compute features on your query image.
Use the dictionary from training to build a BOW histogram for your query image.
Use that feature to find the nearest neighbor(s).
I think you are talking about Content Based Image Retrieval
There are many research paper available on Internet.Get any one of them and Implement Best out of them according to your needs.Select Criteria according to your application like Texture based,color based,shape based image retrieval (This is best when you are working with image retrieval on internet for speed).
So you Need python Implementation, I would like to suggest you to go through Chapter 7, 8 of book Computer Vision Book . It Contains Working Example with code of what you are looking for
One question you may found useful : Are there any API's that'll let me search by image?

Random Config Generation for RRT

I am writing code for Rapidly exploring trees for robotic arm movement. I have two doubts
i) what is the distance metric that I have to use to find the nearest node in the graph? If it is euclidean distance,how do I calculate it because there are two links in each arm configuration of the robot and I have no idea how to find the euclidean distance in that case.
How do I find the distance between ADE and ABC if ABC is the nearest config to ADE in the tree?
ii) How do I generate a random config towards the goal because my random configs never seem to reach goal even after 5000 iterations.
Thanks in advance.
Distance Metrics for the Two Revolute-Joint Arm
RRT is pretty robust to the (pseudo-) metric that you choose, but the quality of the trees (and consequently the paths) will be influenced if you've got something that isn't particularly good. To get good performance overall, the metric function is supposed to be fast, so I'd definitely try simpler things before you move onto something more complex.
In the case of robot arms a number of metrics are possible. Perhaps the simplest is simply to use the Euclidean distance between the end effector in two configurations. You'll almost certainly have to have this working already if you're testing the planning algorithm.
If you've got a full dynamics model of the system, then it is likely that other metrics based on the energy required to move the arm from one configuration to another will perform better.
Other metrics based on the (joint local) angle swept out at the joints, which can be derived from evaluating a path from an inverse kinematics solver may be acceptable - but I haven't tried this in practice. This may also be useful technique to know about if you need to implement your connect-configurations function.
Improving Convergence
Once you've got your metric function working correctly, RRT should just work. However, in practice, you'll almost always need to oversample near the goal configuration to encourage the algorithm to exploit the work done in the rest of the tree building stage. Most commonly, you do this by sampling the goal configuration state with about 5% probability.

Clustering geo-data for heatmap

I have a list of tweets with their geo locations.
They are going to be displayed in a heatmap image transparently placed over Google Map.
The trick is to find groups of locations residing next to each other and display
them as a single heatmap circle/figure of a certain heat/color, based on cluster size.
Is there some library ready to grouping locations in a map into clusters?
Or I better should decide my clusterization params and build a custom algorithm?
I don't know if there is a 'library ready to grouping locations in a map into clusters', maybe it is, maybe it isn't. Anyways, I don't recommend you to build your custom clustering algorithm since there are a lot of libraries already implemented for this.
#recursive sent you a link with a php code for k-means (one clustering algorithm). There is also a huge Java library with other techniques (Java-ML) including k-means too, hierarchical clustering, k-means++ (to select the centroids), etc.
Finally I'd like to tell you that clustering is a non-supervised algorithm, which means that effectively, it will give you a set of clusters with data inside them, but at a first glance you don't know how the algorithm clustered your data. I mean, it may be clustered by locations as you want, but it can be clustered also by another characteristic you don't need so it's all about playing with the parameters of the algorithm and tune your solutions.
I'm interested in the final solution you could find to this problem :) Maybe you can share it in a comment when you end this project!
K means clustering is a technique often used for such problems
The basic idea is this:
Given an initial set of k means m1,…,mk, the
algorithm proceeds by alternating between two steps:
Assignment step: Assign each observation to the cluster with the closest mean
Update step: Calculate the new means to be the centroid of the observations in the cluster.
Here is some sample code for php.
heatmap.js is an HTML5 library for rendering heatmaps, and has a sample for doing it on top of the Google Maps API. It's pretty robust, but only works in browsers that support canvas:
The heatmap.js library is currently supported in Firefox 3.6+, Chrome
10, Safari 5, Opera 11 and IE 9+.
You can try my php class hilbert curve at phpclasses.org. It's a monster curve and reduces 2d complexity to 1d complexity. I use a quadkey to address a coordinate and it has 21 zoom levels like Google maps.
This isn't really a clustering problem. Head maps don't work by creating clusters. Instead they convolute the data with a gaussian kernel. If you're not familiar with image processing, think of it as using a normal or gaussian "stamp" and stamping it over each point. Since the overlays of the stamp will add up on top of each other, areas of high density will have higher values.
One simple alternative for heatmaps is to just round the lat/long to some decimals and group by that.
See this explanation about lat/long decimal accuracy.
1 decimal - 11km
2 decimals - 1.1km
3 decimals - 110m
etc.
For a low zoom level heatmap with lots of data, rounding to 1 or 2 decimals and grouping the results by that should do the trick.

What's a good algorithm for nearest neighbour problem in two dimensions?

I would like to build an app that's going to give you the closest restaurant depending on your location. We'll have a database with all the POI corresponding to the restaurant and we'll get your location with the GPS of your phone...
What algorithm would be appropriate ? Where can I find good doc about it ?
Thanks
Here's an informative presentation: http://dimacs.rutgers.edu/Workshops/MiningTutorial/pindyk-slides.ppt
I would either use a Quadtree or a Kd-tree.
See some benchmarks here: http://www.flegg.net/brett/pubs/spatial/index.html. It really all depends on your data size and range.
The main problem is how do you store and search the data. If you are using a SQL database that doesn't support spatial indexes (let's say SQLite on Android), consider converting the spatial data to a linear Z-order curve. The algorithm is simple, I know about (well, wrote) this implementation.

Resources