-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.js
66 lines (54 loc) · 1.18 KB
/
interfaces.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
/*****************************************************************************
* Interfaces *
*****************************************************************************/
function Edge(from, to) {
this.from = from;
this.to = to;
}
function Graph() {
this.size = 0;
}
Graph.prototype.heuristic = function(e) {
return 0;
}
Graph.prototype.getEdgesFromNode = function(n) {
return [];
}
function Ant(graph, choose_fn) {
if (graph) {
this.graph = graph;
this.chooseEdge = choose_fn;
this.edges = [];
}
}
/**
* Take one step towards building a solution.
*
* This is an example function and should be replaced in subclasses.
*/
Ant.prototype.step = function() {
var e = this.chooseEdge(graph.getAllEdges());
this.edges.push(e);
return e;
}
Ant.prototype.done = function() {
return false;
}
/**
* Returns the ant's solution.
*
* This is an example function and should be replaced in sublcasses.
*/
Ant.prototype.solution = function () {
if (!this.done()) throw new Error("not done");
return {
edges: this.edges,
goodness: 0
}
}
module.exports = {
Ant: Ant,
Graph: Graph,
Edge: Edge,
};