Halfdrawn/undrawn circles when drawing shorstest path #24

Closed
opened 2017-12-25 09:09:44 +00:00 by antograb · 7 comments
Owner

It appears that on horizontal trajectories, circles representing the shortest path are halfdrawn or even not drawn (see screenshot).

It appears that on horizontal trajectories, circles representing the shortest path are halfdrawn or even not drawn (see screenshot).
antograb added the bug label 2017-12-25 09:09:44 +00:00
Collaborator

Ow, never seen this before, that's fun.

Ow, never seen this before, that's fun.
Collaborator

There are probably some nasty things going on…

There are probably some nasty things going on…
Collaborator

I think I identified the problem.
It seems to come from the Maze menu painting. The ovals that should be underneath are not painted, probably because the menu folds after the path is painted, causing this zone to be repainted, but without the path drawn.

I think I identified the problem. It seems to come from the Maze menu painting. The ovals that should be underneath are not painted, probably because the menu folds after the path is painted, causing this zone to be repainted, but without the path drawn.
Collaborator

Here is the exemple maze :

WEEEEEWWWEEEEEWW
WEDEEEWWWEEEEEWW
WEEEEEEEEEWWWEEW
WEEEEEWWWEEWWWEE
WEEEEEWWWWEEEEEW
WEEEEEWWEEEWWWWW
EWWWWEWWWEEEEEWW
EWWEEEWWWEEEEEWW
EEEEWWEEWEEEEEWW
WEEEEEWWWEEEEEWW
EEWWWEEWWEEEEEWW
WEEWWWEEWEEEEEWW
WWEEEEEWWEEEEEWW
EEEWWWWWWEEEEEWW
EWWWWAWWWEEEEEWW
EWWEEEWWWEEEEEWW
EEEEWWEEWEEEEEWW

Here is the exemple maze : > WEEEEEWWWEEEEEWW WEDEEEWWWEEEEEWW WEEEEEEEEEWWWEEW WEEEEEWWWEEWWWEE WEEEEEWWWWEEEEEW WEEEEEWWEEEWWWWW EWWWWEWWWEEEEEWW EWWEEEWWWEEEEEWW EEEEWWEEWEEEEEWW WEEEEEWWWEEEEEWW EEWWWEEWWEEEEEWW WEEWWWEEWEEEEEWW WWEEEEEWWEEEEEWW EEEWWWWWWEEEEEWW EWWWWAWWWEEEEEWW EWWEEEWWWEEEEEWW EEEEWWEEWEEEEEWW
Collaborator

The shortest path bug :

The shortest path bug :
Collaborator

It's even worse in this case and seems to create an infinite path if we keep adding lines :

It's even worse in this case and seems to create an infinite path if we keep adding lines :
Author
Owner

I finally found the answer ! The problem starts at Dijkstra.java#L29 where we ask for g.getCost(pivot, vertex). In the getCost method we execute return generateNeighbours(startBox).contains(endBox) ? 1 : 0;. The thing is that the neighbourList had never been previously generated ! We iterated on the pivot's neighbourListList at Dijkstra.java#L25 but never actually generated it, so the neighbourList attribute of pivot was never changed. This caused that all g.getCost(pivot, vertex) were equal to 0, so that was never a priority to any vertex when looking for the shortest path.

What I had to change was :

  • Dijkstra.java#L25 : Switch for (VertexInterface vertex: g.generateNeighbours(pivot)) { to for (VertexInterface vertex: pivot.generateNeighbours()) {
  • Box.java :
    • Change the generateNeighbours() method of Box.java so it actually updates the neighbourList attribute
    • Add the generateNeighbours() to VertexInterface.java
    • Change the attribute private ArrayList<Box> neighbourList = new ArrayList<Box>() ; to private ArrayList<Box> neighbourList; and the following methods using it.

And now it works fine !

I finally found the answer ! The problem starts at [Dijkstra.java#L29](https://git.regar42.fr/antograb/TpMazeJava/src/branch/drawShortestPath/src/dijkstra/Dijkstra.java#L29) where we ask for `g.getCost(pivot, vertex)`. In the `getCost` method we execute `return generateNeighbours(startBox).contains(endBox) ? 1 : 0;`. The thing is that the `neighbourList` had never been previously generated ! We iterated on the `pivot`'s `neighbourListList` at [Dijkstra.java#L25](https://git.regar42.fr/antograb/TpMazeJava/src/branch/master/src/dijkstra/Dijkstra.java#L25) but never actually generated it, so the `neighbourList` attribute of `pivot` was never changed. This caused that all `g.getCost(pivot, vertex)` were equal to 0, so that was never a priority to any vertex when looking for the shortest path. What I had to change was : - [Dijkstra.java#L25](https://git.regar42.fr/antograb/TpMazeJava/src/branch/master/src/dijkstra/Dijkstra.java#L25) : Switch `for (VertexInterface vertex: g.generateNeighbours(pivot)) {` to `for (VertexInterface vertex: pivot.generateNeighbours()) {` - [Box.java](https://git.regar42.fr/antograb/TpMazeJava/src/branch/master/src/dijkstra/Dijkstra.java) : - Change the `generateNeighbours()` method of `Box.java` so it actually updates the `neighbourList` attribute - Add the `generateNeighbours()` to `VertexInterface.java` - Change the attribute `private ArrayList<Box> neighbourList = new ArrayList<Box>() ;` to `private ArrayList<Box> neighbourList;` and the following methods using it. And now it works fine !
Sign in to join this conversation.
2 Participants
Notifications
Due Date
-
Dependencies

No dependencies set.

Reference: antograb/TpMazeJava#24