|
From: <mrp...@us...> - 2014-04-06 16:38:11
|
Revision: 8063
http://sourceforge.net/p/bigdata/code/8063
Author: mrpersonick
Date: 2014-04-06 16:38:08 +0000 (Sun, 06 Apr 2014)
Log Message:
-----------
fixed SSSP/BigdataGASState to use RDR to take into account the edge value if the linkAttrType property is specified
Modified Paths:
--------------
branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/SSSP.java
branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/analytics/TestSSSP.java
branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASState.java
branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java
Added Paths:
-----------
branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.rq
branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.ttl
Removed Paths:
-------------
branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq
Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/SSSP.java
===================================================================
--- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/SSSP.java 2014-04-06 16:36:28 UTC (rev 8062)
+++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/analytics/SSSP.java 2014-04-06 16:38:08 UTC (rev 8063)
@@ -21,14 +21,11 @@
import java.util.concurrent.atomic.AtomicReference;
import org.apache.log4j.Logger;
+import org.openrdf.model.Literal;
import org.openrdf.model.Statement;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-import com.bigdata.bop.IBindingSet;
-import com.bigdata.bop.IVariable;
import com.bigdata.rdf.graph.BinderBase;
import com.bigdata.rdf.graph.EdgesEnum;
import com.bigdata.rdf.graph.Factory;
@@ -77,7 +74,7 @@
* is a single link attribute type that is of interest, so the caller should
* also be able to specify that.
*/
- private final static int EDGE_LENGTH = 1;
+ private final static double EDGE_LENGTH = 1.0f;
public static class VS {
@@ -90,7 +87,7 @@
* double. We also need tests with non-integer weights and non- positive
* weights.
*/
- private Integer dist = Integer.MAX_VALUE;
+ private Double dist = Double.MAX_VALUE;
// /**
// * Note: This flag is cleared by apply() and then conditionally set
@@ -145,7 +142,7 @@
* to this vertex and {@link Integer#MAX_VALUE} until this vertex is
* visited.
*/
- public int dist() {
+ public double dist() {
synchronized (this) {
return dist;
}
@@ -166,7 +163,7 @@
synchronized private void setStartingVertex() {
// Set distance to zero for starting vertex.
- dist = 0;
+ dist = 0.0;
this.predecessor.set(null);
// // Must be true to trigger scatter in the 1st round!
@@ -220,7 +217,7 @@
* @return <code>true</code> iff this vertex state was changed.
*/
synchronized private boolean scatter(final Value predecessor,
- final int newDist) {
+ final double newDist) {
/*
* Validate that the distance has decreased while holding the lock.
*/
@@ -399,11 +396,22 @@
final VS otherState = state.getState(other);
+ final double edgeLength;
+ if (e.getObject() instanceof Literal) {
+
+ edgeLength = ((Literal) e.getObject()).doubleValue();
+
+ } else {
+
+ edgeLength = EDGE_LENGTH;
+
+ }
+
// new distance for the remote vertex.
- final int newDist = selfState.dist() + EDGE_LENGTH;
+ final double newDist = selfState.dist() + edgeLength; //EDGE_LENGTH;
// last observed distance for the remote vertex.
- final int otherDist = otherState.dist();
+ final double otherDist = otherState.dist();
// Note: test first without lock.
if (newDist < otherDist) {
Modified: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/analytics/TestSSSP.java
===================================================================
--- branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/analytics/TestSSSP.java 2014-04-06 16:36:28 UTC (rev 8062)
+++ branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/analytics/TestSSSP.java 2014-04-06 16:38:08 UTC (rev 8063)
@@ -70,13 +70,13 @@
// Converge.
gasContext.call();
- assertEquals(0, gasState.getState(p.getMike()).dist());
+ assertEquals(0.0, gasState.getState(p.getMike()).dist());
- assertEquals(1, gasState.getState(p.getFoafPerson()).dist());
+ assertEquals(1.0, gasState.getState(p.getFoafPerson()).dist());
- assertEquals(1, gasState.getState(p.getBryan()).dist());
+ assertEquals(1.0, gasState.getState(p.getBryan()).dist());
- assertEquals(2, gasState.getState(p.getMartyn()).dist());
+ assertEquals(2.0, gasState.getState(p.getMartyn()).dist());
} finally {
Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASState.java
===================================================================
--- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASState.java 2014-04-06 16:36:28 UTC (rev 8062)
+++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASState.java 2014-04-06 16:38:08 UTC (rev 8063)
@@ -191,4 +191,29 @@
}
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Value getOtherVertex(final Value u, final Statement e) {
+
+ if (e.getSubject() instanceof SidIV) {
+
+ final ISPO spo = ((SidIV) e.getSubject()).getInlineValue();
+
+ if (spo.s().equals(u))
+ return spo.o();
+
+ return spo.s();
+
+ } else {
+
+ if (e.getSubject().equals(u))
+ return e.getObject();
+
+ return e.getSubject();
+
+ }
+
+ }
+
+
}
Modified: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java
===================================================================
--- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java 2014-04-06 16:36:28 UTC (rev 8062)
+++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java 2014-04-06 16:38:08 UTC (rev 8063)
@@ -139,7 +139,47 @@
//
// }
//
-// public void testSimpleSSSP() throws Exception {
+ public void testSimpleSSSP() throws Exception {
+
+ final BigdataSail sail = getSail();
+ sail.initialize();
+ final BigdataSailRepository repo = new BigdataSailRepository(sail);
+
+ final BigdataSailRepositoryConnection cxn = repo.getConnection();
+ cxn.setAutoCommit(false);
+
+ try {
+
+ cxn.add(open("sssp.ttl"), "", RDFFormat.TURTLE);
+ cxn.commit();
+
+ log.trace("\n" + sail.getDatabase().dumpStore());
+
+ final String query = IOUtils.toString(open("sssp.rq"));
+
+ log.trace("\n" + query);
+
+ final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL,
+ query);
+
+ final TupleQueryResult result = tqr.evaluate();
+
+ while (result.hasNext()) {
+
+ log.trace(result.next());
+
+ }
+
+ result.close();
+
+ } finally {
+ cxn.close();
+ sail.__tearDownUnitTest();
+ }
+
+ }
+
+// public void testPaths() throws Exception {
//
// final BigdataSail sail = getSail();
// sail.initialize();
@@ -150,12 +190,12 @@
//
// try {
//
-// cxn.add(open("paths2.ttl"), "", RDFFormat.TURTLE);
+// cxn.add(open("paths4.ttl"), "", RDFFormat.TURTLE);
// cxn.commit();
//
// log.trace("\n"+sail.getDatabase().dumpStore());
//
-// final String query = IOUtils.toString(open("paths2.rq"));
+// final String query = IOUtils.toString(open("paths4.rq"));
//
// log.trace("\n"+query);
//
@@ -178,43 +218,4 @@
//
// }
- public void testPaths() throws Exception {
-
- final BigdataSail sail = getSail();
- sail.initialize();
- final BigdataSailRepository repo = new BigdataSailRepository(sail);
-
- final BigdataSailRepositoryConnection cxn = repo.getConnection();
- cxn.setAutoCommit(false);
-
- try {
-
- cxn.add(open("paths4.ttl"), "", RDFFormat.TURTLE);
- cxn.commit();
-
- log.trace("\n"+sail.getDatabase().dumpStore());
-
- final String query = IOUtils.toString(open("paths4.rq"));
-
- log.trace("\n"+query);
-
- final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
-
- final TupleQueryResult result = tqr.evaluate();
-
- while (result.hasNext()) {
-
- log.trace(result.next());
-
- }
-
- result.close();
-
- } finally {
- cxn.close();
- sail.__tearDownUnitTest();
- }
-
- }
-
}
Deleted: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq
===================================================================
--- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq 2014-04-06 16:36:28 UTC (rev 8062)
+++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq 2014-04-06 16:38:08 UTC (rev 8063)
@@ -1,11 +0,0 @@
-PREFIX gas: <http://www.bigdata.com/rdf/gas#>
-SELECT * {
- SERVICE gas:service {
- gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" .
- gas:program gas:in </:source> . # starting point
- gas:program gas:target </:target> . # target vertices
- gas:program gas:out ?s . # bound to the visited vertices.
- gas:program gas:out1 ?distance . # bound to the distance of the visited vertices.
- gas:program gas:out2 ?pred . # bound to the predecessor
- }
-} order by ?distance
\ No newline at end of file
Copied: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.rq (from rev 8059, branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq)
===================================================================
--- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.rq (rev 0)
+++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.rq 2014-04-06 16:38:08 UTC (rev 8063)
@@ -0,0 +1,13 @@
+PREFIX gas: <http://www.bigdata.com/rdf/gas#>
+SELECT * {
+ SERVICE gas:service {
+ gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" .
+ gas:program gas:in </:source> . # starting point
+ gas:program gas:target </:target1> . # target vertices
+ gas:program gas:target </:target2> . # target vertices
+ gas:program gas:linkAttrType </:cost> . # link attribute type
+ gas:program gas:out ?v . # bound to the visited vertices.
+ gas:program gas:out1 ?distance . # bound to the distance of the visited vertices.
+ gas:program gas:out2 ?pred . # bound to the predecessor
+ }
+} order by ?distance
\ No newline at end of file
Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.ttl
===================================================================
--- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.ttl (rev 0)
+++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/sssp.ttl 2014-04-06 16:38:08 UTC (rev 8063)
@@ -0,0 +1,14 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix bd: <http://www.bigdata.com/rdf#> .
+@prefix : <:> .
+
+# target1: 3 hops, cost = 1.5
+<<:source :edge :a>> :cost "0.5"^^xsd:float .
+<<:a :edge :b>> :cost "0.5"^^xsd:float .
+<<:b :edge :target1>> :cost "0.5"^^xsd:float .
+
+# target2: 4 hops, cost = 1.0
+<<:source :edge :c>> :cost "0.25"^^xsd:float .
+<<:c :edge :d>> :cost "0.25"^^xsd:float .
+<<:d :edge :e>> :cost "0.25"^^xsd:float .
+<<:e :edge :target2>> :cost "0.25"^^xsd:float .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|