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

82 lines
3.0 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_BOP_INTEGRAL_SOLVER_H_
#define ORTOOLS_BOP_INTEGRAL_SOLVER_H_
#include "absl/base/attributes.h"
#include "ortools/bop/bop_parameters.pb.h"
#include "ortools/bop/bop_types.h"
#include "ortools/lp_data/lp_data.h"
#include "ortools/lp_data/lp_types.h"
#include "ortools/util/time_limit.h"
namespace operations_research {
namespace bop {
// This class implements an Integer Programming solver, i.e. the solver solves
// problems with both integral and boolean variables, linear constraint and
// linear objective function.
class IntegralSolver {
public:
IntegralSolver();
// This type is neither copyable nor movable.
IntegralSolver(const IntegralSolver&) = delete;
IntegralSolver& operator=(const IntegralSolver&) = delete;
~IntegralSolver() = default;
// Sets the solver parameters.
// See the proto for an extensive documentation.
void SetParameters(const BopParameters& parameters) {
parameters_ = parameters;
}
BopParameters parameters() const { return parameters_; }
// Solves the given linear program and returns the solve status.
ABSL_MUST_USE_RESULT BopSolveStatus
Solve(const glop::LinearProgram& linear_problem);
ABSL_MUST_USE_RESULT BopSolveStatus SolveWithTimeLimit(
const glop::LinearProgram& linear_problem, TimeLimit* time_limit);
// Same as Solve() but starts from the given solution.
// TODO(user): Change the API to accept a partial solution instead since the
// underlying solver supports it.
ABSL_MUST_USE_RESULT BopSolveStatus
Solve(const glop::LinearProgram& linear_problem,
const glop::DenseRow& user_provided_initial_solution);
ABSL_MUST_USE_RESULT BopSolveStatus
SolveWithTimeLimit(const glop::LinearProgram& linear_problem,
const glop::DenseRow& user_provided_initial_solution,
TimeLimit* time_limit);
// Returns the objective value of the solution with its offset.
glop::Fractional objective_value() const { return objective_value_; }
// Returns the best bound found so far.
glop::Fractional best_bound() const { return best_bound_; }
// Returns the solution values. Note that the values only make sense when a
// solution is found.
const glop::DenseRow& variable_values() const { return variable_values_; }
private:
BopParameters parameters_;
glop::DenseRow variable_values_;
glop::Fractional objective_value_;
glop::Fractional best_bound_;
};
} // namespace bop
} // namespace operations_research
#endif // ORTOOLS_BOP_INTEGRAL_SOLVER_H_