Java Code Examples for it.unimi.dsi.webgraph.ImmutableGraph#numNodes()

The following examples show how to use it.unimi.dsi.webgraph.ImmutableGraph#numNodes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalVisitStats.java    From fasten with Apache License 2.0 6 votes vote down vote up
public static int reachable(final ImmutableGraph graph, final int startingNode) {
	final int n = graph.numNodes();
	final boolean[] known = new boolean[n];
	final IntArrayFIFOQueue queue = new IntArrayFIFOQueue();

	queue.enqueue(startingNode);
	known[startingNode] = true;
	int visited = 0;

	while (!queue.isEmpty()) {
		final int currentNode = queue.dequeueInt();
		visited++;
		final LazyIntIterator iterator = graph.successors(currentNode);
		for (int succ; (succ = iterator.nextInt()) != -1;) {
			if (!known[succ]) {
				known[succ] = true;
				queue.enqueue(succ);
			}
		}
	}

	return visited;
}
 
Example 2
Source File: CallGraphGenerator.java    From fasten with Apache License 2.0 6 votes vote down vote up
/** Given <code>g</code>, returns a Fenwick tree for the nodes of <code>g</code> whose counter number <code>i+1</code> corresponds to node <code>i</code>
 *  and it is initialized to <code>d</code> or to <code>D-d+1</code> (the latter iff <code>reverse</code> is true),
 *  where <code>D</code> is the maximum indegree in <code>g</code>, and <code>d</code> is <code>i</code>'s indegree.
 *
 * @param g a graph.
 * @param reverse if true, we generate the <em>reverse</em> distribution.
 * @return a Fenwick tree as above.
 */
public static FenwickTree getPreferentialDistribution(final ImmutableGraph g, final boolean reverse) {
	final int n = g.numNodes();
	final int[] indegree = new int[n];
	int maxIndegree = 0;
	final NodeIterator nodeIterator = g.nodeIterator();
	while (nodeIterator.hasNext()) {
		nodeIterator.nextInt();
		final LazyIntIterator successors = nodeIterator.successors();
		int target;
		while ((target = successors.nextInt()) >= 0) {
			indegree[target]++;
			if (indegree[target] > maxIndegree) maxIndegree = indegree[target];
		}
	}
	final FenwickTree t = new FenwickTree(n);
	for (int i = 0; i < indegree.length; i++)
		t.incrementCount(i + 1, reverse? maxIndegree - indegree[i] + 1 : indegree[i]);

	return t;
}
 
Example 3
Source File: VisitStats.java    From fasten with Apache License 2.0 6 votes vote down vote up
public static int reachable(final ImmutableGraph graph, final int startingNode) {
	final int n = graph.numNodes();
	final boolean[] known = new boolean[n];
	final IntArrayFIFOQueue queue = new IntArrayFIFOQueue();

	queue.enqueue(startingNode);
	known[startingNode] = true;
	int visited = 0;

	while (!queue.isEmpty()) {
		final int currentNode = queue.dequeueInt();
		visited++;
		final LazyIntIterator iterator = graph.successors(currentNode);
		for (int succ; (succ = iterator.nextInt()) != -1;) {
			if (!known[succ]) {
				known[succ] = true;
				queue.enqueue(succ);
			}
		}
	}

	return visited;
}
 
Example 4
Source File: LayeredLabelPropagation.java    From fasten with Apache License 2.0 6 votes vote down vote up
/** Creates a new instance using a specific initial permutation and specified number of threads.
 *
 * <p>If <code>exact</code> is true, the final permutation is
 * <em>exactly</em> the same as if you first permute the graph with <code>startPerm</code> and
 * then apply LLP with an {@code null} starting permutation.
 *
 * @param symGraph a symmetric, loopless graph.
 * @param startPerm an initial permutation of the graph, or {@code null} for no permutation.
 * @param numberOfThreads the number of threads to be used (0 for automatic sizing).
 * @param seed a random seed.
 * @param exact a boolean flag that forces the algorithm to run exactly.
 */
public LayeredLabelPropagation(final ImmutableGraph symGraph, final int[] startPerm, final int numberOfThreads, final long seed, final boolean exact) throws IOException {
	this.symGraph = symGraph;
	this.n = symGraph.numNodes();
	this.startPerm = startPerm;
	this.seed = seed;
	this.r = new XoRoShiRo128PlusRandom(seed);
	this.exact = exact;
	this.label = new AtomicIntegerArray(n);
	this.volume = new AtomicIntegerArray(n);
	cumulativeOutdegrees = new EliasFanoCumulativeOutdegreeList(symGraph, symGraph.numArcs(), 1);

	this.gapCost = new MutableDouble();
	this.updateList = Util.identity(n);
	simpleUncaughtExceptionHandler = new SimpleUncaughtExceptionHandler();
	labelling = File.createTempFile(this.getClass().getName(), "labelling");
	labelling.deleteOnExit();

	this.numberOfThreads = numberOfThreads != 0 ? numberOfThreads : Runtime.getRuntime().availableProcessors();
	this.canChange = new boolean[n];
	this.modified = new AtomicInteger(0);
	this.objectiveFunction = new double[this.numberOfThreads];
}
 
Example 5
Source File: InGraphArray.java    From tagme with Apache License 2.0 6 votes vote down vote up
@Override
protected int[][] parseSet() throws IOException
{
	
	ImmutableGraph in_graph = WikiGraphs.get(lang, IndexType.IN_GRAPH);
	int[][] arrayGraph = new int[in_graph.numNodes()][];
	for(int i=0; i<arrayGraph.length; i++)
	{
		int i_deg = in_graph.outdegree(i);
		if (i_deg > 0){
			arrayGraph[i] = new int[i_deg];
			LazyIntIterator iter = in_graph.successors(i);
			for (int j=0; j<arrayGraph[i].length; j++)
				arrayGraph[i][j] = iter.nextInt();
		}
	}

	return arrayGraph;
}
 
Example 6
Source File: ImmutableGraphNamedGraphServer.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Builds the server.
 *
 * @param graph the graph.
 * @param map a string map representing the URLs of the graph.
 */
public ImmutableGraphNamedGraphServer(final ImmutableGraph graph, StringMap<? extends CharSequence> map) {
	if (graph.numNodes() != map.size()) throw new IllegalArgumentException("The graph has " + graph.numNodes() + " nodes, but the map has " + map.size() + " keys.");
	this.graph = graph;
	this.map = map;
	this.list = map.list();
}