blob: 2ec3db7220305bbc25efb1cf8bf9cd820c0a1556 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -07002// Copyright 2023 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -08003// http://ceres-solver.org/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// * Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28//
29// Author: sameeragarwal@google.com (Sameer Agarwal)
30
31#ifndef CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_
32#define CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_
33
Austin Schuh3de38b02024-06-25 18:25:10 -070034#include <memory>
Austin Schuh70cc9552019-01-21 19:46:48 -080035#include <vector>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080036
Austin Schuh70cc9552019-01-21 19:46:48 -080037#include "ceres/graph.h"
Austin Schuh3de38b02024-06-25 18:25:10 -070038#include "ceres/internal/disable_warnings.h"
39#include "ceres/internal/export.h"
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080040#include "ceres/ordered_groups.h"
Austin Schuh70cc9552019-01-21 19:46:48 -080041#include "ceres/types.h"
42
Austin Schuh3de38b02024-06-25 18:25:10 -070043namespace ceres::internal {
Austin Schuh70cc9552019-01-21 19:46:48 -080044
45class Program;
46class ParameterBlock;
47
48// Uses an approximate independent set ordering to order the parameter
Austin Schuh3de38b02024-06-25 18:25:10 -070049// blocks of a problem so that it is suitable for use with Schur-
50// complement-based solvers. The output variable ordering contains an
Austin Schuh70cc9552019-01-21 19:46:48 -080051// ordering of the parameter blocks and the return value is size of
52// the independent set or the number of e_blocks (see
53// schur_complement_solver.h for an explanation). Constant parameters
54// are added to the end.
55//
56// The ordering vector has the structure
57//
58// ordering = [independent set,
59// complement of the independent set,
60// fixed blocks]
Austin Schuh3de38b02024-06-25 18:25:10 -070061CERES_NO_EXPORT int ComputeSchurOrdering(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080062 const Program& program, std::vector<ParameterBlock*>* ordering);
Austin Schuh70cc9552019-01-21 19:46:48 -080063
64// Same as above, except that ties while computing the independent set
65// ordering are resolved in favour of the order in which the parameter
66// blocks occur in the program.
Austin Schuh3de38b02024-06-25 18:25:10 -070067CERES_NO_EXPORT int ComputeStableSchurOrdering(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080068 const Program& program, std::vector<ParameterBlock*>* ordering);
Austin Schuh70cc9552019-01-21 19:46:48 -080069
70// Use an approximate independent set ordering to decompose the
71// parameter blocks of a problem in a sequence of independent
72// sets. The ordering covers all the non-constant parameter blocks in
73// the program.
Austin Schuh3de38b02024-06-25 18:25:10 -070074CERES_NO_EXPORT void ComputeRecursiveIndependentSetOrdering(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080075 const Program& program, ParameterBlockOrdering* ordering);
Austin Schuh70cc9552019-01-21 19:46:48 -080076
77// Builds a graph on the parameter blocks of a Problem, whose
78// structure reflects the sparsity structure of the Hessian. Each
79// vertex corresponds to a parameter block in the Problem except for
80// parameter blocks that are marked constant. An edge connects two
81// parameter blocks, if they co-occur in a residual block.
Austin Schuh3de38b02024-06-25 18:25:10 -070082CERES_NO_EXPORT std::unique_ptr<Graph<ParameterBlock*>> CreateHessianGraph(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080083 const Program& program);
Austin Schuh70cc9552019-01-21 19:46:48 -080084
85// Iterate over each of the groups in order of their priority and fill
86// summary with their sizes.
Austin Schuh3de38b02024-06-25 18:25:10 -070087CERES_NO_EXPORT void OrderingToGroupSizes(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080088 const ParameterBlockOrdering* ordering, std::vector<int>* group_sizes);
Austin Schuh70cc9552019-01-21 19:46:48 -080089
Austin Schuh3de38b02024-06-25 18:25:10 -070090} // namespace ceres::internal
91
92#include "ceres/internal/reenable_warnings.h"
Austin Schuh70cc9552019-01-21 19:46:48 -080093
94#endif // CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_