Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
2cfdb731
Commit
2cfdb731
authored
Aug 12, 2016
by
LEFEBVREJP email
Browse files
Starting on annealing alorithm for defining a colorset.
parent
a220c0e5
Changes
7
Hide whitespace changes
Inline
Side-by-side
radixcolor/colorset.cc
View file @
2cfdb731
#include "radixbug/bug.hh"
#include "radixcolor/colorset.hh"
#include <random>
#include "radixbug/bug.hh"
#include "radixcolor/color.hh"
namespace
radix
...
...
@@ -42,8 +45,36 @@ Color ColorSet::next() const
void
ColorSet
::
evaluate
()
const
{
// random device for generator
std
::
random_device
rd
;
// mersienne twister algorithm
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<>
rgb_dis
(
0
,
255
);
// initialize mColors to mSize random colors
mColors
.
resize
(
mSize
);
std
::
vector
<
LAB
>
labs
(
mSize
);
for
(
int
i
=
0
;
i
<
mSize
;
++
i
)
{
mColors
[
i
].
setR
(
rgb_dis
(
gen
));
mColors
[
i
].
setG
(
rgb_dis
(
gen
));
mColors
[
i
].
setB
(
rgb_dis
(
gen
));
radix_line
(
"Random color["
<<
mColors
[
i
].
r
()
<<
","
<<
mColors
[
i
].
g
()
<<
","
<<
mColors
[
i
].
b
()
<<
"]"
);
// convert RGB to LAB spectrum
labs
[
i
]
=
mColors
[
i
].
toLAB
();
}
//
// define energy function
//
// define temperature function
//
//
convert all rgb colors to cielab colors
//
define next_function
//
// annealing algorithm
...
...
radixcolor/colorset.hh
View file @
2cfdb731
...
...
@@ -2,6 +2,7 @@
#define RADIX_RADIXCOLOR_COLORSET_HH_
#include <vector>
#include <cstdlib>
namespace
radix
{
...
...
radixcolor/tests/tstColor.cc
View file @
2cfdb731
...
...
@@ -2,6 +2,7 @@
#include "gtest/gtest.h"
#include "radixcolor/color.hh"
#include "radixcolor/colorset.hh"
using
namespace
radix
;
TEST
(
Radix
,
RGBtoLAB
)
{
...
...
@@ -20,3 +21,8 @@ TEST(Radix, RGBtoLAB)
EXPECT_FLOAT_EQ
(
82.658813
,
lab
.
b
());
}
}
TEST
(
Radix
,
ColorSet
)
{
ColorSet
set
;
Color
first
=
set
.
next
();
}
radixmath/CMakeLists.txt
View file @
2cfdb731
...
...
@@ -7,6 +7,7 @@ IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
ENDIF
()
SET
(
SOURCE
annealing.cc
matrix.cc
normal.cc
point3d.cc
...
...
@@ -16,6 +17,8 @@ vector3d.cc
)
SET
(
HEADERS
annealing.hh
annealing.i.hh
constants.hh
matrix.hh
matrix.i.hh
...
...
radixmath/annealing.cc
0 → 100644
View file @
2cfdb731
/*
* File: annealing.cc
* Author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
*
* Created on August 12, 2016, 10:50 AM
*/
#include "radixmath/annealing.hh"
#include <algorithm>
namespace
radix
{
}
// namespace radix
radixmath/annealing.hh
0 → 100644
View file @
2cfdb731
/*
* File: annealing.hh
* Author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
*
* Created on August 12, 2016, 10:50 AM
*/
#ifndef RADIX_RADIXMATH_ANNEALING_HH_
#define RADIX_RADIXMATH_ANNEALING_HH_
#include "radixbug/bug.hh"
#include "radixmath/constants.hh"
#include <vector>
namespace
radix
{
// To find a status with lower energy according to the given condition
template
<
typename
status
,
typename
energy_function
,
typename
temperature_function
,
typename
next_function
>
status
simulated_annealing
(
status
iOld
,
int
c
,
const
energy_function
&
ef
,
const
temperature_function
&
tf
,
const
next_function
&
nf
);
}
//
// Include templated implementation file
#include "radixmath/annealing.i.hh"
#endif
/* RADIX_RADIXMATH_ANNEALING_HH_ */
radixmath/annealing.i.hh
0 → 100644
View file @
2cfdb731
#include "radixmath/annealing.hh"
#include <cmath>
#include <random>
#include <utility>
#include <algorithm>
namespace
radix
{
template
<
typename
status
,
typename
energy_function
,
typename
temperature_function
,
typename
next_function
,
typename
generator
>
status
simulated_annealing
(
status
iOld
,
int
c
,
const
energy_function
&
ef
,
const
temperature_function
&
tf
,
const
next_function
&
nf
)
{
// mersienne twister generator
std
::
mt19937_64
g
(
std
::
random_device
());
auto
eOld
=
ef
(
iOld
);
status
iBest
=
iOld
;
auto
eBest
=
eOld
;
std
::
uniform_real_distribution
<
decltype
(
eOld
)
>
rf
(
0
,
1
);
for
(;
c
>
0
;
--
c
){
status
iNew
=
nf
(
iOld
);
auto
eNew
=
ef
(
iNew
);
if
(
eNew
<
eBest
){
iBest
=
iNew
;
eBest
=
eNew
;
}
if
(
eNew
<
eOld
||
std
::
exp
((
eOld
-
eNew
)
/
tf
(
c
))
>
rf
(
g
)
){
iOld
=
std
::
move
(
iNew
);
eOld
=
std
::
move
(
eNew
);
}
}
return
iBest
;
}
}
// namespace radix
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment