java - Why does my recursive backtracking stop at seemingly random points -


i attempting generate closed curves in finite region of simple hexagonal lattice. isn't important, finite set of points distance of 1 away each other. code however, generate closed curves while, , program quit working , stuck in infinite loop? have tried forcing java garbage collect command, same code stops @ different points. far can tell, stops random. sphere array storing points in region under consideration

private static sphere sphere1 = new sphere(); private static double [][] vectors =  {{0, 0, 1},{0, 0, -1},{1, 0, 0},{-1,0,0},{.5, (math.sqrt(3))/2, 0},{-.5, -(math.sqrt(3))/2, 0},{.5, -(math.sqrt(3))/2, 0},{-.5, (math.sqrt(3))/2, 0}}; private static stringbuilder loopstring = new stringbuilder("r"); private static string pospoints = "abcdefghijklmnopqrstuvwxyz1234567"; private static int garbage = 0;  private static boolean once = false; private static printwriter output = null;  public static void main (string [] args){      try {         output = new printwriter(new fileoutputstream("closedloops.txt"));     } catch (filenotfoundexception e){         system.out.println("error");     }     system.out.println("start");     knotpoint looppoint = new knotpoint(0,0,1);     addvector(looppoint, vectors);  }  public static void addvector(knotpoint looppoint, double [][] vectors){     garbage ++;     if (garbage == 200){         system.gc();         garbage = 0;     }     if (loopstring.length() > 19        && (loopstring.charat(loopstring.length()-1) == 'z' ||            loopstring.charat(loopstring.length()-1) == '3' ||            loopstring.charat(loopstring.length()-1) == 'u' ||            loopstring.charat(loopstring.length()-1) == 'o' ||            loopstring.charat(loopstring.length()-1) == 'g' ||            loopstring.charat(loopstring.length()-1) == 'j' ||            loopstring.charat(loopstring.length()-1) == 'q'))      {         system.out.println(loopstring);         output.println(loopstring);         once = true;          return;     }     (int = 0; < 8 ; ++){         if (validadd(looppoint, vectors[i], loopstring, pospoints)){             looppoint.addnext(vectors[i]);              addvector(looppoint, vectors);             //system.gc();             loopstring.deletecharat(loopstring.length()-1);             looppoint.subtractlast(vectors[i]);             if(loopstring.tostring().equals("r") ){                 output.println("you did it");                 output.close();                 system.out.println("you did job");                 system.exit(0);             }         }     }      return; }  public static boolean validadd(knotpoint looppoint, double [] vector, stringbuilder loopstring, string pospoints){     knotpoint testadd = new knotpoint();     testadd.set(looppoint);     testadd.addnext(vector);     int pointindex = 0;     boolean pointcheck = false;     char point = '.';     (int = 0; < 33; ++){         if( testadd.equals(sphere1.getknotpoint(i))){             pointindex = i;             pointcheck = true;             point = pospoints.charat(i);         }     }     if (pointcheck && !loopstring.tostring().contains(pospoints.substring(pointindex, pointindex + 1))&& point != 'r'){// added not r check         loopstring.append(point);         return true;     } else {         return false;     } } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -