Apollo 11.0
自动驾驶开放平台
affine_constraint.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include "cyber/common/log.h"
24
25namespace apollo {
26namespace planning {
27
29 : is_equality_(is_equality) {}
30
31AffineConstraint::AffineConstraint(const Eigen::MatrixXd& constraint_matrix,
32 const Eigen::MatrixXd& constraint_boundary,
33 const bool is_equality)
34 : constraint_matrix_(constraint_matrix),
35 constraint_boundary_(constraint_boundary),
36 is_equality_(is_equality) {
37 CHECK_EQ(constraint_boundary.rows(), constraint_matrix.rows());
38}
39
40void AffineConstraint::SetIsEquality(const double is_equality) {
41 is_equality_ = is_equality;
42}
43
44const Eigen::MatrixXd& AffineConstraint::constraint_matrix() const {
45 return constraint_matrix_;
46}
47
48const Eigen::MatrixXd& AffineConstraint::constraint_boundary() const {
49 return constraint_boundary_;
50}
51
53 const Eigen::MatrixXd& constraint_matrix,
54 const Eigen::MatrixXd& constraint_boundary) {
55 if (constraint_matrix.rows() != constraint_boundary.rows()) {
56 AERROR << "Fail to add constraint because constraint matrix rows != "
57 "constraint boundary rows.";
58 AERROR << "constraint matrix rows = " << constraint_matrix.rows();
59 AERROR << "constraint boundary rows = " << constraint_boundary.rows();
60 return false;
61 }
62
63 if (constraint_matrix_.rows() == 0) {
64 constraint_matrix_ = constraint_matrix;
65 constraint_boundary_ = constraint_boundary;
66 return true;
67 }
68 if (constraint_matrix_.cols() != constraint_matrix.cols()) {
69 AERROR
70 << "constraint_matrix_ cols and constraint_matrix cols do not match.";
71 AERROR << "constraint_matrix_.cols() = " << constraint_matrix_.cols();
72 AERROR << "constraint_matrix.cols() = " << constraint_matrix.cols();
73 return false;
74 }
75 if (constraint_boundary.cols() != 1) {
76 AERROR << "constraint_boundary.cols() should be 1.";
77 return false;
78 }
79
80 Eigen::MatrixXd n_matrix(constraint_matrix_.rows() + constraint_matrix.rows(),
81 constraint_matrix_.cols());
82 Eigen::MatrixXd n_boundary(
83 constraint_boundary_.rows() + constraint_boundary.rows(), 1);
84
85 n_matrix << constraint_matrix_, constraint_matrix;
86 n_boundary << constraint_boundary_, constraint_boundary;
87 constraint_matrix_ = n_matrix;
88 constraint_boundary_ = n_boundary;
89 return true;
90}
91
92} // namespace planning
93} // namespace apollo
const Eigen::MatrixXd & constraint_boundary() const
bool AddConstraint(const Eigen::MatrixXd &constraint_matrix, const Eigen::MatrixXd &constraint_boundary)
void SetIsEquality(const double is_equality)
const Eigen::MatrixXd & constraint_matrix() const
Planning module main class.
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37