From 8e8167bceb119b11573d544b5c38a7b0cfa39421 Mon Sep 17 00:00:00 2001 From: Unick Soft Date: Sun, 21 Jun 2020 21:57:15 +0200 Subject: [PATCH] Added sandbox to algorithm creating. --- .htaccess | 2 +- sandbox/NewAlgorithm.js | 103 +++++++ sandbox/index.html | 666 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 770 insertions(+), 1 deletion(-) create mode 100644 sandbox/NewAlgorithm.js create mode 100644 sandbox/index.html diff --git a/.htaccess b/.htaccess index 5b38215..76d9fe7 100755 --- a/.htaccess +++ b/.htaccess @@ -9,6 +9,6 @@ RewriteBase / RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] -RewriteCond $1 !^(index\.php|script/merge\.php|script/*.|robots\.txt|favicon\.ico|sitemap\.xml|i/.*|tmp/.*|upl/.*|lib/ckeditor4/.*|cgi-bin/*.|wiki/*.|en/wiki/*.|google53bafd5cff611af3\.html|script/plugins/*.|awstats/*.) +RewriteCond $1 !^(index\.php|script/merge\.php|script/*.|robots\.txt|favicon\.ico|sitemap\.xml|i/.*|tmp/.*|upl/.*|lib/ckeditor4/.*|cgi-bin/*.|wiki/*.|en/wiki/*.|google53bafd5cff611af3\.html|script/plugins/*.|awstats/*.|sandbox/*.) RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA] diff --git a/sandbox/NewAlgorithm.js b/sandbox/NewAlgorithm.js new file mode 100644 index 0000000..8756f7b --- /dev/null +++ b/sandbox/NewAlgorithm.js @@ -0,0 +1,103 @@ +/** + * Find short path. + * + */ +function NewAlgorithm(graph, app) +{ + BaseAlgorithm.apply(this, arguments); + this.message = "Please select vertex"; + this.selectObject = null; + this.neighbours = []; +} + +// inheritance. +NewAlgorithm.prototype = Object.create(BaseAlgorithm.prototype); + +NewAlgorithm.prototype.getName = function(local) +{ + return "New algorithm"; +} + +NewAlgorithm.prototype.getId = function() +{ + return "Unknown.Unknown"; +} + +// @return message for user. +NewAlgorithm.prototype.getMessage = function(local) +{ + return this.message; +} + +NewAlgorithm.prototype.selectVertex = function(vertex) +{ + this.message = "Processing..."; + this.selectObject = vertex; + this.neighbours = []; + + return true; +} + +NewAlgorithm.prototype.deselectAll = function() +{ + this.selectObject = null; + this.neighbours = []; + this.message = "Please select vertex"; + + return true; +} + +NewAlgorithm.prototype.result = function(resultCallback) +{ + if (this.selectObject) + { + var result = {}; + result["version"] = 1; + + for (var i = 0; i < this.graph.vertices.length; i ++) + { + var nextVertex = this.graph.vertices[i]; + var edge = this.graph.FindEdgeAny(this.selectObject.id, nextVertex.id); + if (edge) + this.neighbours.push(nextVertex); + } + + result.selectedObjects = this.neighbours; + this.message = "Found " + this.neighbours.length + " neighbours"; + + return result; + } + + return null; +} + +NewAlgorithm.prototype.getObjectSelectedGroup = function(object) +{ + return (object == this.selectObject) ? 1 : + (this.neighbours.includes(object) ? 2 : 0); +} + +NewAlgorithm.prototype.getPriority = function() +{ + return 0; +} + +// Algorithm support multi graph +NewAlgorithm.prototype.IsSupportMultiGraph = function() +{ + return false; +} + +NewAlgorithm.prototype.instance = function() +{ + return false; +} + +// Factory for connected components. +function CreateNewAlgorithm(graph, app) +{ + return new NewAlgorithm(graph, app) +} + +// Gerister connected component. +RegisterAlgorithm (CreateNewAlgorithm); diff --git a/sandbox/index.html b/sandbox/index.html new file mode 100644 index 0000000..45ddf42 --- /dev/null +++ b/sandbox/index.html @@ -0,0 +1,666 @@ + + + + + + Sandbox to create new algorithms + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +

Developer sandbox to create new algorithms. Readme.md

+ +
+ +
+ +
+ +
+ +
+ + + Your browser is not supported +
+

Create algorithm

+ Paste your algorith below and press Run + + + +
+
+ +
+
+
+
+
+     +
+
+ has no weight + 1 +
+
+    +
+
+
+ + +
+
+ + +
+
+
+
+
+ +
+
+
+ +

+
+
+
+ +
+
+
+

Enter text for each vertex in separate line

+
+
+
+ +
+
+
+

Setup adjacency matrix. Use comma "," as separator

+

Multigraph matrix contains weight of minimum edges between vertices.

+ +

Matrix is incorrect. Use comma "," as separator. Matrix should be square

+
+
+
+ +
+
+
+

Set up incidence matrix. Use comma "," as separator.

+ +

Matrix is incorrect. Use comma "," as separator.

+
+
+
+ +
+
+
+

Matrix of minimal distances

+ +
+
+
+ +
+
+
+

Graph was saved. Follow this link to see it.
+ +

+

Share link in social networks:

+ + +
+
+
+ +
+
+
+ +

+ +

+

Share link in social networks:

+ + +
+
+
+ +
+

Your algorithm was sent to check and in success case it will be add to site.

+
+ + +
+
Cannot create graph. Adjacency Matrix has wrong format. Click "fix matrix" button to fix matrix or "help" button to open help about Adjacency Matrix format
+
+ +
+
Cannot create graph. Incidence Matrix has wrong format. Click "fix matrix" button to fix matrix or "help" button to open help about Incidence Matrix format
+
+ +
+
+
+

What functions should we add firstly?

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ + +
+
+
+

Please, write what kind of algorithm would you like to see on this website?

+ +

Our service already supports these features: Find the shortest path using Dijkstra's algorithm, Adjacency matrix, Incidence Matrix.

+
+
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+ +

Select and move objects by mouse or move workspace.

+

Drag cursor to move objects

+ +

Select and move objects by mouse or move workspace.

+

Drag cursor to move objects

+

Click to workspace to add a new vertex. Vertex enumeration

+

Select first vertex of edge

+

Select second vertext of edge

+

Select the initial vertex of the shortest path

+

Select the end vertex of the shortest path

+

Shortest path length is %d

+

Path does not exist

+

Click on the object to remove

+ +

Add edge

+

Directed

+

Undirected

+ +

Adjacency Matrix

+

Save

+

Cancel

+

the lowest distance is

+

Incidence matrix

+ + +

Saving Graph

+

close

+ +

The number of connected components is

+

The number of weakly connected components is

+ + +

What do you think about the site?

+

Name (email for feedback)

+

Feedback

+

Send

+

To ask us a question or send us a comment, write us at

+ + +

fix matrix

+

help

+

Matrix has wrong format

+ +

Save Graph Image

+ +

Full report

+

Short report

+ +

Graph has not Eulerian cycle

+

Graph has Eulerian cycle

+

Processing...

+ +

Custom text

+

Add vertex

+ +

Rename vertex

+

Rename

+

+

+

+

en

+

Edit weight

+

has no weight

+

Group rename

+

Vote

+

Recommend algorithms

+ +

Graph has not Eulerian path

+

Graph has Eulerian path

+ +

Graph of minimal distances

+

Check to save

+

Show distance matrix

+

Distance matrix

+ +

Select a source of the maximum flow

+

Select a sink of the maximum flow

+

Maximum flow from %2 to %3 equals %1

+

Flow from %1 in %2 does not exist

+ +

Source

+

Sink

+ +

Graph has not Hamiltonian cycle

+

Graph has Hamiltonian cycle

+ +

Graph has not Hamiltonian path

+

Graph has Hamiltonian path

+ +

Select start traversal vertex

+

Traversal order:

+ +

Edge bend

+

Undo

+

Save graph

+

Default

+

Vertex Style

+

Edge Style

+

Background color

+ +

Multigraph does not support all algorithms

+

+

has no weight

+ +

Use Cmd⌘ to select several objects.

+

Use Ctrl to select several objects.

+

Drag group.

+

Copy group

+

Delete group

+ +

Breadth-first search

+

Graph coloring

+

Find connected components

+

Depth-first search

+

Find Eulerian cycle

+

Find Eulerian path

+

Floyd–Warshall algorithm

+

Arrange the graph

+

Find Hamiltonian cycle

+

Find Hamiltonian path

+

Find Maximum flow

+

Search of minimum spanning tree

+

Visualisation based on weight

+

Search graph radius and diameter

+

Find shortest path using Dijkstra's algorithm

+

Calculate vertexes degree

+ +
+
+ + + + +
+ + + + + + + + + + + + +