2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
15 ///original version written by Erwin Coumans, October 2013
17 #ifndef BT_PATH_SOLVER_H
18 #define BT_PATH_SOLVER_H
25 #include "PATH/SimpleLCP.h"
26 #include "PATH/License.h"
27 #include "PATH/Error_Interface.h"
29 void __stdcall MyError(Void *data, Char *msg)
31 printf("Path Error: %s\n", msg);
33 void __stdcall MyWarning(Void *data, Char *msg)
35 printf("Path Warning: %s\n", msg);
40 #include "btMLCPSolverInterface.h"
41 #include "Dantzig/lcp.h"
43 class btPathSolver : public btMLCPSolverInterface
48 License_SetString("2069810742&Courtesy_License&&&USR&2013&14_12_2011&1000&PATH&GEN&31_12_2013&0_0_0&0&0_0");
50 e.warning = MyWarning;
52 Error_SetInterface(&e);
55 virtual bool solveMLCP(const btMatrixXu &A, const btVectorXu &b, btVectorXu &x, const btVectorXu &lo, const btVectorXu &hi, const btAlignedObjectArray<int> &limitDependency, int numIterations, bool useSparsity = true)
57 MCP_Termination status;
59 int numVariables = b.rows();
60 if (0 == numVariables)
63 /* - variables - the number of variables in the problem
64 - m_nnz - the number of nonzeros in the M matrix
65 - m_i - a vector of size m_nnz containing the row indices for M
66 - m_j - a vector of size m_nnz containing the column indices for M
67 - m_ij - a vector of size m_nnz containing the data for M
68 - q - a vector of size variables
69 - lb - a vector of size variables containing the lower bounds on x
70 - ub - a vector of size variables containing the upper bounds on x
72 btAlignedObjectArray<double> values;
73 btAlignedObjectArray<int> rowIndices;
74 btAlignedObjectArray<int> colIndices;
76 for (int i = 0; i < A.rows(); i++)
78 for (int j = 0; j < A.cols(); j++)
82 //add 1, because Path starts at 1, instead of 0
83 rowIndices.push_back(i + 1);
84 colIndices.push_back(j + 1);
85 values.push_back(A(i, j));
89 int numNonZero = rowIndices.size();
90 btAlignedObjectArray<double> zResult;
91 zResult.resize(numVariables);
92 btAlignedObjectArray<double> rhs;
93 btAlignedObjectArray<double> upperBounds;
94 btAlignedObjectArray<double> lowerBounds;
95 for (int i = 0; i < numVariables; i++)
97 upperBounds.push_back(hi[i]);
98 lowerBounds.push_back(lo[i]);
102 SimpleLCP(numVariables, numNonZero, &rowIndices[0], &colIndices[0], &values[0], &rhs[0], &lowerBounds[0], &upperBounds[0], &status, &zResult[0]);
104 if (status != MCP_Solved)
106 static const char *gReturnMsgs[] = {
108 "MCP_Solved: The problem was solved",
109 "MCP_NoProgress: A stationary point was found",
110 "MCP_MajorIterationLimit: Major iteration limit met",
111 "MCP_MinorIterationLimit: Cumulative minor iteration limit met",
112 "MCP_TimeLimit: Ran out of time",
113 "MCP_UserInterrupt: Control-C, typically",
114 "MCP_BoundError: Problem has a bound error",
115 "MCP_DomainError: Could not find starting point",
116 "MCP_Infeasible: Problem has no solution",
117 "MCP_Error: An error occurred within the code",
118 "MCP_LicenseError: License could not be found",
121 printf("ERROR: The PATH MCP solver failed: %s\n", gReturnMsgs[(unsigned int)status]); // << std::endl;
122 printf("using Projected Gauss Seidel fallback\n");
128 for (int i = 0; i < numVariables; i++)
132 if (x[i] != zResult[i])
142 #endif //BT_PATH_SOLVER_H