Update algorithm limits and error handling

This commit is contained in:
Oleg Sh
2025-10-04 19:00:08 +02:00
parent e057a2d5ab
commit 46c05d94fd
31 changed files with 225 additions and 29 deletions

View File

@@ -152,6 +152,17 @@ BaseAlgorithm.prototype.IsSupportNegativeWeight = function()
return false;
}
// Limit by number of vertexes for the algorithm.
BaseAlgorithm.prototype.MaxGraphSize = function()
{
return 1000;
}
BaseAlgorithm.prototype.MaxEgdeNumber = function()
{
return 10000;
}
/**
* Default handler.
* Select using mouse, drag.
@@ -218,20 +229,16 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(algorithmName, otherPara
var $xml = $( xmlDoc );
$results = $xml.find( "result" );
$results.each(function(){
$values = $(this).find( "value" );
$values.each(function(){
var type = $(this).attr('type');
var value = $(this).text();
var res = {};
res.type = type;
res.value = value;
result.push(res);
});
});
// Use native because jqueary hangs for results with 10000+ nodes.
let values = $results[0].getElementsByTagName("value");
for (var j = 0; j < values.length; j++)
{
var type = values[j].getAttribute('type');
var value = values[j].textContent;
result.push({ type: type, value: value });
}
$nodes = $xml.find( "node" );
$nodes.each(function(){

View File

@@ -35,6 +35,16 @@ FindEulerianLoop.prototype.getCategory = function()
return 1;
}
FindEulerianLoop.prototype.MaxGraphSize = function()
{
return 50;
}
FindEulerianLoop.prototype.MaxEgdeNumber = function()
{
return 500;
}
FindEulerianLoop.prototype.result = function(resultCallback)
{
this.outResultCallback = function (result ) { resultCallback(result); };

View File

@@ -35,6 +35,16 @@ FindEulerianPath.prototype.getCategory = function()
return 1;
}
FindEulerianPath.prototype.MaxGraphSize = function()
{
return 50;
}
FindEulerianPath.prototype.MaxEgdeNumber = function()
{
return 500;
}
FindEulerianPath.prototype.result = function(resultCallback)
{
this.outResultCallback = function (result ) { resultCallback(result); };

View File

@@ -46,6 +46,16 @@ FindAllPathes.prototype.getCategory = function()
return 1;
}
FindAllPathes.prototype.MaxGraphSize = function()
{
return 50;
}
FindAllPathes.prototype.MaxEgdeNumber = function()
{
return 40;
}
FindAllPathes.prototype.result = function(resultCallback)
{
if (this.firstObject && this.secondObject)

View File

@@ -47,6 +47,16 @@ FindAllShortestPathes.prototype.getCategory = function()
return 1;
}
FindAllShortestPathes.prototype.MaxGraphSize = function()
{
return 50;
}
FindAllShortestPathes.prototype.MaxEgdeNumber = function()
{
return 40;
}
FindAllShortestPathes.prototype.result = function(resultCallback)
{
if (this.firstObject && this.secondObject)

View File

@@ -47,6 +47,16 @@ FindLongestPath.prototype.getCategory = function()
return 1;
}
FindLongestPath.prototype.MaxGraphSize = function()
{
return 50;
}
FindLongestPath.prototype.MaxEgdeNumber = function()
{
return 40;
}
FindLongestPath.prototype.result = function(resultCallback)
{
if (this.firstObject && this.secondObject)

View File

@@ -35,6 +35,16 @@ FindHamiltonianLoop.prototype.getCategory = function()
return 1;
}
FindHamiltonianLoop.prototype.MaxGraphSize = function()
{
return 30;
}
FindHamiltonianLoop.prototype.MaxEgdeNumber = function()
{
return 450;
}
FindHamiltonianLoop.prototype.result = function(resultCallback)
{
this.outResultCallback = function (result ) { resultCallback(result); };

View File

@@ -35,6 +35,16 @@ FindHamiltonianPath.prototype.getCategory = function()
return 1;
}
FindHamiltonianPath.prototype.MaxGraphSize = function()
{
return 30;
}
FindHamiltonianPath.prototype.MaxEgdeNumber = function()
{
return 450;
}
FindHamiltonianPath.prototype.result = function(resultCallback)
{
this.outResultCallback = function (result ) { resultCallback(result); };

View File

@@ -86,6 +86,16 @@ MaxIndependentSet.prototype.getPriority = function()
return -5;
}
MaxIndependentSet.prototype.MaxGraphSize = function()
{
return 100;
}
MaxIndependentSet.prototype.MaxEgdeNumber = function()
{
return 4000;
}
MaxIndependentSet.prototype.IsSupportNegativeWeight = function()
{
return true;

View File

@@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=101","/script/shared/point.js?v=101","/script/entities/edge/api/index.js?v=101","/script/entities/edge/model/BaseEdge.js?v=101","/script/entities/edge/model/EdgeModel.js?v=101","/script/entities/vertex/api/index.js?v=101","/script/entities/vertex/model/BaseVertex.js?v=101","/script/entities/vertex/model/VertexModel.js?v=101","/script/entities/graph/model/Graph.js?v=101",]);{let modulDir="pages/create_graph_by_edge_list/";doInclude([include("entities/graph/api/index.js")]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=102","/script/shared/point.js?v=102","/script/entities/edge/api/index.js?v=102","/script/entities/edge/model/BaseEdge.js?v=102","/script/entities/edge/model/EdgeModel.js?v=102","/script/entities/vertex/api/index.js?v=102","/script/entities/vertex/model/BaseVertex.js?v=102","/script/entities/vertex/model/VertexModel.js?v=102","/script/entities/graph/model/Graph.js?v=102",]);{let modulDir="pages/create_graph_by_edge_list/";doInclude([include("entities/graph/api/index.js")]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

View File

@@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=101","/script/shared/point.js?v=101","/script/entities/edge/api/index.js?v=101","/script/entities/edge/model/BaseEdge.js?v=101","/script/entities/edge/model/EdgeModel.js?v=101","/script/entities/vertex/api/index.js?v=101","/script/entities/vertex/model/BaseVertex.js?v=101","/script/entities/vertex/model/VertexModel.js?v=101","/script/entities/graph/model/Graph.js?v=101",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js")]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=102","/script/shared/point.js?v=102","/script/entities/edge/api/index.js?v=102","/script/entities/edge/model/BaseEdge.js?v=102","/script/entities/edge/model/EdgeModel.js?v=102","/script/entities/vertex/api/index.js?v=102","/script/entities/vertex/model/BaseVertex.js?v=102","/script/entities/vertex/model/VertexModel.js?v=102","/script/entities/graph/model/Graph.js?v=102",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js")]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

View File

@@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=101","/script/shared/point.js?v=101","/script/entities/edge/api/index.js?v=101","/script/entities/edge/model/BaseEdge.js?v=101","/script/entities/edge/model/EdgeModel.js?v=101","/script/entities/vertex/api/index.js?v=101","/script/entities/vertex/model/BaseVertex.js?v=101","/script/entities/vertex/model/VertexModel.js?v=101","/script/entities/graph/model/Graph.js?v=101","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=101","/script/pages/create_graph_by_matrix/model/main.js?v=101",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js"),include("model/createByMatrixMain.js",modulDir),include("model/main.js",modulDir)]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=102","/script/shared/point.js?v=102","/script/entities/edge/api/index.js?v=102","/script/entities/edge/model/BaseEdge.js?v=102","/script/entities/edge/model/EdgeModel.js?v=102","/script/entities/vertex/api/index.js?v=102","/script/entities/vertex/model/BaseVertex.js?v=102","/script/entities/vertex/model/VertexModel.js?v=102","/script/entities/graph/model/Graph.js?v=102","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=102","/script/pages/create_graph_by_matrix/model/main.js?v=102",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js"),include("model/createByMatrixMain.js",modulDir),include("model/main.js",modulDir)]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

File diff suppressed because one or more lines are too long

View File

@@ -222,6 +222,8 @@ var g_FindAllShortestPathes = "Find all shortest paths";
var g_numberOfShortestPathesFrom = "Number of shortest paths from ";
var g_length_is = "length is ";
var g_error = "Error";
function loadTexts()
{
g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML;
@@ -451,4 +453,6 @@ function loadTexts()
g_FindAllShortestPathes = document.getElementById("findAllShortestPathes").innerHTML;
g_numberOfShortestPathesFrom = document.getElementById("numberOfShortestPathesFrom").innerHTML;
g_length_is = document.getElementById("lengthIs").innerHTML;
g_error = document.getElementById("error").innerHTML;
}

View File

@@ -687,9 +687,41 @@ Editor.prototype.createAlgorithmMenu = function()
{
e["closeThisMenu"] = true;
userAction(this.id);
self.restButtons ("");
self.application.SetHandler(new AlgorithmGraphHandler(self.application,
g_Algorithms[g_AlgorithmIds.indexOf(this.id)](self.application.graph, self.application)));
let algorithm = g_Algorithms[g_AlgorithmIds.indexOf(this.id)](self.application.graph, self.application);
let is_vertex_fits_to_limits = self.application.graph.vertices.length <= algorithm.MaxGraphSize()
let is_edge_fits_to_limits = self.application.graph.edges.length <= algorithm.MaxEgdeNumber();
if (is_vertex_fits_to_limits && is_edge_fits_to_limits)
{
self.restButtons ("");
self.application.SetHandler(new AlgorithmGraphHandler(self.application, algorithm));
}
else
{
let warring_cond_begin = "<span class=\"text-danger\">";
let warring_cond_end = "</span>";
$("#current_graph_size").html((is_vertex_fits_to_limits ? "" : warring_cond_begin ) + self.application.graph.vertices.length
+ (is_vertex_fits_to_limits ? "" : warring_cond_end ));
$("#current_edge_number").html((is_edge_fits_to_limits ? "" : warring_cond_begin ) + self.application.graph.edges.length
+ (is_edge_fits_to_limits ? "" : warring_cond_end ));
$("#algorithm_max_limit").html(algorithm.MaxGraphSize());
$("#algorithm_edge_limit").html(algorithm.MaxEgdeNumber());
var dialogButtons = {};
dialogButtons[g_close] = function() {
$( this ).dialog( "close" );
};
// Show error message that graph is too large.
$("#graphMaxVerexLimit").dialog({
resizable: false,
title: g_error,
width: 400,
modal: true,
dialogClass: 'EdgeDialog',
buttons: dialogButtons,
});
}
}
var eventData = {};