|
Java example source code file (TestGraphLoadingWeighted.java)
The TestGraphLoadingWeighted.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.WeightedEdgeLineProcessor; 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 junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; public class TestGraphLoadingWeighted { @Test public void testWeightedDirected() throws IOException{ String path = new ClassPathResource("WeightedGraph.txt").getFile().getAbsolutePath(); int numVertices = 9; String delim = ","; String[] ignoreLinesStartingWith = new String[]{"//"}; //Comment lines start with "//" IGraph<String,Double> graph = GraphLoader.loadWeightedEdgeListFile(path,numVertices,delim,true,ignoreLinesStartingWith); assertEquals(numVertices, graph.numVertices()); int[] vertexOutDegrees = {2,2,1,2,2,1,1,1,1}; for( int i=0; i<numVertices; i++ ) assertEquals(vertexOutDegrees[i],graph.getVertexDegree(i)); int[][] edges = new int[][]{ {1, 3}, //0->1 and 1->3 {2, 4}, //1->2 and 1->4 {5}, //etc {4, 6}, {5, 7}, {8}, {7}, {8}, {0} }; double[][] edgeWeights = new double[][]{ {1, 3}, {12, 14}, {25}, {34, 36}, {45, 47}, {58}, {67}, {78}, {80} }; for( int i=0; i<numVertices; i++ ){ List<Edge Other Java examples (source code examples)Here is a short list of links related to this Java TestGraphLoadingWeighted.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.