Search This Blog

30 April 2017

EndorRouting - pathfinding between planets in a solar system

I came across this interesting challenge
https://www.questers.com/news/quest-wars-II-new-frontiers 

It seems more of a Math Wars than Star Wars, than their previous one (solution for the Quest Wars I challenge - Store Locations), but here goes nothing :)

Solution

GitHub repository:
https://github.com/ektodorov/EndorRouting
there you can find the source code for the Android application, as an Android Studio project.

As we have a solar system, we are using a polar coordinate system.
We can find the implementation of the routing algorithm in
ConstantsE.java source file, method: getRouteMinimax

In the same source file we can also find other implementations of routing calculations, but as we have commented in the source, they are either not optimal; a lot less correct or both.

Of course the shortest path between two planets would be a straight line. In "figure 1" we see this route, but while we are traveling in our space ship, the planet keeps traveling on its orbit as well and by the time we reach the planet we see that it has moved and is no longer where we made our route - "figure 2".
We can constantly keep updating our route while we travel - "figure 3". But this means a bit longer path. Instead we calculate where would the planet be at the time that it takes us to cover the route and make our route to that location - "figure 4". We are calculating it to 1 kilometer, but we can calculate it to as much or as little as we need it.

 figure 1

figure 2

figure 3

figure 4




We have lavishly used floats and doubles, but if we want to speed things up we have to consider where we can sacrifice on precision and use integers instead.
The Minimax calculations are performed on a single thread and as we know most of the star citizens use multi-core mobile devices that have at least 2 or 4 cores and the marketing people sent on new market planets are bound to have the newest and flashiest CPUs with more than 8 cores, so updating that part of the calculations to take advantage of multi-threading would bring a big benefit.

Please do not install the software on your space ships yet, because it is not production ready. It has small pieces missing like validation of input and such. It is just a prototype.

 (Planets)


 (Solar system -
The movement is updated only 4 times a second. If we want it to be smoother, we just need to update it more times per second)


01 February 2017

Complicated, by design

Or as I say why should it be simple, easy and fast when it can be complicated, difficult and slow.

    'Simple, readable easy to maintain implementation.'
    'Complicated, hard to read and follow, difficult to maintain implementation.'
    It is not hard to say which one of both is better and preferred. But there is something that constrains and partially drives the implementation and that is the design.
-if we have simple system design it is easy to have the first kind of implementation.
-if we have somewhat complicated design it is less simple to have the first kind of implementation, but it is still possible.
-if we have an overly and unnecessarily complicated design, then it is almost impossible to have the first kind of design, no matter how much good practice, knowledge and implementation mastery we throw at it.
Don’t forget, design comes first.

03 January 2017

Detect object movement

    Here is our small surveillance camera software. The application uses the camera of the device. The user positions the device to a position and does not have to look all of the time if an event in the camera view happens, when something in the image changes (there is activity on the field that the camera is observing it draws a rectangle on the screen where something has changed or is changing and plays a sound). 
    - feature to select what source to use - Camera; Video file; Sequence of images.
    - feature to not show movements due to camera movement - image stabilization.
    - feature to play a sound when there is a difference detected

    The libraries that we considered for this projects are listed below. Initially we wanted to use Marvin framework, but it uses Java packages that are not available in Android and porting the framework to Android would be a project of its own. That is why our next choice was Catalano Framework which can be used in an Android application without any modifications.

Marvin Image Processing Framework

Processing

JMagick - Java wrapper for ImageMagick API

Catalano Framework

OpenCV - (Open Computer Vision)

    For the image stabilization feature we considered using Phase correlation or Convolution, and decided to use a filter we are already using which is provided by the Catalano Framework - Catalano.Imaging.Filters.Difference.
We thought that it was using Convolution to calculate the difference, but after looking at the source it turns out it is not. If it was using convolution matrix it would probably have had better results in finding differences.
Instead of performing the image stabilization using the whole size of the image we use a subset of the image. We get part of the image and another slightly bigger part of the image and calculate differences with increasing offsets to find the smallest difference and calculate the offset point from it.
Would we have used Phase correlation, we would have done the same with different delays to find where the frequencies match the most.
When there is a movement in different parts of the screen - probably different objects, the whole area will be reported and not individual objects, because we decided that it is not so important to split the areas. To add this functionality, we have to just calculate changes and group them to different clusters, so that we can separate different objects in movement on the screen.
 
Repository of the project at GitHub:
https://github.com/ektodorov/sentinel

13 December 2016

Keeping it localized

    We thought of implementing a small web app in Go for localization of resources and translations. There are such apps available:

    But then we thought it is not that important tool. The job can be accomplished in a shared spreadsheet. Like our example of issue tracking:

    The same can be done when we want to localize our resources or translate a text in multiple languages. One spreadsheet per language and we are done. No need for special tools, when everyone already is familiar and used to using the tool, in this case a spreadsheet editing program.

06 December 2016

Automation, Not ?

    We all know that automation is good. No one likes boring repetitive task that can be passed to a machine to execute. But if we specifically and regularly are forced to change our code just to accommodate automation, well then "you are doing it wrong". Yes there are decisions that we need to make so that automation is possible, but it is possible through clean, well structured and maintainable code. That is it. (here is an article with the same opinion and some more things: http://ithare.com/testing-my-personal-take-on-testing-including-unit-testing-and-atddbdd/).
Automation should bend backwards, sideways and any other way to fit our workflow, not the other way around. Otherwise we are in the case of those memes, which mock "doing automation the manual way".

13 November 2016

Postman

    We were reminded to mention a great tool - Postman, because of this “New from Postman” issue:


    I don’t remember since when I started receiving these Postman newsletters, but they are great, Postman is great. And I am sure we would all be very surprised that there are a lot of people developing services or applications that consume services, that don’t use such tools. It may not be Postman, there are other solutions, but please do use something.

10 November 2016

Someone said let's self sign it

So I wanted to check my voting location for the Presidential elections in Bulgaria and I came across this on the GRAO website:https://www.grao.bg/elections 



Then in one of their pages they explain that the site is not secure and that the user has to install their root certificate in order to secure their connection to the website.




So they are using a self signed certificate and they are telling us it is OK.
Not cool guys. Don’t invent security. Just get a proper certificate !