Marin Capranov

Ranch Hand
+ Follow
since Jan 31, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
1
Total given
13
Given in last 30 days
13
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marin Capranov

Following the question of why I want to use genetic algorithm is simply that I need it for my university dissertation. I need the genetic algorithm for finding shortest routes from A to be and so on, hence solving the TSP(travelling salesman problem).
1 hour ago
Picture added. Thank you!

The genetic algorithm supposedly is generating a route from A -> B , hence TSP.  A and B are names of the places or coordinates taken from the Direction API or Places API. I have got both. I was told that Direction API already is solving all the problem so the genetic algorithm is not suited. Machine learning I don't think is needed. Just a simple genetic algorithm that does same job as the direction API.
2 days ago
Hi there!

I wonder if is there a way to implement a simple genetic algorithm that solves the TSP problem (meaning it finds the shortest path from one place to another without visiting the same place again). I have used Direction API however it is already automated and it actually costs money to use it. I want a genetic algorithm that will do the same job, but I am confused and I don't know how to use with a Directions API. I got the API JSON file which has the distance and duration data. Can I use it as parameters for the genetic algorithm and lastly but most importantly how can I display that on the map.

For now, I got a screen of what I can do with a Directions API. I want the same but using a genetic algorithm. The app I build is for Android, therefore I use JAVA only. Cheers!

Any suggestions?

Directions API
2 days ago
Thank you for your hints. They helped me to find solutions and now I can move to the next phase, which is the genetic algorithm =)
3 days ago
So far I have done some changes and it seems to work, however it shows the polylines as straight lines which is strange. Aslo, I don't know how to test the code to see if the loop doesn't return duplicate values. Is there a way to check that?

Thank you for your recommendations by the way. I might look into JSON-B eventually if I won't make it with this one current.

4 days ago
Regarding the Jackson, I will have a look right now? but if you got any helpful docs I would highly appreciate that.
4 days ago
Example input:

These are polylines from the JSON files. Like: "points" : "{kd_IljoJ" , "points" : "{kd_IljoJd@L|Ab@pA\\r@P", "points" : "qcd_InmoJBSNoAd@}DVsBJk@He@@ERiAPeA@MFi@BMFa@Lu@Hk@",  "points" : "mgc_IltnJLe@DI|B}ELU" ... These are polylines in a order and expected output.

And now that's the actual output: "points": "{kd_IljoJ"

As you can see only the first value and stops there.

I played around with the JSON and noticed that when I change the int value of the getJSONObject(0) ti (1) it gives consequent output. That means that I have to somehow loop through all of the getJSONObject(i), but I can't make it work.

That's the JSON itself for you to have a look at ->
https://gist.github.com/Biseamon/dad9e9c5b91b68d4caebcfa8af7a7eb8
4 days ago
Hi!

I am trying to parse a JSON file that contains polylines and points. The thing is it returns only the first value of the first object and stops. Am I missing something in the loop? I need all the polylines so I can display them on the map. Cheers!





5 days ago
Sorry for the confusion. I have achieved what I wanted. However, if you got any experience with direction API could you help me to decode the path that I have got from the overview_polylines object. I want to display on the map and it doesn't work.




Parser



the message from log "test" shows:

I/test: onPostExecute: [{obj={kd_IljoJhG`BpAuKjAmHhC}BhREnC}F?AAC?EmHmJtHdJDF?D?@JNnHxJj@jHu@`OuB|DoIrCyHaEkFkBsIcCJmFdBkLlCyNrBwOcC]A@?@A@A?C?CGyC}@IGyKyDwDTd@[tPrD?RE?uJzd@`@zCq@vHbHjBnNbEtCrAjIbD|HsCfP~BrS|VtEcBdJnDnK[mHs@lFaKgF{PgGsI{Fc\]eBoGoRx@ab@iBwC{F]_CTCFKBIQQu@g^oWoGoDqKv@_H`GrF_F~SqMfEpQpHhGrPzNJAFN?HfBK`KhBmAxc@fG`Qx@dC?TvFh\~B~FjFj@bJzGNKJR|ClVwBGfG\nC~HDqOoAsVABC@C?EKDKzEaPiJgQkPwPoJaKsN{F[oc@lF{QAK}F_q@oL`@iMhFe@_GlBrErMaFbEeHbAcYdBc^qU{FiIPqEoAcK|\aIjL{JrYk@|FaFxSyC_H_WuDoVmCyLiF{G_YiEfNlDvE`InA`@`@dJfA^tDk\xdA_G`TcJ{@GvD~KtIzKdNnUje@bIfEm]roB}Qlm@|TpNdTnDnK`QzLb[fFpQnEfPg@vHlGdHzIvK@AF?xBgGtBqCpApAdFhBhAbBcJ}FgF|Ha@`A@HILkQ`KsEbAs_@yF}QReKoLwOahAsDyK{@`CxBjc@h@xKtF}LiDoYsDyKsAxAwBwDhHyYzUct@nQ}gAdJgh@kCoEmVsb@{D}G}VoUqCiCjIiFxM{NdNe[~Kil@fNsWdJiYr@kS}Vun@kBfD\zGIcEn@gCl@jFqApBUyIvAmHrAr@xKl\~Hx_@yLrd@mKtYeYh_AsGtUeDdDaFuAcCpB`IfHvPxPpRta@rJtHq@|JkX|wAaFhZkLh[gJ|j@kBbEoCqJcC{GuArEJbEx@`AHj@c@xEfCrBz@qDr@gCHkAhC{A~C}VzUct@nQ}gAdJgh@kCoEmVsb@{D}G}VoUqCiCjIiFxM{NdNe[~Kil@fNsWdJiYr@kS}Vun@jC}Zp@}AlGrCbGnFjNrJvU_CjFFpFm@pKxKzWvHPGxYtHl]tU`G}@fBrGlAx`@~DbWl@`T_Fhw@tS~j@lC~GtWd_AFn@QAiG|T{Brm@DH?JKFu@jJpCtQ~HrWnIlTpBlKqBmKwGqFmBN{\ePCFI?CQkHqDaMgGwIsEqJaAyLhEoPmHmByKwXaIw_@wOgIeLsGaGmDmEvBsZfAkOmCaBcBSsMvHwPj@mOmVoUwb@_TcM_AgI}TilBRzB~ArS|Gla@hHxm@d^|_@xJvXpQlTnEfEtJSrMwHpIlB}]


Thank you! I have fixed some issues, but I still struggle at understanding these threads and async.

I have created a new parser inside the onPostExecute but it returns an error: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference


Parser.class



MyAsync.class




I believe that the parser does not work onPostExecute and should a background task as you suggested earlier but it did not work in the doInBackground either.

What can I do?
I do something wrong?




E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
   Process: com.example.authorisationfirebase, PID: 9912
   java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:309)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
       at com.example.authorisationfirebase.GetDirectionsData$1.doInBackground(GetDirectionsData.java:74)
       at com.example.authorisationfirebase.GetDirectionsData$1.doInBackground(GetDirectionsData.java:71)
       at android.os.AsyncTask$2.call(AsyncTask.java:295)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
       at java.lang.Thread.run(Thread.java:818) 
Yeah it's a different method but it is giving the same error.

SO you suggest creating an Asynctask what? Class or method inside the onPostExecution of the existing Asynctask. I was thinking I have to create another class Asynctask.
And if I create another async task that won't be a problem?