Added radius and diameter search

This commit is contained in:
Unick Soft
2018-02-17 17:32:25 +03:00
parent 8a3ad5c598
commit 9361664643
5 changed files with 316 additions and 37 deletions

View File

@@ -18,6 +18,8 @@ function Graph()
this.hasDirect = false;
};
// infinity
Graph.prototype.infinity = 1E8;
Graph.prototype.AddNewVertex = function(vertex)
{
@@ -146,7 +148,7 @@ Graph.prototype.FindEdge = function(id1, id2)
return res;
}
Graph.prototype.GetAdjacencyMatrix = function ()
Graph.prototype.GetAdjacencyMatrixStr = function ()
{
var matrix = "";
for (var i = 0; i < this.vertices.length; i++)
@@ -175,6 +177,32 @@ Graph.prototype.GetAdjacencyMatrix = function ()
return matrix;
}
Graph.prototype.GetAdjacencyMatrix = function ()
{
var matrix = [];
for (var i = 0; i < this.vertices.length; i ++)
{
matrix.push([]);
var v1 = this.vertices[i];
for (var j = 0; j < this.vertices.length; j ++)
{
var v2 = this.vertices[j];
var edge = this.FindEdge(v1.id, v2.id);
if (edge != null)
{
matrix[i][j] = edge.GetWeight();
}
else
{
matrix[i][j] = this.infinity;
}
}
}
return matrix;
}
Graph.prototype.TestAdjacencyMatrix = function (matrix, rowsObj, colsObj, separator = ",")
{
var bGoodFormat = true;