qpmad
Eigen-based C++ QP solver.
active_set.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2017 Alexander Sherikov. Licensed under the Apache License,
6  Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 #pragma once
12 
13 
14 namespace qpmad
15 {
16  class ActiveSet
17  {
18  public:
19  std::vector<MatrixIndex> active_constraints_indices_;
23 
24 
25  public:
26  void initialize(const MatrixIndex max_size)
27  {
28  active_constraints_indices_.resize(max_size);
29  size_ = 0;
30  num_equalities_ = 0;
32  }
33 
34 
35  MatrixIndex getIndex(const MatrixIndex index) const
36  {
37  return(active_constraints_indices_[index]);
38  }
39 
40 
41  bool hasEmptySpace() const
42  {
43  return(static_cast<std::size_t>(size_) < active_constraints_indices_.size());
44  }
45 
46 
47  void addEquality(const MatrixIndex index)
48  {
50  ++size_;
52  }
53 
54 
55  void addInequality(const MatrixIndex index)
56  {
58  ++size_;
60  }
61 
62 
63  void removeInequality(const MatrixIndex index)
64  {
65  if (size_ - index > 1)
66  {
67  // deactivated constraint is not the last one added
68  std::copy( active_constraints_indices_.begin() + index + 1,
70  active_constraints_indices_.begin() + index);
71  }
72  --size_;
74  }
75  };
76 }
bool hasEmptySpace() const
Definition: active_set.h:41
void initialize(const MatrixIndex max_size)
Definition: active_set.h:26
int MatrixIndex
Definition: common.h:32
MatrixIndex num_inequalities_
Definition: active_set.h:22
void addEquality(const MatrixIndex index)
Definition: active_set.h:47
void addInequality(const MatrixIndex index)
Definition: active_set.h:55
std::vector< MatrixIndex > active_constraints_indices_
Definition: active_set.h:19
MatrixIndex getIndex(const MatrixIndex index) const
Definition: active_set.h:35
MatrixIndex num_equalities_
Definition: active_set.h:21
void removeInequality(const MatrixIndex index)
Definition: active_set.h:63
MatrixIndex size_
Definition: active_set.h:20