-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabuList.c
More file actions
80 lines (66 loc) · 2.46 KB
/
TabuList.c
File metadata and controls
80 lines (66 loc) · 2.46 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* OMA Project of Jacopo Maggio, Stefano Munna, Jacopo Nasi, Andrea Santu and Marco Torlaschi *
* Repository available on https://github.com/Jacopx/OMA_ExamTimeTable *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>
#include "TabuList.h"
#define ITER 7
#define TABU_LIST_SIZE 1000
TabuList* newTabuList () {
int i;
TabuList *tl = malloc(sizeof(TabuList));
tl->listLength = TABU_LIST_SIZE;
tl->list = malloc(TABU_LIST_SIZE * sizeof(tabuMove));
tl->iteration = ITER;
for (i = 0; i < TABU_LIST_SIZE; ++i) {
tl->list[i] = malloc(sizeof(tabuMove));
tl->list[i]->iteration = 0;
}
return tl;
}
void freeTabuList (TabuList *tl) {
int i;
for (i = 0; i < TABU_LIST_SIZE; ++i) free(tl->list[i]);
free(tl);
}
void addTabu (TabuList *TL, TempSol *Tsol, const int *alternative) {
int i, e1 = -1, e2 = -1, exam = -1, found;
for (i = 0; i < TL->listLength; ++i) {
if (TL->list[i]->iteration > 0) TL->list[i]->iteration--;
}
for (i = 0; i < Tsol->length; ++i) {
if (Tsol->temporarySolution[i] != alternative[i]) {
e1 = Tsol->temporarySolution[i];
e2 = alternative[i];
exam = i;
}
}
#ifdef VERBOSE_TABU_LIST
printf("current move: exam %d: %d->%d\n", exam, e1, e2);
#endif
for (i = 0, found = 0; i < TL->listLength && !found; ++i) {
if (TL->list[i]->iteration == 0) {
TL->list[i]->e1 = e2;
TL->list[i]->e2 = e1;
TL->list[i]->exam = exam;
TL->list[i]->iteration = TL->iteration;
found = 1;
}
}
}
int isTabu (TabuList *TL, TempSol *Tsol, const int *alternative, dataStructure *solution) {
int i, e1 = -1, e2 = -1, exam = -1;
for (i = 0; i < solution->E; ++i) {
if (Tsol->temporarySolution[i] != alternative[i]) {
e1 = Tsol->temporarySolution[i];
e2 = alternative[i];
exam = i;
}
}
for (i = 0; i < TL->listLength; ++i) {
if (TL->list[i]->iteration > 0 && TL->list[i]->exam == exam && ((TL->list[i]->e1 == e1 && TL->list[i]->e2 == e2) || (TL->list[i]->e1 == e2 && TL->list[i]->e2 == e1)))
return 1;
}
return 0;
}