17 #ifndef BT_LEMKE_SOLVER_H 
   18 #define BT_LEMKE_SOLVER_H 
   56                         for (
int row = 0; row < n; row++)
 
   71                                 A1.resize(A.rows(), A.cols());
 
   72                                 for (
int row = 0; row < A.rows(); row++)
 
   74                                         for (
int col = 0; col < A.cols(); col++)
 
   76                                                 A1.setElem(row, col, A(row, col));
 
   81                                 matrix.resize(n, 2 * n);
 
   82                                 for (
int row = 0; row < n; row++)
 
   84                                         for (
int col = 0; col < n; col++)
 
   86                                                 matrix.setElem(row, col, A1(row, col));
 
   92                                 for (i = 0; i < n; i++)
 
   94                                         for (j = n; j < 2 * n; j++)
 
   97                                                         matrix.setElem(i, j, 1.0);
 
   99                                                         matrix.setElem(i, j, 0.0);
 
  102                                 for (i = 0; i < n; i++)
 
  104                                         for (j = 0; j < n; j++)
 
  113                                                         ratio = matrix(j, i) / matrix(i, i);
 
  114                                                         for (k = 0; k < 2 * n; k++)
 
  116                                                                 matrix.addElem(j, k, -ratio * matrix(i, k));
 
  121                                 for (i = 0; i < n; i++)
 
  129                                         for (j = 0; j < 2 * n; j++)
 
  131                                                 matrix.mulElem(i, j, invA);
 
  135                                 for (
int row = 0; row < n; row++)
 
  137                                         for (
int col = 0; col < n; col++)
 
  139                                                 B.setElem(row, col, matrix(row, n + col));
 
  147                         for (
int row = 0; row < n; row++)
 
  149                                 b1.setElem(row, 0, -b[row]);
 
  150                                 for (
int col = 0; col < n; col++)
 
  153                                         M.setElem(row, col, v);
 
  154                                         M.setElem(n + row, n + col, v);
 
  155                                         M.setElem(n + row, col, -v);
 
  156                                         M.setElem(row, n + col, -v);
 
  165                         for (
int row = 0; row < n; row++)
 
  167                                 qq[row] = -Bb1(row, 0) - lo[row];
 
  168                                 qq[n + row] = Bb1(row, 0) + hi[row];
 
  181                         for (
int row = 0; row < n; row++)
 
  183                                 y1.setElem(row, 0, z1[2 * n + row] - z1[3 * n + row]);
 
  186                         for (
int i = 0; i < n; i++)
 
  188                                 y1_b1.setElem(i, 0, y1(i, 0) - b1(i, 0));
 
  195                         for (
int row = 0; row < n; row++)
 
  197                                 solution[row] = x1(row, 0);  
 
  200                         int errorIndexMax = -1;
 
  201                         int errorIndexMin = -1;
 
  202                         float errorValueMax = -1e30;
 
  203                         float errorValueMin = 1e30;
 
  205                         for (
int i = 0; i < n; i++)
 
  220                                         if (x[i] > errorValueMax)
 
  224                                                 errorValueMax = x[i];
 
  230                                         if (x[i] < errorValueMin)
 
  233                                                 errorValueMin = x[i];
 
  241                                 int m_errorCountTimes = 0;
 
  242                                 if (errorIndexMin < 0)
 
  244                                 if (errorIndexMax < 0)
 
  248                                 for (
int i = 0; i < n; i++)
 
  258                         int dimension = A.rows();
 
  266                         for (
int row = 0; row < dimension; row++)
 
  280                         int errorIndexMax = -1;
 
  281                         int errorIndexMin = -1;
 
  282                         float errorValueMax = -1e30;
 
  283                         float errorValueMin = 1e30;
 
  285                         for (
int i = 0; i < dimension; i++)
 
  287                                 x[i] = solution[i + dimension];
 
  299                                         if (x[i] > errorValueMax)
 
  303                                                 errorValueMax = x[i];
 
  309                                         if (x[i] < errorValueMin)
 
  312                                                 errorValueMin = x[i];
 
  320                                 static int errorCountTimes = 0;
 
  321                                 if (errorIndexMin < 0)
 
  323                                 if (errorIndexMax < 0)
 
  325                                 printf(
"Error (x[%d] = %f, x[%d] = %f), resetting %d times\n", errorIndexMin, errorValueMin, errorIndexMax, errorValueMax, errorCountTimes++);
 
  326                                 for (
int i = 0; i < dimension; i++)
 
  338 #endif  //BT_LEMKE_SOLVER_H