mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-08-15 23:56:19 +00:00
Add algorithm to find all shortest paths from one vertex to another.
This commit is contained in:
parent
dc6c90991e
commit
63a0cef6cc
Binary file not shown.
@ -230,4 +230,9 @@
|
||||
$g_lang['path_n'] = "Path #";
|
||||
$g_lang['selected_finish_vertex'] = "Select finish vertex";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -268,4 +268,9 @@
|
||||
$g_lang['path_n'] = "Path #";
|
||||
$g_lang['selected_finish_vertex'] = "Select finish vertex";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -267,4 +267,9 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit</a>";
|
||||
$g_lang['path_n'] = "Path #";
|
||||
$g_lang['selected_finish_vertex'] = "Select finish vertex";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -266,5 +266,10 @@ Tenemos traducciones en griego 🇬🇷.</a> <a href=\"https://github.com/UnickS
|
||||
$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";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -234,5 +234,10 @@
|
||||
$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";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
@ -231,5 +231,10 @@
|
||||
$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";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -232,5 +232,10 @@
|
||||
$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";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
@ -268,4 +268,9 @@
|
||||
$g_lang['path_n'] = "Путь №";
|
||||
$g_lang['selected_finish_vertex'] = "Выделите конечную вершину";
|
||||
$g_lang['selected_start_vertex'] = "Выделите начальную вершину";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Найти все кратчайшие пути от вершины";
|
||||
$g_lang['distance_from'] = "Расстояние от ";
|
||||
$g_lang['path_to'] = "Путь до ";
|
||||
?>
|
||||
|
@ -229,4 +229,9 @@
|
||||
$g_lang['path_n'] = "Path #";
|
||||
$g_lang['selected_finish_vertex'] = "Select finish vertex";
|
||||
$g_lang['selected_start_vertex'] = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
$g_lang['find_all_paths_from_vertex'] = "Find all shortest paths from vertex";
|
||||
$g_lang['distance_from'] = "Distance from ";
|
||||
$g_lang['path_to'] = "Path to ";
|
||||
?>
|
||||
|
212
script/plugins/FindShortPatchsFromOne.js
Normal file
212
script/plugins/FindShortPatchsFromOne.js
Normal file
@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Find short path.
|
||||
*
|
||||
*/
|
||||
function FindShortPatchsFromOne(graph, app)
|
||||
{
|
||||
BaseAlgorithmEx.apply(this, arguments);
|
||||
this.message = g_selectStartVertex;
|
||||
this.selectedObjects = {};
|
||||
this.foundSubGraphs = {};
|
||||
this.nSubgraphIndex = 0;
|
||||
this.nSubGraphCount = 0;
|
||||
this.lastVertexInPath = [];
|
||||
this.lengthOfPath = [];
|
||||
}
|
||||
|
||||
|
||||
// inheritance.
|
||||
FindShortPatchsFromOne.prototype = Object.create(BaseAlgorithmEx.prototype);
|
||||
// First selected.
|
||||
FindShortPatchsFromOne.prototype.firstObject = null;
|
||||
// Path
|
||||
FindShortPatchsFromOne.prototype.pathObjects = null;
|
||||
// Infinity
|
||||
FindShortPatchsFromOne.prototype.infinityValue = 1E9 - 1;
|
||||
|
||||
FindShortPatchsFromOne.prototype.getName = function(local)
|
||||
{
|
||||
return g_findAllPathesFromVertex;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.getId = function()
|
||||
{
|
||||
return "Abin.FindShortPatchsFromOne";
|
||||
}
|
||||
|
||||
// @return message for user.
|
||||
FindShortPatchsFromOne.prototype.getMessage = function(local)
|
||||
{
|
||||
return this.message;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.result = function(resultCallback)
|
||||
{
|
||||
if (this.firstObject)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("blf=cgiInput&start=" + this.firstObject.id + "&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.setResultMessage = function()
|
||||
{
|
||||
if (this.nSubGraphCount > 0)
|
||||
{
|
||||
this.message = g_distanceFrom + this.firstObject.mainText +
|
||||
g_to + this.lastVertexInPath[this.nSubgraphIndex] + g_are +
|
||||
this.lengthOfPath[this.nSubgraphIndex] + " <select style=\"float:right\" id=\"enumSubgraphs\"></select>";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.message = g_pathNotExists;
|
||||
}
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.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.foundSubGraphs = {};
|
||||
for (var i = 0; i < this.nSubGraphCount; i++)
|
||||
{
|
||||
this.foundSubGraphs[i] = {};
|
||||
this.lengthOfPath.push(0);
|
||||
this.lastVertexInPath.push(0);
|
||||
}
|
||||
|
||||
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;
|
||||
var vertex = this.graph.FindVertex(nodeId);
|
||||
this.lastVertexInPath[index] = vertex != null ? vertex.mainText : "";
|
||||
|
||||
if (prevNodeId >= 0)
|
||||
{
|
||||
var edgeObject = this.graph.FindEdgeMin(prevNodeId, nodeId);
|
||||
subgGraph[edgeObject.id] = true;
|
||||
this.lengthOfPath[index] += edgeObject.GetWeight();
|
||||
}
|
||||
prevNodeId = nodeId;
|
||||
}
|
||||
}
|
||||
|
||||
this.setResultMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.firstObject = null;
|
||||
this.message = g_pathNotExists;
|
||||
}
|
||||
|
||||
this.outResultCallback(outputResult);
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.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_pathTo + this.lastVertexInPath[i] +
|
||||
"</option>");
|
||||
}
|
||||
|
||||
$('#enumSubgraphs').change(function () {
|
||||
self.nSubgraphIndex = $('#enumSubgraphs').val();
|
||||
self.app.redrawGraph();
|
||||
self.setResultMessage();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.selectVertex = function(vertex)
|
||||
{
|
||||
this.pathObjects = null;
|
||||
this.shortDist = null;
|
||||
|
||||
this.deselectAll();
|
||||
|
||||
this.firstObject = vertex;
|
||||
this.selectedObjects = {};
|
||||
this.message = "Processing...";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.deselectAll = function()
|
||||
{
|
||||
this.firstObject = null;
|
||||
this.selectedObjects = {};
|
||||
this.foundSubGraphs = {};
|
||||
this.nSubgraphIndex = 0;
|
||||
this.nSubGraphCount = 0;
|
||||
this.message = g_selectStartVertex;
|
||||
this.lastVertexInPath = [];
|
||||
this.lengthOfPath = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.instance = function()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.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);
|
||||
}
|
||||
|
||||
FindShortPatchsFromOne.prototype.getPriority = function()
|
||||
{
|
||||
return -9.4;
|
||||
}
|
||||
|
||||
// Algorithm support multi graph
|
||||
FindShortPatchsFromOne.prototype.IsSupportMultiGraph = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factory for connected components.
|
||||
function CreateFindShortPatchsFromOne(graph, app)
|
||||
{
|
||||
return new FindShortPatchsFromOne(graph, app)
|
||||
}
|
||||
|
||||
// Gerister connected component.
|
||||
RegisterAlgorithm (CreateFindShortPatchsFromOne);
|
@ -179,6 +179,11 @@ var g_pathN = "Path #";
|
||||
var g_selectFinishVertex = "Select finish vertex";
|
||||
var g_selectStartVertex = "Select start vertex";
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
var g_findAllPathesFromVertex = "Find all shortest paths from vertex";
|
||||
var g_distanceFrom = "Distance from ";
|
||||
var g_pathTo = "Path to ";
|
||||
|
||||
function loadTexts()
|
||||
{
|
||||
g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML;
|
||||
@ -365,4 +370,9 @@ function loadTexts()
|
||||
g_pathN = document.getElementById("PathN").innerHTML;
|
||||
g_selectFinishVertex = document.getElementById("SelectFinishVertex").innerHTML;
|
||||
g_selectStartVertex = document.getElementById("SelectStartVertex").innerHTML;
|
||||
|
||||
// FindShortPatchsFromOne.js
|
||||
g_findAllPathesFromVertex = document.getElementById("findAllPathsFromVertex").innerHTML;
|
||||
g_distanceFrom = document.getElementById("distanceFrom").innerHTML;
|
||||
g_pathTo = document.getElementById("pathTo").innerHTML;
|
||||
}
|
||||
|
@ -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=49")?>" ></script>
|
||||
<script src="<?= Root("script/example.js?v=50")?>" ></script>
|
||||
</head>
|
||||
<!--
|
||||
<div class="pull-right">
|
||||
@ -177,7 +177,7 @@
|
||||
</section>
|
||||
|
||||
|
||||
<?php elseif (L('current_language') == "ru"): ?>
|
||||
<?php elseif (L('current_language') == "ru" && false): ?>
|
||||
|
||||
<section style="height:32px;text-align: center;" id="bottom_info" class="hidden-phone">
|
||||
<a href="https://beget.com/?id=215303" target="_blank"><img src="https://cp.beget.com/promo_data/static/static468x60_3.png" border="0"></a>
|
||||
@ -780,6 +780,10 @@
|
||||
<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>
|
||||
|
||||
<p id="findAllPathsFromVertex" class="translation"><?= L('find_all_paths_from_vertex')?></p>
|
||||
<p id="distanceFrom" class="translation"><?= L('distance_from')?></p>
|
||||
<p id="pathTo" class="translation"><?= L('path_to')?></p>
|
||||
</section>
|
||||
<!--
|
||||
<script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user