private void findBestPermutation(SubPath[] subPaths, int[] solution, boolean[] reversed, 
			boolean[] used, int depth, int dist){
		
		//add the new distance from the edge added by the caller of this method.
		//also works for the last depth when the depth is -1
		if(depth<subPaths.length-2){
			dist += dist(subPaths, solution, reversed, depth+1);
			//it can't become a better solution then quit
			if(dist>=best){
				return;
			}
		}
		
		//maximum depth check
		if(depth<0){
			
			dist += dist(subPaths, solution, reversed, depth);
			
			//check if it's a best solution
			if(dist<best){
				//save solution
				this.improved=true;
				best=dist;
				bestSolution=Arrays.copyOf(solution, solution.length);
				bestReversed=Arrays.copyOf(reversed, reversed.length);
				
				//DEBUG
//				System.out.println("a k swap:");
//				System.out.println("best "+best);
//				System.out.println(dist+" is best: "+(dist<best));
//				System.out.println(Arrays.toString(solution));
//				System.out.println(Arrays.toString(reversed));
			}
			return;
		}
		
		//first time
		if(depth==subPaths.length-1){
			
			//can keep the first fixed
			solution[depth]=depth;
			reversed[depth]=false;
			used[depth]=true;
			findBestPermutation(subPaths, solution, reversed, used, depth-1,dist);
			used[depth]=false;
			return;
		}
		
		//try all permutations for not used subpaths
		for(int i=0;i<subPaths.length;i++){
			if(!used[i]){
				//set to true before recursion
				used[i]=true;
				
				
				solution[depth]=i;
				//do recursion with the subpath reversed
				reversed[depth]=true;
				findBestPermutation(subPaths, solution, reversed, used, depth-1,dist);
				//do recursion with the subpath not reversed
				reversed[depth]=false;
				findBestPermutation(subPaths, solution, reversed, used, depth-1,dist);
				
				
				//restore after recursion
				used[i]=false;
			}
		}
		
		
		
	}