-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_full_test.c
193 lines (169 loc) · 5.69 KB
/
ts_full_test.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* \file ts_full_test.c
* \brief Full test for tabu search
* \ingroup all
* \author Freddy Mun~oz Ramirez <frmunoz(at)inf.utfsm.cl>
* \date Autumn 2006
* \license <br> This code can be re-distributed under MIT License
*/
#include <stdio.h>
#include <stdlib.h>
#include "tea.h"
#include "tabu_search.h"
#include "io.h"
#include "types.h"
#include "ts_full_test.h"
/**
* Generate a test matrix for tabu search over TEA1, varying Tabu Search parameters
* \param arcg number of input arguments
* \param argv input argument string
*/
int main(int argc,char** argv){
input_options *options;
full_test_input_options *test_options;
cipher_cont *cipher=NULL;
output_report *report;
int lock=TRUE;
unsigned long long tabu_list_length=0;
unsigned long long tabu_iterations=0;
unsigned long long tabu_max_decrease=0;
unsigned long long change_move_limit=0;
float key_eval_percent=0;
if((test_options=MALLOC(full_test_input_options))==NULL){
fprintf(stderr,"ERROR: FAILED TO ALLOCATE MEMORY\n");
exit(1);
}
/*
* parse input parameters
*/
if(argc>1){
parse_full_test_arguments(argc,argv,test_options);
if(test_options->have_input==FALSE){
fprintf(stderr,"ERROR: NO INPUT FILE");
return(1);
}
}
else{
print_full_test_options(argv[0]);
return(1);
}
if(test_options->max_tabu_list_length==0){
test_options->max_tabu_list_length=TS_LIS_MAX;
}
if(test_options->max_tabu_iterations==0){
test_options->max_tabu_iterations=TS_ITER_MAX;
}
if(test_options->max_tabu_max_decrease==0){
test_options->max_tabu_max_decrease=TS_MAX_DEC_MAX;
}
if(test_options->max_change_move_limit==0){
test_options->max_change_move_limit=TS_CHM_MAX;
}
if(test_options->init_tabu_list_length==0){
test_options->init_tabu_list_length=TS_INIT_LIST;
}
if(test_options->init_tabu_iterations==0){
test_options->init_tabu_iterations=TS_INIT_ITER;
}
if(test_options->init_tabu_max_decrease==0){
test_options->init_tabu_max_decrease=TS_INIT_MAX_DEC;
}
if(test_options->init_change_move_limit==0){
test_options->init_change_move_limit=TS_INIT_CHM;
}
if(test_options->var_tabu_list_length==0){
test_options->var_tabu_list_length=TS_LIST_INCREMENT;
}
if(test_options->var_tabu_iterations==0){
test_options->var_tabu_iterations=TS_ITER_INCREMENT;
}
if(test_options->var_tabu_max_decrease==0){
test_options->var_tabu_max_decrease=TS_MAX_DEC_INCREMENT;
}
if(test_options->var_change_move_limit==0){
test_options->var_change_move_limit=TS_CHM_INCREMENT;
}
if(test_options->min_key_eval_percent==0){
test_options->min_key_eval_percent=(float)(TS_INIT_PERCENT);
test_options->min_key_eval_percent=test_options->min_key_eval_percent/100;
}
if(test_options->var_key_eval_percent==0){
test_options->var_key_eval_percent=(float)(TS_PERCENT_INCREMENT);
test_options->var_key_eval_percent=test_options->var_key_eval_percent/100;
}
options=convert_full_test_opt_to_gen(test_options);
/* create report*/
report=open_report(options);
report_use_test_matrix(report);
/* read input from file */
cipher=read_input(test_options->inputfile);
/* tabu serach parameters asignation */
tabu_iterations=test_options->min_key_eval_percent;
tabu_list_length=test_options->init_tabu_list_length;
tabu_max_decrease=test_options->init_tabu_max_decrease;
key_eval_percent=test_options->min_key_eval_percent;
change_move_limit=test_options->init_change_move_limit;
printf("init test matrix\n");
print_mold_test_matrix(stdout);
if(options->save_output)
print_mold_test_matrix(report->report_file);
/* iterative test matrix */
while(lock){
/* tabu search parameters refactory*/
options->tabu_list_length=tabu_list_length; /* tabu list lenght (DEFAULT 0) */
options->tabu_iterations=tabu_iterations; /* tabu iterations (DEFAULT 0) */
options->tabu_max_decrease=tabu_max_decrease; /* tabu performance max decrease (DEFAULT 0) */
options->key_eval_percent=key_eval_percent; /* percer for evaluation key */
options->change_move_limit=change_move_limit;
/* perform tabu search */
tabusearch(cipher,options,report);
/* use iteration test */
if(tabu_iterations<=test_options->max_tabu_iterations+1){
/* use list lenght test */
if(tabu_list_length<=test_options->max_tabu_list_length){
/* use key percent test */
if(key_eval_percent<=1){
/* use performance decreace test */
if(tabu_max_decrease<test_options->max_tabu_max_decrease){
/* use change movement limit test */
if(change_move_limit<test_options->max_change_move_limit){
change_move_limit+=test_options->var_change_move_limit;
}
else{
change_move_limit=test_options->init_change_move_limit;
tabu_max_decrease+=test_options->var_tabu_max_decrease;
}
}
else{
tabu_max_decrease=test_options->init_tabu_max_decrease;
change_move_limit=test_options->init_change_move_limit;
key_eval_percent+=test_options->var_key_eval_percent;
}
}else{
tabu_list_length+=test_options->var_tabu_list_length;
key_eval_percent=test_options->min_key_eval_percent;
tabu_max_decrease=test_options->init_tabu_max_decrease;
change_move_limit=test_options->init_change_move_limit;
}
}
else{
tabu_iterations+=test_options->var_tabu_iterations;
tabu_list_length=test_options->init_tabu_list_length;
tabu_max_decrease=test_options->init_tabu_max_decrease;
key_eval_percent=test_options->min_key_eval_percent;
change_move_limit=test_options->init_change_move_limit;
}
}
else{
lock=FALSE;
}
}
printf("end test matrix\n");
/* end program */
close_report(report);
free((char *)options);
free((char *)test_options);
free((char *)report);
free((char *)cipher);
return(0);
}