Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
5e8e997b
"src/array/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "ff519f98c317eaffc1f753ad8fb28f4c4280596e"
Commit
5e8e997b
authored
Dec 02, 2017
by
Davis King
Browse files
Added python interface to find_min_global()
parent
e273f515
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
tools/python/src/global_optimization.cpp
tools/python/src/global_optimization.cpp
+64
-0
No files found.
tools/python/src/global_optimization.cpp
View file @
5e8e997b
...
@@ -132,6 +132,52 @@ boost::python::tuple py_find_max_global2 (
...
@@ -132,6 +132,52 @@ boost::python::tuple py_find_max_global2 (
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
boost
::
python
::
tuple
py_find_min_global
(
object
f
,
boost
::
python
::
list
bound1
,
boost
::
python
::
list
bound2
,
boost
::
python
::
list
is_integer_variable
,
unsigned
long
num_function_calls
,
double
solver_epsilon
=
0
)
{
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
bound2
));
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
is_integer_variable
));
auto
func
=
[
&
](
const
matrix
<
double
,
0
,
1
>&
x
)
{
return
call_func
(
f
,
x
);
};
auto
result
=
find_min_global
(
func
,
list_to_mat
(
bound1
),
list_to_mat
(
bound2
),
list_to_bool_vector
(
is_integer_variable
),
max_function_calls
(
num_function_calls
),
solver_epsilon
);
return
boost
::
python
::
make_tuple
(
mat_to_list
(
result
.
x
),
result
.
y
);
}
boost
::
python
::
tuple
py_find_min_global2
(
object
f
,
boost
::
python
::
list
bound1
,
boost
::
python
::
list
bound2
,
unsigned
long
num_function_calls
,
double
solver_epsilon
=
0
)
{
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
bound2
));
auto
func
=
[
&
](
const
matrix
<
double
,
0
,
1
>&
x
)
{
return
call_func
(
f
,
x
);
};
auto
result
=
find_min_global
(
func
,
list_to_mat
(
bound1
),
list_to_mat
(
bound2
),
max_function_calls
(
num_function_calls
),
solver_epsilon
);
return
boost
::
python
::
make_tuple
(
mat_to_list
(
result
.
x
),
result
.
y
);
}
// ----------------------------------------------------------------------------------------
void
bind_global_optimization
()
void
bind_global_optimization
()
{
{
/*!
/*!
...
@@ -244,5 +290,23 @@ ensures \n\
...
@@ -244,5 +290,23 @@ ensures \n\
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
);
}
}
{
def
(
"find_min_global"
,
&
py_find_min_global
,
"This function is just like find_max_global(), except it performs minimization rather than maximization."
,
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"is_integer_variable"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
}
{
def
(
"find_min_global"
,
&
py_find_min_global2
,
"This function simply calls the other version of find_min_global() with is_integer_variable set to False for all variables."
,
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
}
}
}
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