OR-Tools  9.6
iteration_stats.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 <optional>
18 #include <vector>
19 
20 #include "Eigen/Core"
22 #include "ortools/pdlp/solve_log.pb.h"
23 #include "ortools/pdlp/solvers.pb.h"
24 
25 namespace operations_research::pdlp {
26 
27 // Returns convergence statistics about a primal/dual solution pair. The stats
28 // are with respect to `sharded_qp` (which is typically scaled).
29 // This function is equivalent to `ComputeConvergenceInformation` given scaling
30 // vectors uniformly equal to one.
31 ConvergenceInformation ComputeScaledConvergenceInformation(
32  const PrimalDualHybridGradientParams& params,
33  const ShardedQuadraticProgram& sharded_qp,
34  const Eigen::VectorXd& primal_solution,
35  const Eigen::VectorXd& dual_solution,
36  double componentwise_primal_residual_offset,
37  double componentwise_dual_residual_offset, PointType candidate_type);
38 
39 // Returns convergence statistics about a primal/dual solution pair. It is
40 // assumed that `scaled_sharded_qp` has been transformed from the original qp by
41 // `ShardedQuadraticProgram::RescaleQuadraticProgram(col_scaling_vec,
42 // row_scaling_vec)`. `scaled_primal_solution` and `scaled_dual_solution` are
43 // solutions for the scaled problem. The stats are computed with respect to the
44 // implicit original problem. `componentwise_primal_residual_offset` and
45 // `componentwise_dual_residual_offset` are the offsets (i.e., eps_ratio) used
46 // for computing the l_inf_componentwise residual norms.
47 // NOTE: This function assumes that `scaled_primal_solution` satisfies the
48 // variable bounds and `scaled_dual_solution` satisfies the dual variable
49 // bounds; see
50 // https://developers.google.com/optimization/lp/pdlp_math#dual_variable_bounds.
51 ConvergenceInformation ComputeConvergenceInformation(
52  const PrimalDualHybridGradientParams& params,
53  const ShardedQuadraticProgram& sharded_qp,
54  const Eigen::VectorXd& col_scaling_vec,
55  const Eigen::VectorXd& row_scaling_vec,
56  const Eigen::VectorXd& scaled_primal_solution,
57  const Eigen::VectorXd& scaled_dual_solution,
58  double componentwise_primal_residual_offset,
59  double componentwise_dual_residual_offset, PointType candidate_type);
60 
61 // Returns infeasibility statistics about a primal/dual infeasibility
62 // certificate estimate. It is assumed that `scaled_sharded_qp` has been
63 // transformed from the original qp by
64 // `ShardedQuadraticProgram::RescaleQuadraticProgram(col_scaling_vec,
65 // row_scaling_vec)`. `scaled_primal_ray` and `scaled_dual_ray` are
66 // potential certificates for the scaled problem. The stats are computed with
67 // respect to the implicit original problem.
68 InfeasibilityInformation ComputeInfeasibilityInformation(
69  const PrimalDualHybridGradientParams& params,
70  const ShardedQuadraticProgram& scaled_sharded_qp,
71  const Eigen::VectorXd& col_scaling_vec,
72  const Eigen::VectorXd& row_scaling_vec,
73  const Eigen::VectorXd& scaled_primal_ray,
74  const Eigen::VectorXd& scaled_dual_ray, PointType candidate_type);
75 
76 // Computes the reduced costs vector, objective_matrix * `primal_solution` +
77 // objective_vector - constraint_matrix * `dual_solution` - dual_residuals, when
78 // `use_zero_primal_objective` is false, and -constraint_matrix *
79 // `dual_solution` - dual_residuals when `use_zero_primal_objective` is true.
80 // The elements of the vector are corrected component-wise to zero to ensure
81 // that the dual objective takes a finite value. See
82 // https://developers.google.com/optimization/lp/pdlp_math#reduced_costs_dual_residuals_and_the_corrected_dual_objective.
83 Eigen::VectorXd ReducedCosts(const PrimalDualHybridGradientParams& params,
84  const ShardedQuadraticProgram& scaled_sharded_qp,
85  const Eigen::VectorXd& primal_solution,
86  const Eigen::VectorXd& dual_solution,
87  bool use_zero_primal_objective = false);
88 
89 // Finds and returns the `ConvergenceInformation` with the specified
90 // `candidate_type`, or std::nullopt if no such candidate exists.
91 std::optional<ConvergenceInformation> GetConvergenceInformation(
92  const IterationStats& stats, PointType candidate_type);
93 
94 // Finds and returns the `InfeasibilityInformation` with the specified
95 // `candidate_type`, or std::nullopt if no such candidate exists.
96 std::optional<InfeasibilityInformation> GetInfeasibilityInformation(
97  const IterationStats& stats, PointType candidate_type);
98 
99 // Finds and returns the `PointMetadata` with the specified
100 // `point_type`, or std::nullopt if no such point exists.
101 std::optional<PointMetadata> GetPointMetadata(const IterationStats& stats,
102  PointType point_type);
103 
104 // For each entry in `random_projection_seeds`, computes a random projection of
105 // the primal/dual solution pair onto pseudo-random vectors generated from that
106 // seed and adds the results to
107 // `random_primal_projections`/`random_dual_projections` in `metadata`.
108 void SetRandomProjections(const ShardedQuadraticProgram& sharded_qp,
109  const Eigen::VectorXd& primal_solution,
110  const Eigen::VectorXd& dual_solution,
111  const std::vector<int>& random_projection_seeds,
112  PointMetadata& metadata);
113 
114 } // namespace operations_research::pdlp
115 
116 #endif // PDLP_ITERATION_STATS_H_
VectorXd ReducedCosts(const PrimalDualHybridGradientParams &params, const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, bool use_zero_primal_objective)
InfeasibilityInformation ComputeInfeasibilityInformation(const PrimalDualHybridGradientParams &params, 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)
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)
std::optional< PointMetadata > GetPointMetadata(const IterationStats &stats, const PointType point_type)
ConvergenceInformation ComputeScaledConvergenceInformation(const PrimalDualHybridGradientParams &params, const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, const double componentwise_primal_residual_offset, const double componentwise_dual_residual_offset, PointType candidate_type)
std::optional< InfeasibilityInformation > GetInfeasibilityInformation(const IterationStats &stats, PointType candidate_type)
std::optional< ConvergenceInformation > GetConvergenceInformation(const IterationStats &stats, PointType candidate_type)
ConvergenceInformation ComputeConvergenceInformation(const PrimalDualHybridGradientParams &params, 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, const double componentwise_primal_residual_offset, const double componentwise_dual_residual_offset, PointType candidate_type)