mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 23:36:00 +00:00
Change spanning tree calculations. Ignore orientation of edges.
This commit is contained in:
parent
ca1733d7ff
commit
cf0970f5a1
@ -200,4 +200,8 @@
|
||||
$g_lang["radius_and_diameter_name"] = "Search graph radius and diameter";
|
||||
$g_lang["find_short_path_name"] = "Find shortest path using Dijkstra's algorithm";
|
||||
$g_lang["vertices_degree_name"] = "Calculate vertexes degree";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
||||
|
@ -199,4 +199,8 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit</a>";
|
||||
$g_lang["radius_and_diameter_name"] = "Search graph radius and diameter";
|
||||
$g_lang["find_short_path_name"] = "Find shortest path using Dijkstra's algorithm";
|
||||
$g_lang["vertices_degree_name"] = "Calculate vertices degree";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
||||
|
@ -199,4 +199,8 @@ Tenemos traducciones en griego 🇬🇷.</a> <a href=\"https://github.com/UnickS
|
||||
$g_lang["radius_and_diameter_name"] = "Buscar radio y diámetro del grafo";
|
||||
$g_lang["find_short_path_name"] = "Encontrar el camino más corto usando el algoritmo de Dijkstra";
|
||||
$g_lang["vertices_degree_name"] = "Calcular grado de los vértices";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
||||
|
@ -167,4 +167,8 @@
|
||||
$g_lang["radius_and_diameter_name"] = "Calcul du rayon et du diamètre du graphe";
|
||||
$g_lang["find_short_path_name"] = "Plus court chemin avec l'algorithme de Dijkstra";
|
||||
$g_lang["vertices_degree_name"] = "Calculer le degré des sommets";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
@ -164,4 +164,8 @@
|
||||
$g_lang["radius_and_diameter_name"] = "Zoek grafiek straal en diameter";
|
||||
$g_lang["find_short_path_name"] = "Kortstepad-algoritme (Dijkstra's algoritme)";
|
||||
$g_lang["vertices_degree_name"] = "Bereken hoekpunten graden";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
||||
|
@ -200,4 +200,8 @@
|
||||
$g_lang["radius_and_diameter_name"] = "Поиск радиуса и диаметра графа";
|
||||
$g_lang["find_short_path_name"] = "Поиск кратчайший путь алгоритмом Дейкстры";
|
||||
$g_lang["vertices_degree_name"] = "Рассчитать степень вершин";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Вес минимального оставного дерева равен ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "Мы игнорировали ориентацию дуг при рассчете.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Граф не является связным";
|
||||
?>
|
||||
|
@ -162,4 +162,7 @@
|
||||
$g_lang["find_short_path_name"] = "Hitta den kortaste vägen med Dijkstras algoritm";
|
||||
$g_lang["vertices_degree_name"] = "Кäkna graden av vertikaler";
|
||||
|
||||
$g_lang["min_spanning_tree_res_is"] = "Weight of minimum spanning tree is ";
|
||||
$g_lang["min_spanning_tree_ignore_direction"] = "We ignored edges direction for calculation.";
|
||||
$g_lang["min_spanning_tree_graph_not_connected"] = "Graph is disconnected";
|
||||
?>
|
||||
|
@ -172,6 +172,27 @@ Graph.prototype.FindEdgeMin = function(id1, id2)
|
||||
return res;
|
||||
}
|
||||
|
||||
Graph.prototype.FindEdgeMinIgnoreDirection = function(id1, id2)
|
||||
{
|
||||
var res = null;
|
||||
var minWeight = this.infinity;
|
||||
for (var i = 0; i < this.edges.length; i++)
|
||||
{
|
||||
var edge = this.edges[i];
|
||||
if ((edge.vertex1.id == id1 && edge.vertex2.id == id2)
|
||||
|| (edge.vertex1.id == id2 && edge.vertex2.id == id1))
|
||||
{
|
||||
if (edge.weight < minWeight)
|
||||
{
|
||||
res = edge;
|
||||
minWeight = edge.weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Graph.prototype.FindAllEdges = function(id1, id2)
|
||||
{
|
||||
var res = [];
|
||||
|
@ -27,11 +27,12 @@ MinimumSpanningTree.prototype.getMessage = function(local)
|
||||
{
|
||||
if (!this.isNotConneted )
|
||||
{
|
||||
return local == "ru" ? "Вес минимального оставного дерева равен " + this.MST : "Weight of minimum spanning tree is " + this.MST;
|
||||
return g_SpanningTreeResult + this.MST + ". " +
|
||||
(this.graph.hasDirectEdge() ? g_SpanningTreeIgnoreDir : "");
|
||||
}
|
||||
else
|
||||
{
|
||||
return local == "ru" ? "Граф не является связным" : "Graph is disconnected";
|
||||
return g_SpanningTreeNotConnected;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,9 +42,10 @@ MinimumSpanningTree.prototype.result = function(resultCallback)
|
||||
this.edges = [];
|
||||
this.isNotConneted = true;
|
||||
var tempVertexes = this.graph.vertices.slice();
|
||||
connectedVertex = getVertexToVertexArray(this.graph, false);
|
||||
connectedVertex = getVertexToVertexArray(this.graph, true);
|
||||
|
||||
if (!this.graph.hasDirectEdge())
|
||||
// We ignore orientation for this algorithm.
|
||||
//if (!this.graph.hasDirectEdge())
|
||||
{
|
||||
res = this.resultStartedFrom(tempVertexes[0], connectedVertex);
|
||||
this.isNotConneted = res.isNotConneted;
|
||||
@ -53,7 +55,7 @@ MinimumSpanningTree.prototype.result = function(resultCallback)
|
||||
this.edges = res.edges;
|
||||
}
|
||||
}
|
||||
else
|
||||
/*else
|
||||
{
|
||||
for (var i = 0; i < tempVertexes.length; i++)
|
||||
{
|
||||
@ -69,7 +71,7 @@ MinimumSpanningTree.prototype.result = function(resultCallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
var result = {};
|
||||
result["version"] = 1;
|
||||
@ -105,7 +107,8 @@ MinimumSpanningTree.prototype.resultStartedFrom = function(vertex, connectedVert
|
||||
for (j = 0; j < connectedVertex[element.id].length; j++)
|
||||
{
|
||||
var connectedElement = connectedVertex[element.id][j];
|
||||
var connectedEdge = this.graph.FindEdgeMin(element.id, connectedElement.id);
|
||||
var connectedEdge = this.graph.FindEdgeMinIgnoreDirection(element.id, connectedElement.id);
|
||||
|
||||
if (inTree.indexOf(connectedElement) < 0)
|
||||
{
|
||||
if (minEdge == null || minEdge.weight > connectedEdge.weight)
|
||||
|
@ -128,6 +128,9 @@ var g_modernGraphStyleName = "Visualisation based on weight";
|
||||
var g_RadiusAndDiameter = "Search graph radius and diameter";
|
||||
var g_findShortPathName = "Find shortest path using Dijkstra's algorithm";
|
||||
var g_VerticesDegreeName = "Calculate vertexes degree";
|
||||
var g_SpanningTreeResult = "Min Spanning Tree is";
|
||||
var g_SpanningTreeIgnoreDir = "We ignored edges direction for calculation";
|
||||
var g_SpanningTreeNotConnected = "Graph is not connected";
|
||||
|
||||
function loadTexts()
|
||||
{
|
||||
@ -264,4 +267,8 @@ function loadTexts()
|
||||
g_RadiusAndDiameter = document.getElementById("RadiusAndDiameter").innerHTML;
|
||||
g_findShortPathName = document.getElementById("findShortPathName").innerHTML;
|
||||
g_VerticesDegreeName = document.getElementById("VerticesDegreeName").innerHTML;
|
||||
|
||||
g_SpanningTreeResult = document.getElementById("MinSpanningTreeResult").innerHTML;
|
||||
g_SpanningTreeIgnoreDir = document.getElementById("MinSpanningIgnoreDir").innerHTML;
|
||||
g_SpanningTreeNotConnected = document.getElementById("MinSpanningNotConnected").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=31")?>" ></script>
|
||||
<script src="<?= Root("script/example.js?v=32")?>" ></script>
|
||||
</head>
|
||||
<!--
|
||||
<div class="pull-right">
|
||||
@ -602,6 +602,10 @@
|
||||
<p id="findShortPathName" class="translation"><?= L('find_short_path_name')?></p>
|
||||
<p id="VerticesDegreeName" class="translation"><?= L('vertices_degree_name')?></p>
|
||||
|
||||
<p id="MinSpanningTreeResult" class="translation"><?= L('min_spanning_tree_res_is')?></p>
|
||||
<p id="MinSpanningIgnoreDir" class="translation"><?= L('min_spanning_tree_ignore_direction')?></p>
|
||||
<p id="MinSpanningNotConnected" class="translation"><?= L('min_spanning_tree_graph_not_connected')?></p>
|
||||
|
||||
</section>
|
||||
<!--
|
||||
<script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user