mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-01 15:26:12 +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.
|
||||
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")
|
||||
console.log(queryString);
|
||||
console.log(algorithmName + " " + otherParams);
|
||||
|
||||
var graph = this.graph;
|
||||
var ignoreNodes = {};
|
||||
@ -175,14 +175,7 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
||||
var xml = creator.GetXMLString();
|
||||
console.log(xml);
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/" + SiteDir + "cgi-bin/GraphCGI.exe?" + queryString,
|
||||
data: xml,
|
||||
dataType: "text",
|
||||
})
|
||||
.done(function( msg )
|
||||
{
|
||||
var processResult = function (msg) {
|
||||
console.log(msg);
|
||||
$('#debug').text(msg);
|
||||
xmlDoc = $.parseXML( msg );
|
||||
@ -191,38 +184,38 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
||||
$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);
|
||||
});
|
||||
});
|
||||
$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);
|
||||
});
|
||||
});
|
||||
|
||||
$nodes = $xml.find( "node" );
|
||||
|
||||
$nodes.each(function(){
|
||||
var id = $(this).attr('id');
|
||||
$data = $(this).find("data");
|
||||
$data.each(function(){
|
||||
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
||||
{
|
||||
$nodes.each(function(){
|
||||
var id = $(this).attr('id');
|
||||
$data = $(this).find("data");
|
||||
$data.each(function(){
|
||||
if ("hightlightNode" == $(this).attr('key') && $(this).text() == "1")
|
||||
{
|
||||
pathObjects.push(graph.FindVertex(id));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!properties[id])
|
||||
{
|
||||
properties[id] = {};
|
||||
}
|
||||
properties[id][$(this).attr('key')] = $(this).text();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$edges = $xml.find( "edge" );
|
||||
|
||||
@ -249,12 +242,35 @@ BaseAlgorithmEx.prototype.CalculateAlgorithm = function(queryString, resultCallb
|
||||
console.log(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;
|
||||
}
|
||||
|
||||
|
||||
BaseAlgorithmEx.prototype.GetNodesPath = function(array, start, count)
|
||||
{
|
||||
var res = [];
|
||||
|
@ -53,6 +53,7 @@ function Application(document, window)
|
||||
|
||||
this.defaultVertexSize = null;
|
||||
this.defaultEdgeWidth = null;
|
||||
this.processEmscriptenFunction = null;
|
||||
};
|
||||
|
||||
// List of graph.
|
||||
@ -1839,4 +1840,20 @@ Application.prototype.ResetEdgeWidth = function()
|
||||
{
|
||||
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);
|
||||
|
||||
@ -686,6 +687,20 @@ $(document).ready(function ()
|
||||
document.getElementById('canvas').addEventListener("touchend", 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(){
|
||||
//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); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("elloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
this.CalculateAlgorithm("elloop", [], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
}, true);
|
||||
|
@ -34,7 +34,7 @@ FindEulerianPath.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("elpath=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
this.CalculateAlgorithm("elpath", [], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
}, true);
|
||||
|
@ -46,10 +46,14 @@ FindAllPathes.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("prnpaths=cgiInput&start=" + this.firstObject.id + "&finish=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
this.CalculateAlgorithm("prnpaths", [
|
||||
{name: "start", value: this.firstObject.id},
|
||||
{name: "finish", value: this.secondObject.id}
|
||||
],
|
||||
function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -46,10 +46,12 @@ FindShortPatchsFromOne.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("blf=cgiInput&start=" + this.firstObject.id + "&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
this.CalculateAlgorithm("blf", [
|
||||
{name: "start", value : this.firstObject.id}
|
||||
], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -76,19 +76,6 @@ FloidAlgorithm.prototype.result = function(resultCallback)
|
||||
this.app.redrawGraph();
|
||||
|
||||
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); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("hamloop=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
this.CalculateAlgorithm("hamloop", [], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ FindHamiltonianPath.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("hampath=cgiInput&report=xml", function (pathObjects, properties, results)
|
||||
this.CalculateAlgorithm("hampath", [], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
|
@ -53,7 +53,14 @@ IsomorphismCheck.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
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);
|
||||
});
|
||||
|
@ -47,10 +47,15 @@ FindMaxFlow.prototype.result = function(resultCallback)
|
||||
{
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("mfpr=cgiInput&source=" + this.firstObject.id + "&drain=" + this.secondObject.id + "&report=xml", function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
this.CalculateAlgorithm("mfpr",
|
||||
[
|
||||
{name: "source", value: this.firstObject.id},
|
||||
{name: "drain", value: this.secondObject.id}
|
||||
],
|
||||
function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -43,10 +43,14 @@ FindShortPathNew.prototype.result = function(resultCallback)
|
||||
{
|
||||
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);
|
||||
});
|
||||
this.CalculateAlgorithm("dsp",
|
||||
[
|
||||
{name: "start", value: this.firstObject.id},
|
||||
{name: "finish", value: this.secondObject.id}
|
||||
], function (pathObjects, properties, results)
|
||||
{
|
||||
self.resultCallback(pathObjects, properties, results);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user