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