0

When I run this class an out of memory error occurs. The program is for detection of cycles in directed/un-directed graph. The error message comes after 100% cpu and memory usage.

package Project;

// Imports for Java API 
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.sql.*;
import org.jgrapht.alg.CycleDetector;
import org.jgrapht.alg.DijkstraShortestPath;
import org.jgrapht.alg.DirectedNeighborIndex;
import org.jgrapht.alg.FloydWarshallShortestPaths;
import org.jgrapht.alg.cycle.JohnsonSimpleCycles;
import org.jgrapht.alg.cycle.SzwarcfiterLauerSimpleCycles;
import org.jgrapht.*;
import org.jgrapht.graph.DefaultEdge;
import org.sqlite.SQLite;
import org.jgrapht.graph.DefaultDirectedGraph;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Sort {

    final static String fileVertices ="C:/Users/a2z/Desktop/Video/Processed data/Author_Vertices/JLee_Vertices.txt";
    final static String fileEdges ="C:/Users/a2z/Desktop/Video/Processed data/Author_Edges/JLee_Edges.txt";
    public static void main(String[] args) throws FileNotFoundException, IOException {

        // // Create Directed Empty Graph Instance and class Object
        //////////////////////////////////////////////////////////////////////////////////
        //DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<> (DefaultEdge.class);
        DirectedGraph<String, DefaultEdge> diGraph = new DefaultDirectedGraph<> (DefaultEdge.class);
        // Addsvertices and edges in the graph
        fileLoad.addVertices(fileVertices, (DirectedGraph<String, DefaultEdge>) diGraph);
        System.out.println("Vertices added in the graph!!!");
        fileLoad.addEdges(fileEdges, (DirectedGraph<String, DefaultEdge>) diGraph);
        System.out.println("Edges added in the graph!!!");
        SzwarcfiterLauerSimpleCycles s = new SzwarcfiterLauerSimpleCycles( diGraph);
        List<DefaultEdge> cycles = s.findSimpleCycles();
        System.out.println(cycles);
    }

    public void addVertices(String fp, DirectedGraph<String, DefaultEdge> digra) throws FileNotFoundException, IOException
    {
        try (BufferedReader br = new BufferedReader(new FileReader(fp)))
        {
            String line="";
            while ((line = br.readLine()) != null) {
                digra.addVertex(line);
            }

        }

    }

    public void addEdges(String fpe, DirectedGraph<String, DefaultEdge> digrae) throws FileNotFoundException, IOException
    {
        try (BufferedReader br = new BufferedReader(new FileReader(fpe)))
        {
            String line="";
            int counter = 1;
            while ((line = br.readLine()) != null) {
                String [] s = line.split(",");
                for(int i=0;i<s.length;i=i+2){
                    digrae.addEdge(s[i], s[i+1]);
                    counter++;
                    //System.out.println(counter);
                }
            }
        }

    }   

} // End of Class

JLEE Vertices file is something like this with 1379 distinct vertices, i.e

H R Park
T Butzer
Jaiyong Lee
Kwang Sik Eom
A Townsend
M Jang
Dong-Min Kim
Daya Atapatta
R Machiraju
Mann Ho Lee
K P Fung
R Cox
G Yang
Edmund H Durfee
M Kim
Ching-Ren Lee
Jabeom Gu
Arjun Kapur
D W Kim
Gurpreet Dhillon
M Papazoglou
Yongho Cho
Lisa Masterman
T W Kang
Jin-Seok Chae
Y -W Chang
Hai Fang
S W Jeong
Y S Kwon
Zehra Sura

JLEE_Edges file is something like this with 14440 Edges, i.e

Tosiyasu L Kunii,J Lee
Yan Solihin,Jaejin Lee
Jaejin Lee,Yan Solihin
Yan Solihin,Josep Torrellas
Josep Torrellas,Yan Solihin
Jaejin Lee,Josep Torrellas
Josep Torrellas,Jaejin Lee
Yan Solihin,Jaejin Lee
Jaejin Lee,Yan Solihin
Yan Solihin,Josep Torrellas
Josep Torrellas,Yan Solihin
Jaejin Lee,Josep Torrellas
Josep Torrellas,Jaejin Lee
Yan Solihin,Jaejin Lee
Jaejin Lee,Yan Solihin
Yan Solihin,Josep Torrellas
Josep Torrellas,Yan Solihin
Jaejin Lee,Josep Torrellas
Josep Torrellas,Jaejin Lee
J Lee,Josep Torrellas
Josep Torrellas,J Lee
J Lee,Yan Solihin
Yan Solihin,J Lee
Josep Torrellas,Yan Solihin
Yan Solihin,Josep Torrellas
J Lee,Josep Torrellas
Josep Torrellas,J Lee
J Lee,Yan Solihin
RealSkeptic
  • 33,993
  • 7
  • 53
  • 79
paras
  • 49
  • 1
  • 6

1 Answers1

1

Run it with -Xmx2048m or more if you need. See https://stackoverflow.com/a/1596040/2931889

Community
  • 1
  • 1
honzzyk
  • 169
  • 2
  • 7