mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 15:26:12 +00:00
Fix search Eulerian path/loop if graph has separate nodes.
This commit is contained in:
parent
d8ed01c438
commit
5076ba07c5
@ -154,13 +154,20 @@ function BaseAlgorithmEx(graph, app)
|
||||
// inheritance.
|
||||
BaseAlgorithmEx.prototype = Object.create(BaseAlgorithm.prototype);
|
||||
|
||||
BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallback)
|
||||
BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallback, ignoreSeparateNodes = false)
|
||||
{
|
||||
if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
|
||||
console.log(queryString);
|
||||
|
||||
var graph = this.graph;
|
||||
var creator = new GraphMLCreater(graph.vertices, graph.edges);
|
||||
var ignoreNodes = {};
|
||||
|
||||
if (ignoreSeparateNodes)
|
||||
for (var i = 0; i < graph.vertices.length; i++)
|
||||
if (!graph.HasConnectedNodes(graph.vertices[i]))
|
||||
ignoreNodes[graph.vertices[i].id] = 1;
|
||||
|
||||
var creator = new GraphMLCreater(graph.vertices, graph.edges, ignoreNodes);
|
||||
var pathObjects = [];
|
||||
var properties = {};
|
||||
var result = [];
|
||||
@ -204,15 +211,15 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
||||
$data.each(function(){
|
||||
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
||||
{
|
||||
pathObjects.push(graph.FindVertex(id));
|
||||
pathObjects.push(graph.FindVertex(id));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!properties[id])
|
||||
{
|
||||
properties[id] = {};
|
||||
}
|
||||
properties[id][$(this).attr('key')] = $(this).text();
|
||||
if (!properties[id])
|
||||
{
|
||||
properties[id] = {};
|
||||
}
|
||||
properties[id][$(this).attr('key')] = $(this).text();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -99,6 +99,26 @@ Graph.prototype.DeleteVertex = function(vertexObject)
|
||||
}
|
||||
}
|
||||
|
||||
Graph.prototype.HasConnectedNodes = function(vertexObject)
|
||||
{
|
||||
var res = false;
|
||||
|
||||
var index = this.vertices.indexOf(vertexObject);
|
||||
if (index > -1)
|
||||
{
|
||||
for (var i = 0; i < this.edges.length; i++)
|
||||
{
|
||||
if (this.edges[i].vertex1 == vertexObject || this.edges[i].vertex2 == vertexObject)
|
||||
{
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Graph.prototype.FindVertex = function(id)
|
||||
{
|
||||
var res = null;
|
||||
|
@ -4,10 +4,11 @@
|
||||
*/
|
||||
|
||||
|
||||
function GraphMLCreater(nodes, arcs)
|
||||
function GraphMLCreater(nodes, arcs, ignoreNodes = {})
|
||||
{
|
||||
this.nodes = nodes;
|
||||
this.arcs = arcs;
|
||||
this.ignoreNodes = ignoreNodes;
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +28,8 @@ GraphMLCreater.prototype.GetXMLString = function()
|
||||
|
||||
for (var i = 0; i < this.nodes.length; i++)
|
||||
{
|
||||
xmlBoby = xmlBoby + "<node id=\"" + this.nodes[i].id + "\"/>";
|
||||
if (!this.ignoreNodes.hasOwnProperty(this.nodes[i].id))
|
||||
xmlBoby = xmlBoby + "<node id=\"" + this.nodes[i].id + "\"/>";
|
||||
}
|
||||
var hasDirected = false;
|
||||
for (var i = 0; i < this.arcs.length; i++)
|
||||
|
@ -37,7 +37,7 @@ FindEulerianLoop.prototype.result = function(resultCallback)
|
||||
this.CalculateAlgorithm("elloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ FindEulerianPath.prototype.result = function(resultCallback)
|
||||
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user