Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
iteration_stats.h
Go to the documentation of this file.
1// Copyright 2010-2024 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
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.
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.
51ConvergenceInformation 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// `primal_solution_for_residual_tests` is used instead of `scaled_primal_ray`
69// when deciding whether or not to treat a primal gradient as a dual residual
70// or not.
71InfeasibilityInformation ComputeInfeasibilityInformation(
72 const PrimalDualHybridGradientParams& params,
73 const ShardedQuadraticProgram& scaled_sharded_qp,
74 const Eigen::VectorXd& col_scaling_vec,
75 const Eigen::VectorXd& row_scaling_vec,
76 const Eigen::VectorXd& scaled_primal_ray,
77 const Eigen::VectorXd& scaled_dual_ray,
78 const Eigen::VectorXd& primal_solution_for_residual_tests,
79 PointType candidate_type);
80
81// Computes the reduced costs vector, objective_matrix * `primal_solution` +
82// objective_vector - constraint_matrix * `dual_solution`, when
83// `use_zero_primal_objective` is false, and -constraint_matrix *
84// `dual_solution` when `use_zero_primal_objective` is true. See
85// https://developers.google.com/optimization/lp/pdlp_math#reduced_costs_dual_residuals_and_the_corrected_dual_objective.
86Eigen::VectorXd ReducedCosts(const PrimalDualHybridGradientParams& params,
87 const ShardedQuadraticProgram& scaled_sharded_qp,
88 const Eigen::VectorXd& primal_solution,
89 const Eigen::VectorXd& dual_solution,
90 bool use_zero_primal_objective = false);
91
92// Finds and returns the `ConvergenceInformation` with the specified
93// `candidate_type`, or std::nullopt if no such candidate exists.
94std::optional<ConvergenceInformation> GetConvergenceInformation(
95 const IterationStats& stats, PointType candidate_type);
96
97// Finds and returns the `InfeasibilityInformation` with the specified
98// `candidate_type`, or std::nullopt if no such candidate exists.
99std::optional<InfeasibilityInformation> GetInfeasibilityInformation(
100 const IterationStats& stats, PointType candidate_type);
101
102// Finds and returns the `PointMetadata` with the specified
103// `point_type`, or std::nullopt if no such point exists.
104std::optional<PointMetadata> GetPointMetadata(const IterationStats& stats,
105 PointType point_type);
106
107// For each entry in `random_projection_seeds`, computes a random projection of
108// the primal/dual solution pair onto pseudo-random vectors generated from that
109// seed and adds the results to
110// `random_primal_projections`/`random_dual_projections` in `metadata`.
111void SetRandomProjections(const ShardedQuadraticProgram& sharded_qp,
112 const Eigen::VectorXd& primal_solution,
113 const Eigen::VectorXd& dual_solution,
114 const std::vector<int>& random_projection_seeds,
115 PointMetadata& metadata);
116
117} // namespace operations_research::pdlp
118
119#endif // PDLP_ITERATION_STATS_H_
Validation utilities for solvers.proto.
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, const Eigen::VectorXd &primal_solution_for_residual_tests, PointType candidate_type)
std::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)
VectorXd ReducedCosts(const PrimalDualHybridGradientParams &params, const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, bool use_zero_primal_objective)
std::optional< InfeasibilityInformation > GetInfeasibilityInformation(const IterationStats &stats, PointType candidate_type)
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)
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)