Added EulerianPath

This commit is contained in:
Unick Soft 2017-11-19 22:17:21 +03:00
parent 22ba44ecb5
commit d6d27397a4
5 changed files with 107 additions and 1 deletions

View File

@ -108,4 +108,7 @@
$g_lang["recommend_algorithm"] = "Recommend algorithms"; $g_lang["recommend_algorithm"] = "Recommend algorithms";
$g_lang["what_algorithm_we_have"] = "Our service already supports these features: <a href=\"/en/wiki/Help/FindTheShortestPath\" target=\"_blank\" style=\"text-decoration: underline\">Find the shortest path using Dijkstra's algorithm</a>, <a href=\"/en/wiki/Help/AdjacencyMatrix\" target=\"_blank\" style=\"text-decoration: underline\">Adjacency matrix</a>, <a href=\"/en/wiki/Help/IncidenceMatrix\" target=\"_blank\" style=\"text-decoration: underline\">Incidence Matrix</a>."; $g_lang["what_algorithm_we_have"] = "Our service already supports these features: <a href=\"/en/wiki/Help/FindTheShortestPath\" target=\"_blank\" style=\"text-decoration: underline\">Find the shortest path using Dijkstra's algorithm</a>, <a href=\"/en/wiki/Help/AdjacencyMatrix\" target=\"_blank\" style=\"text-decoration: underline\">Adjacency matrix</a>, <a href=\"/en/wiki/Help/IncidenceMatrix\" target=\"_blank\" style=\"text-decoration: underline\">Incidence Matrix</a>.";
$g_lang["has_eulerian_path"] = "Graph has Eulerian path";
$g_lang["has_not_eulerian_path"] = "Graph has not Eulerian path";
?> ?>

View File

@ -112,5 +112,7 @@
$g_lang["what_algorithm_we_have"] = "Сервис уже поддерживает следущий функционал: <a href=\"/wiki/Справка/ПоискКратчайшегоПути\" target=\"_blank\" style=\"text-decoration: underline\">Поиск пути алгоритмом Дейкстры</a>, <a href=\"/wiki/Справка/МатрицаСмежности\" target=\"_blank\" style=\"text-decoration: underline\">матрицу смежности</a>, <a href=\"/wiki/Справка/МатрицаИнцидентности\" target=\"_blank\" style=\"text-decoration: underline\">матрицу инцидентности</a>."; $g_lang["what_algorithm_we_have"] = "Сервис уже поддерживает следущий функционал: <a href=\"/wiki/Справка/ПоискКратчайшегоПути\" target=\"_blank\" style=\"text-decoration: underline\">Поиск пути алгоритмом Дейкстры</a>, <a href=\"/wiki/Справка/МатрицаСмежности\" target=\"_blank\" style=\"text-decoration: underline\">матрицу смежности</a>, <a href=\"/wiki/Справка/МатрицаИнцидентности\" target=\"_blank\" style=\"text-decoration: underline\">матрицу инцидентности</a>.";
$g_lang["has_eulerian_path"] = "Граф содержит Эйлерову цепь";
$g_lang["has_not_eulerian_path"] = "Граф не содержит Эйлерову цепь";
?> ?>

View File

@ -0,0 +1,92 @@
/**
* Find Eulerian Path.
*
*/
function FindEulerianPath(graph, app)
{
BaseAlgorithmEx.apply(this, arguments);
this.message = g_processing;
this.selectedObjects = [];
}
// inheritance.
FindEulerianPath.prototype = Object.create(BaseAlgorithmEx.prototype);
FindEulerianPath.prototype.getName = function(local)
{
return local == "ru" ? "Найти Эйлерову цепь" : "Find Eulerian path";
}
FindEulerianPath.prototype.getId = function()
{
return "OlegSh.FindEulerianPath";
}
// @return message for user.
FindEulerianPath.prototype.getMessage = function(local)
{
return this.message;
}
FindEulerianPath.prototype.result = function(resultCallback)
{
this.outResultCallback = function (result ) { resultCallback(result); };
self = this;
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
{
self.resultCallback(pathObjects, properties, results);
});
return true;
}
FindEulerianPath.prototype.resultCallback = function(pathObjects, properties, results)
{
result = results.length > 0 && results[0].value > 0 && results[0].type == 1;
var outputResult = {};
outputResult["version"] = 1;
this.message = result > 0 ? g_hasEulerianPath : g_hasNotEulerianPath;
if (result > 0)
{
var nodesPath = this.GetNodesPath(results, 1, results.length - 1);
outputResult["paths"] = [];
outputResult["paths"].push(nodesPath);
this.selectedObjects = [];
for (var i = 0; i < pathObjects.length; i++)
{
this.selectedObjects[pathObjects[i].id] = 1;
}
this.message = this.message + ": ";
for (var i = 0; i < nodesPath.length; i++)
{
this.message = this.message + this.graph.FindVertex(nodesPath[i]).mainText + ((i < nodesPath.length - 1) ? "&rArr;" : "");
}
}
this.outResultCallback(outputResult);
}
FindEulerianPath.prototype.getObjectSelectedGroup = function(object)
{
return (object.id in this.selectedObjects) ? this.selectedObjects[object.id] : 0;
}
FindEulerianPath.prototype.getPriority = function()
{
return -7;
}
// Factory for connected components.
function CreateFindEulerianPath(graph, app)
{
return new FindEulerianPath(graph, app)
}
// Gerister connected component.
RegisterAlgorithm (CreateFindEulerianPath);

View File

@ -52,6 +52,9 @@ var g_shortReport = "Short report";
var g_hasEulerianLoop = "Graph has Eulerian Loop"; var g_hasEulerianLoop = "Graph has Eulerian Loop";
var g_hasNotEulerianLoop = "Graph has not Eulerian Loop"; var g_hasNotEulerianLoop = "Graph has not Eulerian Loop";
var g_hasEulerianPath = "Graph has Eulerian Path";
var g_hasNotEulerianPath = "Graph has not Eulerian Path";
var g_processing = "Processing..."; var g_processing = "Processing...";
var g_customEnumVertex = "Custom"; var g_customEnumVertex = "Custom";
@ -139,4 +142,7 @@ function loadTexts()
g_vote = document.getElementById("voteText").innerHTML; g_vote = document.getElementById("voteText").innerHTML;
g_recommendAlgorithm = document.getElementById("recommend_algorithm").innerHTML; g_recommendAlgorithm = document.getElementById("recommend_algorithm").innerHTML;
g_hasEulerianPath = document.getElementById("hasEulerianPath").innerHTML;
g_hasNotEulerianPath = document.getElementById("hasNotEulerianPath").innerHTML;
} }

View File

@ -383,6 +383,9 @@
<p id="voteText" class="translation"><?= L('vote')?></p> <p id="voteText" class="translation"><?= L('vote')?></p>
<p id="recommend_algorithm" class="translation"><?= L('recommend_algorithm')?></p> <p id="recommend_algorithm" class="translation"><?= L('recommend_algorithm')?></p>
<p id="hasNotEulerianPath" class="translation"><?= L('has_not_eulerian_path')?></p>
<p id="hasEulerianPath" class="translation"><?= L('has_eulerian_path')?></p>
</section> </section>
<!-- <!--