Files
ortools-clone/ortools/sat/cumulative.h
Corentin Le Molgat b4b226801b update include guards
2025-11-05 11:54:02 +01:00

76 lines
3.1 KiB
C++

// Copyright 2010-2025 Google LLC
// 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.
#ifndef ORTOOLS_SAT_CUMULATIVE_H_
#define ORTOOLS_SAT_CUMULATIVE_H_
#include <functional>
#include <vector>
#include "absl/types/span.h"
#include "ortools/sat/integer_base.h"
#include "ortools/sat/intervals.h"
#include "ortools/sat/model.h"
#include "ortools/sat/sat_base.h"
#include "ortools/sat/scheduling_helpers.h"
namespace operations_research {
namespace sat {
// Adds a cumulative constraint on the given intervals, the associated demands
// and the capacity expressions.
//
// Each interval represents a task to be scheduled in time such that the task
// consumes the resource during the time range [lb, ub) where lb and ub
// respectively represent the lower and upper bounds of the corresponding
// interval variable. The amount of resource consumed by the task is the value
// of its associated demand variable.
//
// The cumulative constraint forces the set of task to be scheduled such that
// the sum of the demands of all the tasks that overlap any time point cannot
// exceed the capacity of the resource.
//
// This constraint assumes that an interval can be optional or have a size
// of zero. The demands and the capacity can be any non-negative number.
//
// Optimization: If one already have an helper constructed from the interval
// variable, it can be passed as last argument.
std::function<void(Model*)> Cumulative(
const std::vector<Literal>& enforcement_literals,
const std::vector<IntervalVariable>& vars,
absl::Span<const AffineExpression> demands, AffineExpression capacity,
SchedulingConstraintHelper* helper = nullptr);
// Adds a simple cumulative constraint. See the comment of Cumulative() above
// for a definition of the constraint. This is only used for testing.
//
// This constraint assumes that task demands and the resource capacity are fixed
// to non-negative number.
std::function<void(Model*)> CumulativeTimeDecomposition(
absl::Span<const Literal> enforcement_literals,
absl::Span<const IntervalVariable> vars,
absl::Span<const AffineExpression> demands, AffineExpression capacity,
SchedulingConstraintHelper* helper = nullptr);
// Another testing code, same assumptions as the CumulativeTimeDecomposition().
std::function<void(Model*)> CumulativeUsingReservoir(
absl::Span<const Literal> enforcement_literals,
absl::Span<const IntervalVariable> vars,
absl::Span<const AffineExpression> demands, AffineExpression capacity,
SchedulingConstraintHelper* helper = nullptr);
} // namespace sat
} // namespace operations_research
#endif // ORTOOLS_SAT_CUMULATIVE_H_