OR-Tools  9.3
iteration_stats.h
Go to the documentation of this file.
1// Copyright 2010-2021 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef PDLP_ITERATION_STATS_H_
15#define PDLP_ITERATION_STATS_H_
16
17#include <limits>
18#include <string>
19#include <vector>
20
21#include "Eigen/Core"
22#include "absl/types/optional.h"
24#include "ortools/pdlp/solve_log.pb.h"
25#include "ortools/pdlp/solvers.pb.h"
26
28
29// Returns convergence statistics about a primal/dual solution pair. The stats
30// are with respect to sharded_qp (which is typically scaled).
31// This function is equivalent to ComputeConvergenceInformation given scaling
32// vectors uniformly equal to one.
34 const ShardedQuadraticProgram& sharded_qp,
35 const Eigen::VectorXd& primal_solution,
36 const Eigen::VectorXd& dual_solution, PointType candidate_type);
37
38// Returns convergence statistics about a primal/dual solution pair. It is
39// assumed that scaled_sharded_qp has been transformed from the original qp by
40// ShardedQuadraticProgram::RescaleQuadraticProgram(col_scaling_vec,
41// row_scaling_vec). scaled_primal_solution and scaled_dual_solution are
42// solutions for the scaled problem. The stats are computed with respect to the
43// implicit original problem.
44// NOTE: This function assumes that scaled_primal_solution satisfies the
45// variable bounds and scaled_dual_solution satisfies the dual variable bounds;
46// see
47// https://developers.google.com/optimization/lp/pdlp_math#dual_variable_bounds.
48ConvergenceInformation ComputeConvergenceInformation(
49 const ShardedQuadraticProgram& sharded_qp,
50 const Eigen::VectorXd& col_scaling_vec,
51 const Eigen::VectorXd& row_scaling_vec,
52 const Eigen::VectorXd& scaled_primal_solution,
53 const Eigen::VectorXd& scaled_dual_solution, PointType candidate_type);
54
55// Returns infeasibility statistics about a primal/dual infeasibility
56// certificate estimate. It is assumed that scaled_sharded_qp has been
57// transformed from the original qp by
58// ShardedQuadraticProgram::RescaleQuadraticProgram(col_scaling_vec,
59// row_scaling_vec). primal_ray and dual_ray are certificates for the scaled
60// problem. The stats are computed with respect to the implicit original
61// problem.
62InfeasibilityInformation ComputeInfeasibilityInformation(
63 const ShardedQuadraticProgram& scaled_sharded_qp,
64 const Eigen::VectorXd& col_scaling_vec,
65 const Eigen::VectorXd& row_scaling_vec,
66 const Eigen::VectorXd& scaled_primal_ray,
67 const Eigen::VectorXd& scaled_dual_ray, PointType candidate_type);
68
69// Computes the reduced costs vector, objective_matrix * primal_solution +
70// objective_vector - constraint_matrix * dual_solution - dual_residuals, when
71// use_zero_primal_objective is false, and -constraint_matrix * dual_solution -
72// dual_residuals when use_zero_primal_objective is true. The elements of the
73// vector are corrected component-wise to zero to ensure that the dual objective
74// takes a finite value. See
75// https://developers.google.com/optimization/lp/pdlp_math#reduced_costs_dual_residuals_and_the_corrected_dual_objective.
76Eigen::VectorXd ReducedCosts(const ShardedQuadraticProgram& scaled_sharded_qp,
77 const Eigen::VectorXd& primal_solution,
78 const Eigen::VectorXd& dual_solution,
79 bool use_zero_primal_objective = false);
80
81// Finds and returns the ConvergenceInformation with the specified
82// candidate_type, or absl::nullopt if no such candidate exists.
83absl::optional<ConvergenceInformation> GetConvergenceInformation(
84 const IterationStats& stats, PointType candidate_type);
85
86// Finds and returns the InfeasibilityInformation with the specified
87// candidate_type, or absl::nullopt if no such candidate exists.
88absl::optional<InfeasibilityInformation> GetInfeasibilityInformation(
89 const IterationStats& stats, PointType candidate_type);
90
91// Finds and returns the PointMetadata with the specified
92// point_type, or absl::nullopt if no such point exists.
93absl::optional<PointMetadata> GetPointMetadata(const IterationStats& stats,
94 PointType point_type);
95
96// For each entry in random_projection_seeds, computes a random projection of
97// the primal/dual solution pair onto pseudo-random vectors generated from that
98// seed and adds the results to
99// random_primal_projections/random_dual_projections in metadata.
100void SetRandomProjections(const ShardedQuadraticProgram& sharded_qp,
101 const Eigen::VectorXd& primal_solution,
102 const Eigen::VectorXd& dual_solution,
103 const std::vector<int>& random_projection_seeds,
104 PointMetadata& metadata);
105
106} // namespace operations_research::pdlp
107
108#endif // PDLP_ITERATION_STATS_H_
ConvergenceInformation ComputeScaledConvergenceInformation(const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, PointType candidate_type)
VectorXd ReducedCosts(const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, bool use_zero_primal_objective)
absl::optional< PointMetadata > GetPointMetadata(const IterationStats &stats, const PointType point_type)
InfeasibilityInformation ComputeInfeasibilityInformation(const ShardedQuadraticProgram &scaled_sharded_qp, const Eigen::VectorXd &col_scaling_vec, const Eigen::VectorXd &row_scaling_vec, const Eigen::VectorXd &scaled_primal_ray, const Eigen::VectorXd &scaled_dual_ray, PointType candidate_type)
absl::optional< ConvergenceInformation > GetConvergenceInformation(const IterationStats &stats, PointType candidate_type)
void SetRandomProjections(const ShardedQuadraticProgram &sharded_qp, const Eigen::VectorXd &primal_solution, const Eigen::VectorXd &dual_solution, const std::vector< int > &random_projection_seeds, PointMetadata &metadata)
absl::optional< InfeasibilityInformation > GetInfeasibilityInformation(const IterationStats &stats, PointType candidate_type)
ConvergenceInformation ComputeConvergenceInformation(const ShardedQuadraticProgram &scaled_sharded_qp, const Eigen::VectorXd &col_scaling_vec, const Eigen::VectorXd &row_scaling_vec, const Eigen::VectorXd &scaled_primal_solution, const Eigen::VectorXd &scaled_dual_solution, PointType candidate_type)