mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-10-27 14:30:12 +00:00
Add Emsctipted implementation for algorithm.
This commit is contained in:
1 parent
056d4fce12
commit
513fb80a0c
15 files changed
+91
-33
No files matched your search
+27
-11
@@ -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 );
|
||||||
@@ -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.
|
||||||
@@ -1840,3 +1841,19 @@ 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);
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var arguments_=[];var thisProgram="./this.program";var quit_=function(status,toThrow){throw toThrow};var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;function logExceptionOnExit(e){if(e instanceof ExitStatus)return;var toLog=e;err("exiting due to exception: "+toLog)}var nodeFS;var nodePath;if(ENVIRONMENT_IS_NODE){if(ENVIRONMENT_IS_WORKER){scriptDirectory=require("path").dirname(scriptDirectory)+"/"}else{scriptDirectory=__dirname+"/"}read_=function shell_read(filename,binary){if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);return nodeFS["readFileSync"](filename,binary?null:"utf8")};readBinary=function readBinary(filename){var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};readAsync=function readAsync(filename,onload,onerror){if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);nodeFS["readFile"](filename,function(err,data){if(err)onerror(err);else onload(data.buffer)})};if(process["argv"].length>1){thisProgram=process["argv"][1].replace(/\\/g,"/")}arguments_=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",function(ex){if(!(ex instanceof ExitStatus)){throw ex}});process["on"]("unhandledRejection",function(reason){throw reason});quit_=function(status,toThrow){if(keepRuntimeAlive()){process["exitCode"]=status;throw toThrow}logExceptionOnExit(toThrow);process["exit"](status)};Module["inspect"]=function(){return"[Emscripten Module object]"}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!=="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=function(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=function(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=function(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=function(title){document.title=title}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);for(key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;if(typeof WebAssembly!=="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;function assert(condition,text){if(!condition){abort("Assertion failed: "+text)}}function getCFunc(ident){var func=Module["_"+ident];assert(func,"Cannot call unknown function "+ident+", make sure it is exported");return func}function ccall(ident,returnType,argTypes,args,opts){var toC={"string":function(str){var ret=0;if(str!==null&&str!==undefined&&str!==0){var len=(str.length<<2)+1;ret=stackAlloc(len);stringToUTF8(str,ret,len)}return ret},"array":function(arr){var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string")return UTF8ToString(ret);if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func.apply(null,cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret}function cwrap(ident,returnType,argTypes,opts){argTypes=argTypes||[];var numericArgs=argTypes.every(function(type){return type==="number"});var numericRet=returnType!=="string";if(numericLine truncated
|
||||||
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,7 +46,11 @@ 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},
|
||||||
|
{name: "finish", value: this.secondObject.id}
|
||||||
|
],
|
||||||
|
function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ 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}
|
||||||
|
], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,7 +47,12 @@ 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",
|
||||||
|
[
|
||||||
|
{name: "source", value: this.firstObject.id},
|
||||||
|
{name: "drain", value: this.secondObject.id}
|
||||||
|
],
|
||||||
|
function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,7 +43,11 @@ 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",
|
||||||
|
[
|
||||||
|
{name: "start", value: this.firstObject.id},
|
||||||
|
{name: "finish", value: this.secondObject.id}
|
||||||
|
], function (pathObjects, properties, results)
|
||||||
{
|
{
|
||||||
self.resultCallback(pathObjects, properties, results);
|
self.resultCallback(pathObjects, properties, results);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user