Android Question How can I increase speed for calculatons?

Mark Read

Well-Known Member
Licensed User
Longtime User
I am moving from a starting point on the screen to a finishing point via the quickest route, which is not as the crow flies. To do this i take each point and check each of the 8 neighbours to see which is the best route. This gives roughly 14500 points to check, which takes 330 seconds. Apart from optimising code, which I have done, is there any other possibility tp speed this up? 30 seconds would be perfect! A tall order.
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Okay, here is the code. To use: wait until the map is drawn (if the map will not draw, select a different tile source). Select two points on the map with long click (markers will be shown). Any points are okay, I have not added the "only river" function yet. B4A 3.80 + OSMDroid.
 

Attachments

  • mapview.zip
    11.9 KB · Views: 135
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Depending on the length of the route, between 1000 and 2000 times.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Mark,
inspired by Erel's question on post #4 above, I am inclined to believe list.Size function has to compute each time it's called the actual number of list elements. If this holds true, you may shorten that delay maintaining a separate counter for OpenList. I mean, dim an int var like OpenListSize and manage it yourself when adding/subtracting elements from the list. So when you'll need the number of actual elements you simply read that value from this new var instead of asking a computation to the list object.
Maybe it's worth giving it a try.

Umberto
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Depending on the length of the route, between 1000 and 2000 times.
You kill completely the performance with these 3 lines:
B4X:
        cvs.DrawCircle(CurrentSquare.X,CurrentSquare.Y,2,Colors.blue,False,2)    'draw point for parent
        iv.Invalidate
        DoEvents
They have no reason to be in the loop. The path should be drawn only when the computation is done.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
You kill completely the performance with these 3 lines:

Not a problem, I only wanted to see what was happening. Will try the timing again with these lines commented out. Many thanks.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Just for info. I rewrote a lot of the code and created just a pathfinding activity. Informatix was correct, the canvas draw + invalidate + doevents killed the speed.

I now have the following speed without obstacles (working on that still!)

We are at destination
Path from:100,100 to 400,250
Using an interval of 1
Total Time: 113.683 secs
iterations: 761

We are at destination
Path from:100,100 to 400,250
Using an interval of 3
Total Time: 11.339 secs
iterations: 192

We are at destination
Path from:100,100 to 400,250
Using an interval of 5
Total Time: 4.02 secs
iterations: 108

We are at destination
Path from:100,100 to 400,250
Using an interval of 7
Total Time: 2.031 secs
iterations: 76

The interval in this case refers to the distance from the middle to the outside (radius) of the 8 points.
 
Upvote 0
Top