From: <tho...@us...> - 2014-03-14 21:23:56
|
Revision: 7968 http://sourceforge.net/p/bigdata/code/7968 Author: thompsonbry Date: 2014-03-14 21:23:52 +0000 (Fri, 14 Mar 2014) Log Message: ----------- Added logic to extract the label for CC and the rank for PageRank. Updated the wiki page to document the outX variables for each of these algorithms. See #810 (Expose GAS as a SERVICE). Modified Paths: -------------- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/CC.java branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/PR.java Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/CC.java =================================================================== --- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/CC.java 2014-03-14 20:59:25 UTC (rev 7967) +++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/CC.java 2014-03-14 21:23:52 UTC (rev 7968) @@ -16,6 +16,7 @@ package com.bigdata.rdf.graph.analytics; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -24,6 +25,7 @@ import org.apache.log4j.Logger; import org.openrdf.model.Statement; import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; import com.bigdata.rdf.graph.EdgesEnum; import com.bigdata.rdf.graph.Factory; @@ -305,6 +307,57 @@ } /** + * {@inheritDoc} + * <p> + * <dl> + * <dt>{@value Bindings#LABEL}</dt> + * <dd>The label associated with all of the vertices in the same subgraph. + * The label is a vertex identifier and can be used to jump into the + * subgraph.</dd> + * </dl> + */ + @Override + public List<IBinder<CC.VS, CC.ES, Value>> getBinderList() { + + final List<IBinder<CC.VS, CC.ES, Value>> tmp = super.getBinderList(); + + tmp.add(new IBinder<CC.VS, CC.ES, Value>() { + + @Override + public int getIndex() { + return Bindings.LABEL; + } + + @Override + public Value bind(final ValueFactory vf, + final IGASState<CC.VS, CC.ES, Value> state, final Value u) { + + return state.getState(u).label.get(); + + } + }); + + return tmp; + + } + + /** + * Additional {@link IBinder}s exposed by {@link CC}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ + public interface Bindings extends BaseGASProgram.Bindings { + + /** + * The label associated with all of the vertices in a subgraph. The + * label is a vertex identifier and can be used to jump into the + * subgraph. + */ + int LABEL = 1; + + } + + /** * Returns a map containing the labels assigned to each connected component * (which gives you a vertex in that connected component) and the #of * vertices in each connected component. Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/PR.java =================================================================== --- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/PR.java 2014-03-14 20:59:25 UTC (rev 7967) +++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/PR.java 2014-03-14 21:23:52 UTC (rev 7968) @@ -16,12 +16,14 @@ package com.bigdata.rdf.graph.analytics; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.openrdf.model.Statement; import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; import com.bigdata.rdf.graph.EdgesEnum; import com.bigdata.rdf.graph.Factory; @@ -30,6 +32,8 @@ import com.bigdata.rdf.graph.IGASScheduler; import com.bigdata.rdf.graph.IGASState; import com.bigdata.rdf.graph.IReducer; +import com.bigdata.rdf.graph.IGASProgram.IBinder; +import com.bigdata.rdf.graph.analytics.CC.Bindings; import com.bigdata.rdf.graph.impl.BaseGASProgram; /** @@ -115,8 +119,12 @@ * updated in each iteration to the new estimated value by apply(). */ public double getValue() { + + synchronized (this) { - return value; + return value; + + } } @@ -196,10 +204,15 @@ final PR.VS us = state.getState(u); - us.value = resetProb; + synchronized (us) { - us.outEdges = ctx.getGraphAccessor().getEdgeCount(ctx, u, - EdgesEnum.OutEdges); + us.value = resetProb; + + us.outEdges = ctx.getGraphAccessor().getEdgeCount(ctx, u, + EdgesEnum.OutEdges); + + } + } /** @@ -219,7 +232,11 @@ * that we used to discover [v] is an out-edge of [v]. */ - return (vs.value / vs.outEdges); + synchronized (vs) { + + return (vs.value / vs.outEdges); + + } } @@ -255,7 +272,9 @@ * from the frontier. */ - us.lastChange = 0d; + synchronized (us) { + us.lastChange = 0d; + } return null; @@ -263,10 +282,14 @@ final double newval = resetProb + (1.0 - resetProb) * sum; - us.lastChange = (newval - us.value); + synchronized (us) { - us.value = newval; + us.lastChange = (newval - us.value); + us.value = newval; + + } + return us; } @@ -317,6 +340,53 @@ } /** + * {@inheritDoc} + * <p> + * <dl> + * <dt>{@value Bindings#RANK}</dt> + * <dd>The page rank associated with the vertex..</dd> + * </dl> + */ + @Override + public List<IBinder<PR.VS, PR.ES, Double>> getBinderList() { + + final List<IBinder<PR.VS, PR.ES, Double>> tmp = super.getBinderList(); + + tmp.add(new IBinder<PR.VS, PR.ES, Double>() { + + @Override + public int getIndex() { + return Bindings.RANK; + } + + @Override + public Value bind(final ValueFactory vf, + final IGASState<PR.VS, PR.ES, Double> state, final Value u) { + + return vf.createLiteral(state.getState(u).getValue()); + + } + }); + + return tmp; + + } + + /** + * Additional {@link IBinder}s exposed by {@link PR}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ + public interface Bindings extends BaseGASProgram.Bindings { + + /** + * The computed page rank for the vertex. + */ + int RANK = 1; + + } + + /** * Class reports a map containing the page rank associated with each visited * vertex. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |