Created
May 19, 2024 18:07
-
-
Save halitanildonmez/d2eb16fdf12f4a5c5d746151af828555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 10; | |
var numAnts = 5; | |
var randomAntIndex = [1, 2, 3, 6, 9]; | |
var alpha = 1.0; | |
var beta = 5.0; | |
var Q = 100; | |
var V = 0.01 | |
var cities = []; | |
var ants = []; | |
var edges = []; | |
var precision = 0.001; | |
var speedFactor = 15; | |
var enablePathDrawing = true; | |
var antMap = new Map(); | |
var globalShortestDistance = 0.0; | |
var globalShortestPath = []; | |
var globalPheromones = []; | |
var simulationIteration = 0; | |
var animFinished = false; | |
class Edge { | |
e; | |
from; | |
to; | |
pheromone; | |
constructor(e, from, to, pheromone) { | |
this.e = e; | |
this.from = from; | |
this.to = to; | |
this.pheromone = pheromone; | |
} | |
} | |
class Node { | |
p; | |
index; | |
symbol; | |
constructor(index, p, symbol) { | |
this.p = p; | |
this.index = index; | |
this.symbol = symbol; | |
} | |
} | |
function createGraph() { | |
var s = new Size(900, 750); | |
// Place the instances of the symbol: | |
for (var i = 0; i < count; i++) { | |
var sr = Size.random(); | |
var sizeX = s.width * sr.width; | |
var sizeY = s.height * sr.height; | |
var tmpX = sizeX; | |
var tmpY = sizeY; | |
var p = new Point(tmpX, tmpY); | |
var myCircle = new Path.Circle(p, 10); | |
myCircle.fillColor = 'black'; | |
cities[i] = new Node(i, p, myCircle); | |
} | |
for (var i = 0; i < count; i++) { | |
var start = cities[i]; | |
edges[i] = []; | |
for (var j = 0; j < count; j++) { | |
var end = cities[j]; | |
var path = new Path(); | |
path.add(start.p); | |
path.add(end.p); | |
if (enablePathDrawing) { | |
path.strokeColor = 'black'; | |
} | |
edges[i][j] = new Edge(path, i, j, 0.001); | |
} | |
} | |
} | |
function update(event) { | |
} | |
paper.install(window); | |
// Only executed our code once the DOM is ready. | |
window.onload = function() { | |
var canvas = document.getElementById("myCanvas"); | |
paper.setup(canvas); | |
createGraph(); | |
view.onFrame = update; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment