c# - OutOfMemoryException For Maze Solver of Large Dimensions -



c# - OutOfMemoryException For Maze Solver of Large Dimensions -

the programme works arrays upto 20x20 larger throws outofmemoryexception.

below code:

public static point getfinalpath(int x, int y) { queue.enqueue(new point(x,y, null)); while(queue.count>0) { point p = queue.dequeue(); if (arr[p.x,p.y] == 9) { console.writeline("found destination"); homecoming p; } if(isopen(p.x+1,p.y)) { arr[p.x,p.y] = 1; queue.enqueue(new point(p.x+1,p.y, p)); } //similarly other directions } homecoming null; } public int[,] solutionmaze() { point p = getfinalpath(0, 0); while (p.getparent() != null) { solvedarray[p.x, p.y] = 9; p = p.getparent(); } homecoming solvedarray; }

ok people here rest of code

public static queue<point> queue=new queue<point>(); public static bool isopen(int x, int y) { //bound checking if ((x >= 0 && x < xmax) && (y >= 0 && y < ymax) && (arr[x,y] == 0 || arr[x,y] == 9)) { homecoming true; } homecoming false; } public class point { public int x; public int y; point parent; public point(int x, int y, point parent) { this.x = x; this.y = y; this.parent = parent; } public point getparent() { homecoming this.parent; } }

assumes start 0,0 , final destination set 9 @ constructor.

help me implement array of size 500x500

well, looking @ code found 1 problem. perform wrong check. should check if point added queue. do now? we'll, marking processed cell not open. it's easy see can add together queue same node twice.

let's follow example:

1 | . . 0 | ! . --+---- yx| 0 1 queue: point (0,0)

we starting @ point(0,0). @ moment, adding points (0, 1) , (1,0) our queue , mark point(0,0) processed

1 | . . 0 | x ! --+---- yx| 0 1 queue: point (0,1), point (1,0)

now dequeue point(0,1), marking processed , adding point(1,1) queue.

1 | ! . 0 | x x --+---- yx| 0 1 queue: point (1,0), point(1,1)

now dequeue point(1,0), marking processed , adding point(1,1) queue:

1 | x ! 0 | x x --+---- yx| 0 1 queue: point (1,1), point (1,1)

and have same point twice in queue. , not lastly problem. points have reference parents, previous points (doubled too) can't processed garbage collector.

c# arrays maze

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -