fix async problem when the transition time is added after the creation of the sequence variable

This commit is contained in:
lperron@google.com
2014-05-26 01:25:01 +00:00
parent 763bef35cb
commit fe15d4daa0
2 changed files with 12 additions and 8 deletions

View File

@@ -5081,13 +5081,19 @@ class DisjunctiveConstraint : public Constraint {
// least transit_evaluator->Run(a, b). This evaluator must always returns
// a positive or null value.
// This method takes ownership of the evaluator.
virtual void SetTransitionTime(Solver::IndexEvaluator2* transit_evaluator) {
void SetTransitionTime(Solver::IndexEvaluator2* transit_evaluator) {
transition_time_.reset(transit_evaluator);
if (transition_time_.get() != nullptr) {
transition_time_->CheckIsRepeatable();
}
}
int64 TransitionTime(int before_index, int after_index) {
return transition_time_ != nullptr
? transition_time_->Run(before_index, after_index)
: 0;
}
#if !defined(SWIG)
virtual const std::vector<IntVar*>& nexts() const = 0;
virtual const std::vector<IntVar*>& actives() const = 0;

View File

@@ -636,12 +636,12 @@ class RankedPropagator : public Constraint {
RankedPropagator(Solver* const solver, const std::vector<IntVar*>& nexts,
const std::vector<IntervalVar*>& intervals,
const std::vector<IntVar*>& slacks,
Solver::IndexEvaluator2* const transition_time)
DisjunctiveConstraint* const disjunctive)
: Constraint(solver),
nexts_(nexts),
intervals_(intervals),
slacks_(slacks),
transition_time_(transition_time),
disjunctive_(disjunctive),
partial_sequence_(intervals.size()),
previous_(intervals.size() + 2, 0) {}
@@ -818,9 +818,7 @@ class RankedPropagator : public Constraint {
const int before_index = partial_sequence_[before];
const int after_index = partial_sequence_[after];
return transition_time_ != nullptr
? transition_time_->Run(before_index, after_index)
: 0;
return disjunctive_->TransitionTime(before_index, after_index);
}
virtual std::string DebugString() const {
@@ -840,7 +838,7 @@ class RankedPropagator : public Constraint {
std::vector<IntVar*> nexts_;
std::vector<IntervalVar*> intervals_;
std::vector<IntVar*> slacks_;
Solver::IndexEvaluator2* const transition_time_;
DisjunctiveConstraint* const disjunctive_;
RevPartialSequence partial_sequence_;
std::vector<int> previous_;
};
@@ -999,7 +997,7 @@ class FullDisjunctiveConstraint : public DisjunctiveConstraint {
std::vector<IntVar*> short_slacks(time_slacks_.begin() + 1, time_slacks_.end());
s->AddConstraint(s->RevAlloc(new RankedPropagator(
s, nexts_, intervals_, short_slacks, transition_time_.get())));
s, nexts_, intervals_, short_slacks, this)));
}
SequenceVar* sequence_var_;