Package edu.ucla.sspace.graph

Examples of edu.ucla.sspace.graph.SparseUndirectedGraph


    @Override public Graph<Edge> readUndirected(File f, Indexer<String> vertexIndexer)
            throws IOException {       
        BufferedReader br = new BufferedReader(new FileReader(f));
        Graph<Edge> g = //new GenericGraph<Edge>();
            new SparseUndirectedGraph();
        int lineNo = 0;
        for (String line = null; (line = br.readLine()) != null; ) {
            ++lineNo;
            line = line.trim();
            if (line.startsWith("#"))
                continue;
            else if (line.length() == 0)
                continue;
            String[] arr = line.split("\\s+");
            if (arr.length < 2) {
                throw new IOException("Missing vertex on line " + lineNo);
            }
            int v1 = vertexIndexer.index(arr[0]);
            int v2 = vertexIndexer.index(arr[1]);
            g.add(new SimpleEdge(v1, v2));
            if (lineNo % 100000 == 0)
                verbose(LOGGER, "Read %d lines from %s", lineNo, f);
        }
        verbose(LOGGER, "Read undirected graph with %d vertices and %d edges",
                g.order(), g.size());
        return g;
    }
View Full Code Here


     */
    @Override public Graph<Edge> readUndirectedFromWeighted(
            File f, Indexer<String> vertexIndexer, double minWeight) throws IOException {       

        BufferedReader br = new BufferedReader(new FileReader(f));
        Graph<Edge> g = new SparseUndirectedGraph();

        int lineNo = 0;
        for (String line = null; (line = br.readLine()) != null; ) {
            ++lineNo;
            line = line.trim();
            if (line.startsWith("#"))
                continue;
            else if (line.length() == 0)
                continue;
            String[] arr = line.split("\\s+");
            if (arr.length < 2)
                throw new IOException("Missing vertex on line " + lineNo);
            if (arr.length < 3)
                throw new IOException("Missing edge weight on line " + lineNo);
            int v1 = vertexIndexer.index(arr[0]);
            int v2 = vertexIndexer.index(arr[1]);
            double weight = Double.parseDouble(arr[2]);
            if (weight >= minWeight)
                g.add(new SimpleEdge(v1, v2));

            if (lineNo % 100000 == 0)
                veryVerbose(LOGGER, "Read %d lines from %s", lineNo, f);
        }
        verbose(LOGGER, "Read directed graph with %d vertices and %d edges",
                g.order(), g.size());
        return g;
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.graph.SparseUndirectedGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.