Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More migration to <chrono> #235

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions solvers/gecode/gecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,14 @@ GecodeSolver::Stop::Stop(GecodeSolver &solver)
: solver_(solver) {
output_or_limit_ = solver.output_ || solver.time_limit_ < DBL_MAX ||
solver.node_limit_ != ULONG_MAX || solver.fail_limit_ != ULONG_MAX;
steady_clock::time_point start = steady_clock::now();
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
double end_time_in_ticks = start.time_since_epoch().count() +
solver.time_limit_ * steady_clock::period::den /
steady_clock::period::num;
end_time_ = steady_clock::time_point(steady_clock::duration(
end_time_in_ticks >= std::numeric_limits<steady_clock::rep>::max() ?
std::numeric_limits<steady_clock::rep>::max() :
static_cast<steady_clock::rep>(end_time_in_ticks)));
solver.time_limit_ * std::chrono::steady_clock::period::den /
std::chrono::steady_clock::period::num;
end_time_ = std::chrono::steady_clock::time_point(std::chrono::steady_clock::duration(
end_time_in_ticks >= std::numeric_limits<std::chrono::steady_clock::rep>::max() ?
std::numeric_limits<std::chrono::steady_clock::rep>::max() :
static_cast<std::chrono::steady_clock::rep>(end_time_in_ticks)));
next_output_time_ = start + GetOutputInterval();
}

Expand All @@ -536,7 +536,7 @@ bool GecodeSolver::Stop::stop(
return true;
}
if (!output_or_limit_) return false;
steady_clock::time_point time = steady_clock::now();
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();
if (solver_.output_ && time >= next_output_time_) {
solver_.Output("{:10} {:10} {:10}\n", s.depth, s.node, s.fail);
next_output_time_ += GetOutputInterval();
Expand Down Expand Up @@ -783,7 +783,7 @@ GecodeSolver::ProblemPtr GecodeSolver::Search(
}

void GecodeSolver::Solve(Problem &p, SolutionHandler &sh) {
steady_clock::time_point time = steady_clock::now();
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();

SetStatus(-1, "");

Expand Down
14 changes: 7 additions & 7 deletions solvers/gecode/gecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# pragma warning(pop)
#endif

#include "mp/clock.h"
#include "mp/utils-clock.h"
#include "mp/expr-visitor.h"
#include "mp/problem.h"
#include "mp/solver.h"
Expand Down Expand Up @@ -358,14 +358,14 @@ class GecodeSolver : public SolverImpl<Problem> {
class Stop : public Gecode::Search::Stop {
private:
GecodeSolver &solver_;
steady_clock::time_point end_time_;
steady_clock::time_point next_output_time_;
std::chrono::steady_clock::time_point end_time_;
std::chrono::steady_clock::time_point next_output_time_;
bool output_or_limit_;

steady_clock::duration GetOutputInterval() const {
return steady_clock::duration(
static_cast<steady_clock::rep>(solver_.output_frequency_ *
steady_clock::period::den / steady_clock::period::num));
std::chrono::steady_clock::duration GetOutputInterval() const {
return std::chrono::steady_clock::duration(
static_cast<std::chrono::steady_clock::rep>(solver_.output_frequency_ *
std::chrono::steady_clock::period::den / std::chrono::steady_clock::period::num));
}

public:
Expand Down
2 changes: 1 addition & 1 deletion solvers/ilogcp/ilogcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void IlogCPSolver::Solve(Problem &p, SolutionHandler &sh) {
}

void IlogCPSolver::InitProblemModificationPhase(const Problem &p) {
stats.time = steady_clock::now();
stats.time = std::chrono::steady_clock::now();

optimizer = optimizer_;
if (optimizer == AUTO) {
Expand Down
4 changes: 2 additions & 2 deletions solvers/ilogcp/ilogcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <limits.h> /* Needed for g++ -m32 on MacOSX. */
#include <string>

#include "mp/clock.h"
#include "mp/utils-clock.h"
#include "mp/solver.h"

namespace mp {
Expand Down Expand Up @@ -144,7 +144,7 @@ class IlogCPSolver : public SolverImpl<Problem> {
void SetCPLEXIntOption(const SolverOption &opt, int value, int param);

struct Stats {
steady_clock::time_point time;
std::chrono::steady_clock::time_point time;
double setup_time;
double solution_time;
};
Expand Down
6 changes: 3 additions & 3 deletions solvers/jacop/jacop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void JaCoPSolver::Output(fmt::CStringRef format, const fmt::ArgList &args) {
}

void JaCoPSolver::PrintLogEntry() {
if (outlev_ == 0 || steady_clock::now() < next_output_time_)
if (outlev_ == 0 || std::chrono::steady_clock::now() < next_output_time_)
return;
Output("{:10} {:10} {:10}\n",
env_.CallIntMethodKeepException(search_.get(), get_depth_),
Expand Down Expand Up @@ -544,7 +544,7 @@ JNIEXPORT jboolean JNICALL JaCoPSolver::Stop(JNIEnv *, jobject, jlong data) {
}

void JaCoPSolver::Solve(Problem &p, SolutionHandler &sh) {
steady_clock::time_point time = steady_clock::now();
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();

std::vector<const char*> jvm_options(jvm_options_.size() + 2);
for (size_t i = 0, n = jvm_options_.size(); i != n; ++i)
Expand Down Expand Up @@ -660,7 +660,7 @@ void JaCoPSolver::Solve(Problem &p, SolutionHandler &sh) {
"Max Depth", "Nodes", "Fails", (has_obj ? "Best Obj" : ""));
jboolean found = false;
output_count_ = 0;
next_output_time_ = steady_clock::now() + GetOutputInterval();
next_output_time_ = std::chrono::steady_clock::now() + GetOutputInterval();
try {
if (has_obj) {
jmethodID labeling = env_.GetMethod(dfs_class.get(), "labeling",
Expand Down
12 changes: 6 additions & 6 deletions solvers/jacop/jacop.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <vector>

#include "mp/clock.h"
#include "mp/utils-clock.h"
#include "mp/expr-visitor.h"
#include "mp/problem.h"
#include "mp/solver.h"
Expand Down Expand Up @@ -398,7 +398,7 @@ class JaCoPSolver : public SolverImpl<Problem> {
std::vector<std::string> jvm_options_;
jlong outlev_;
double output_frequency_;
steady_clock::time_point next_output_time_;
std::chrono::steady_clock::time_point next_output_time_;
unsigned output_count_;
std::string header_;
const char *var_select_;
Expand Down Expand Up @@ -456,10 +456,10 @@ class JaCoPSolver : public SolverImpl<Problem> {
void Output(fmt::CStringRef format, const fmt::ArgList &args);
FMT_VARIADIC(void, Output, fmt::CStringRef)

steady_clock::duration GetOutputInterval() const {
return steady_clock::duration(
static_cast<steady_clock::rep>(output_frequency_ *
steady_clock::period::den / steady_clock::period::num));
std::chrono::steady_clock::duration GetOutputInterval() const {
return std::chrono::steady_clock::duration(
static_cast<std::chrono::steady_clock::rep>(output_frequency_ *
std::chrono::steady_clock::period::den / std::chrono::steady_clock::period::num));
}

// Prints the solution log entry if the time is right.
Expand Down
4 changes: 2 additions & 2 deletions solvers/localsolver/localsolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <cmath>
#include <limits>
#include "mp/clock.h"
#include "mp/utils-clock.h"
#include "mp/safeint.h"

#ifndef MP_DRIVER_DATE
Expand Down Expand Up @@ -559,7 +559,7 @@ LocalSolver::LocalSolver()
}

void LocalSolver::Solve(ProblemBuilder &builder, SolutionHandler &sh) {
steady_clock::time_point time = steady_clock::now();
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();

ls::LocalSolver &solver = builder.solver();
ls::LSModel model = solver.getModel();
Expand Down
4 changes: 2 additions & 2 deletions solvers/sulum/sulum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

#include "sulum/sulum.h"
#include "mp/clock.h"
#include "mp/utils-clock.h"

#include <limits>

Expand Down Expand Up @@ -151,7 +151,7 @@ SulumSolver::~SulumSolver() {
}

void SulumSolver::Solve(ColProblem &p, SolutionHandler &sh) {
steady_clock::time_point time = steady_clock::now();
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();

if (p.has_nonlinear_cons() || p.num_logical_cons() != 0)
throw Error("Sulum doesn't support nonlinear problems");
Expand Down
6 changes: 3 additions & 3 deletions test/solvers/numberofmap-speed-test.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ilogcp/concert.h"
#include "mp/clock.h"
#include "mp/utils-clock.h"
#include "mp/problem.h"

struct CreateVar {
Expand All @@ -17,10 +17,10 @@ int main() {
b.AddArg(p.MakeVariable(i));
exprs[i] = p.EndNumberOf(b);
}
mp::steady_clock::time_point start = mp::steady_clock::now();
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
for (int i = 0; i < num_exprs; ++i)
map.Add(0, exprs[i]);
mp::steady_clock::time_point end = mp::steady_clock::now();
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
fmt::print("Executed NumberOfMap.Add {} times in {} s.\n",
num_exprs, mp::duration_cast< mp::duration<double> >(end - start).count());
}