Skip to content

Commit

Permalink
fixed small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodnf committed Jul 11, 2021
1 parent 1f3c95e commit 7422da7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<a class="nav-link" href="#" id="navbarDropdown" data-bs-toggle="dropdown">View</a>
<ul class="dropdown-menu">
<li>
<label class="dropdown-item dropdown-item-checkbox" for="menubar-show-pheromones">
<input class="form-check-input" type="checkbox" value="" id="menubar-show-pheromones"/>
<label class="dropdown-item dropdown-item-checkbox" for="menubar-view-pheromones">
<input class="form-check-input" type="checkbox" value="" id="menubar-view-pheromones"/>
<span>Pheromones</span>
</label>
</li>
Expand Down
27 changes: 14 additions & 13 deletions js/aco/model/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Environment {

this.aco = aco;

this.nodes = [];
this.ants = [];

this.bestTour = [];
this.bestPath = [];
this.bestTourDistance = Number.NaN;
Expand All @@ -12,8 +15,7 @@ class Environment {
this.tau = [];
this.distances = [];

this.nodes = [];
this.ants = [];


this.cnn = 1.0;
this.alpha = 1.0;
Expand All @@ -25,9 +27,8 @@ class Environment {
}

init(){
console.log("init")

this.bestTour = [];
this.bestPath = [];
this.bestTourDistance = Number.NaN;
this.averageTourDistance = Number.NaN;

Expand All @@ -53,6 +54,10 @@ class Environment {
}
}

upateCnn() {
this.cnn = this.evaluate(NearestNeighbour.solve(this));
}

updateBestTour() {

let that = this;
Expand All @@ -74,15 +79,11 @@ class Environment {

if (Number.isNaN(this.bestTourDistance) || bestAnt.tourDistance < this.bestTourDistance) {
this.bestTour = bestAnt.visitedNodeIds;
this.bestTourDistance = bestAnt.tourDistance;
this.bestPath = bestAnt.path;
this.bestTourDistance = bestAnt.tourDistance;
}
}

upateCnn() {
this.cnn = this.evaluate(NearestNeighbour.solve(this));
}

getNumberOfAnts() {
return this.ants.length;
}
Expand All @@ -95,14 +96,14 @@ class Environment {
this.nodes.push(node);
}

isGenerationDone(){
return this.ants.map(e => e.isGenerationDone()).reduce((acc, v) => acc && v);
}

addAnt(ant){
this.ants.push(ant);
}

isGenerationDone(){
return this.ants.map(e => e.isGenerationDone()).reduce((acc, v) => acc && v);
}

evaluate(array) {

if (array.length <= 1) {
Expand Down
10 changes: 5 additions & 5 deletions js/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class Canvas extends fabric.Canvas {
this.selectedOption;
this.index = null;

this.aco = new AntSystem(this.environment);

this.setAddNode();

this.on('mouse:up', (event) => this.onMoveUp(event))
this.on('mouse:down', (event) => this.onMoveDown(event))
this.on('mouse:move', (event) => this.onMoveMove(event))
this.on('mouse:wheel', (event) => this.onMoveWheel(event))

this.aco = new AntSystem(this.environment);

this.setAddNode();
}

onMoveUp(event) {
Expand Down Expand Up @@ -203,7 +203,7 @@ class Canvas extends fabric.Canvas {
this.fire('generationUpdated', canvas);
}

toggleShowPheromones() {
toggleViewPheromones() {

if (this.pheromones) {
this.remove(this.pheromones);
Expand Down
2 changes: 1 addition & 1 deletion js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ $(function () {
});
});

$('#menubar-show-pheromones').change(() => canvas.toggleShowPheromones());
$('#menubar-view-pheromones').change(() => canvas.toggleViewPheromones());

$('#menubar-view-shortest-path').change(() => {
canvas.toggleViewShortestPath()
Expand Down

0 comments on commit 7422da7

Please sign in to comment.