Add multigraph support. Visualization and some algorithms.

This commit is contained in:
Unick Soft
2019-10-05 16:11:40 +02:00
parent c580c5aef9
commit 063c2f9ec0
21 changed files with 367 additions and 85 deletions

View File

@@ -92,7 +92,7 @@ BFSAlgorithm.prototype.bfs = function(vertex, vertexArray, edgeArray)
for (var i = 0; i < this.graph.vertices.length; i ++)
{
var nextVertex = this.graph.vertices[i];
var edge = this.graph.FindEdge(vertex.id, nextVertex.id);
var edge = this.graph.FindEdgeAny(vertex.id, nextVertex.id);
if (edge && !vertexArray.includes(nextVertex))
{
edgeArray.push(edge);
@@ -104,6 +104,12 @@ BFSAlgorithm.prototype.bfs = function(vertex, vertexArray, edgeArray)
return false;
}
// Algorithm support multi graph
BFSAlgorithm.prototype.IsSupportMultiGraph = function()
{
return true;
}
// Factory for connected components.
function CreateBFSAlgorithm(graph, app)
{

View File

@@ -369,6 +369,12 @@ Coloring.prototype.getPriority = function()
return -9.0;
}
// Algorithm support multi graph
Coloring.prototype.IsSupportMultiGraph = function()
{
return true;
}
// Factory for connected components.
function CreateColoring(graph, app)

View File

@@ -76,7 +76,7 @@ FindConnectedComponentNew.prototype.calculate = function(fillUpText = false)
for (j = 0; j < connectedVertex[stackElement.id].length; j++)
{
var nextVertex = connectedVertex[stackElement.id][j];
var connectedEdge = this.graph.FindEdge(stackElement.id, nextVertex.id);
var connectedEdge = this.graph.FindEdgeAny(stackElement.id, nextVertex.id);
if (stack.indexOf(nextVertex) < 0)
{
stack.push(nextVertex);
@@ -113,6 +113,12 @@ FindConnectedComponentNew.prototype.getPriority = function()
return 0;
}
// Algorithm support multi graph
FindConnectedComponentNew.prototype.IsSupportMultiGraph = function()
{
return true;
}
// Factory for connected components.
function CreateConnectedComponetsNew(graph, app)

View File

@@ -91,7 +91,7 @@ DFSAlgorithm.prototype.dfs = function(vertex, vertexArray, edgeArray)
for (var i = 0; i < this.graph.vertices.length; i ++)
{
var nextVertex = this.graph.vertices[i];
var edge = this.graph.FindEdge(vertex.id, nextVertex.id);
var edge = this.graph.FindEdgeAny(vertex.id, nextVertex.id);
if (edge && !vertexArray.includes(nextVertex))
{
edgeArray.push(edge);
@@ -103,6 +103,12 @@ DFSAlgorithm.prototype.dfs = function(vertex, vertexArray, edgeArray)
return false;
}
// Algorithm support multi graph
DFSAlgorithm.prototype.IsSupportMultiGraph = function()
{
return true;
}
// Factory for connected components.
function CreateDFSAlgorithm(graph, app)
{

View File

@@ -103,7 +103,7 @@ FloidAlgorithm.prototype.resultMatrix = function()
for (var j = 0; j < this.graph.vertices.length; j ++)
{
var v2 = this.graph.vertices[j];
var edge = this.graph.FindEdge(v1.id, v2.id);
var edge = this.graph.FindEdgeMin(v1.id, v2.id);
if (edge != null)
{
this.matrix[i][j] = edge.GetWeight();

View File

@@ -159,6 +159,11 @@ GraphReorder.prototype.getPriority = function()
return -8.5;
}
// Algorithm support multi graph
GraphReorder.prototype.IsSupportMultiGraph = function()
{
return true;
}
// Factory for connected components.
function CreateAlgorithmGraphReorder(graph, app)

View File

@@ -104,7 +104,7 @@ MinimumSpanningTree.prototype.resultStartedFrom = function(vertex, connectedVert
for (j = 0; j < connectedVertex[element.id].length; j++)
{
var connectedElement = connectedVertex[element.id][j];
var connectedEdge = this.graph.FindEdge(element.id, connectedElement.id);
var connectedEdge = this.graph.FindEdgeMin(element.id, connectedElement.id);
if (inTree.indexOf(connectedElement) < 0)
{
if (minEdge == null || minEdge.weight > connectedEdge.weight)

View File

@@ -182,7 +182,6 @@ ModernGraphStyle.prototype.getObjectSelectedGroup = function(object)
return 0;
}
// Factory for connected components.
function CreateAlgorithmModernGraphStyle(graph, app)
{

View File

@@ -183,7 +183,7 @@ RadiusAndDiameter.prototype.getPathByMatrix = function(adjacencyMatrix, minPathM
if (minPathMatrix[i][finishNode] == length - adjacencyMatrix[startNode][i] && i != startNode)
{
res.push(vertices[startNode]);
res.push(this.graph.FindEdge(vertices[startNode].id, vertices[i].id));
res.push(this.graph.FindEdgeMin(vertices[startNode].id, vertices[i].id));
length -= adjacencyMatrix[startNode][i];
startNode = i;
@@ -193,7 +193,7 @@ RadiusAndDiameter.prototype.getPathByMatrix = function(adjacencyMatrix, minPathM
}
res.push(vertices[startNode]);
res.push(this.graph.FindEdge(vertices[startNode].id, vertices[finishNode].id));
res.push(this.graph.FindEdgeMin(vertices[startNode].id, vertices[finishNode].id));
res.push(vertices[finishNode]);
return res;