HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_LinearProgram.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __UT_LinearProgram_h__
9 #define __UT_LinearProgram_h__
10 
11 #include "UT_API.h"
12 #include "UT_Matrix.h"
13 #include "UT_NonCopyable.h"
14 #include "UT_Vector.h"
15 
16 typedef enum {
22 
23 // This class implements a linear program solver using the simplex method.
24 // The solver algorithm is from "Numerical Recipes in C, Second Edition"
25 // by W.H. Press, S.A. Teukolsky, W.T. Vetterling, and B.P. Flannery.
26 
28 public:
30  virtual ~UT_LinearProgram();
31 
33 
34  // Set up the linear programming problem. Input number of constraints
35  // or <= type, >= type, and = type, and the number of values in the
36  // result. Input matrix has resultSize+1 columns and total num rules + 1
37  // rows. First column is equation constants, subsequent columns are
38  // coefficients in constraint equations. The first row is the objective
39  // function, followed by rows that express the <= constraints, then >=
40  // constraints, then = constraints. Input matrix should start at (1,1).
41  // Returns 0 if there was some problem with the input (matrix wrong size),
42  // otherwise returns 1.
43  int setupProblem( int leRules, int geRules,
44  int equalRules, int resultSize,
45  UT_MatrixF *input, fpreal tolerance );
46 
47  // Solve the problem set up in setupProblem. Returns UT_LPERROR if no
48  // problem has been set up, or if any of the constants (first column)
49  // in the matrix are negative. Modifies the input matrix.
50  UT_LPSolutionType minimize();
51  UT_LPSolutionType maximize();
52 
53  // Fills result with the solution vector. Returns 0 if there has been
54  // no problem set up, or the problem hasn't been solved, or did not
55  // produce an optimal solution (output would be meaningless). Otherwise
56  // it returns 1. This function is required because after calling solve(),
57  // the input matrix requires some small massaging to get the output vector.
58  int getSolution( UT_Vector *result );
59 
60 private:
61  // Performs the solution for both minimize and maximize
63 
64  void destroyWorkingVectors();
65  void createWorkingVectors();
66  void findPivotCol( float *factors, int *indices,
67  int maxIndex, int abs, int findMax,
68  int &pivotCol, float &factor );
69  void findPivotRow( int &pivotRow, int pivotCol );
70  void doPivot( int doAux, int row, int col );
71 
72  int myMaximize;
73  int myNumLERules; // Number of rules of each
74  int myNumGERules; // type. Less than, greater
75  int myNumEqualRules; // than, and equality.
76  int myNumRules; // Total number of rules
77  int myResultSize; // Size of result vector
78  int mySolved; // Set to 1 when solve() called
79  float myTolerance; // Tolerance value
80  UT_MatrixF *myInput; // Input array
81  float *myAuxObj; // Auxiliary objective function
82  int *myL1, *myL3; // Temp vectors
83  int *myRowIndices; // Row number of each variable
84  int *myColumnIndices; // Column number of each var
85 };
86 
87 #endif
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
#define UT_API
Definition: UT_API.h:14
**But if you need a result
Definition: thread.h:613
UT_LPSolutionType
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
fpreal64 fpreal
Definition: SYS_Types.h:277
GU_API void solve(const GU_Detail &gdp_a, const GA_Range &pts_a, const GU_Detail &gdp_b, const GA_Range &pts_b, Method method, bool compute_distortion, Result &result)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
Definition: ImathFun.h:26
GLenum GLenum GLsizei void * row
Definition: glad.h:5135