DualSolver.h
Go to the documentation of this file.
1 /* Copyright 2020 CNRS-AIST JRL */
2 
3 #pragma once
4 
5 #include <Eigen/Core>
6 
7 #include <jrl-qp/SolverOptions.h>
8 #include <jrl-qp/api.h>
9 #include <jrl-qp/defs.h>
14 #include <jrl-qp/utils/Logger.h>
15 #include <jrl-qp/utils/debug.h>
16 
17 namespace jrl::qp
18 {
24 {
25 public:
26  DualSolver();
29  DualSolver(int nbVar, int nbCstr, bool useBounds);
30 
31  virtual ~DualSolver() = default;
32 
38  void resize(int nbVar, int nbCstr, bool useBounds);
39 
41  void options(const SolverOptions & options);
42 
44  WConstVector solution() const;
46  WConstVector multipliers() const;
48  double objectiveValue() const;
50  int iterations() const;
51 
57  const std::vector<ActivationStatus> & activeSet() const;
58 
60  void resetActiveSet();
61 
62 protected:
63  struct StepLength
64  {
65  double t1;
66  double t2;
67  int l;
68  };
69 
71  TerminationStatus solve();
73  TerminationStatus terminate(TerminationStatus status);
74 
80  internal::SelectedConstraint selectViolatedConstraint(const VectorConstRef & x) const;
82  void computeStep(VectorRef z, VectorRef r, const internal::SelectedConstraint & sc) const;
84  StepLength computeStepLength(const internal::SelectedConstraint & sc,
85  const VectorConstRef & x,
86  const VectorConstRef & u,
87  const VectorConstRef & z,
88  const VectorConstRef & r) const;
90  bool addConstraint(const internal::SelectedConstraint & sc);
94  bool removeConstraint(int l, VectorRef u);
96  virtual double dot(const internal::SelectedConstraint & sc, const VectorConstRef & z);
97 
101  virtual internal::InitTermination init_() = 0;
103  virtual internal::SelectedConstraint selectViolatedConstraint_(const VectorConstRef & x) const = 0;
105  virtual void computeStep_(VectorRef z, VectorRef r, const internal::SelectedConstraint & sc) const = 0;
107  virtual StepLength computeStepLength_(const internal::SelectedConstraint & sc,
108  const VectorConstRef & x,
109  const VectorConstRef & u,
110  const VectorConstRef & z,
111  const VectorConstRef & r) const = 0;
113  virtual bool addConstraint_(const internal::SelectedConstraint & sc) = 0;
117  virtual bool removeConstraint_(int l) = 0;
119  virtual double dot_(const internal::SelectedConstraint & sc, const VectorConstRef & z) = 0;
121  virtual void resize_(int nbVar, int nbCstr, bool useBounds) = 0;
122 
123 private:
125  void resize_p(int nbVar, int nbCstr, bool useBounds);
126 
127 protected:
130 
131  int it_; // number of iterations
132 
133  int nbVar_;
135 
136  double f_;
142 };
143 
144 } // namespace jrl::qp
jrl::qp::internal::SelectedConstraint
Definition: SelectedConstraint.h:13
Workspace.h
jrl::qp::DualSolver::needToExpandMultipliers_
bool needToExpandMultipliers_
Definition: DualSolver.h:141
jrl::qp::utils::Logger
Definition: Logger.h:18
jrl::qp::SolverOptions
Definition: SolverOptions.h:14
jrl::qp::DualSolver::work_r_
internal::Workspace work_r_
Definition: DualSolver.h:140
jrl::qp::internal::Workspace
Definition: Workspace.h:18
jrl::qp::DualSolver::A_
internal::ActiveSet A_
Definition: DualSolver.h:134
TerminationType.h
jrl::qp::VectorConstRef
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
Definition: defs.h:13
jrl::qp::TerminationStatus
TerminationStatus
Definition: enums.h:26
jrl::qp::DualSolver::work_z_
internal::Workspace work_z_
Definition: DualSolver.h:138
jrl::qp::DualSolver::StepLength::t2
double t2
Definition: DualSolver.h:66
Logger.h
jrl::qp
Definition: blockArrowLLT.h:12
jrl::qp::DualSolver::StepLength
Definition: DualSolver.h:63
ActiveSet.h
jrl::qp::WConstVector
decltype(std::add_const_t< internal::Workspace< double > >().asVector(0)) WConstVector
Definition: Workspace.h:150
jrl::qp::DualSolver::f_
double f_
Definition: DualSolver.h:136
SolverOptions.h
jrl::qp::DualSolver
Definition: DualSolver.h:23
jrl::qp::DualSolver::work_x_
internal::Workspace work_x_
Definition: DualSolver.h:137
jrl::qp::DualSolver::options_
SolverOptions options_
Definition: DualSolver.h:128
JRLQP_DLLAPI
#define JRLQP_DLLAPI
Definition: api.h:35
jrl::qp::DualSolver::StepLength::t1
double t1
Definition: DualSolver.h:65
jrl::qp::DualSolver::work_u_
internal::Workspace work_u_
Definition: DualSolver.h:139
jrl::qp::DualSolver::nbVar_
int nbVar_
Definition: DualSolver.h:133
jrl::qp::DualSolver::it_
int it_
Definition: DualSolver.h:131
defs.h
SelectedConstraint.h
jrl::qp::VectorRef
Eigen::Ref< Eigen::VectorXd > VectorRef
Definition: defs.h:14
jrl::qp::DualSolver::StepLength::l
int l
Definition: DualSolver.h:67
debug.h
jrl::qp::DualSolver::log_
utils::Logger log_
Definition: DualSolver.h:129
jrl::qp::internal::ActiveSet
Definition: ActiveSet.h:23
api.h
jrl::qp::internal::InitTermination
Definition: TerminationType.h:38