public void testZeroNodes() { GraphGenerator<Integer, DefaultEdge, Integer> gen = new GnpRandomBipartiteGraphGenerator<>(0, 0, 0.5); DirectedGraph<Integer, DefaultEdge> g = new DirectedPseudograph<>(DefaultEdge.class); gen.generateGraph(g, new IntegerVertexFactory(), null); assertEquals(0, g.vertexSet().size()); assertEquals(0, g.edgeSet().size()); }
public static void main(String[] args) { GraphGenerator gen = new GraphGenerator(30, 3); try { gen.outputGraph(new FileOutputStream(new File("graph.out"))); gen.outputCluster(new FileOutputStream(new File("cluster.out"))); } catch (Exception e) { e.printStackTrace(); } }
public void testDirectedGraphGnp2() { GraphGenerator<Integer, DefaultEdge, Integer> gen = new GnpRandomBipartiteGraphGenerator<>(4, 4, 1.0, SEED); DirectedGraph<Integer, DefaultEdge> g = new DirectedPseudograph<>(DefaultEdge.class); gen.generateGraph(g, new IntegerVertexFactory(), null); assertEquals(4 + 4, g.vertexSet().size()); assertEquals(32, g.edgeSet().size()); }
public void testUndirectedGraphGnp3() { GraphGenerator<Integer, DefaultEdge, Integer> gen = new GnpRandomBipartiteGraphGenerator<>(4, 4, 0.0, SEED); UndirectedGraph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class); gen.generateGraph(g, new IntegerVertexFactory(), null); assertEquals(4 + 4, g.vertexSet().size()); assertEquals(0, g.edgeSet().size()); }
public void testDirectedGraphGnp3() { GraphGenerator<Integer, DefaultEdge, Integer> gen = new GnpRandomBipartiteGraphGenerator<>(4, 4, 0.1, SEED); DirectedGraph<Integer, DefaultEdge> g = new DirectedPseudograph<>(DefaultEdge.class); gen.generateGraph(g, new IntegerVertexFactory(), null); int[][] edges = {{5, 1}, {7, 3}, {3, 8}, {8, 4}}; assertEquals(4 + 4, g.vertexSet().size()); for (int[] e : edges) { assertTrue(g.containsEdge(e[0], e[1])); } assertEquals(edges.length, g.edgeSet().size()); }
public void testUndirectedGraphGnp1() { GraphGenerator<Integer, DefaultEdge, Integer> gen = new GnpRandomBipartiteGraphGenerator<>(4, 4, 0.5, SEED); UndirectedGraph<Integer, DefaultEdge> g = new SimpleGraph<>(DefaultEdge.class); gen.generateGraph(g, new IntegerVertexFactory(), null); int[][] edges = {{1, 6}, {1, 7}, {1, 8}, {2, 5}, {2, 7}, {3, 5}, {3, 8}, {4, 6}, {4, 7}}; assertEquals(4 + 4, g.vertexSet().size()); for (int[] e : edges) { assertTrue(g.containsEdge(e[0], e[1])); } assertEquals(edges.length, g.edgeSet().size()); }
public static void main(String[] args) { String filename = args[0]; String delimiter = args[1]; In in = new In(filename); Graph G = GraphGenerator.read(in, delimiter); StdOut.println(G); }
@Test public void testGetTable() { GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); for (Node n : graphStore.getNodes()) { Assert.assertSame(n.getTable(), graphStore.getModel().getNodeTable()); } }
@SuppressWarnings("serial") @Test public void testRun() throws Exception { int verticesCount = 5000; int edgesCount = verticesCount * 2; ExecutionEnvironment environment = ExecutionEnvironment.getExecutionEnvironment(); environment.getConfig().disableSysoutLogging(); Graph<Long, Long, Long> graph = GraphGenerator.generateGraph(verticesCount, edgesCount, environment); PCConnectedComponents<Long, Long> algo = new PCConnectedComponents<>(verticesCount); List<Tuple2<Long, Long>> result = algo.run(graph) .map( new RichMapFunction<Vertex<Long, Long>, Tuple2<Long, Long>>() { @Override public Tuple2<Long, Long> map(Vertex<Long, Long> value) throws Exception { return new Tuple2<>(value.getId(), value.getValue()); } }) .collect(); ConnectedComponentsData.checkOddEvenResult(result); }
public AIWorld(World gameWorld) { synchronized (gameWorld) { movementGraph = GraphGenerator.generateGraph(gameWorld); } logger.info( "Initialized graph with " + movementGraph.edgeSet().size() + " edges and " + movementGraph.vertexSet().size() + " vertices"); world = new World(new Vector2(), true); PhysicsHelper.createLoaderBodies( world, Gdx.files.internal("data/world/world.json"), "strategicPoints"); strategicPoints = GraphGenerator.generateStrategicPoints(world); logger.info("Loaded ai world and found " + strategicPoints.size() + " strategic points"); createGraphVisible(); EventManager.addListener(EventEnum.PARSER_AI_GRAPH_VISIBLE, this); }
public void runFinish() { getFileHandler().refreshFolder(); getFileHandler().refreshAll(getSootSelection().getProject()); // for updating markers SootPlugin.getDefault().getManager().updateSootRanFlag(); final IEditorPart activeEdPart = SootPlugin.getDefault() .getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .getActiveEditor(); SootPlugin.getDefault().getPartManager().updatePart(activeEdPart); // run cfgviewer if (getCfgList() != null) { // currently this is the call graph list of pkgs GraphGenerator generator = new GraphGenerator(); generator.setChildren(convertPkgList(getCfgList())); GraphPlugin.getDefault().setGenerator(generator); generator.run(null); } }
@Nullable private static Pair<List<String>, Boolean> keysOrder(final ResourceBundle resourceBundle) { final boolean[] isAlphaSorted = new boolean[] {true}; final Graph<String> generator = GraphGenerator.generate( CachingSemiGraph.cache( new InboundSemiGraph<String>() { @Override public Collection<String> getNodes() { final Set<String> nodes = new LinkedHashSet<>(); for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) { for (IProperty property : propertiesFile.getProperties()) { final String key = property.getKey(); if (key != null) { nodes.add(key); } } } return nodes; } @Override public Iterator<String> getIn(String n) { final Collection<String> siblings = new LinkedHashSet<>(); for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) { for (IProperty property : propertiesFile.findPropertiesByKey(n)) { PsiElement sibling = property.getPsiElement().getNextSibling(); while (sibling instanceof PsiWhiteSpace || sibling instanceof PsiComment) { sibling = sibling.getNextSibling(); } if (sibling instanceof IProperty) { final String key = ((IProperty) sibling).getKey(); if (key != null) { if (isAlphaSorted[0] && String.CASE_INSENSITIVE_ORDER.compare(n, key) > 0) { isAlphaSorted[0] = false; } siblings.add(key); } } } } return siblings.iterator(); } })); DFSTBuilder<String> dfstBuilder = new DFSTBuilder<>(generator); final boolean acyclic = dfstBuilder.isAcyclic(); if (acyclic) { if (isAlphaSorted[0]) { final List<String> sortedNodes = new ArrayList<>(generator.getNodes()); Collections.sort(sortedNodes, String.CASE_INSENSITIVE_ORDER); return Pair.create(sortedNodes, true); } else { final List<String> dfsNodes = dfstBuilder.getSortedNodes(); Collections.reverse(dfsNodes); return Pair.create(dfsNodes, false); } } else { return null; } }
/** * The main function! * * @param argv - Arguments to the program */ public static void main(String argv[]) { if (argv.length != 2) { System.out.println("USAGE: UPAMain <handle> <out_dir>"); System.exit(1); } String handle = argv[0]; String outdir = argv[1]; /*List of users to calculate later*/ LinkedList<UPUser> usersToCalc = new LinkedList<UPUser>(); /*Set up the database and service objects*/ TwitterDatabase db = null; TwitterService ts = null; LangTweetConverter converter = null; try { db = new TwitterDatabase(TwitterDatabase.DEFAULT_CONFIG_PATH); ts = new TwitterService(db, TwitterService.DEFAULT_CONFIG_PATH); converter = new LangTweetConverter(db); } catch (SQLException sqle) { System.out.println("DB Connection error!" + sqle.getMessage()); System.exit(2); } catch (IOException ioe) { System.out.println("Failed to open configuration file: " + ioe.getMessage()); System.exit(2); } UserRiskCalculator userCalc = new UserRiskCalculator(db); /*Turn on database debugging*/ db.enableDebug(); /* Check to see if the user is already in the DB, if not, get them */ System.out.println("STATUS: Getting user data"); UPUser base = null; try { base = db.queryUserByHandle(handle); if (base == null) { /*Not in the DB, we need to get them*/ base = ts.getUserByHandle(handle); if (base == null) { System.out.println("Failed to find user in Twitter Service"); db.close(); System.exit(3); } } } catch (SQLException sqle) { System.out.println("DB Error getting user"); System.exit(3); } /*Get tweets for this user*/ System.out.println("STATUS: Getting tweets for base user"); LinkedList<UPTweet> baseTweets = null; try { baseTweets = ts.getUserTimeline(handle); } catch (SQLException sqle) { System.out.println("Failed getting base user timeline\n"); System.out.println(sqle.getMessage()); System.exit(4); } if (baseTweets == null) { System.out.println("Failed getting base user timeline (null list)\n"); System.exit(4); } /* Do any conversions for this user text */ System.out.println("STATUS: Converting and scoring base user tweets"); for (UPTweet tweet : baseTweets) { try { converter.convertTweet(tweet); } catch (SQLException sqle) { System.err.println("Failed to convert tweet text\n"); System.err.println(sqle.getMessage()); } } /* Get users that this user is following */ System.out.println("STATUS: Getting users being followed by base"); LinkedList<UPUser> followed = null; followed = ts.getFollowing(base, 1000); if (followed == null) { System.out.println("Failed getting followed users.\n"); System.exit(5); } /*Get tweets for followed users*/ System.out.println("STATUS: Getting tweets for followed users"); for (UPUser f : followed) { usersToCalc.add(f); System.out.println("STATUS: Getting tweets for: " + f.getHandle()); LinkedList<UPTweet> l = null; try { l = ts.getUserTimeline(f.getHandle(), 1000); } catch (SQLException sqle) { System.out.println("Failed getting timeline for user: "******" continuing"); System.out.println(sqle.getMessage()); continue; } if (l == null) { System.out.println("Failed getting timeline for user: "******" continuing"); continue; } /* Do any conversions for this user text */ for (UPTweet tweet : l) { try { converter.convertTweet(tweet); } catch (SQLException sqle) { System.err.println("Failed to convert tweet text\n"); System.err.println(sqle.getMessage()); } } } // for each user : get timeline tweets /*Calculate the score for all users, and store in the DB for later*/ // base user int score = userCalc.getUserRiskScore(base); try { db.insertPersonPrivacyScore(base, score); } catch (SQLException sqle) { System.out.println("Failed to insert user base score: " + sqle.getMessage()); System.exit(5); } // all other users for (UPUser u : usersToCalc) { try { // calculate the user score score = userCalc.getUserRiskScore(u); db.insertPersonPrivacyScore(base, score); } catch (SQLException sqle) { System.out.println("Failed to insert user score: " + sqle.getMessage()); System.exit(5); } } /*Generate the graph file!*/ System.out.println("STATUS: Generating graph file"); String contents = null; try { contents = GraphGenerator.getDotFormatGraph(handle, db); } catch (SQLException sqle) { System.out.println("Failed generating graph!"); System.out.println(sqle.getMessage()); System.exit(5); } System.out.println("STATUS: Writing graph file"); try { BufferedWriter out = new BufferedWriter(new FileWriter(outdir + "/" + handle + ".dot")); out.write(contents); out.close(); } catch (IOException ioe) { System.out.println("Failed to write dot file."); System.exit(6); } System.out.println("STATUS: Done!"); } // main
/* * The program starts here. Parsing the input parameters and calls * corresponding methods */ public static void main(String[] args) { int argLen = args.length; GraphGenerator minSpanTree = new GraphGenerator(); // no of params should be either 2 or 3 if (argLen != 2 && argLen != 3) { System.out.println("Please enter valid input arguments"); return; } String arg1 = args[0]; if (arg1.equalsIgnoreCase("-f")) { // fibonacci heap scheme FheapScheme fScheme; try { String fileName = args[1]; fScheme = new FheapScheme(); // generating graph minSpanTree.generateGraph(fScheme, fileName); int noOfVertices = minSpanTree.getNoOfVertices(); // calling the method that runs Prim's algo fScheme.spanTree(noOfVertices, minSpanTree.getVtxPool()); fScheme.printSol(); } catch (Exception e) { System.out.println(e.getMessage()); } } else if (arg1.equalsIgnoreCase("-s")) { // simple scheme SimpleScheme sScheme; try { String fileName = args[1]; sScheme = new SimpleScheme(); // generating graph minSpanTree.generateGraph(sScheme, fileName); int noOfVertices = minSpanTree.getNoOfVertices(); // calling the method that runs Prim's algo sScheme.spanTree(noOfVertices, minSpanTree.getVtxPool()); sScheme.printSol(); } catch (Exception e) { System.out.println(e.getMessage()); } } else if (arg1.equalsIgnoreCase("-r")) { // random generator case try { int limit = Integer.parseInt(args[1]); int density = Integer.parseInt(args[2]); // generating random graph minSpanTree.generateRandomGraph(limit, density); SimpleScheme ss = new SimpleScheme(); FheapScheme fs = new FheapScheme(); long t1 = System.currentTimeMillis(); // calling fibonacci scheme fs.spanTree(limit, minSpanTree.getVtxPool()); long t2 = System.currentTimeMillis(); // calling simple scheme ss.spanTree(limit, minSpanTree.getVtxPool()); long t3 = System.currentTimeMillis(); System.out.println("Fibona Scheme - " + (t2 - t1)); System.out.println("Simple Scheme - " + (t3 - t2)); // ss.printSol(); // fs.printSol(); } catch (NumberFormatException numFormat) { System.out.println("Invalid Input - " + numFormat.getMessage()); } catch (ArrayIndexOutOfBoundsException arrEx) { System.out.println("Array Index Out of bound for input - " + arrEx.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); } } else { System.out.println("Enter valid inputs"); } }