-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
43 lines (40 loc) · 2.26 KB
/
main.ts
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
import fs from "fs";
import createGraphsFromFile from "./typescript_files/read_from_files";
import {held_karp} from "./typescript_files/held_karp";
import {approx_t_tsp} from "./typescript_files/approx_t_tsp"
import {nearest_neighbor} from "./typescript_files/nearest_neighbor";
let graphList = createGraphsFromFile();
let fileName = "TSP"
writeOnFile(fileName+"_approx", "[NOME GRAFO] ---- [PESO TOTALE] ---- [TEMPO]");
writeOnFile(fileName+"_nearest_neighbor", "[NOME GRAFO] ---- [PESTO TOTALE] ---- [TEMPO]");
writeOnFile(fileName+"_held_karp", "[NOME GRAFO] ---- [PESO TOTALE] ---- [TEMPO]");
//──── Approx_t_TSP con Prim ────────────────────────────────────────────────
for(let index = 0; index < graphList.length; index++){
let tsp_weight;
let elapsedTime;
let graph = graphList[index];
[tsp_weight, elapsedTime] = approx_t_tsp(graph);
writeOnFile(fileName+"_approx", graph.getName() + " - " + tsp_weight + " - " + elapsedTime);
}
//──── Nearest Neighbor ──────────────────────────────────────────────────────────────────
for(let index = 0; index < graphList.length; index++){
let tsp_weight;
let elapsedTime;
let graph = graphList[index];
[tsp_weight, elapsedTime] = nearest_neighbor(graph);
writeOnFile(fileName+"_nearest_neighbor", graph.getName() + " - " + tsp_weight +" - " + elapsedTime);
}
//──── Held-Karp ─────────────────────────────────────────────────────────────────────────
for(let index = 0; index < graphList.length; index++){
let tsp_weight;
let elapsedTime;
let graph = graphList[index];
[tsp_weight, elapsedTime] = held_karp(graph);
writeOnFile(fileName+"_held_karp", graph.getName() + " - " + tsp_weight + " - " + elapsedTime);
}
async function writeOnFile(fileName: string, text: string){
await fs.appendFile(fileName+".txt", text+"\r\n", function(err) {
if (err)
return console.error(err);
});
}