mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 23:36:00 +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.
|
// inheritance.
|
||||||
BaseAlgorithmEx.prototype = Object.create(BaseAlgorithm.prototype);
|
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")
|
if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
|
||||||
console.log(queryString);
|
console.log(queryString);
|
||||||
|
|
||||||
var graph = this.graph;
|
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 pathObjects = [];
|
||||||
var properties = {};
|
var properties = {};
|
||||||
var result = [];
|
var result = [];
|
||||||
@ -204,15 +211,15 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
|||||||
$data.each(function(){
|
$data.each(function(){
|
||||||
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
||||||
{
|
{
|
||||||
pathObjects.push(graph.FindVertex(id));
|
pathObjects.push(graph.FindVertex(id));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!properties[id])
|
if (!properties[id])
|
||||||
{
|
{
|
||||||
properties[id] = {};
|
properties[id] = {};
|
||||||
}
|
}
|
||||||
properties[id][$(this).attr('key')] = $(this).text();
|
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)
|
Graph.prototype.FindVertex = function(id)
|
||||||
{
|
{
|
||||||
var res = null;
|
var res = null;
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function GraphMLCreater(nodes, arcs)
|
function GraphMLCreater(nodes, arcs, ignoreNodes = {})
|
||||||
{
|
{
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
this.arcs = arcs;
|
this.arcs = arcs;
|
||||||
|
this.ignoreNodes = ignoreNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +28,8 @@ GraphMLCreater.prototype.GetXMLString = function()
|
|||||||
|
|
||||||
for (var i = 0; i < this.nodes.length; i++)
|
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;
|
var hasDirected = false;
|
||||||
for (var i = 0; i < this.arcs.length; i++)
|
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)
|
this.CalculateAlgorithm("elloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ FindEulerianPath.prototype.result = function(resultCallback)
|
|||||||
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user