2016-07-19 14:19:21 -07:00
|
|
|
// Copyright 2010-2014 Google
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "sat/intervals.h"
|
|
|
|
|
|
|
|
|
|
namespace operations_research {
|
|
|
|
|
namespace sat {
|
|
|
|
|
|
2017-01-18 10:50:37 +01:00
|
|
|
IntervalVariable IntervalsRepository::CreateInterval(IntegerVariable start,
|
|
|
|
|
IntegerVariable end,
|
|
|
|
|
IntegerVariable size,
|
|
|
|
|
IntegerValue fixed_size,
|
|
|
|
|
LiteralIndex is_present) {
|
|
|
|
|
// Create the interval.
|
|
|
|
|
const IntervalVariable i(start_vars_.size());
|
2016-10-29 20:12:59 +02:00
|
|
|
start_vars_.push_back(start);
|
2017-01-18 10:50:37 +01:00
|
|
|
end_vars_.push_back(end);
|
2016-10-29 20:12:59 +02:00
|
|
|
size_vars_.push_back(size);
|
2017-01-18 10:50:37 +01:00
|
|
|
fixed_sizes_.push_back(fixed_size);
|
|
|
|
|
is_present_.push_back(is_present);
|
|
|
|
|
|
|
|
|
|
// Link properly all its components.
|
|
|
|
|
if (SizeVar(i) != kNoIntegerVariable) {
|
|
|
|
|
precedences_->AddPrecedenceWithVariableOffset(StartVar(i), EndVar(i),
|
|
|
|
|
SizeVar(i));
|
|
|
|
|
precedences_->AddPrecedenceWithVariableOffset(EndVar(i), StartVar(i),
|
|
|
|
|
NegationOf(SizeVar(i)));
|
|
|
|
|
} else {
|
|
|
|
|
precedences_->AddPrecedenceWithOffset(StartVar(i), EndVar(i), fixed_size);
|
|
|
|
|
precedences_->AddPrecedenceWithOffset(EndVar(i), StartVar(i), -fixed_size);
|
|
|
|
|
}
|
|
|
|
|
if (IsOptional(i)) {
|
|
|
|
|
const Literal literal(is_present);
|
|
|
|
|
precedences_->MarkIntegerVariableAsOptional(StartVar(i), literal);
|
|
|
|
|
integer_trail_->MarkIntegerVariableAsOptional(StartVar(i), literal);
|
|
|
|
|
precedences_->MarkIntegerVariableAsOptional(EndVar(i), literal);
|
|
|
|
|
integer_trail_->MarkIntegerVariableAsOptional(EndVar(i), literal);
|
|
|
|
|
if (SizeVar(i) != kNoIntegerVariable) {
|
|
|
|
|
// TODO(user): This is not currently fully supported in precedences_
|
|
|
|
|
// if the size is not a constant variable.
|
|
|
|
|
CHECK_EQ(integer_trail_->LowerBound(SizeVar(i)),
|
|
|
|
|
integer_trail_->UpperBound(SizeVar(i)));
|
|
|
|
|
precedences_->MarkIntegerVariableAsOptional(SizeVar(i), literal);
|
|
|
|
|
integer_trail_->MarkIntegerVariableAsOptional(SizeVar(i), literal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return i;
|
2016-07-19 14:19:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace sat
|
|
|
|
|
} // namespace operations_research
|