Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthias Mayr
limbo
Commits
00638372
Commit
00638372
authored
Oct 15, 2015
by
Konstantinos Chatzilygeroudis
Browse files
Switched to Stroustrup break braces version
parent
086bd2a4
Changes
45
Expand all
Show whitespace changes
Inline
Side-by-side
src/benchmarks/multi.cpp
View file @
00638372
...
...
@@ -5,43 +5,41 @@
using
namespace
limbo
;
struct
Params
{
struct
boptimizer
{
struct
Params
{
struct
boptimizer
{
BO_PARAM
(
double
,
noise
,
0.01
);
BO_PARAM
(
int
,
dump_period
,
1
);
};
struct
init
{
struct
init
{
BO_PARAM
(
int
,
nb_samples
,
10
);
// calandra: number of dimensions * 5
// knowles : 11 * dim - 1
};
struct
parego
:
public
defaults
::
parego
{
struct
parego
:
public
defaults
::
parego
{
};
struct
maxiterations
{
struct
maxiterations
{
BO_PARAM
(
int
,
n_iterations
,
30
);
};
struct
ucb
:
public
defaults
::
ucb
{
struct
ucb
:
public
defaults
::
ucb
{
};
struct
gp_ucb
:
public
defaults
::
gp_ucb
{
struct
gp_ucb
:
public
defaults
::
gp_ucb
{
};
struct
cmaes
:
public
defaults
::
cmaes
{
struct
cmaes
:
public
defaults
::
cmaes
{
};
struct
gp_auto
:
public
defaults
::
gp_auto
{
struct
gp_auto
:
public
defaults
::
gp_auto
{
};
struct
meanconstant
:
public
defaults
::
meanconstant
{
struct
meanconstant
:
public
defaults
::
meanconstant
{
};
struct
ehvi
{
struct
ehvi
{
BO_PARAM
(
double
,
x_ref
,
-
11
);
BO_PARAM
(
double
,
y_ref
,
-
11
);
};
...
...
@@ -55,8 +53,7 @@ struct Params
#define ZDT_DIM 30
#endif
struct
zdt1
{
struct
zdt1
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -73,8 +70,7 @@ struct zdt1
}
};
struct
zdt2
{
struct
zdt2
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -91,8 +87,7 @@ struct zdt2
}
};
struct
zdt3
{
struct
zdt3
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -109,8 +104,7 @@ struct zdt3
}
};
struct
mop2
{
struct
mop2
{
static
constexpr
size_t
dim
=
2
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -129,13 +123,12 @@ struct mop2
}
};
namespace
limbo
{
namespace
stat
{
namespace
limbo
{
namespace
stat
{
template
<
typename
F
>
struct
ParetoBenchmark
{
struct
ParetoBenchmark
{
template
<
typename
BO
>
void
operator
()(
BO
&
opt
)
{
...
...
src/cmaes/boundary_transformation.c
View file @
00638372
...
...
@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
t
->
lower_bounds
=
default_lower
;
if
(
upper_bounds
==
NULL
&&
len_of_bounds
<=
1
)
t
->
upper_bounds
=
default_upper
;
if
(
len_of_bounds
==
0
)
{
if
(
len_of_bounds
==
0
)
{
t
->
lower_bounds
=
default_lower
;
t
->
upper_bounds
=
default_upper
;
t
->
len_of_bounds
=
1
;
...
...
@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
lb
=
t
->
lower_bounds
;
ub
=
t
->
upper_bounds
;
for
(
i
=
0
;
i
<
t
->
len_of_bounds
;
++
i
)
{
for
(
i
=
0
;
i
<
t
->
len_of_bounds
;
++
i
)
{
if
(
lb
[
i
]
==
ub
[
i
])
_FatalError
(
"in _init: lower and upper bounds must be different in all "
"variables"
);
...
...
@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x,
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
boundary_transformation_shift_into_feasible_preimage
(
t
,
x
,
y
,
len
);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t,
unsigned
long
i
;
// boundary_transformation_shift_into_feasible_preimage(t, x, y, len);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage(
double
lb
,
ub
,
al
,
au
,
r
,
xlow
,
xup
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage(
y
[
i
]
=
x
[
i
];
if
(
y
[
i
]
<
xlow
)
{
/* shift up */
if
(
y
[
i
]
<
xlow
)
{
/* shift up */
y
[
i
]
+=
r
*
(
1
+
(
int
)((
xlow
-
y
[
i
])
/
r
));
}
if
(
y
[
i
]
>
xup
)
{
/* shift down */
if
(
y
[
i
]
>
xup
)
{
/* shift down */
y
[
i
]
-=
r
*
(
1
+
(
int
)((
y
[
i
]
-
xup
)
/
r
));
/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
}
...
...
@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage(
if
(
y
[
i
]
>
ub
+
au
)
y
[
i
]
-=
2
*
(
y
[
i
]
-
ub
-
au
);
if
((
y
[
i
]
<
lb
-
al
-
1e-15
)
||
(
y
[
i
]
>
ub
+
au
+
1e-15
))
{
if
((
y
[
i
]
<
lb
-
al
-
1e-15
)
||
(
y
[
i
]
>
ub
+
au
+
1e-15
))
{
printf
(
"BUG in boundary_transformation_shift_into_feasible_preimage: "
"lb=%f, ub=%f, al=%f au=%f, y=%f
\n
"
,
lb
,
ub
,
al
,
au
,
y
[
i
]);
...
...
@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
else
if
(
y
[
i
]
>
ub
-
au
)
y
[
i
]
=
(
ub
+
au
)
-
2
*
sqrt
(
au
*
(
ub
-
y
[
i
]));
}
if
(
11
<
3
||
do_assertions
)
{
if
(
11
<
3
||
do_assertions
)
{
double
*
z
=
calloc
(
len
,
sizeof
(
double
));
for
(
i
=
0
;
i
<
len
;
++
i
)
z
[
i
]
=
y
[
i
];
...
...
src/cmaes/boundary_transformation.h
View file @
00638372
...
...
@@ -26,7 +26,7 @@ extern "C" {
*/
typedef
struct
{
{
double
const
*
lower_bounds
;
/* array of size len_of_bounds */
double
const
*
upper_bounds
;
/* array of size len_of_bounds */
unsigned
long
len_of_bounds
;
/* in case, last value is recycled */
...
...
src/cmaes/cmaes.c
View file @
00638372
This diff is collapsed.
Click to expand it.
src/cmaes/cmaes.h
View file @
00638372
...
...
@@ -18,10 +18,10 @@
#include <time.h>
typedef
struct
/* random_t
/* random_t
* sets up a pseudo random number generator instance
*/
{
{
/* Variables for Uniform() */
long
int
startseed
;
long
int
aktseed
;
...
...
@@ -34,10 +34,10 @@ typedef struct
}
random_t
;
typedef
struct
/* timings_t
/* timings_t
* time measurement, used to time eigendecomposition
*/
{
{
/* for outside use */
double
totaltime
;
/* zeroed by calling re-calling timings_start */
double
totaltotaltime
;
...
...
@@ -57,11 +57,11 @@ typedef struct
}
timings_t
;
typedef
struct
/* readpara_t
/* readpara_t
* collects all parameters, in particular those that are read from
* a file before to start. This should split in future?
*/
{
{
char
*
filename
;
/* keep record of the file that was taken to read parameters */
...
...
@@ -120,10 +120,10 @@ typedef struct
}
readpara_t
;
typedef
struct
/* cmaes_t
/* cmaes_t
* CMA-ES "object"
*/
{
{
const
char
*
version
;
/* char *signalsFilename; */
readpara_t
sp
;
...
...
src/ehvi/ehvi_calculations.cc
View file @
00638372
...
...
@@ -25,31 +25,25 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[])
int
Sstart
=
k
-
1
,
Shorizontal
=
0
;
// See thesis for explanation of how the O(1) iteration complexity
// is reached. NOTE: i = y = f[1], j = x = f[0]
for
(
int
i
=
0
;
i
<=
k
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
k
;
i
++
)
{
Sminus
=
0
;
Shorizontal
=
Sstart
;
for
(
int
j
=
k
-
i
;
j
<=
k
;
j
++
)
{
for
(
int
j
=
k
-
i
;
j
<=
k
;
j
++
)
{
double
fmax
[
2
];
// staircase width and height
double
cl1
,
cl2
,
cu1
,
cu2
;
// Boundaries of grid cells
if
(
j
==
k
)
{
if
(
j
==
k
)
{
fmax
[
1
]
=
r
[
1
];
cu1
=
INFINITY
;
}
else
{
else
{
fmax
[
1
]
=
P
[
j
]
->
f
[
1
];
cu1
=
P
[
j
]
->
f
[
0
];
}
if
(
i
==
k
)
{
if
(
i
==
k
)
{
fmax
[
0
]
=
r
[
0
];
cu2
=
INFINITY
;
}
else
{
else
{
fmax
[
0
]
=
P
[
k
-
i
-
1
]
->
f
[
0
];
cu2
=
P
[
k
-
i
-
1
]
->
f
[
1
];
}
...
...
@@ -58,17 +52,14 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[])
// Cell boundaries have been decided. Determine Sminus.
#ifdef NAIVE_DOMPOINTS
dompoints
.
clear
();
for
(
int
m
=
0
;
m
<
k
;
m
++
)
{
if
(
cl1
>=
P
[
m
]
->
f
[
0
]
&&
cl2
>=
P
[
m
]
->
f
[
1
])
{
for
(
int
m
=
0
;
m
<
k
;
m
++
)
{
if
(
cl1
>=
P
[
m
]
->
f
[
0
]
&&
cl2
>=
P
[
m
]
->
f
[
1
])
{
dompoints
.
push_back
(
P
[
m
]);
}
}
Sminus
=
calculateS
(
dompoints
,
fmax
);
#else
if
(
Shorizontal
>
Sstart
)
{
if
(
Shorizontal
>
Sstart
)
{
Sminus
+=
(
P
[
Shorizontal
]
->
f
[
0
]
-
fmax
[
0
])
*
(
P
[
Shorizontal
]
->
f
[
1
]
-
fmax
[
1
]);
}
Shorizontal
++
;
...
...
@@ -97,22 +88,17 @@ double ehvi3d_2term(deque<individual*> P, double r[], double mu[],
double
Sminus
;
// Correction term for the integral.
deque
<
individual
*>
Py
,
Pz
;
// P sorted by y/z coordinate
sort
(
P
.
begin
(),
P
.
end
(),
ycomparator
);
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Py
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
zcomparator
);
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Pz
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
xcomparator
);
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
double
fmax
[
3
];
// upper corner of hypervolume improvement box
double
cl
[
3
],
cu
[
3
];
// Boundaries of grid cells
cl
[
0
]
=
(
x
==
0
?
r
[
0
]
:
P
[
x
-
1
]
->
f
[
0
]);
...
...
@@ -159,22 +145,17 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
double
Sminus
;
// Correction term for the integral.
deque
<
individual
*>
Py
,
Pz
;
// P sorted by y/z coordinate
sort
(
P
.
begin
(),
P
.
end
(),
ycomparator
);
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Py
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
zcomparator
);
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Pz
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
xcomparator
);
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
double
v
[
3
];
// upper corner of hypervolume improvement box
double
cl
[
3
],
cu
[
3
];
// Boundaries of grid cells
cl
[
0
]
=
(
x
==
0
?
r
[
0
]
:
P
[
x
-
1
]
->
f
[
0
]);
...
...
@@ -188,25 +169,20 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
v
[
1
]
=
r
[
1
];
v
[
2
]
=
r
[
2
];
bool
dominated
=
false
;
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
dominated
=
true
;
break
;
}
else
if
(
P
[
i
]
->
f
[
0
]
<=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
<=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
0
]
>
v
[
0
])
v
[
0
]
=
P
[
i
]
->
f
[
0
];
}
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
<=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
<=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
1
]
>
v
[
1
])
v
[
1
]
=
P
[
i
]
->
f
[
1
];
}
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
<=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
<=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
2
]
>
v
[
2
])
v
[
2
]
=
P
[
i
]
->
f
[
2
];
}
...
...
@@ -255,22 +231,17 @@ double ehvi3d_8term(deque<individual*> P, double r[], double mu[],
tempimp
;
// Correction term, rectangular volume, temp. improvement
deque
<
individual
*>
Py
,
Pz
;
// P sorted by y/z coordinate
sort
(
P
.
begin
(),
P
.
end
(),
ycomparator
);
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Py
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
zcomparator
);
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
Pz
.
push_back
(
P
[
i
]);
}
sort
(
P
.
begin
(),
P
.
end
(),
xcomparator
);
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
for
(
int
z
=
0
;
z
<=
n
;
z
++
)
{
for
(
int
y
=
0
;
y
<=
n
;
y
++
)
{
for
(
int
x
=
0
;
x
<=
n
;
x
++
)
{
double
v
[
3
];
// upper corner of hypervolume improvement box
double
cl
[
3
],
cu
[
3
];
// Boundaries of grid cell
cl
[
0
]
=
(
x
==
0
?
r
[
0
]
:
P
[
x
-
1
]
->
f
[
0
]);
...
...
@@ -284,25 +255,20 @@ double ehvi3d_8term(deque<individual*> P, double r[], double mu[],
v
[
1
]
=
r
[
1
];
v
[
2
]
=
r
[
2
];
bool
dominated
=
false
;
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
for
(
unsigned
int
i
=
0
;
i
<
P
.
size
();
i
++
)
{
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
dominated
=
true
;
break
;
}
else
if
(
P
[
i
]
->
f
[
0
]
<=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
<=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
0
]
>
v
[
0
])
v
[
0
]
=
P
[
i
]
->
f
[
0
];
}
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
<=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
<=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
>=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
1
]
>
v
[
1
])
v
[
1
]
=
P
[
i
]
->
f
[
1
];
}
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
<=
cu
[
2
])
{
else
if
(
P
[
i
]
->
f
[
0
]
>=
cu
[
0
]
&&
P
[
i
]
->
f
[
1
]
>=
cu
[
1
]
&&
P
[
i
]
->
f
[
2
]
<=
cu
[
2
])
{
if
(
P
[
i
]
->
f
[
2
]
>
v
[
2
])
v
[
2
]
=
P
[
i
]
->
f
[
2
];
}
...
...
src/ehvi/ehvi_hvol.cc
View file @
00638372
...
...
@@ -18,8 +18,7 @@ using namespace std;
// Some prototypes:
struct
avlnode
;
struct
point
{
struct
point
{
// the data for a single point in the set + links to its AVL trees
double
x
;
double
y
;
...
...
@@ -27,8 +26,7 @@ struct point
avlnode
*
xnode
;
};
struct
avlnode
{
struct
avlnode
{
// an AVL tree node
avlnode
*
left
;
avlnode
*
right
;
...
...
@@ -37,8 +35,7 @@ struct avlnode
point
*
data
;
};
class
bitree
{
class
bitree
{
// Implementation of the AVL tree
public:
// stats treestats;
...
...
@@ -92,19 +89,16 @@ avlnode* bitree::getprevious(avlnode* start)
// Returns the previous node in the sort order, or NULL if there is no
// previous node
avlnode
*
answer
;
if
(
start
==
NULL
)
{
if
(
start
==
NULL
)
{
return
NULL
;
}
if
(
start
->
left
)
{
// return rightmost left child
if
(
start
->
left
)
{
// return rightmost left child
answer
=
start
->
left
;
while
(
answer
->
right
!=
NULL
)
answer
=
answer
->
right
;
return
answer
;
}
else
{
else
{
answer
=
start
;
while
(
answer
->
parent
!=
NULL
&&
answer
->
parent
->
right
!=
answer
)
answer
=
answer
->
parent
;
...
...
@@ -117,21 +111,17 @@ avlnode* bitree::getnext(avlnode* start)
{
// Returns the next node in the sort order, or NULL if there is no next node
avlnode
*
answer
;
if
(
start
==
NULL
)
{
if
(
start
==
NULL
)
{
return
NULL
;
}
if
(
start
->
right
)
{
// return leftmost right child
if
(
start
->
right
)
{
// return leftmost right child
answer
=
start
->
right
;
while
(
answer
->
left
!=
NULL
)
{
while
(
answer
->
left
!=
NULL
)
{
answer
=
answer
->
left
;
}
return
answer
;
}
else
{
else
{
answer
=
start
;
while
(
answer
->
parent
!=
NULL
&&
answer
->
parent
->
left
!=
answer
)
answer
=
answer
->
parent
;
...
...
@@ -147,17 +137,14 @@ point* bitree::removenode(avlnode* node)
point
*
returnvalue
;
if
(
!
node
)
return
NULL
;
if
(
node
->
parent
)
{
if
(
node
->
parent
)
{
if
(
node
->
parent
->
left
==
node
)
change
=
-
1
;
else
change
=
1
;
}
if
(
node
->
left
==
NULL
)
{
if
(
node
->
right
==
NULL
)
{
if
(
node
->
left
==
NULL
)
{
if
(
node
->
right
==
NULL
)
{
// leaf node, easy deletion
if
(
node
->
parent
==
NULL
)
root
=
NULL
;
...
...
@@ -166,42 +153,34 @@ point* bitree::removenode(avlnode* node)
else
node
->
parent
->
right
=
NULL
;
}
else
if
(
node
->
parent
==
NULL
)
{
else
if
(
node
->
parent
==
NULL
)
{
root
=
node
->
right
;
node
->
right
->
parent
=
NULL
;
}
else
if
(
node
->
parent
->
left
==
node
)
{
else
if
(
node
->
parent
->
left
==
node
)
{
node
->
parent
->
left
=
node
->
right
;
node
->
right
->
parent
=
node
->
parent
;
}
else
{
else
{
node
->
parent
->
right
=
node
->
right
;
node
->
right
->
parent
=
node
->
parent
;