|
Java example source code file (TestGraphLoading.java)
The TestGraphLoading.java Java example source codepackage org.deeplearning4j.graph.data; import org.apache.commons.lang3.ArrayUtils; import org.deeplearning4j.graph.api.Edge; import org.deeplearning4j.graph.api.IGraph; import org.deeplearning4j.graph.data.impl.DelimitedEdgeLineProcessor; import org.deeplearning4j.graph.data.impl.DelimitedVertexLoader; import org.deeplearning4j.graph.graph.Graph; import org.deeplearning4j.graph.vertexfactory.StringVertexFactory; import org.deeplearning4j.graph.vertexfactory.VertexFactory; import org.junit.Test; import org.nd4j.linalg.io.ClassPathResource; import java.io.IOException; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; public class TestGraphLoading { @Test public void testEdgeListGraphLoading() throws IOException { ClassPathResource cpr = new ClassPathResource("testgraph_7vertices.txt"); IGraph<String,String> graph = GraphLoader.loadUndirectedGraphEdgeListFile(cpr.getFile().getAbsolutePath(),7,","); System.out.println(graph); assertEquals(graph.numVertices(),7); int[][] edges = { {1,2}, {0,2,4}, {0,1,3,4}, {2,4,5}, {1,2,3,5,6}, {3,4,6}, {4,5} }; for( int i=0; i<7; i++ ){ assertEquals(edges[i].length,graph.getVertexDegree(i)); int[] connectedVertices = graph.getConnectedVertexIndices(i); for( int j=0; j<edges[i].length; j++ ){ assertTrue(ArrayUtils.contains(connectedVertices,edges[i][j])); } } } @Test public void testGraphLoading() throws IOException{ ClassPathResource cpr = new ClassPathResource("simplegraph.txt"); EdgeLineProcessor<String> edgeLineProcessor = new DelimitedEdgeLineProcessor(",",false,"//"); VertexFactory<String> vertexFactory = new StringVertexFactory("v_%d"); Graph<String,String> graph = GraphLoader.loadGraph(cpr.getFile().getAbsolutePath(), edgeLineProcessor,vertexFactory,10,false); System.out.println(graph); for (int i = 0; i < 10; i++) { List<Edge Other Java examples (source code examples)Here is a short list of links related to this Java TestGraphLoading.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.