AGX Dynamics  2.35.0.1
BoxedKellerAlgorithm.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_BOXEDKELLERALGORITHM_H
18 #define AGX_BOXEDKELLERALGORITHM_H
19 
20 #include <agx/MixedLCP.h>
21 #include <agx/Logger.h>
22 
23 
24 namespace agx
25 {
27  {
28  public:
32  BoxedKellerAlgorithm( agx::Real globalTolerance, agx::UInt maxNumIterations, bool gatherStatistics );
33 
38 
43 
50  agx::Bool makeSolutionFeasible( Args& args, agx::UInt maxNumIterations = agx::UInt( 64 ) );
51 
52  protected:
53 
57  struct PivotIndex
58  {
59  PivotIndex() : index( agx::InvalidIndex ), sign( agx::Real( 0 ) ), done( false ) {}
60 
65  };
66 
71  struct StepLength
72  {
81  };
82 
83 #if 0
84 // List of solver statistics we want to extract. Some of these are not specific
85 // to Keller and should therefore be included in McpAlgorithmStats.
86  struct Stats
87  {
88  std::vector<int> inner_iterations;
89  size_t rank_update;
90  std::vector<int> updates;
91  int projections;
92  int projection_deletions;
93  int variables;
94  int active;
95  Stats( size_t n ) : inner_iterations(), updates(n, -1), rank_update(0), projections(0),
96  projection_deletions(0), variables(n), active(0){}
97 
98  Stats() : Stats(0){}
99  };
100 #endif
101 
102  protected:
103 
104 
105 
110 
114  virtual agx::UInt switchIndices( const agx::RealValarray& z, const agx::RealValarray& w, const agx::SparseRangeReal& bounds, agx::IndexSet& indexSet, agx::Real tolerance = agx::Real( 1E-8 ) ) const override;
115 
116 
117  protected:
122  void initializeIndexSet( Args& args ) const;
123 
128  void getInitialPoint( Args& args );
129 
135  PivotIndex getPivotIndex( Args& args ) const;
136 
144 
153  StepLength getStepLength( Args& args, const agx::RealValarray& searchDirection, const PivotIndex& pi, const agx::RealValarray& pivotRow ) const;
154 
163  void doStep( Args& args, const StepLength& sl, agx::RealValarray& searchDirection, const PivotIndex& pi, const agx::RealValarray& pivotCol ) const;
164 
172  agx::Bool doPivot( Args& args, const StepLength& sl, const PivotIndex& pi ) const;
173 
174 
175  protected:
177  };
178 
180 }
181 
182 #endif
#define AGXPHYSICS_EXPORT
agx::Bool makeSolutionFeasible(Args &args, agx::UInt maxNumIterations=agx::UInt(64))
Calculates a feasible solution z and switches indices.
void initializeIndexSet(Args &args) const
Initializes the index set.
agx::RealValarray getSearchDirection(Args &args, const agx::RealValarray &pivotCol)
Finds the search direction given most violated index.
agx::Bool doPivot(Args &args, const StepLength &sl, const PivotIndex &pi) const
Given step length, updates the index set.
PivotIndex getPivotIndex(Args &args) const
Finds and returns the most violated index.
StepLength getStepLength(Args &args, const agx::RealValarray &searchDirection, const PivotIndex &pi, const agx::RealValarray &pivotRow) const
Calculates the step length given search direction.
virtual ~BoxedKellerAlgorithm()
Reference counted object - protected destructor.
virtual agx::UInt switchIndices(const agx::RealValarray &z, const agx::RealValarray &w, const agx::SparseRangeReal &bounds, agx::IndexSet &indexSet, agx::Real tolerance=agx::Real(1E-8)) const override
Custom implementation of switch indices where slack is ignored and we only pivot on infeasible elemen...
void doStep(Args &args, const StepLength &sl, agx::RealValarray &searchDirection, const PivotIndex &pi, const agx::RealValarray &pivotCol) const
Perform step, i.e., update z and w given search direction and step length.
virtual agx::NlMixedCp::McpAlgorithm::SolveReport solve(agx::NlMixedCp::McpAlgorithm::Args &args) override
Solves MCP using Keller's Principal Pivot Method.
BoxedKellerAlgorithm(agx::Real globalTolerance, agx::UInt maxNumIterations, bool gatherStatistics)
Construct given global tolerance and the maximum iterations.
agx::NlMixedCp::McpAlgorithm::SolveReport searchSolution(agx::NlMixedCp::McpAlgorithm::Args &args)
Searches solution assuming z is feasible and the index set is up to date.
void getInitialPoint(Args &args)
Finds the initial starting point.
Interface class for algorithm to solve general mixed complementarity problem.
Definition: MixedLCP.h:115
Essentially a sparse array of bounds.
Definition: SparseTypes.h:74
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
T sign(T v)
Definition: Math.h:328
bool Bool
Definition: Integer.h:48
agx::ref_ptr< BoxedKellerAlgorithm > BoxedKellerAlgorithmRef
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Data for pivot index with sign and current range of the most violated index.
Data for step length with the different thetas and indices (r2 and r3) of other bounded equations tha...
Structure for all the arguments passed around.
Definition: MixedLCP.h:159