<commit_before>package ptyxiakh;

import java.util.*;

/**
 *
 * @author kostas
 */
public class DijkstraAllPaths {
    
    
    public DijkstraAllPaths(){
        
    }
    
    
    public List<List<List<List<Integer>>>> DijkstraPaths(double[][] matrix){
        
        List<List<List<List<Integer>>>> paths = new ArrayList<>();

        for (int source=0; source<5; source++) {
            paths.add(dijkstra(source, matrix));
            System.out.println(paths.get(source));
        }

        return paths;
    }
    
        
    public List<List<List<Integer>>> dijkstra(int source, double[][] matrix) {
        
        List<List<List<Integer>>> paths = new ArrayList<>();
        double[] d = new double[5]; // the distance matrix
        int[][] prev = new int[5][5]; // the distance matrix
        boolean[] visited = new boolean[5]; // the distance matrix
        int min;

        for (int i=0; i<5; i++) {
            d[i] = Double.POSITIVE_INFINITY;
            prev[i][0] = 0;
            visited[i] = false;
        }

        d[source] = 0;

        for (int k=0; k<5; k++) {
            min = -1;

            for (int i=0; i<5; i++) {
                if (!visited[i] && ((min == -1) || (d[i] < d[min]))) {
                    min = i;
                }
            }

            visited[min] = true;

            for (int i=0; i<5; i++) {
                if (min!=i && matrix[min][i] != Double.POSITIVE_INFINITY) {
                    if (d[min] + matrix[min][i] < d[i]) {
                        d[i] = d[min] + matrix[min][i];
                        prev[i][0] = 1;
                        prev[i][1] = min;
                    }
                    else if (d[min] + matrix[min][i] == d[i]) {
                        prev[i][0]++;
                        prev[i][prev[i][0]] = min;
                    }
                }
            }
        }

        for (int i=0; i<5; i++) {
            if (i == source || d[i] == Double.POSITIVE_INFINITY) continue;

            paths.add(buildPaths(i, 0, prev));
        }

        return paths;
    }
        
    public List<List<Integer>> buildPaths(int dest, int depth, int[][] prev) {
        List<List<Integer>> list = new ArrayList<>();

        for (int i = 0; i < prev[dest][0]; ++i) {
            list.addAll(buildPaths(prev[dest][i+1], depth + 1, prev));
        }

        if (list.isEmpty()) {
            List<Integer> l = new ArrayList<>();
            l.add(dest);

            list.add(l);
        }
        else {
            for (int i=0; i<list.size(); i++) {
                list.get(i).add(dest);
            }
        }

        return list;
    }
}<commit_msg>Fixed number of iterations in DijkstraAllPaths<commit_after>package ptyxiakh;

import java.util.*;

/**
 *
 * @author kostas
 */
public class DijkstraAllPaths {
    
    
    public DijkstraAllPaths(){
        
    }
    
    
    public List<List<List<List<Integer>>>> DijkstraPaths(double[][] matrix){
        
        List<List<List<List<Integer>>>> paths = new ArrayList<>();

        for (int source=0; source<matrix.length; source++) {
            paths.add(dijkstra(source, matrix));
            System.out.println(paths.get(source));
        }

        return paths;
    }
    
        
    public List<List<List<Integer>>> dijkstra(int source, double[][] matrix) {
        
        List<List<List<Integer>>> paths = new ArrayList<>();
        double[] d = new double[matrix.length]; // the distance matrix
        int[][] prev = new int[matrix.length][matrix.length]; // the distance matrix
        boolean[] visited = new boolean[matrix.length]; // the distance matrix
        int min;

        for (int i=0; i<matrix.length; i++) {
            d[i] = Double.POSITIVE_INFINITY;
            prev[i][0] = 0;
            visited[i] = false;
        }

        d[source] = 0;

        for (int k=0; k<matrix.length; k++) {
            min = -1;

            for (int i=0; i<matrix.length; i++) {
                if (!visited[i] && ((min == -1) || (d[i] < d[min]))) {
                    min = i;
                }
            }

            visited[min] = true;

            for (int i=0; i<matrix.length; i++) {
                if (min!=i && matrix[min][i] != Double.POSITIVE_INFINITY) {
                    if (d[min] + matrix[min][i] < d[i]) {
                        d[i] = d[min] + matrix[min][i];
                        prev[i][0] = 1;
                        prev[i][1] = min;
                    }
                    else if (d[min] + matrix[min][i] == d[i]) {
                        prev[i][0]++;
                        prev[i][prev[i][0]] = min;
                    }
                }
            }
        }

        for (int i=0; i<matrix.length; i++) {
            if (i == source || d[i] == Double.POSITIVE_INFINITY) continue;

            paths.add(buildPaths(i, 0, prev));
        }

        return paths;
    }
        
    public List<List<Integer>> buildPaths(int dest, int depth, int[][] prev) {
        List<List<Integer>> list = new ArrayList<>();

        for (int i = 0; i < prev[dest][0]; ++i) {
            list.addAll(buildPaths(prev[dest][i+1], depth + 1, prev));
        }

        if (list.isEmpty()) {
            List<Integer> l = new ArrayList<>();
            l.add(dest);

            list.add(l);
        }
        else {
            for (int i=0; i<list.size(); i++) {
                list.get(i).add(dest);
            }
        }

        return list;
    }
}
{'fraction_non_alphanumeric': 0.16285452881976212, 'fraction_numerical': 0.009881061299176578, 'mean_word_length': 1.3910761154855642, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1265554', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1676, 'n_words': 367}