rename demon_monitor_ field to demon_profiler_ on Solver; Add tracing on sequence variables
This commit is contained in:
@@ -1350,7 +1350,7 @@ Solver::Solver(const string& name, const SolverParameters& parameters)
|
||||
fail_stamp_(GG_ULONGLONG(1)),
|
||||
balancing_decision_(new BalancingDecision),
|
||||
fail_intercept_(NULL),
|
||||
demon_monitor_(BuildDemonProfiler(this)),
|
||||
demon_profiler_(BuildDemonProfiler(this)),
|
||||
true_constraint_(NULL),
|
||||
false_constraint_(NULL),
|
||||
fail_decision_(new FailDecision()),
|
||||
@@ -1385,7 +1385,7 @@ Solver::Solver(const string& name)
|
||||
fail_stamp_(GG_ULONGLONG(1)),
|
||||
balancing_decision_(new BalancingDecision),
|
||||
fail_intercept_(NULL),
|
||||
demon_monitor_(BuildDemonProfiler(this)),
|
||||
demon_profiler_(BuildDemonProfiler(this)),
|
||||
true_constraint_(NULL),
|
||||
false_constraint_(NULL),
|
||||
fail_decision_(new FailDecision()),
|
||||
@@ -1411,7 +1411,7 @@ void Solver::Init() {
|
||||
timer_->Restart();
|
||||
model_cache_.reset(BuildModelCache(this));
|
||||
dependency_graph_.reset(BuildDependencyGraph(this));
|
||||
AddPropagationMonitor(reinterpret_cast<PropagationMonitor*>(demon_monitor_));
|
||||
AddPropagationMonitor(reinterpret_cast<PropagationMonitor*>(demon_profiler_));
|
||||
}
|
||||
|
||||
Solver::~Solver() {
|
||||
@@ -1431,7 +1431,7 @@ Solver::~Solver() {
|
||||
CHECK(searches_.empty())
|
||||
<< "non empty list of searches when ending the solver";
|
||||
delete search;
|
||||
DeleteDemonProfiler(demon_monitor_);
|
||||
DeleteDemonProfiler(demon_profiler_);
|
||||
DeleteBuilders();
|
||||
}
|
||||
|
||||
@@ -1882,8 +1882,8 @@ void Solver::NewSearch(DecisionBuilder* const db,
|
||||
|
||||
// Always install the main propagation monitor.
|
||||
propagation_monitor_->Install();
|
||||
if (demon_monitor_ != NULL) {
|
||||
InstallDemonProfiler(demon_monitor_);
|
||||
if (demon_profiler_ != NULL) {
|
||||
InstallDemonProfiler(demon_profiler_);
|
||||
}
|
||||
|
||||
// Push monitors and enter search.
|
||||
@@ -2396,8 +2396,8 @@ bool Solver::NestedSolve(DecisionBuilder* const db,
|
||||
// Always install the main propagation monitor.
|
||||
propagation_monitor_->Install();
|
||||
// Install the demon monitor if needed.
|
||||
if (demon_monitor_ != NULL) {
|
||||
InstallDemonProfiler(demon_monitor_);
|
||||
if (demon_profiler_ != NULL) {
|
||||
InstallDemonProfiler(demon_profiler_);
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
@@ -3107,6 +3107,18 @@ class Trace : public PropagationMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void RankFirst(SequenceVar* const var, int index) {
|
||||
for (int i = 0; i < monitors_.size(); ++i) {
|
||||
monitors_[i]->RankFirst(var, index);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void RankNotFirst(SequenceVar* const var, int index) {
|
||||
for (int i = 0; i < monitors_.size(); ++i) {
|
||||
monitors_[i]->RankNotFirst(var, index);
|
||||
}
|
||||
}
|
||||
|
||||
// Does not take ownership of monitor.
|
||||
void Add(PropagationMonitor* const monitor) {
|
||||
if (monitor != NULL) {
|
||||
|
||||
@@ -2703,8 +2703,8 @@ class Solver {
|
||||
// set_fail_intercept does not take ownership of the closure.
|
||||
void set_fail_intercept(Closure* const c) { fail_intercept_ = c; }
|
||||
void clear_fail_intercept() { fail_intercept_ = NULL; }
|
||||
// Access to demon monitor.
|
||||
DemonProfiler* demon_monitor() const { return demon_monitor_; }
|
||||
// Access to demon profiler.
|
||||
DemonProfiler* demon_profiler() const { return demon_profiler_; }
|
||||
// Returns whether the object has been named or not.
|
||||
bool HasName(const PropagationBaseObject* object) const;
|
||||
// Adds a new demon and wraps it inside a DemonProfiler if necessary.
|
||||
@@ -2844,7 +2844,7 @@ class Solver {
|
||||
// intercept failures
|
||||
Closure* fail_intercept_;
|
||||
// Demon monitor
|
||||
DemonProfiler* const demon_monitor_;
|
||||
DemonProfiler* const demon_profiler_;
|
||||
|
||||
// interval of constants cached, inclusive:
|
||||
enum { MIN_CACHED_INT_CONST = -8, MAX_CACHED_INT_CONST = 8 };
|
||||
|
||||
@@ -1034,6 +1034,9 @@ class PropagationMonitor : public SearchMonitor {
|
||||
int64 new_min,
|
||||
int64 new_max) = 0;
|
||||
virtual void SetPerformed(IntervalVar* const var, bool value) = 0;
|
||||
// SequenceVar modifiers
|
||||
virtual void RankFirst(SequenceVar* const var, int index) = 0;
|
||||
virtual void RankNotFirst(SequenceVar* const var, int index) = 0;
|
||||
// Install itself on the solver.
|
||||
virtual void Install();
|
||||
};
|
||||
|
||||
@@ -223,6 +223,8 @@ return WallTimer::GetTimeInMicroSeconds() - start_time_;
|
||||
int64 new_min,
|
||||
int64 new_max) {}
|
||||
virtual void SetPerformed(IntervalVar* const var, bool value) {}
|
||||
virtual void RankFirst(SequenceVar* const var, int index) {}
|
||||
virtual void RankNotFirst(SequenceVar* const var, int index) {}
|
||||
|
||||
// Useful for unit tests.
|
||||
void AddFakeRun(const Demon* const demon,
|
||||
@@ -400,7 +402,7 @@ return WallTimer::GetTimeInMicroSeconds() - start_time_;
|
||||
}
|
||||
}
|
||||
|
||||
// The demon_monitor is added by default on the main propagation
|
||||
// The demon_profiler is added by default on the main propagation
|
||||
// monitor. It just needs to be added to the search monitors at the
|
||||
// start of the search.
|
||||
virtual void Install() {
|
||||
@@ -417,8 +419,8 @@ return WallTimer::GetTimeInMicroSeconds() - start_time_;
|
||||
};
|
||||
|
||||
void Solver::ExportProfilingOverview(const string& filename) {
|
||||
if (demon_monitor_ != NULL) {
|
||||
demon_monitor_->PrintOverview(this, filename);
|
||||
if (demon_profiler_ != NULL) {
|
||||
demon_profiler_->PrintOverview(this, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1940,6 +1940,7 @@ void SequenceVar::AddPrecedence(int before, int after) {
|
||||
}
|
||||
|
||||
void SequenceVar::RankFirst(int index) {
|
||||
solver()->GetPropagationMonitor()->RankFirst(this, index);
|
||||
IntervalVar* const t = intervals_[index];
|
||||
t->SetPerformed(true);
|
||||
Solver* const s = solver();
|
||||
@@ -1958,6 +1959,7 @@ void SequenceVar::RankFirst(int index) {
|
||||
}
|
||||
|
||||
void SequenceVar::RankNotFirst(int index) {
|
||||
solver()->GetPropagationMonitor()->RankNotFirst(this, index);
|
||||
solver()->SaveAndSetValue(&min_ranks_[index], current_rank_ + 1);
|
||||
int possible_first_count = 0;
|
||||
int possible_first = -1;
|
||||
|
||||
@@ -732,6 +732,18 @@ class PrintTrace : public PropagationMonitor {
|
||||
value));
|
||||
}
|
||||
|
||||
virtual void RankFirst(SequenceVar* const var, int index) {
|
||||
DisplayModification(StringPrintf("RankFirst(%s, %d)",
|
||||
var->DebugString().c_str(),
|
||||
index));
|
||||
}
|
||||
|
||||
virtual void RankNotFirst(SequenceVar* const var, int index) {
|
||||
DisplayModification(StringPrintf("RankNotFirst(%s, %d)",
|
||||
var->DebugString().c_str(),
|
||||
index));
|
||||
}
|
||||
|
||||
virtual void Install() {
|
||||
SearchMonitor::Install();
|
||||
if (solver()->SolveDepth() <= 1) {
|
||||
|
||||
Reference in New Issue
Block a user