mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-04-02 22:06:08 +00:00
Add Max Independent Set algorithm.
This commit is contained in:
@@ -28,7 +28,8 @@ function loadAsyncAlgorithms(onFinish) {
|
||||
"ModernGraphStyle.js",
|
||||
"RadiusAndDiameter.js",
|
||||
"ShortestPath.js",
|
||||
"VerticesDegree.js"];
|
||||
"VerticesDegree.js",
|
||||
"MaxIndependentSet.js"];
|
||||
|
||||
doIncludeAsync (pluginsList.map((plugin) => include ("model/plugins/" + plugin, modulDir)), onFinish);
|
||||
}
|
||||
|
||||
@@ -96,11 +96,6 @@ MaxClique.prototype.IsSupportNegativeWeight = function()
|
||||
return true;
|
||||
}
|
||||
|
||||
MaxClique.prototype.IsSupportNegativeWeight = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function CreateMaxClique(graph, app)
|
||||
{
|
||||
return new MaxClique(graph, app)
|
||||
|
||||
100
script/features/algorithms/model/plugins/MaxIndependentSet.js
Normal file
100
script/features/algorithms/model/plugins/MaxIndependentSet.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Find Eulerian Loop.
|
||||
*
|
||||
*/
|
||||
function MaxIndependentSet(graph, app)
|
||||
{
|
||||
BaseAlgorithmEx.apply(this, arguments);
|
||||
this.message = g_processing;
|
||||
this.selectedObjects = [];
|
||||
}
|
||||
|
||||
|
||||
// inheritance.
|
||||
MaxIndependentSet.prototype = Object.create(BaseAlgorithmEx.prototype);
|
||||
|
||||
|
||||
MaxIndependentSet.prototype.getName = function(local)
|
||||
{
|
||||
return g_MaxIndependentSet;
|
||||
}
|
||||
|
||||
MaxIndependentSet.prototype.getId = function()
|
||||
{
|
||||
return "AbdallaE.MaxIndependentSet";
|
||||
}
|
||||
|
||||
// @return message for user.
|
||||
MaxIndependentSet.prototype.getMessage = function(local)
|
||||
{
|
||||
return this.message;
|
||||
}
|
||||
|
||||
MaxIndependentSet.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("mis", [], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MaxIndependentSet.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_MaxIndependentSetNotFound;
|
||||
if (result > 0)
|
||||
{
|
||||
let size = results[0].value;
|
||||
this.message = g_MaxIndependentSetSizeIs + size;
|
||||
|
||||
this.selectedObjects = [];
|
||||
|
||||
this.message = this.message + g_MaxIndependentSetContains;
|
||||
|
||||
var vertexIndex = 0;
|
||||
for (var i = 1; i < results.length; i++)
|
||||
{
|
||||
let objectId = results[i].value;
|
||||
if (results[i].type == 8)
|
||||
{
|
||||
let mainText = this.graph.FindVertex(objectId).mainText;
|
||||
this.message = this.message + mainText + ((vertexIndex < size - 1) ? ", " : ".");
|
||||
vertexIndex++;
|
||||
}
|
||||
this.selectedObjects[objectId] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.outResultCallback(outputResult);
|
||||
}
|
||||
|
||||
MaxIndependentSet.prototype.getObjectSelectedGroup = function(object)
|
||||
{
|
||||
return (object.id in this.selectedObjects) ? this.selectedObjects[object.id] : 0;
|
||||
}
|
||||
|
||||
MaxIndependentSet.prototype.getPriority = function()
|
||||
{
|
||||
return -5;
|
||||
}
|
||||
|
||||
MaxIndependentSet.prototype.IsSupportNegativeWeight = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function CreateMaxIndependentSet(graph, app)
|
||||
{
|
||||
return new MaxIndependentSet(graph, app)
|
||||
}
|
||||
|
||||
// Gerister connected component.
|
||||
RegisterAlgorithm (CreateMaxIndependentSet);
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=98","/script/shared/point.js?v=98","/script/entities/edge/api/index.js?v=98","/script/entities/edge/model/BaseEdge.js?v=98","/script/entities/edge/model/EdgeModel.js?v=98","/script/entities/vertex/api/index.js?v=98","/script/entities/vertex/model/BaseVertex.js?v=98","/script/entities/vertex/model/VertexModel.js?v=98","/script/entities/graph/model/Graph.js?v=98",]);{let modulDir="pages/create_graph_by_edge_list/";doInclude([include("entities/graph/api/index.js")]);}
|
||||
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=99","/script/shared/point.js?v=99","/script/entities/edge/api/index.js?v=99","/script/entities/edge/model/BaseEdge.js?v=99","/script/entities/edge/model/EdgeModel.js?v=99","/script/entities/vertex/api/index.js?v=99","/script/entities/vertex/model/BaseVertex.js?v=99","/script/entities/vertex/model/VertexModel.js?v=99","/script/entities/graph/model/Graph.js?v=99",]);{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()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=98","/script/shared/point.js?v=98","/script/entities/edge/api/index.js?v=98","/script/entities/edge/model/BaseEdge.js?v=98","/script/entities/edge/model/EdgeModel.js?v=98","/script/entities/vertex/api/index.js?v=98","/script/entities/vertex/model/BaseVertex.js?v=98","/script/entities/vertex/model/VertexModel.js?v=98","/script/entities/graph/model/Graph.js?v=98",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js")]);}
|
||||
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=99","/script/shared/point.js?v=99","/script/entities/edge/api/index.js?v=99","/script/entities/edge/model/BaseEdge.js?v=99","/script/entities/edge/model/EdgeModel.js?v=99","/script/entities/vertex/api/index.js?v=99","/script/entities/vertex/model/BaseVertex.js?v=99","/script/entities/vertex/model/VertexModel.js?v=99","/script/entities/graph/model/Graph.js?v=99",]);{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()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=98","/script/shared/point.js?v=98","/script/entities/edge/api/index.js?v=98","/script/entities/edge/model/BaseEdge.js?v=98","/script/entities/edge/model/EdgeModel.js?v=98","/script/entities/vertex/api/index.js?v=98","/script/entities/vertex/model/BaseVertex.js?v=98","/script/entities/vertex/model/VertexModel.js?v=98","/script/entities/graph/model/Graph.js?v=98","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=98","/script/pages/create_graph_by_matrix/model/main.js?v=98",]);{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=99","/script/shared/point.js?v=99","/script/entities/edge/api/index.js?v=99","/script/entities/edge/model/BaseEdge.js?v=99","/script/entities/edge/model/EdgeModel.js?v=99","/script/entities/vertex/api/index.js?v=99","/script/entities/vertex/model/BaseVertex.js?v=99","/script/entities/vertex/model/VertexModel.js?v=99","/script/entities/graph/model/Graph.js?v=99","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=99","/script/pages/create_graph_by_matrix/model/main.js?v=99",]);{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
@@ -213,6 +213,11 @@ var g_selectGraphToLoad = "Would you like to load original graph or autosaved gr
|
||||
|
||||
var g_vertexNamePlaceHolder = "vertex name";
|
||||
|
||||
var g_MaxIndependentSet = "Max Independent Set";
|
||||
var g_MaxIndependentSetNotFound = "Max Independent Set is not found";
|
||||
var g_MaxIndependentSetSizeIs = "Max Independent Set size is ";
|
||||
var g_MaxIndependentSetContains = ". Set contains these vertecies: ";
|
||||
|
||||
function loadTexts()
|
||||
{
|
||||
g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML;
|
||||
@@ -433,4 +438,9 @@ function loadTexts()
|
||||
g_autoSavedGraph = document.getElementById("autoSavedGraph").innerHTML;
|
||||
g_selectGraphToLoad = document.getElementById("selectGraphToLoad").innerHTML;
|
||||
g_vertexNamePlaceHolder = document.getElementById("vertexNamePlaceHolder").innerHTML;
|
||||
|
||||
g_MaxIndependentSet = document.getElementById("maxIndependentSet").innerHTML;
|
||||
g_MaxIndependentSetNotFound = document.getElementById("maxIndependentSetNotFound").innerHTML;
|
||||
g_MaxIndependentSetSizeIs = document.getElementById("maxIndependentSetSizeIs").innerHTML;
|
||||
g_MaxIndependentSetContains = document.getElementById("maxIndependentSetContains").innerHTML;
|
||||
}
|
||||
Reference in New Issue
Block a user