mirror of https://gitee.com/bigwinds/arangodb
parent
ecf09fc4dc
commit
07366afcfc
|
@ -1493,6 +1493,47 @@ Graph.prototype.size = function () {
|
||||||
return this._edges.count();
|
return this._edges.count();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief calculate a measurement
|
||||||
|
///
|
||||||
|
/// @FUN{@FA{vertex}.measurement(@FA{measurement})}
|
||||||
|
///
|
||||||
|
/// Calculates the eccentricity or closeness of the vertex
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Graph.prototype.measurement = function (measurement) {
|
||||||
|
var graph = this,
|
||||||
|
vertices = graph._vertices.toArray(),
|
||||||
|
start_value;
|
||||||
|
|
||||||
|
switch (measurement) {
|
||||||
|
case "diameter":
|
||||||
|
start_value = 0;
|
||||||
|
break;
|
||||||
|
case "radius":
|
||||||
|
start_value = Infinity;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw "Unknown Measurement '" + measurement + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
return vertices.reduce(function (calculated, vertex) {
|
||||||
|
vertex = graph.getVertex(vertex._id);
|
||||||
|
|
||||||
|
switch (measurement) {
|
||||||
|
case "diameter":
|
||||||
|
calculated = Math.max(calculated, vertex.measurement("eccentricity"));
|
||||||
|
break;
|
||||||
|
case "radius":
|
||||||
|
calculated = Math.min(calculated, vertex.measurement("eccentricity"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return calculated;
|
||||||
|
}, start_value);
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -179,14 +179,43 @@ function measurementSuite() {
|
||||||
/// @brief test to get an unknown measurement for a vertex
|
/// @brief test to get an unknown measurement for a vertex
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
testUnknownMeasurement : function () {
|
testUnknownMeasurementOnVertex : function () {
|
||||||
var v1 = graph.addVertex(1);
|
var v1 = graph.addVertex(1);
|
||||||
|
|
||||||
assertException(function () {
|
assertException(function () {
|
||||||
v1.measurement("unknown");
|
v1.measurement("unknown");
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test to get diameter and radius for a graph
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testDiameterAndRadius : function () {
|
||||||
|
var v1 = graph.addVertex(1),
|
||||||
|
v2 = graph.addVertex(2),
|
||||||
|
v3 = graph.addVertex(3),
|
||||||
|
v4 = graph.addVertex(4),
|
||||||
|
v5 = graph.addVertex(5);
|
||||||
|
|
||||||
|
graph.addEdge(v1, v2);
|
||||||
|
graph.addEdge(v1, v3);
|
||||||
|
graph.addEdge(v1, v4);
|
||||||
|
graph.addEdge(v4, v5);
|
||||||
|
|
||||||
|
assertEqual(graph.measurement("diameter"), 3);
|
||||||
|
assertEqual(graph.measurement("radius"), 2);
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test to get an unknown measurement for a graph
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testUnknownMeasurementOnGraph : function () {
|
||||||
|
assertException(function () {
|
||||||
|
graph.measurement("unknown");
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue