Skip to main content
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
anado el codigo de mean
Origen Enlace

Y aqui es el mean(List l)

    public static double mean(List<Long> l){
    long res=0;
    for (Long val: l)
        res+=val/1000000000;
    return (1.0*res) / l.size();
}

Y aqui es el mean(List l)

    public static double mean(List<Long> l){
    long res=0;
    for (Long val: l)
        res+=val/1000000000;
    return (1.0*res) / l.size();
}
Origen Enlace

Dificultades para caluclar medios de mas de uno algoritmos con mean en Java

Tengo un problema : tengo el tiempo que le toma a los algoritmos BFS, DFS y A* para solucionar juegos del 15 segun sus dificultades propias. Hay varios juegos por cada nivel de dificultad). Esta capaz calcular el medio para BFS pero no lo esta para los demas y no entiendo porque...

Pueden ayudarme entender este problema?

Aqui es el codigo para escribir los resultados en writer.

                    PrintWriter writer = new PrintWriter("result.txt", "UTF-8");
                    writer.println("runTime DFS" + runTimesDFS);
                    writer.println("run time BFS : " + runTimesBFS);
                    writer.println("run Times AStar1" + runTimesAStar1);
                    writer.println("run Times AStar2" + runTimesAStar2);
                    
                    writer.close();
                    
                    meanDFS.addLast((double)mean(runTimesDFS));
                    meanBFS.addLast((double)mean(runTimesBFS));
                    meanAStar1.addLast((double)mean(runTimesAStar1));
                    meanAStar2.addLast((double)mean(runTimesAStar2));
                    
                    PrintWriter writer1 = new PrintWriter("mean.txt", "UTF-8");
                    writer1.print("d\t");
                    writer1.print("BFS\t");
                    writer1.print("DFS\t");
                    writer1.print("A*(h1)\t");
                    writer1.println("A*(h2)\t");
                    
                    for(int i =0;i<problemSize;i++){
                        if(i<=1||i==3)continue;
                        if(i==2){
                            writer1.print(i+"\t");
                            writer1.print(meanDFS.get(0)+"\t");
                            writer1.print(meanBFS.get(0)+"\t");
                            writer1.print(meanAStar1.get(0)+"\t");
                            writer1.println(meanAStar2.get(0)+"\t");
                            continue;
                        }
                        writer1.print(i+"\t");
                        writer1.print(meanDFS.get(i-2)+"\t");
                        writer1.print(meanBFS.get(i-2)+"\t");
                        writer1.print(meanAStar1.get(i-2)+"\t");
                        writer1.println(meanAStar2.get(i-2)+"\t");
                        
                        
                    }
                    writer1.close();

Aqui es los resultados de result.txt:

runTime DFS[1002275500, -1, 30671, 30671, 201439, 201439, 130626, 130626, 613260, 613260, 150597, 150597, 230334797, 230334797, 119078, 119078, 1000880068, -1, 1000898024, -1, 1001873664, -1, 1001111309, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
run time BFS : [-1, 60196, 234840, 230154, 856084, 1249830, 223248477, 229813, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
run Times AStar1[316141, 100123, 599730, 621865, 2437748, 891661, 441231, 3304836, 448971, 10450851, 1031470, 1364444, 2150342, 1236668, 2398004, 1012777, 3577413, 930346, 1342229, 1287399, 833987, 923909, 991805, 736422, 1089391, 1529460, 2102012, 1818439, 2150166, 1362405, 2274912, 1821755, 1783043, 1497208, 1394854, 2566307, 2116257, 16251554, 1131473, 977269, 12538716, 1937947, 6316898, 1526144, 1015829, 2391290, 1061151, 4212817, 3203434, 7697831, 4004167, 11981158, 18767610, 10363610, 7720948, 5812849, 5035632, 5151903, 4242567, 11205300, 19161910, 7364846, 8246685, 10374449, 6356850, 3127472, 4460724, 4658711, 34526503, 15950820, 19204683, 3039093, 4819100, 4231508, 2774177, 3387505, 2192512, 3775054, 8767586, 6299780, 4685219, 8116913, 2962584, 3138993, 4242035]
run Times AStar2[307918, 111674, 502747, 503270, 6069636, 845279, 413490, 3172552, 544288, 2758568, 1050064, 2634507, 1503979, 1257892, 1886224, 1020397, 5118195, 667317, 1954363, 1891691, 583031, 792316, 844829, 691413, 811217, 1490068, 2100134, 1852067, 1626993, 1375678, 1540837, 2324116, 1415832, 2015665, 1459347, 2592766, 1630265, 1423187, 1100070, 13949628, 10510684, 1581410, 5928335, 3257547, 1009206, 1794131, 1033910, 4065738, 5294198, 4902085, 39496174, 6987337, 8793467, 15267404, 7290771, 4825445, 4212857, 8364815, 2500645, 22345290, 13907331, 5114238, 6964583, 12030011, 4264531, 3634794, 4771136, 2367023, 15850205, 15110779, 4679247, 3816970, 8592082, 3839918, 2827192, 3510492, 68274340, 10894103, 19928970, 5991074, 4862344, 4680440, 3192033, 3180315, 53607999]

Aqui es los resultados de mean.txt file

d   BFS DFS A*(h1)  A*(h2)  
2   0.25    0.0 0.0 0.0 
4   0.07142857142857142 0.0 0.0 0.0 
5   0.1111111111111111  0.0 0.0 0.0 
6   0.13513513513513514 0.0 0.0 0.0 
7   0.0847457627118644  0.0 0.0 0.0 
8   0.05154639175257732 0.0 0.0 0.0 
9   0.05154639175257732 0.0 0.0 0.0 
10  0.05154639175257732 0.0 0.0 0.0 
11  0.05154639175257732 0.0 0.0 0.0 
12  0.05154639175257732 0.0 0.0 0.0 
13  0.05154639175257732 0.0 0.0 0.0 
14  0.05154639175257732 0.0 0.0 0.0 
15  0.05154639175257732 0.0 0.0 0.0 
16  0.05154639175257732 0.0 0.0 0.0 
17  0.05154639175257732 0.0 0.0 0.0 
18  0.05154639175257732 0.0 0.0 0.0 
19  0.05154639175257732 0.0 0.0 0.0 
20  0.05154639175257732 0.0 0.0 0.0 
21  0.05154639175257732 0.0 0.0 0.0 
22  0.05154639175257732 0.0 0.0 0.0 
23  0.05154639175257732 0.0 0.0 0.0 
24  0.05154639175257732 0.0 0.0 0.0 
25  0.05154639175257732 0.0 0.0 0.0 
26  0.05154639175257732 0.0 0.0 0.0 
27  0.05154639175257732 0.0 0.0 0.0 
28  0.05154639175257732 0.0 0.0 0.0 
29  0.05154639175257732 0.0 0.0 0.0 
30  0.05154639175257732 0.0 0.0 0.0 
31  0.05154639175257732 0.0 0.0 0.0