mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-10-20 15:27:20 +00:00
Support multigraph for algorithms:
- Find all paths. - Find longest path. - Find all shortest paths.
This commit is contained in:
1 parent
d3416b63b3
commit
dfeac352c1
27 files changed
+89
-59
No files matched your search
@@ -110,13 +110,11 @@ FindAllPathes.prototype.resultCallback = function(pathObjects, properties, resul
|
||||
}
|
||||
|
||||
var subGraphIndex = 0;
|
||||
var prevNodeId = -1;
|
||||
for (var i = 0; i < results.length; i++)
|
||||
{
|
||||
if (results[i].type == 6)
|
||||
{
|
||||
subGraphIndex++;
|
||||
prevNodeId = -1;
|
||||
}
|
||||
|
||||
if (results[i].type == 4)
|
||||
@@ -126,14 +124,15 @@ FindAllPathes.prototype.resultCallback = function(pathObjects, properties, resul
|
||||
var subgGraph = this.foundSubGraphs[index];
|
||||
subgGraph[nodeId] = true;
|
||||
|
||||
this.foundPaths[index].push(nodeId);
|
||||
|
||||
if (prevNodeId >= 0)
|
||||
{
|
||||
var edgeObject = this.graph.FindEdgeMin(prevNodeId, nodeId);
|
||||
subgGraph[edgeObject.id] = true;
|
||||
}
|
||||
prevNodeId = nodeId;
|
||||
this.foundPaths[index].push(nodeId);
|
||||
}
|
||||
|
||||
if (results[i].type == 5)
|
||||
{
|
||||
var edgeId = parseInt(results[i].value);
|
||||
var index = subGraphIndex;
|
||||
var subgGraph = this.foundSubGraphs[index];
|
||||
subgGraph[edgeId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +225,11 @@ FindAllPathes.prototype.IsSupportNegativeWeight = function()
|
||||
return true;
|
||||
}
|
||||
|
||||
FindAllPathes.prototype.IsSupportMultiGraph = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factory for connected components.
|
||||
function CreateFindAllPathes(graph, app)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ function FindAllShortestPathes(graph, app)
|
||||
this.nSubgraphIndex = 0;
|
||||
this.nSubGraphCount = 0;
|
||||
this.foundPaths = {};
|
||||
this.min_len = 1E10;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +51,8 @@ FindAllShortestPathes.prototype.result = function(resultCallback)
|
||||
{
|
||||
if (this.firstObject && this.secondObject)
|
||||
{
|
||||
this.min_len = 1E10;
|
||||
|
||||
this.outResultCallback = function (result ) { resultCallback(result); };
|
||||
self = this;
|
||||
this.CalculateAlgorithm("prnpaths", [
|
||||
@@ -77,7 +80,7 @@ FindAllShortestPathes.prototype.setResultMessage = function()
|
||||
|
||||
this.message = g_numberOfShortestPathesFrom + this.firstObject.mainText +
|
||||
g_to + this.secondObject.mainText + g_are +
|
||||
this.nSubGraphCount + ". " + g_pathN + (1 + parseInt(this.nSubgraphIndex)) + ": " + currentPath +
|
||||
this.nSubGraphCount + " (" + g_length_is + this.min_len + ")" +". " + g_pathN + (1 + parseInt(this.nSubgraphIndex)) + ": " + currentPath +
|
||||
" <select style=\"float:right\" id=\"enumSubgraphs\"></select>";
|
||||
}
|
||||
else
|
||||
@@ -100,14 +103,12 @@ FindAllShortestPathes.prototype.resultCallback = function(pathObjects, propertie
|
||||
if (bFound)
|
||||
{
|
||||
let patches_len = {};
|
||||
let min_len = 1E10;
|
||||
|
||||
// Search minimal patches
|
||||
{
|
||||
let current_len = 0;
|
||||
|
||||
var subGraphIndex = 0;
|
||||
var prevNodeId = -1;
|
||||
let any_found = false;
|
||||
for (var i = 0; i < results.length; i++)
|
||||
{
|
||||
@@ -115,35 +116,28 @@ FindAllShortestPathes.prototype.resultCallback = function(pathObjects, propertie
|
||||
{
|
||||
patches_len[subGraphIndex] = current_len;
|
||||
subGraphIndex++;
|
||||
prevNodeId = -1;
|
||||
min_len = Math.min(min_len, current_len);
|
||||
this.min_len = Math.min(this.min_len, current_len);
|
||||
current_len = 0;
|
||||
}
|
||||
|
||||
if (results[i].type == 4)
|
||||
if (results[i].type == 5)
|
||||
{
|
||||
any_found = true;
|
||||
var nodeId = parseInt(results[i].value);
|
||||
var index = subGraphIndex;
|
||||
|
||||
if (prevNodeId >= 0)
|
||||
{
|
||||
var edgeObject = this.graph.FindEdgeMin(prevNodeId, nodeId);
|
||||
current_len = current_len + edgeObject.GetWeight();
|
||||
}
|
||||
prevNodeId = nodeId;
|
||||
var edgeId = parseInt(results[i].value);
|
||||
let edgeObject = this.graph.FindEdgeById(edgeId);
|
||||
current_len = current_len + edgeObject.GetWeight();
|
||||
}
|
||||
}
|
||||
if (any_found)
|
||||
{
|
||||
patches_len[subGraphIndex] = current_len;
|
||||
min_len = Math.min(min_len, current_len);
|
||||
this.min_len = Math.min(this.min_len, current_len);
|
||||
}
|
||||
}
|
||||
|
||||
let min_pathes_count = 0;
|
||||
for (const [key, value] of Object.entries(patches_len)) {
|
||||
if (value == min_len)
|
||||
if (value == this.min_len)
|
||||
{
|
||||
min_pathes_count = min_pathes_count + 1;
|
||||
}
|
||||
@@ -160,17 +154,20 @@ FindAllShortestPathes.prototype.resultCallback = function(pathObjects, propertie
|
||||
}
|
||||
|
||||
var subGraphIndex = 0;
|
||||
var prevNodeId = -1;
|
||||
let skipGraphsCount = patches_len[subGraphIndex] > this.min_len ? 1 : 0;
|
||||
for (var i = 0; i < results.length; i++)
|
||||
{
|
||||
if (results[i].type == 6)
|
||||
{
|
||||
subGraphIndex++;
|
||||
prevNodeId = -1;
|
||||
}
|
||||
|
||||
if (patches_len[subGraphIndex] > min_len)
|
||||
if (patches_len[subGraphIndex] > this.min_len)
|
||||
{
|
||||
if (results[i].type == 6)
|
||||
{
|
||||
skipGraphsCount++;
|
||||
}
|
||||
// Skip
|
||||
continue;
|
||||
}
|
||||
@@ -178,18 +175,18 @@ FindAllShortestPathes.prototype.resultCallback = function(pathObjects, propertie
|
||||
if (results[i].type == 4)
|
||||
{
|
||||
var nodeId = parseInt(results[i].value);
|
||||
var index = subGraphIndex;
|
||||
var index = subGraphIndex - skipGraphsCount;
|
||||
var subgGraph = this.foundSubGraphs[index];
|
||||
subgGraph[nodeId] = true;
|
||||
|
||||
this.foundPaths[index].push(nodeId);
|
||||
|
||||
if (prevNodeId >= 0)
|
||||
{
|
||||
var edgeObject = this.graph.FindEdgeMin(prevNodeId, nodeId);
|
||||
subgGraph[edgeObject.id] = true;
|
||||
}
|
||||
prevNodeId = nodeId;
|
||||
}
|
||||
|
||||
if (results[i].type == 5)
|
||||
{
|
||||
var index = subGraphIndex - skipGraphsCount;
|
||||
var subgGraph = this.foundSubGraphs[index];
|
||||
var edgeId = parseInt(results[i].value);
|
||||
subgGraph[edgeId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +255,7 @@ FindAllShortestPathes.prototype.deselectAll = function()
|
||||
this.nSubgraphIndex = 0;
|
||||
this.nSubGraphCount = 0;
|
||||
this.message = g_selectStartVertex;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -282,6 +280,11 @@ FindAllShortestPathes.prototype.IsSupportNegativeWeight = function()
|
||||
return true;
|
||||
}
|
||||
|
||||
FindAllShortestPathes.prototype.IsSupportMultiGraph = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factory for connected components.
|
||||
function CreateFindAllShortestPathes(graph, app)
|
||||
{
|
||||
|
||||
@@ -113,7 +113,6 @@ FindLongestPath.prototype.resultCallback = function(pathObjects, properties, res
|
||||
}
|
||||
|
||||
var subGraphIndex = 0;
|
||||
var prevNodeId = -1;
|
||||
for (var i = 0; i < results.length; i++)
|
||||
{
|
||||
if (results[i].type == 6)
|
||||
@@ -124,7 +123,6 @@ FindLongestPath.prototype.resultCallback = function(pathObjects, properties, res
|
||||
}
|
||||
currentLength = 0;
|
||||
subGraphIndex++;
|
||||
prevNodeId = -1;
|
||||
}
|
||||
|
||||
if (results[i].type == 4)
|
||||
@@ -135,14 +133,16 @@ FindLongestPath.prototype.resultCallback = function(pathObjects, properties, res
|
||||
subgGraph[nodeId] = true;
|
||||
|
||||
this.foundPaths[index].push(nodeId);
|
||||
|
||||
if (prevNodeId >= 0)
|
||||
{
|
||||
var edgeObject = this.graph.FindEdgeMax(prevNodeId, nodeId);
|
||||
subgGraph[edgeObject.id] = true;
|
||||
currentLength += edgeObject.GetWeight();
|
||||
}
|
||||
prevNodeId = nodeId;
|
||||
}
|
||||
|
||||
if (results[i].type == 5)
|
||||
{
|
||||
var edgeId = parseInt(results[i].value);
|
||||
var index = subGraphIndex;
|
||||
var subgGraph = this.foundSubGraphs[index];
|
||||
subgGraph[edgeId] = true;
|
||||
let edgeObject = this.graph.FindEdgeById(edgeId);
|
||||
currentLength += edgeObject.GetWeight();
|
||||
}
|
||||
}
|
||||
if (currentLength > this.maxPathLength) {
|
||||
@@ -223,6 +223,11 @@ FindLongestPath.prototype.IsSupportNegativeWeight = function()
|
||||
return true;
|
||||
}
|
||||
|
||||
FindLongestPath.prototype.IsSupportMultiGraph = function()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factory for connected components.
|
||||
function CreateFindLongestPath(graph, app)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ FindShortPatchsFromOne.prototype.setResultMessage = function()
|
||||
if (this.nSubGraphCount > 0)
|
||||
{
|
||||
this.message = g_distanceFrom + this.firstObject.mainText +
|
||||
g_to + this.lastVertexInPath[this.nSubgraphIndex] + g_are +
|
||||
g_to + this.lastVertexInPath[this.nSubgraphIndex] + g_are +
|
||||
this.lengthOfPath[this.nSubgraphIndex] + " <select style=\"float:right\" id=\"enumSubgraphs\"></select>";
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1 +1 @@
|
||||
var Module=typeof Module!="undefined"?Module:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&process.versions?.node&&process.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=typeof document!="undefined"?document.currentScript?.src:undefined;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var wasmMemory;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;if(!Module["noFSInit"]&&!FS.initialized)FS.init();TTY.init();wasmExports["o"]();FS.ignorePermissions=false}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("Graphoffline.Emscripten.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiLine truncated
|
||||
var Module=typeof Module!="undefined"?Module:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&process.versions?.node&&process.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=typeof document!="undefined"?document.currentScript?.src:undefined;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var wasmMemory;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;if(!Module["noFSInit"]&&!FS.initialized)FS.init();TTY.init();wasmExports["o"]();FS.ignorePermissions=false}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("Graphoffline.Emscripten.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiLine truncated
|
||||
Binary file not shown.
Reference in new issue
Block a user