OPAL (Object Oriented Parallel Accelerator Library)
2024.1
OPAL
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
optimizer
extlib
wfgHypervolume
read.cpp
Go to the documentation of this file.
1
#include "
wfg.h
"
2
#include "
avl.h
"
3
4
static
void
trimLine(
char
line[])
5
{
6
int
i = 0;
7
8
while
(line[i] !=
'\0'
)
9
{
10
if
(line[i] ==
'\r'
|| line[i] ==
'\n'
)
11
{
12
line[i] =
'\0'
;
13
break
;
14
}
15
i++;
16
}
17
}
18
19
void
printContents
(
FILECONTENTS
*f)
20
{
21
int
i;
22
for
( i = 0; i < f->
nFronts
; i++)
23
{
24
printf(
"Front %d:\n"
, i+1);
25
int
j;
26
for
( j = 0; j < f->
fronts
[i].
nPoints
; j++)
27
{
28
printf(
"\t"
);
29
int
k;
30
for
(k = 0; k < f->
fronts
[i].
n
; k++)
31
{
32
printf(
"%f "
, f->
fronts
[i].
points
[j].
objectives
[k]);
33
}
34
printf(
"\n"
);
35
}
36
printf(
"\n"
);
37
}
38
}
39
40
FILECONTENTS
*
readFile
(
const
char
filename[])
41
{
42
FILE *fp;
43
char
line[BUFSIZ];
44
int
front = 0, point = 0, objective = 0;
45
46
FILECONTENTS
*fc = (
FILECONTENTS
*) malloc(
sizeof
(
FILECONTENTS
));
47
fc->
nFronts
= 0;
48
fc->
fronts
= NULL;
49
50
fp = fopen(filename,
"r"
);
51
if
(fp == NULL)
52
{
53
fprintf(stderr,
"File %s could not be opened\n"
, filename);
54
exit(EXIT_FAILURE);
55
}
56
57
while
(fgets(line,
sizeof
line, fp) != NULL)
58
{
59
trimLine(line);
60
if
(strcmp(line,
"#"
) == 0)
61
{
62
front = fc->
nFronts
;
63
fc->
nFronts
++;
64
fc->
fronts
= (
FRONT
*)realloc(fc->
fronts
,
sizeof
(
FRONT
) * fc->
nFronts
);
65
fc->
fronts
[front].
nPoints
= 0;
66
fc->
fronts
[front].
points
= NULL;
67
}
68
else
69
{
70
FRONT
*f = &fc->
fronts
[front];
71
point = f->
nPoints
;
72
f->
nPoints
++;
73
f->
points
= (
POINT
*)realloc(f->
points
,
sizeof
(
POINT
) * f->
nPoints
);
74
f->
n
= 0;
75
f->
points
[point].
objectives
= NULL;
76
f->
points
[point].
tnode
= (
avl_node_t
*) malloc(
sizeof
(
avl_node_t
));
77
char
*tok = strtok(line,
" \t\n"
);
78
do
79
{
80
POINT
*p = &f->
points
[point];
81
objective = f->
n
;
82
f->
n
++;
83
p->
objectives
= (
OBJECTIVE
*) realloc(p->
objectives
,
sizeof
(
OBJECTIVE
) * f->
n
);
84
p->
objectives
[objective] = atof(tok);
85
}
while
((tok = strtok(NULL,
" \t\n"
)) != NULL);
86
}
87
}
88
89
fc->
nFronts
--;
90
// for (int i = 0; i < fc->nFronts; i++) fc->fronts[i].n = fc->fronts[i].points[0].nObjectives;
91
fclose(fp);
92
/* printf("Read %d fronts\n", fc->nFronts);
93
printContents(fc); */
94
return
fc;
95
}
POINT::objectives
OBJECTIVE * objectives
Definition:
wfg.h:12
FRONT::n
int n
Definition:
wfg.h:19
FILECONTENTS::fronts
FRONT * fronts
Definition:
wfg.h:26
printContents
void printContents(FILECONTENTS *f)
Definition:
read.cpp:19
OBJECTIVE
double OBJECTIVE
Definition:
wfg.h:8
avl_node_t
Definition:
avl.h:52
wfg.h
readFile
FILECONTENTS * readFile(const char filename[])
Definition:
read.cpp:40
avl.h
FRONT::nPoints
int nPoints
Definition:
wfg.h:18
POINT::tnode
struct avl_node_t * tnode
Definition:
wfg.h:13
FILECONTENTS
Definition:
wfg.h:23
POINT
Definition:
wfg.h:10
FRONT
Definition:
wfg.h:16
FILECONTENTS::nFronts
int nFronts
Definition:
wfg.h:25
FRONT::points
POINT * points
Definition:
wfg.h:20
Generated on Tue Jul 2 2024 15:05:16 for OPAL (Object Oriented Parallel Accelerator Library) by
1.8.5