some patches to moveonedge to trigger a callback rather than using forward tables

This commit is contained in:
2025-09-08 12:46:17 -05:00
parent a7ea3ed49e
commit 5714564bd5
2 changed files with 52 additions and 3 deletions
+11 -3
View File
@@ -13,6 +13,7 @@ class CompleteNodeOnEdgeEngine {
this.edges = edges;
this.dotNodes = dotNodes;
this.forwTable = forwTable;
this.onArrival = null;
this.linksByEdges = {};
@@ -30,6 +31,10 @@ class CompleteNodeOnEdgeEngine {
this.targetInterval = this.time_delay;
}
setArrivalCallback(callback) {
this.onArrival = callback;
}
/**
* Initializes the movement of the nodes on edges.
*/
@@ -143,9 +148,9 @@ class CompleteNodeOnEdgeEngine {
this.maxTime = Math.max(this.maxTime, this.currentTime);
}
document.getElementById("currenttime").innerHTML = this.currentTime/1000;
/*document.getElementById("currenttime").innerHTML = this.currentTime/1000;
document.getElementById("ratio_inc").innerHTML = this.ratio_inc/100;
document.getElementById("maxtime").innerHTML = this.maxTime/1000;
document.getElementById("maxtime").innerHTML = this.maxTime/1000;*/
}
/**
@@ -186,7 +191,10 @@ class CompleteNodeOnEdgeEngine {
dotNode.ratio += current_ratio;
if (dotNode.ratio > 100) {
this.traces_table[dotNode.id].push(dotNode.target);
if (!this.updateDotNode(dotNode, dotNode.target, this.forwTable[dotNode.target][dotNode.source], dotNode.ratio - 100)) {
if (typeof this.onArrival === 'function') {
try {
this.onArrival({ from: dotNode.source, to: dotNode.target, dot: dotNode });
} catch (e) {}
this.dotNodes.remove(dotNode, time);
return;
}
+41
View File
@@ -42,6 +42,20 @@ var options = {
var network = new vis.Network(container, data, options);
let selectedNode = null;
var dotNodes = new vis.DataSet([
]);
var forwardTable = {};
var onEdgeEngine = new CompleteNodeOnEdgeEngine(network, nodes, dotNodes, edges, forwardTable);
onEdgeEngine.createEdgesTable();
onEdgeEngine.initMovement();
onEdgeEngine.setArrivalCallback(({ from, to, dot }) => {
// Example: log arrival; dot removal is handled by engine
// For flood behavior, you can spawn new dots here if needed
console.log(`Dot ${dot.id} arrived from ${from} to ${to}`);
});
function nodeSelectUpdateHandler(properties) {
// get containers
const incomingTable = document.getElementById('incomingConnections');
@@ -177,6 +191,9 @@ function main() {
const currentNodesKeys = Object.keys(currentNodes);
for (let node1 of currentNodesKeys) {
let neighbors = [];
if (!nodeTable[node1]) {
continue;
}
for (let node2 of currentNodesKeys) {
if (node1 !== node2) {
const node1data = currentNodes[node1];
@@ -199,6 +216,9 @@ function main() {
}
const scores = [];
for (let neighbor of neighbors) {
if (!nodeTable[neighbor.node]) {
continue;
}
let connectionScore = 0;
let dropScore = 0;
connectionScore += (100 + neighbor.distance);
@@ -275,4 +295,25 @@ document.getElementById('addNode').addEventListener('click', function() {
const nodeId = generateRealisticLabel();
nodes.add({id: nodeId, label: nodeId});
nodeTable[nodeId] = {'incoming': [], 'outgoing': []};
});
document.getElementById('sendPacket').addEventListener('click', function() {
onEdgeEngine.createEdgesTable();
onEdgeEngine.initMovement();
const packetId = generateRealisticLabel();
const packetShift = 0;
for (let connection of nodeTable[selectedNode].outgoing) {
var movingNode = {
id: packetId + packetShift,
label: packetId,
shape: 'dot',
size: 6,
color: {
background: 'white',
border: 'black'
},
};
onEdgeEngine.createDotNode(movingNode, selectedNode, connection);
packetShift++;
}
});