mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 23:36:00 +00:00
Add Emsctipted implementation for algorithm.
This commit is contained in:
parent
056d4fce12
commit
513fb80a0c
@ -154,10 +154,10 @@ function BaseAlgorithmEx(graph, app)
|
|||||||
// inheritance.
|
// inheritance.
|
||||||
BaseAlgorithmEx.prototype = Object.create(BaseAlgorithm.prototype);
|
BaseAlgorithmEx.prototype = Object.create(BaseAlgorithm.prototype);
|
||||||
|
|
||||||
BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallback, ignoreSeparateNodes = false)
|
BaseAlgorithmEx.prototype.CalculateAlgorithm = function(algorithmName, otherParams, resultCallback, ignoreSeparateNodes = false)
|
||||||
{
|
{
|
||||||
if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
|
if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
|
||||||
console.log(queryString);
|
console.log(algorithmName + " " + otherParams);
|
||||||
|
|
||||||
var graph = this.graph;
|
var graph = this.graph;
|
||||||
var ignoreNodes = {};
|
var ignoreNodes = {};
|
||||||
@ -175,14 +175,7 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
|||||||
var xml = creator.GetXMLString();
|
var xml = creator.GetXMLString();
|
||||||
console.log(xml);
|
console.log(xml);
|
||||||
|
|
||||||
$.ajax({
|
var processResult = function (msg) {
|
||||||
type: "POST",
|
|
||||||
url: "/" + SiteDir + "cgi-bin/GraphCGI.exe?" + queryString,
|
|
||||||
data: xml,
|
|
||||||
dataType: "text",
|
|
||||||
})
|
|
||||||
.done(function( msg )
|
|
||||||
{
|
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
$('#debug').text(msg);
|
$('#debug').text(msg);
|
||||||
xmlDoc = $.parseXML( msg );
|
xmlDoc = $.parseXML( msg );
|
||||||
@ -191,38 +184,38 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
|||||||
$results = $xml.find( "result" );
|
$results = $xml.find( "result" );
|
||||||
|
|
||||||
$results.each(function(){
|
$results.each(function(){
|
||||||
$values = $(this).find( "value" );
|
$values = $(this).find( "value" );
|
||||||
|
|
||||||
$values.each(function(){
|
$values.each(function(){
|
||||||
var type = $(this).attr('type');
|
var type = $(this).attr('type');
|
||||||
var value = $(this).text();
|
var value = $(this).text();
|
||||||
var res = {};
|
var res = {};
|
||||||
res.type = type;
|
res.type = type;
|
||||||
res.value = value;
|
res.value = value;
|
||||||
result.push(res);
|
result.push(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$nodes = $xml.find( "node" );
|
$nodes = $xml.find( "node" );
|
||||||
|
|
||||||
$nodes.each(function(){
|
$nodes.each(function(){
|
||||||
var id = $(this).attr('id');
|
var id = $(this).attr('id');
|
||||||
$data = $(this).find("data");
|
$data = $(this).find("data");
|
||||||
$data.each(function(){
|
$data.each(function(){
|
||||||
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
||||||
{
|
{
|
||||||
pathObjects.push(graph.FindVertex(id));
|
pathObjects.push(graph.FindVertex(id));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!properties[id])
|
if (!properties[id])
|
||||||
{
|
{
|
||||||
properties[id] = {};
|
properties[id] = {};
|
||||||
}
|
}
|
||||||
properties[id][$(this).attr('key')] = $(this).text();
|
properties[id][$(this).attr('key')] = $(this).text();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$edges = $xml.find( "edge" );
|
$edges = $xml.find( "edge" );
|
||||||
|
|
||||||
@ -249,12 +242,35 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
|||||||
console.log(result);
|
console.log(result);
|
||||||
|
|
||||||
resultCallback(pathObjects, properties, result);
|
resultCallback(pathObjects, properties, result);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (this.app.isSupportEmscripten()) {
|
||||||
|
console.log("Use Emscripten");
|
||||||
|
var delimiter = "<s\\emscript_split\\s>";
|
||||||
|
var processData = algorithmName + delimiter + xml +
|
||||||
|
delimiter + "report" + delimiter + "xml";
|
||||||
|
otherParams.forEach ( (param) => processData += delimiter + param.name + delimiter + param.value);
|
||||||
|
var res = this.app.processEmscripten(processData);
|
||||||
|
processResult(res);
|
||||||
|
} else {
|
||||||
|
console.log("Use new CGI");
|
||||||
|
var queryString = algorithmName + "=cgiInput&report=xml";
|
||||||
|
otherParams.forEach ( (param) => queryString += "&" + param.name + "=" + param.value);
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/" + SiteDir + "cgi-bin/GraphCGI.exe?" + queryString,
|
||||||
|
data: xml,
|
||||||
|
dataType: "text",
|
||||||
|
})
|
||||||
|
.done(function( msg )
|
||||||
|
{
|
||||||
|
processResult(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BaseAlgorithmEx.prototype.GetNodesPath = function(array, start, count)
|
BaseAlgorithmEx.prototype.GetNodesPath = function(array, start, count)
|
||||||
{
|
{
|
||||||
var res = [];
|
var res = [];
|
||||||
|
@ -53,6 +53,7 @@ function Application(document, window)
|
|||||||
|
|
||||||
this.defaultVertexSize = null;
|
this.defaultVertexSize = null;
|
||||||
this.defaultEdgeWidth = null;
|
this.defaultEdgeWidth = null;
|
||||||
|
this.processEmscriptenFunction = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// List of graph.
|
// List of graph.
|
||||||
@ -1839,4 +1840,20 @@ Application.prototype.ResetEdgeWidth = function()
|
|||||||
{
|
{
|
||||||
this.graph.edges[i].model.width = this.GetDefaultEdgeWidth();
|
this.graph.edges[i].model.width = this.GetDefaultEdgeWidth();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Application.prototype.setEmscripten = function(processFunction)
|
||||||
|
{
|
||||||
|
this.processEmscriptenFunction = processFunction;
|
||||||
|
console.log("Emscripten set");
|
||||||
|
}
|
||||||
|
|
||||||
|
Application.prototype.isSupportEmscripten = function ()
|
||||||
|
{
|
||||||
|
return this.processEmscriptenFunction != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Application.prototype.processEmscripten = function (inputData)
|
||||||
|
{
|
||||||
|
return this.processEmscriptenFunction(inputData);
|
||||||
}
|
}
|
1
script/Graphoffline.Emscripten.js
Normal file
1
script/Graphoffline.Emscripten.js
Normal file
File diff suppressed because one or more lines are too long
BIN
script/Graphoffline.Emscripten.wasm
Normal file
BIN
script/Graphoffline.Emscripten.wasm
Normal file
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
var SiteDir = "";
|
var SiteDir = "";
|
||||||
|
var DisableEmscripted = false;
|
||||||
|
|
||||||
var application = new Application(document, window);
|
var application = new Application(document, window);
|
||||||
|
|
||||||
@ -686,6 +687,20 @@ $(document).ready(function ()
|
|||||||
document.getElementById('canvas').addEventListener("touchend", touchHandler, true);
|
document.getElementById('canvas').addEventListener("touchend", touchHandler, true);
|
||||||
document.getElementById('canvas').addEventListener("touchcancel", touchHandler, true);
|
document.getElementById('canvas').addEventListener("touchcancel", touchHandler, true);
|
||||||
|
|
||||||
|
// Try load emscripted implementation
|
||||||
|
var isMobile = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i);
|
||||||
|
if (!isMobile && !DisableEmscripted) {
|
||||||
|
const jsScript = document.createElement('script');
|
||||||
|
jsScript.src = 'script/Graphoffline.Emscripten.js';
|
||||||
|
document.body.appendChild(jsScript);
|
||||||
|
jsScript.addEventListener('load', () => {
|
||||||
|
Module['onRuntimeInitialized'] = onRuntimeInitialized;
|
||||||
|
var process = Module.cwrap('ProcessAlgorithm', 'string', ['string']);
|
||||||
|
function onRuntimeInitialized() {
|
||||||
|
application.setEmscripten(process);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
//set up some basic options for the feedback_me plugin
|
//set up some basic options for the feedback_me plugin
|
||||||
|
@ -34,7 +34,7 @@ FindEulerianLoop.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("elloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("elloop", [], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -34,7 +34,7 @@ FindEulerianPath.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("elpath", [], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -46,10 +46,14 @@ FindAllPathes.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("prnpaths=cgiInput&start=" + this.firstObject.id + "&finish=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("prnpaths", [
|
||||||
{
|
{name: "start", value: this.firstObject.id},
|
||||||
self.resultCallback(pathObjects, properties, results);
|
{name: "finish", value: this.secondObject.id}
|
||||||
});
|
],
|
||||||
|
function (pathObjects, properties, results)
|
||||||
|
{
|
||||||
|
self.resultCallback(pathObjects, properties, results);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,12 @@ FindShortPatchsFromOne.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("blf=cgiInput&start=" + this.firstObject.id + "&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("blf", [
|
||||||
{
|
{name: "start", value : this.firstObject.id}
|
||||||
self.resultCallback(pathObjects, properties, results);
|
], function (pathObjects, properties, results)
|
||||||
});
|
{
|
||||||
|
self.resultCallback(pathObjects, properties, results);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -76,19 +76,6 @@ FloidAlgorithm.prototype.result = function(resultCallback)
|
|||||||
this.app.redrawGraph();
|
this.app.redrawGraph();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
/*
|
|
||||||
if (this.firstObject && this.secondObject)
|
|
||||||
{
|
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
|
||||||
self = this;
|
|
||||||
this.CalculateAlgorithm("dsp=cgiInput&start=" + this.firstObject.id + "&finish=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
|
||||||
{
|
|
||||||
self.resultCallback(pathObjects, properties, results);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ FindHamiltonianLoop.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("hamloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("hamloop", [], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,7 @@ FindHamiltonianPath.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("hampath=cgiInput&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("hampath", [], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
@ -53,7 +53,14 @@ IsomorphismCheck.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("isocheck=cgiInput&graph1=" + this.getGraphEdges(this.firstGraph) + "&graph2=" + this.getGraphEdges(this.secondGraph) + "&report=xml" + (this.searchSubGraphs ? "&searchSubgraphs=true": ""), function (pathObjects, properties, results)
|
var params = [
|
||||||
|
{name : "graph1", value: this.getGraphEdges(this.firstGraph)},
|
||||||
|
{name : "graph2", value: this.getGraphEdges(this.secondGraph)},
|
||||||
|
];
|
||||||
|
if (this.searchSubGraphs) {
|
||||||
|
params.push({name: "searchSubgraphs", value: true});
|
||||||
|
}
|
||||||
|
this.CalculateAlgorithm("isocheck", params, function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
@ -47,10 +47,15 @@ FindMaxFlow.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("mfpr=cgiInput&source=" + this.firstObject.id + "&drain=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("mfpr",
|
||||||
{
|
[
|
||||||
self.resultCallback(pathObjects, properties, results);
|
{name: "source", value: this.firstObject.id},
|
||||||
});
|
{name: "drain", value: this.secondObject.id}
|
||||||
|
],
|
||||||
|
function (pathObjects, properties, results)
|
||||||
|
{
|
||||||
|
self.resultCallback(pathObjects, properties, results);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,14 @@ FindShortPathNew.prototype.result = function(resultCallback)
|
|||||||
{
|
{
|
||||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||||
self = this;
|
self = this;
|
||||||
this.CalculateAlgorithm("dsp=cgiInput&start=" + this.firstObject.id + "&finish=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
this.CalculateAlgorithm("dsp",
|
||||||
{
|
[
|
||||||
self.resultCallback(pathObjects, properties, results);
|
{name: "start", value: this.firstObject.id},
|
||||||
});
|
{name: "finish", value: this.secondObject.id}
|
||||||
|
], function (pathObjects, properties, results)
|
||||||
|
{
|
||||||
|
self.resultCallback(pathObjects, properties, results);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user