Added find all patches algorithm.

This commit is contained in:
Oleg Sh 2021-09-29 21:10:14 +02:00
parent 947a3072ba
commit dc6c90991e
14 changed files with 319 additions and 3 deletions

View File

@ -221,4 +221,13 @@
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -259,4 +259,13 @@
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -258,4 +258,13 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit</a>";
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -258,4 +258,13 @@ Tenemos traducciones en griego 🇬🇷.</a> <a href=\"https://github.com/UnickS
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -226,4 +226,13 @@
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -222,5 +222,14 @@
$g_lang['edge_width'] = "Edge width";
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -224,4 +224,13 @@
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -259,4 +259,13 @@
$g_lang['selected_index'] = "Группа выделения";
$g_lang['all'] = "Все";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Поиск всех путей";
$g_lang['number_of_pathes_from'] = "Количество путей из ";
$g_lang['to'] = " в ";
$g_lang['are'] = " равно ";
$g_lang['path_n'] = "Путь №";
$g_lang['selected_finish_vertex'] = "Выделите конечную вершину";
$g_lang['selected_start_vertex'] = "Выделите начальную вершину";
?>

View File

@ -220,4 +220,13 @@
$g_lang['selected_index'] = "Selection group";
$g_lang['all'] = "All";
//FindAllPatches.js
$g_lang['find_all_pathes'] = "Find all pathes";
$g_lang['number_of_pathes_from'] = "Number of pathes from ";
$g_lang['to'] = " to ";
$g_lang['are'] = " are ";
$g_lang['path_n'] = "Path #";
$g_lang['selected_finish_vertex'] = "Select finish vertex";
$g_lang['selected_start_vertex'] = "Select start vertex";
?>

View File

@ -0,0 +1,209 @@
/**
* Find short path.
*
*/
function FindAllPathes(graph, app)
{
BaseAlgorithmEx.apply(this, arguments);
this.message = g_selectStartVertex;
this.selectedObjects = {};
this.foundSubGraphs = {};
this.nSubgraphIndex = 0;
this.nSubGraphCount = 0;
}
// inheritance.
FindAllPathes.prototype = Object.create(BaseAlgorithmEx.prototype);
// First selected.
FindAllPathes.prototype.firstObject = null;
// Second selected.
FindAllPathes.prototype.secondObject = null;
// Path
FindAllPathes.prototype.pathObjects = null;
// Infinity
FindAllPathes.prototype.infinityValue = 1E9 - 1;
FindAllPathes.prototype.getName = function(local)
{
return g_findAllPathes;
}
FindAllPathes.prototype.getId = function()
{
return "Abin.FindAllPathes";
}
// @return message for user.
FindAllPathes.prototype.getMessage = function(local)
{
return this.message;
}
FindAllPathes.prototype.result = function(resultCallback)
{
if (this.firstObject && this.secondObject)
{
this.outResultCallback = function (result ) { resultCallback(result); };
self = this;
this.CalculateAlgorithm("prnpaths=cgiInput&start=" + this.firstObject.id + "&finish=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
{
self.resultCallback(pathObjects, properties, results);
});
}
return null;
}
FindAllPathes.prototype.setResultMessage = function()
{
if (this.nSubGraphCount > 0)
{
this.message = g_numberOfPathesFrom + this.firstObject.mainText +
g_to + this.secondObject.mainText + g_are +
this.nSubGraphCount + " <select style=\"float:right\" id=\"enumSubgraphs\"></select>";
}
else
{
this.message = g_pathNotExists;
}
}
FindAllPathes.prototype.resultCallback = function(pathObjects, properties, results)
{
var outputResult = {};
outputResult["version"] = 1;
outputResult["minPath"] = true;
this.pathObjects = pathObjects;
this.properties = properties;
var bFound = results.length > 0 && results[0].value < this.infinityValue && (results[0].type == 1 || results[0].type == 2);
if (bFound)
{
this.nSubGraphCount = results.length > 0 && results[0].type == 1 ? results[0].value : 0;
this.setResultMessage();
this.foundSubGraphs = {};
for (var i = 0; i < this.nSubGraphCount; i++)
{
this.foundSubGraphs[i] = {};
}
var subGraphIndex = 0;
var prevNodeId = -1;
for (var i = 0; i < results.length; i++)
{
if (results[i].type == 6)
{
subGraphIndex++;
prevNodeId = -1;
}
if (results[i].type == 4)
{
var nodeId = parseInt(results[i].value);
var index = subGraphIndex;
var subgGraph = this.foundSubGraphs[index];
subgGraph[nodeId] = true;
if (prevNodeId >= 0)
{
var edgeObject = this.graph.FindEdgeMin(prevNodeId, nodeId);
subgGraph[edgeObject.id] = true;
}
prevNodeId = nodeId;
}
}
}
else
{
this.secondObject = null;
this.firstObject = null;
this.message = g_pathNotExists;
}
this.outResultCallback(outputResult);
}
FindAllPathes.prototype.messageWasChanged = function()
{
var self = this;
if ($('#enumSubgraphs'))
{
for (var i = 0; i < this.nSubGraphCount; i++)
{
$('#enumSubgraphs').append("<option value=\"" + i + "\"" + (self.nSubgraphIndex==i ? "selected": "") + ">" +
g_pathN + (i + 1) +
"</option>");
}
$('#enumSubgraphs').change(function () {
self.nSubgraphIndex = $('#enumSubgraphs').val();
self.app.redrawGraph();
self.setResultMessage();
});
}
}
FindAllPathes.prototype.selectVertex = function(vertex)
{
this.pathObjects = null;
this.shortDist = null;
if (this.firstObject)
{
this.message = g_processing;
this.secondObject = vertex;
this.selectedObjects = [];
}
else
{
this.firstObject = vertex;
this.secondObject = null;
this.selectedObjects = {};
this.message = g_selectFinishVertex;
}
return true;
}
FindAllPathes.prototype.deselectAll = function()
{
this.firstObject = null;
this.secondObject = null;
this.selectedObjects = {};
this.foundSubGraphs = {};
this.nSubgraphIndex = 0;
this.nSubGraphCount = 0;
this.message = g_selectStartVertex;
return true;
}
FindAllPathes.prototype.instance = function()
{
return false;
}
FindAllPathes.prototype.getObjectSelectedGroup = function(object)
{
return (this.nSubgraphIndex in this.foundSubGraphs && object.id in this.foundSubGraphs[this.nSubgraphIndex]) ? 1 :
(object.id in this.selectedObjects) ? this.selectedObjects[object.id] : ((object == this.firstObject || object == object.secondObject) ? 1 : 0);
}
FindAllPathes.prototype.getPriority = function()
{
return -9.4;
}
// Factory for connected components.
function CreateFindAllPathes(graph, app)
{
return new FindAllPathes(graph, app)
}
// Gerister connected component.
RegisterAlgorithm (CreateFindAllPathes);

View File

@ -146,7 +146,7 @@ MinimumSpanningTree.prototype.getObjectSelectedGroup = function(object)
MinimumSpanningTree.prototype.getPriority = function()
{
return -9.5;
return -9.3;
}
// Algorithm support multi graph

View File

@ -170,6 +170,15 @@ var g_selectedEdgeStyle = "Selected Edge Style";
var g_commonVertexStyle = "Common Vertex Style";
var g_selectedVertexStyle = "Selected Vertex Style";
// FindAllPatches.js
var g_findAllPathes = "Find all pathes";
var g_numberOfPathesFrom = "Number of pathes from "
var g_to = " to ";
var g_are = " are ";
var g_pathN = "Path #";
var g_selectFinishVertex = "Select finish vertex";
var g_selectStartVertex = "Select start vertex";
function loadTexts()
{
g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML;
@ -347,4 +356,13 @@ function loadTexts()
g_selectedEdgeStyle = document.getElementById("SelectedEdgeStyleText").innerHTML;
g_commonVertexStyle = document.getElementById("CommonVertexStyleText").innerHTML;
g_selectedVertexStyle = document.getElementById("SelectedVertexStyleText").innerHTML;
// FindAllPatches.js
g_findAllPathes = document.getElementById("FindAllPathes").innerHTML;
g_numberOfPathesFrom = document.getElementById("NumberOfPathesFrom").innerHTML;
g_to = document.getElementById("To").innerHTML;
g_are = document.getElementById("Are").innerHTML;
g_pathN = document.getElementById("PathN").innerHTML;
g_selectFinishVertex = document.getElementById("SelectFinishVertex").innerHTML;
g_selectStartVertex = document.getElementById("SelectStartVertex").innerHTML;
}

View File

@ -10,7 +10,7 @@
<script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script>
<script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script>
<script src="<?= Root("script/example.js?v=48")?>" ></script>
<script src="<?= Root("script/example.js?v=49")?>" ></script>
</head>
<!--
<div class="pull-right">
@ -772,6 +772,14 @@
<p id="CommonVertexStyleText" class="translation"><?= L('common_vertex_style')?></p>
<p id="SelectedVertexStyleText" class="translation"><?= L('selected_vertex_style')?></p>
<!-- FindAllPatches.js -->
<p id="FindAllPathes" class="translation"><?= L('find_all_pathes')?></p>
<p id="NumberOfPathesFrom" class="translation"><?= L('number_of_pathes_from')?></p>
<p id="To" class="translation"><?= L('to')?></p>
<p id="Are" class="translation"><?= L('are')?></p>
<p id="PathN" class="translation"><?= L('path_n')?></p>
<p id="SelectFinishVertex" class="translation"><?= L('selected_finish_vertex')?></p>
<p id="SelectStartVertex" class="translation"><?= L('selected_start_vertex')?></p>
</section>
<!--
<script>