Commit 918bbd5d authored by Davis King's avatar Davis King

Added a max runtime option to the oca solver.

parent d3006ab3
......@@ -9,6 +9,7 @@
#include "optimization_solve_qp_using_smo.h"
#include <vector>
#include "../sequence.h"
#include <chrono>
// ----------------------------------------------------------------------------------------
......@@ -88,6 +89,19 @@ namespace dlib
unsigned long get_subproblem_max_iterations (
) const { return sub_max_iter; }
void set_max_runtime (
const std::chrono::nanoseconds& max_runtime_
)
{
max_runtime = max_runtime_;
}
std::chrono::nanoseconds get_max_runtime (
) const
{
return max_runtime;
}
void set_inactive_plane_threshold (
unsigned long inactive_thresh_
)
......@@ -249,6 +263,8 @@ namespace dlib
const double prior_norm = have_prior ? 0.5*dot(prior,prior) : 0;
const auto time_to_stop = std::chrono::steady_clock::now() + max_runtime;
unsigned long counter = 0;
while (true)
{
......@@ -297,6 +313,8 @@ namespace dlib
{
break;
}
if (std::chrono::steady_clock::now() >= time_to_stop)
break;
// compute kernel matrix for all the planes
K.swap(Ktmp);
......@@ -398,6 +416,8 @@ namespace dlib
unsigned long sub_max_iter;
unsigned long inactive_thresh;
std::chrono::nanoseconds max_runtime = std::chrono::hours(24*356*290); // 290 years
};
}
......
......@@ -3,6 +3,8 @@
#undef DLIB_OPTIMIZATION_OCA_ABsTRACT_Hh_
#ifdef DLIB_OPTIMIZATION_OCA_ABsTRACT_Hh_
#include <chrono>
// ----------------------------------------------------------------------------------------
namespace dlib
......@@ -131,6 +133,8 @@ namespace dlib
- get_subproblem_epsilon() == 1e-2
- get_subproblem_max_iterations() == 50000
- get_inactive_plane_threshold() == 20
- get_max_runtime() == std::chrono::hours(24*356*290)
(i.e. 290 years, so basically forever)
WHAT THIS OBJECT REPRESENTS
This object is a tool for solving the optimization problem defined above
......@@ -324,6 +328,22 @@ namespace dlib
inactivity required before a cutting plane is removed.
!*/
void set_max_runtime (
const std::chrono::nanoseconds& max_runtime
) const;
/*!
ensures
- #get_max_runtime() == max_runtime
!*/
std::chrono::nanoseconds get_max_runtime (
) const;
/*!
ensures
- returns the maximum amount of time we will let the solver run before
making it terminate.
!*/
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment