lp_interior_point.cpp 39.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/**
 * @file math/python/LPInteriorPoint.cc
 * @date Fri Jan 27 21:06:59 2012 +0100
 * @author Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
 *
 * @brief Binds the interior point methods which allow to solve a
 *        Linear Programming problem (LP).
 *
 * Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
 */

12
13
#include "lp_interior_point.h"
#include <xbob.blitz/cppapi.h>
14
#include <bob/math/LPInteriorPoint.h>
15
#include <structmember.h>
16

17
18
19
20
/************************************************
 * Implementation of LPInteriorPoint base class *
 ************************************************/

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PyDoc_STRVAR(s_lpinteriorpoint_str, XBOB_EXT_MODULE_PREFIX ".LPInteriorPoint");

PyDoc_STRVAR(s_lpinteriorpoint_doc,
"Base class to solve a linear program using interior point methods.\n\
For more details about the algorithms,please refer to the following\n\
book: *\"Primal-Dual Interior-Point Methods\", Stephen J. Wright,\n\
ISBN: 978-0898713824, Chapter 5, \"Path-Following Algorithms\"*.\n\
\n\
.. warning::\n\
\n\
   You cannot instantiate an object of this type directly, you must\n\
   use it through one of the inherited types.\n\
\n\
The primal linear program (LP) is defined as follows:\n\
\n\
   min transpose(c)*x, s.t. A*x=b, x>=0\n\
\n\
The dual formulation is:\n\
\n\
   min transpose(b)*lambda, s.t. transpose(A)*lambda+mu=c\n\
\n\
");

/* Type definition for PyBobMathLpInteriorPointObject */
typedef struct {
  PyObject_HEAD

  /* Type-specific fields go here. */
49
  bob::math::LPInteriorPoint* base;
50
51
52
53
54
55

} PyBobMathLpInteriorPointObject;


static int PyBobMathLpInteriorPoint_init(PyBobMathLpInteriorPointObject* self, PyObject*, PyObject*) {

André Anjos's avatar
André Anjos committed
56
  PyErr_Format(PyExc_NotImplementedError, "cannot initialize object of base type `%s' - use one of the inherited classes", s_lpinteriorpoint_str);
57
58
  return -1;

59
60
}

61
PyDoc_STRVAR(s_M_str, "m");
62
63
64
65
PyDoc_STRVAR(s_M_doc,
"The first dimension of the problem/A matrix"
);

66
67
static PyObject* PyBobMathLpInteriorPoint_getM (PyBobMathLpInteriorPointObject* self,
    void* /*closure*/) {
68
  return Py_BuildValue("n", self->base->getDimM());
69
70
}

71
72
73
74
75
76
77
78
79
80
81
82
83
84
static int PyBobMathLpInteriorPoint_setM (PyBobMathLpInteriorPointObject* self,
    PyObject* o, void* /*closure*/) {

  Py_ssize_t M = PyNumber_AsSsize_t(o, PyExc_OverflowError);
  if (PyErr_Occurred()) return -1;

  try {
    self->base->setDimM(M);
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
    return -1;
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
85
    PyErr_Format(PyExc_RuntimeError, "cannot reset size M of `%s': unknown exception caught", s_lpinteriorpoint_str);
86
87
88
89
90
91
92
    return -1;
  }

  return 0;

}

93
PyDoc_STRVAR(s_N_str, "n");
94
95
96
97
PyDoc_STRVAR(s_N_doc,
"The second dimension of the problem/A matrix"
);

98
99
static PyObject* PyBobMathLpInteriorPoint_getN (PyBobMathLpInteriorPointObject* self,
    void* /*closure*/) {
100
101
102
  return Py_BuildValue("n", self->base->getDimN());
}

103
104
105
106
107
108
109
110
111
112
113
114
115
116
static int PyBobMathLpInteriorPoint_setN (PyBobMathLpInteriorPointObject* self,
    PyObject* o, void* /*closure*/) {

  Py_ssize_t N = PyNumber_AsSsize_t(o, PyExc_OverflowError);
  if (PyErr_Occurred()) return -1;

  try {
    self->base->setDimN(N);
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
    return -1;
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
117
    PyErr_Format(PyExc_RuntimeError, "cannot reset size N of `%s': unknown exception caught", s_lpinteriorpoint_str);
118
119
120
121
122
123
124
    return -1;
  }

  return 0;

}

125
126
127
128
129
PyDoc_STRVAR(s_epsilon_str, "epsilon");
PyDoc_STRVAR(s_epsilon_doc,
"The precision to determine whether an equality constraint is fulfilled or not"
);

130
static PyObject* PyBobMathLpInteriorPoint_getEpsilon (PyBobMathLpInteriorPointObject* self, void* /*closure*/) {
131
132
133
  return Py_BuildValue("d", self->base->getEpsilon());
}

134
135
136
137
138
139
140
141
142
143
144
145
146
147
static int PyBobMathLpInteriorPoint_setEpsilon (PyBobMathLpInteriorPointObject* self,
    PyObject* o, void* /*closure*/) {

  double e = PyFloat_AsDouble(o);
  if (PyErr_Occurred()) return -1;

  try {
    self->base->setEpsilon(e);
  }
  catch (std::exception& ex) {
    PyErr_SetString(PyExc_RuntimeError, ex.what());
    return -1;
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
148
    PyErr_Format(PyExc_RuntimeError, "cannot reset `epsilon' of `%s': unknown exception caught", s_lpinteriorpoint_str);
149
150
151
152
153
154
155
    return -1;
  }

  return 0;

}

156
PyDoc_STRVAR(s_lambda_str, "lambda_");
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
PyDoc_STRVAR(s_lambda_doc,
"The value of the lambda dual variable (read-only)"
);

static PyObject* PyBobMathLpInteriorPoint_lambda (PyBobMathLpInteriorPointObject* self) {
  Py_ssize_t length = self->base->getDimM();
  PyObject* retval = PyBlitzArray_SimpleNew(NPY_FLOAT64, 1, &length);
  if (!retval) return 0;

  blitz::Array<double,1>* wrapper = PyBlitzArrayCxx_AsBlitz<double,1>
    (reinterpret_cast<PyBlitzArrayObject*>(retval));
  (*wrapper) = self->base->getLambda();

  return retval;
}

PyDoc_STRVAR(s_mu_str, "mu");
PyDoc_STRVAR(s_mu_doc,
"The value of the mu dual variable (read-only)"
);

static PyObject* PyBobMathLpInteriorPoint_mu (PyBobMathLpInteriorPointObject* self) {
  Py_ssize_t length = self->base->getDimN();
  PyObject* retval = PyBlitzArray_SimpleNew(NPY_FLOAT64, 1, &length);
  if (!retval) return 0;

  blitz::Array<double,1>* wrapper = PyBlitzArrayCxx_AsBlitz<double,1>
    (reinterpret_cast<PyBlitzArrayObject*>(retval));
  (*wrapper) = self->base->getMu();

  return retval;
}

static PyGetSetDef PyBobMathLpInteriorPoint_getseters[] = {
    {
      s_M_str, 
193
194
      (getter)PyBobMathLpInteriorPoint_getM,
      (setter)PyBobMathLpInteriorPoint_setM,
195
196
197
198
199
      s_M_doc,
      0
    },
    {
      s_N_str, 
200
201
      (getter)PyBobMathLpInteriorPoint_getN,
      (setter)PyBobMathLpInteriorPoint_setN,
202
203
204
205
206
      s_N_doc,
      0
    },
    {
      s_epsilon_str, 
207
208
      (getter)PyBobMathLpInteriorPoint_getEpsilon,
      (setter)PyBobMathLpInteriorPoint_setEpsilon,
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
      s_epsilon_doc,
      0
    },
    {
      s_lambda_str, 
      (getter)PyBobMathLpInteriorPoint_lambda,
      0,
      s_lambda_doc,
      0
    },
    {
      s_mu_str, 
      (getter)PyBobMathLpInteriorPoint_mu,
      0,
      s_mu_doc,
      0
    },
    {0}  /* Sentinel */
};

PyDoc_STRVAR(s_reset_str, "reset");
PyDoc_STRVAR(s_reset_doc,
"o.reset(M, N) -> None\n\
\n\
Resets the size of the problem (M and N correspond to the dimensions of the\n\
A matrix");

static PyObject* PyBobMathLpInteriorPoint_reset 
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"M", "N", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  Py_ssize_t M = 0;
  Py_ssize_t N = 0;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "nn", kwlist, &M, &N)) return 0;

  try {
    self->base->reset(M, N);
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
    return 0;
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
256
    PyErr_Format(PyExc_RuntimeError, "cannot reset `%s': unknown exception caught", s_lpinteriorpoint_str);
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
    return 0;
  }

  Py_RETURN_NONE;

}

PyDoc_STRVAR(s_solve_str, "solve");
PyDoc_STRVAR(s_solve_doc, 
"o.solve(A, b, c, x0, [lambda, mu]) -> x\n\
\n\
Solves an LP problem\n\
");

static PyObject* PyBobMathLpInteriorPoint_solve 
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"A", "b", "c", "x0", "lambda", "mu", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyBlitzArrayObject* A = 0;
  PyBlitzArrayObject* b = 0;
  PyBlitzArrayObject* c = 0;
  PyBlitzArrayObject* x0 = 0;
  PyBlitzArrayObject* lambda = 0;
  PyBlitzArrayObject* mu = 0;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&|O&O&", kwlist, 
        &PyBlitzArray_Converter, &A,
        &PyBlitzArray_Converter, &b,
        &PyBlitzArray_Converter, &c,
        &PyBlitzArray_Converter, &x0,
        &PyBlitzArray_Converter, &lambda,
        &PyBlitzArray_Converter, &mu
        )) return 0;

  if (A->type_num != NPY_FLOAT64 || A->ndim != 2) {
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 2D arrays for input vector `A'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

  if (b->type_num != NPY_FLOAT64 || b->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 1D arrays for input vector `b'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

  if (c->type_num != NPY_FLOAT64 || c->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 1D arrays for input vector `c'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

  if (x0->type_num != NPY_FLOAT64 || x0->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 1D arrays for input vector `x0'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

338
  if (lambda && (lambda->type_num != NPY_FLOAT64 || lambda->ndim != 1)) {
339
340
341
342
343
344
345
346
347
348
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 1D arrays for input vector `lambda'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

349
  if (mu && (mu->type_num != NPY_FLOAT64 || mu->ndim != 1)) {
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    PyErr_SetString(PyExc_TypeError, "Linear program solver only supports 64-bit floats 1D arrays for input vector `mu'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

  if ( (lambda && !mu) || (mu && !lambda) ) {
    PyErr_SetString(PyExc_RuntimeError, "Linear program solver requires none or both `mu' and `lambda' - you cannot just specify one of them");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }

  /* This is where the output is going to be stored */
  PyObject* retval = PyBlitzArray_SimpleNew(NPY_FLOAT64, x0->ndim, x0->shape);
  if (!retval) {
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x0);
    Py_XDECREF(lambda);
    Py_XDECREF(mu);
    return 0;
  }
  blitz::Array<double,1>* wrapper = PyBlitzArrayCxx_AsBlitz<double,1>(reinterpret_cast<PyBlitzArrayObject*>(retval));
  (*wrapper) = *PyBlitzArrayCxx_AsBlitz<double,1>(x0);
  Py_DECREF(x0);

  try {
    if (lambda && mu) {
      self->base->solve(
          *PyBlitzArrayCxx_AsBlitz<double,2>(A),
          *PyBlitzArrayCxx_AsBlitz<double,1>(b),
          *PyBlitzArrayCxx_AsBlitz<double,1>(c),
          *wrapper,
          *PyBlitzArrayCxx_AsBlitz<double,1>(lambda),
          *PyBlitzArrayCxx_AsBlitz<double,1>(mu)
          );
    }
    else {
      self->base->solve(
          *PyBlitzArrayCxx_AsBlitz<double,2>(A),
          *PyBlitzArrayCxx_AsBlitz<double,1>(b),
          *PyBlitzArrayCxx_AsBlitz<double,1>(c),
          *wrapper
          );
    }
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
410
    PyErr_Format(PyExc_RuntimeError, "cannot solve `%s': unknown exception caught", s_lpinteriorpoint_str);
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
  }

  Py_DECREF(A);
  Py_DECREF(b);
  Py_DECREF(c);
  Py_XDECREF(lambda);
  Py_XDECREF(mu);

  if (PyErr_Occurred()) {
    Py_DECREF(retval);
    return 0;
  }

  /* We only "return" the first half of the `x' vector */
  (reinterpret_cast<PyBlitzArrayObject*>(retval))->shape[0] /= 2;
  return retval;

}

PyDoc_STRVAR(s_is_feasible_str, "is_feasible");
PyDoc_STRVAR(s_is_feasible_doc, 
"o.is_feasible(A, b, c, x, lambda, mu) -> bool\n\
\n\
Checks if a primal-dual point (x,lambda,mu) belongs to the set of\n\
feasible point (i.e. fulfill the constraints)\n\
\n\
");

static PyObject* PyBobMathLpInteriorPoint_is_feasible
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"A", "b", "c", "x", "lambda", "mu", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyBlitzArrayObject* A = 0;
  PyBlitzArrayObject* b = 0;
  PyBlitzArrayObject* c = 0;
  PyBlitzArrayObject* x = 0;
  PyBlitzArrayObject* lambda = 0;
  PyBlitzArrayObject* mu = 0;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&O&O&", kwlist,
        &PyBlitzArray_Converter, &A,
        &PyBlitzArray_Converter, &b,
        &PyBlitzArray_Converter, &c,
        &PyBlitzArray_Converter, &x,
        &PyBlitzArray_Converter, &lambda,
        &PyBlitzArray_Converter, &mu
        )) return 0;

  if (A->type_num != NPY_FLOAT64 || A->ndim != 2) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 2D arrays for input vector `A'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (b->type_num != NPY_FLOAT64 || b->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 1D arrays for input vector `b'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (c->type_num != NPY_FLOAT64 || c->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 1D arrays for input vector `c'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (x->type_num != NPY_FLOAT64 || x->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 1D arrays for input vector `x0'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (lambda->type_num != NPY_FLOAT64 || lambda->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 1D arrays for input vector `lambda'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (mu->type_num != NPY_FLOAT64 || mu->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_feasible only supports 64-bit floats 1D arrays for input vector `mu'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  bool feasible = false;

  try {
    feasible = self->base->isFeasible(
        *PyBlitzArrayCxx_AsBlitz<double,2>(A),
        *PyBlitzArrayCxx_AsBlitz<double,1>(b),
        *PyBlitzArrayCxx_AsBlitz<double,1>(c),
        *PyBlitzArrayCxx_AsBlitz<double,1>(x),
        *PyBlitzArrayCxx_AsBlitz<double,1>(lambda),
        *PyBlitzArrayCxx_AsBlitz<double,1>(mu)
        );
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
544
    PyErr_Format(PyExc_RuntimeError, "cannot check feasibility of `%s': unknown exception caught", s_lpinteriorpoint_str);
545
546
547
548
549
550
551
552
553
  }

  Py_DECREF(A);
  Py_DECREF(b);
  Py_DECREF(c);
  Py_DECREF(x);
  Py_DECREF(lambda);
  Py_DECREF(mu);

554
555
  if (PyErr_Occurred()) return 0;

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  if (feasible) Py_RETURN_TRUE;
  Py_RETURN_FALSE;

}

PyDoc_STRVAR(s_is_in_v_str, "is_in_v");
PyDoc_STRVAR(s_is_in_v_doc, 
"o.is_in_v(x, mu, theta) -> bool\n\
\n\
Check if a primal-dual point (x,lambda,mu) belongs to the V2\n\
neighborhood of the central path.\n\
\n\
");

static PyObject* PyBobMathLpInteriorPoint_is_in_v
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"x", "mu", "theta", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyBlitzArrayObject* x = 0;
  PyBlitzArrayObject* mu = 0;
  double theta = 0.;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&d", kwlist,
        &PyBlitzArray_Converter, &x,
        &PyBlitzArray_Converter, &mu,
        &theta
        )) return 0;

  if (x->type_num != NPY_FLOAT64 || x->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v only supports 64-bit floats 1D arrays for input vector `x0'");
    Py_DECREF(x);
    Py_DECREF(mu);
    return 0;
  }

  if (mu->type_num != NPY_FLOAT64 || mu->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v only supports 64-bit floats 1D arrays for input vector `mu'");
    Py_DECREF(x);
    Py_DECREF(mu);
    return 0;
  }

  bool in_v = false;

  try {
    in_v = self->base->isInV(
        *PyBlitzArrayCxx_AsBlitz<double,1>(x),
        *PyBlitzArrayCxx_AsBlitz<double,1>(mu),
        theta
        );
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
614
    PyErr_Format(PyExc_RuntimeError, "cannot check if point is in V at `%s': unknown exception caught", s_lpinteriorpoint_str);
615
616
617
618
619
  }

  Py_DECREF(x);
  Py_DECREF(mu);

620
621
  if (PyErr_Occurred()) return 0;

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
  if (in_v) Py_RETURN_TRUE;
  Py_RETURN_FALSE;

}

PyDoc_STRVAR(s_is_in_v_s_str, "is_in_v_s");
PyDoc_STRVAR(s_is_in_v_s_doc, 
"o.is_in_v_s(A, b, c, x, lambda, mu) -> bool\n\
\n\
Checks if a primal-dual point (x,lambda,mu) belongs to the V\n\
neighborhood of the central path and the set of feasible points.\n\
\n\
");

static PyObject* PyBobMathLpInteriorPoint_is_in_v_s
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"A", "b", "c", "x", "lambda", "mu", "theta", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyBlitzArrayObject* A = 0;
  PyBlitzArrayObject* b = 0;
  PyBlitzArrayObject* c = 0;
  PyBlitzArrayObject* x = 0;
  PyBlitzArrayObject* lambda = 0;
  PyBlitzArrayObject* mu = 0;
  double theta = 0.;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&O&O&d", kwlist,
        &PyBlitzArray_Converter, &A,
        &PyBlitzArray_Converter, &b,
        &PyBlitzArray_Converter, &c,
        &PyBlitzArray_Converter, &x,
        &PyBlitzArray_Converter, &lambda,
        &PyBlitzArray_Converter, &mu,
        &theta
        )) return 0;

  if (A->type_num != NPY_FLOAT64 || A->ndim != 2) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 2D arrays for input vector `A'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (b->type_num != NPY_FLOAT64 || b->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 1D arrays for input vector `b'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (c->type_num != NPY_FLOAT64 || c->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 1D arrays for input vector `c'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (x->type_num != NPY_FLOAT64 || x->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 1D arrays for input vector `x0'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (lambda->type_num != NPY_FLOAT64 || lambda->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 1D arrays for input vector `lambda'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  if (mu->type_num != NPY_FLOAT64 || mu->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program is_in_v_s only supports 64-bit floats 1D arrays for input vector `mu'");
    Py_DECREF(A);
    Py_DECREF(b);
    Py_DECREF(c);
    Py_DECREF(x);
    Py_DECREF(lambda);
    Py_DECREF(mu);
    return 0;
  }

  bool in_v_s = false;

  try {
    in_v_s = self->base->isInVS(
        *PyBlitzArrayCxx_AsBlitz<double,2>(A),
        *PyBlitzArrayCxx_AsBlitz<double,1>(b),
        *PyBlitzArrayCxx_AsBlitz<double,1>(c),
        *PyBlitzArrayCxx_AsBlitz<double,1>(x),
        *PyBlitzArrayCxx_AsBlitz<double,1>(lambda),
        *PyBlitzArrayCxx_AsBlitz<double,1>(mu),
        theta
        );
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
744
    PyErr_Format(PyExc_RuntimeError, "cannot check if point is in VS at `%s': unknown exception caught", s_lpinteriorpoint_str);
745
746
747
748
749
750
751
752
753
  }

  Py_DECREF(A);
  Py_DECREF(b);
  Py_DECREF(c);
  Py_DECREF(x);
  Py_DECREF(lambda);
  Py_DECREF(mu);

754
755
  if (PyErr_Occurred()) return 0;

756
757
758
  if (in_v_s) Py_RETURN_TRUE;
  Py_RETURN_FALSE;

759
760
}

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
PyDoc_STRVAR(s_initialize_dual_lambda_mu_str, "initialize_dual_lambda_mu");
PyDoc_STRVAR(s_initialize_dual_lambda_mu_doc,
"o.initialize_dual_lambda_mu(A, c) -> None\n\
\n\
Initializes the dual variables `lambda' and `mu' by minimizing the\n\
logarithmic barrier function.\n\
\n\
");

static PyObject* PyBobMathLpInteriorPoint_initialize_dual_lambda_mu
(PyBobMathLpInteriorPointObject* self, PyObject *args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"A", "c", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyBlitzArrayObject* A = 0;
  PyBlitzArrayObject* c = 0;

780
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&", kwlist,
781
        &PyBlitzArray_Converter, &A,
782
        &PyBlitzArray_Converter, &c
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
        )) return 0;

  if (A->type_num != NPY_FLOAT64 || A->ndim != 2) {
    PyErr_SetString(PyExc_TypeError, "Linear program initialize_dual_lambda_mu only supports 64-bit floats 2D arrays for input vector `A'");
    Py_DECREF(A);
    Py_DECREF(c);
    return 0;
  }

  if (c->type_num != NPY_FLOAT64 || c->ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Linear program initialize_dual_lambda_mu only supports 64-bit floats 1D arrays for input vector `c'");
    Py_DECREF(A);
    Py_DECREF(c);
    return 0;
  }

  try {
    self->base->initializeDualLambdaMu(
        *PyBlitzArrayCxx_AsBlitz<double,2>(A),
        *PyBlitzArrayCxx_AsBlitz<double,1>(c)
        );
  }
  catch (std::exception& e) {
    PyErr_SetString(PyExc_RuntimeError, e.what());
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
809
    PyErr_Format(PyExc_RuntimeError, "cannot initialize dual lambda-mu at `%s': unknown exception caught", s_lpinteriorpoint_str);
810
811
812
813
814
815
816
817
818
819
820
  }

  Py_DECREF(A);
  Py_DECREF(c);

  if (PyErr_Occurred()) return 0;

  Py_RETURN_NONE;

}

821
822
823
824
static PyMethodDef PyBobMathLpInteriorPoint_methods[] = {
    {
      s_reset_str,
      (PyCFunction)PyBobMathLpInteriorPoint_reset,
825
      METH_VARARGS|METH_KEYWORDS,
826
827
828
829
830
      s_reset_doc
    },
    {
      s_solve_str,
      (PyCFunction)PyBobMathLpInteriorPoint_solve,
831
      METH_VARARGS|METH_KEYWORDS,
832
833
834
835
836
      s_solve_doc
    },
    {
      s_is_feasible_str,
      (PyCFunction)PyBobMathLpInteriorPoint_is_feasible,
837
      METH_VARARGS|METH_KEYWORDS,
838
839
840
841
842
      s_is_feasible_doc
    },
    {
      s_is_in_v_str,
      (PyCFunction)PyBobMathLpInteriorPoint_is_in_v,
843
      METH_VARARGS|METH_KEYWORDS,
844
845
846
847
848
      s_is_in_v_doc
    },
    {
      s_is_in_v_s_str,
      (PyCFunction)PyBobMathLpInteriorPoint_is_in_v_s,
849
      METH_VARARGS|METH_KEYWORDS,
850
851
      s_is_in_v_s_doc
    },
852
853
854
    {
      s_initialize_dual_lambda_mu_str,
      (PyCFunction)PyBobMathLpInteriorPoint_initialize_dual_lambda_mu,
855
      METH_VARARGS|METH_KEYWORDS,
856
857
      s_initialize_dual_lambda_mu_doc
    },
858
859
860
    {0}  /* Sentinel */
};

André Anjos's avatar
André Anjos committed
861
862
863
864
865
866
867
868
869
870
871
872
873
static int PyBobMathLpInteriorPoint_Check(PyObject* o) {
  return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobMathLpInteriorPoint_Type));
}

static PyObject* PyBobMathLpInteriorPoint_RichCompare (PyBobMathLpInteriorPointObject* self, PyObject* other, int op) {

  if (!PyBobMathLpInteriorPoint_Check(other)) {
    PyErr_Format(PyExc_TypeError, "cannot compare `%s' with `%s'",
        s_lpinteriorpoint_str, other->ob_type->tp_name);
    return 0;
  }
  
  PyBobMathLpInteriorPointObject* other_ = reinterpret_cast<PyBobMathLpInteriorPointObject*>(other);
874
875
876

  switch (op) {
    case Py_EQ:
André Anjos's avatar
André Anjos committed
877
      if (*(self->base) == *(other_->base)) Py_RETURN_TRUE;
878
879
880
      Py_RETURN_FALSE;
      break;
    case Py_NE:
André Anjos's avatar
André Anjos committed
881
      if (*(self->base) != *(other_->base)) Py_RETURN_TRUE;
882
883
884
885
886
887
888
889
890
      Py_RETURN_FALSE;
      break;
    default:
      Py_INCREF(Py_NotImplemented);
      return Py_NotImplemented;
  }

}

891
892
PyTypeObject PyBobMathLpInteriorPoint_Type = {
    PyObject_HEAD_INIT(0)
893
894
895
896
    0,                                                 /*ob_size*/
    s_lpinteriorpoint_str,                             /*tp_name*/
    sizeof(PyBobMathLpInteriorPointObject),            /*tp_basicsize*/
    0,                                                 /*tp_itemsize*/
897
    0,                                                 /*tp_dealloc*/
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
    0,                                                 /*tp_print*/
    0,                                                 /*tp_getattr*/
    0,                                                 /*tp_setattr*/
    0,                                                 /*tp_compare*/
    0,                                                 /*tp_repr*/
    0,                                                 /*tp_as_number*/
    0,                                                 /*tp_as_sequence*/
    0,                                                 /*tp_as_mapping*/
    0,                                                 /*tp_hash */
    0,                                                 /*tp_call*/
    0,                                                 /*tp_str*/
    0,                                                 /*tp_getattro*/
    0,                                                 /*tp_setattro*/
    0,                                                 /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,          /*tp_flags*/
    s_lpinteriorpoint_doc,                             /* tp_doc */
    0,		                                             /* tp_traverse */
    0,		                                             /* tp_clear */
    (richcmpfunc)PyBobMathLpInteriorPoint_RichCompare, /* tp_richcompare */
    0,		                                             /* tp_weaklistoffset */
    0,		                                             /* tp_iter */
    0,		                                             /* tp_iternext */
    PyBobMathLpInteriorPoint_methods,                  /* tp_methods */
    0,                                                 /* tp_members */
    PyBobMathLpInteriorPoint_getseters,                /* tp_getset */
    0,                                                 /* tp_base */
    0,                                                 /* tp_dict */
    0,                                                 /* tp_descr_get */
    0,                                                 /* tp_descr_set */
    0,                                                 /* tp_dictoffset */
    (initproc)PyBobMathLpInteriorPoint_init,           /* tp_init */
    0,                                                 /* tp_alloc */
930
931
932
933
934
935
936
937
938
939
940
    0,                                                 /* tp_new */
};

/****************************************************
 * Implementation of LPInteriorPointShortstep class *
 ****************************************************/

PyDoc_STRVAR(s_lpinteriorpointshortstep_str, XBOB_EXT_MODULE_PREFIX ".LPInteriorPointShortstep");

PyDoc_STRVAR(s_lpinteriorpointshortstep_doc,
"LPInteriorPointShortstep(M, N, theta, epsilon) -> new LPInteriorPointShortstep\n\
André Anjos's avatar
André Anjos committed
941
LPInteriorPointShortstep(solver) -> new LPInteriorPointShortstep\n\
942
943
944
945
946
\n\
A Linear Program solver based on a short step interior point method.\n\
\n\
See :py:class:`LPInteriorPoint` for more details on the base class.\n\
\n\
André Anjos's avatar
André Anjos committed
947
948
949
950
951
Objects of this class can be initialized in two different ways: a\n\
detailed constructor with the parameters described below or a copy\n\
constructor, that deep-copies the input object and creates a new\n\
object (**not** a new reference to the same object).\n\
\n\
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
Constructor parameters:\n\
\n\
M\n\
  (int) first dimension of the A matrix\n\
\n\
N\n\
  (int) second dimension of the A matrix\n\
\n\
theta\n\
  (float) theta The value defining the size of the V2 neighborhood\n\
\n\
epsilon\n\
  (float) The precision to determine whether an equality constraint\n\
  is fulfilled or not.\n\
\n\
");

/* Type definition for PyBobMathLpInteriorPointObject */
typedef struct {
  PyBobMathLpInteriorPointObject parent;

  /* Type-specific fields go here. */
  bob::math::LPInteriorPointShortstep* base;

} PyBobMathLpInteriorPointShortstepObject;

André Anjos's avatar
André Anjos committed
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
static int PyBobMathLpInteriorPointShortstep_Check(PyObject* o) {
  return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobMathLpInteriorPointShortstep_Type));
}

static int PyBobMathLpInteriorPointShortstep_init1(PyBobMathLpInteriorPointShortstepObject* self, PyObject* args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"solver", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  PyObject* solver = 0;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &solver)) return -1;

  if (!PyBobMathLpInteriorPointShortstep_Check(solver)) {
    PyErr_Format(PyExc_TypeError, "copy-constructor for %s requires an object of the same type, not %s", s_lpinteriorpointshortstep_str, solver->ob_type->tp_name);
    Py_DECREF(solver);
    return -1;
  }

  PyBobMathLpInteriorPointShortstepObject* other = reinterpret_cast<PyBobMathLpInteriorPointShortstepObject*>(solver);

  try {
    self->base = new bob::math::LPInteriorPointShortstep(*other->base);
  }
  catch (std::exception& ex) {
    PyErr_SetString(PyExc_RuntimeError, ex.what());
  }
  catch (...) {
    PyErr_Format(PyExc_RuntimeError, "cannot deep-copy object of type %s: unknown exception caught", s_lpinteriorpointshortstep_str);
  }
  
  Py_DECREF(solver);
  self->parent.base = self->base;

  if (PyErr_Occurred()) return -1;

  return 0;

}

static int PyBobMathLpInteriorPointShortstep_init4(PyBobMathLpInteriorPointShortstepObject* self, PyObject* args, PyObject* kwds) {
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

  /* Parses input arguments in a single shot */
  static const char* const_kwlist[] = {"M", "N", "theta", "epsilon", 0};
  static char** kwlist = const_cast<char**>(const_kwlist);

  Py_ssize_t M = 0;
  Py_ssize_t N = 0;
  double theta = 0.;
  double epsilon = 0.;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "nndd", kwlist, 
        &M, &N, &theta, &epsilon)) return -1;

André Anjos's avatar
André Anjos committed
1033
1034
1035
1036
1037
  try {
    self->base = new bob::math::LPInteriorPointShortstep(M, N, theta, epsilon);
  }
  catch (std::exception& ex) {
    PyErr_SetString(PyExc_RuntimeError, ex.what());
1038
1039
    return -1;
  }
André Anjos's avatar
André Anjos committed
1040
1041
1042
1043
1044
  catch (...) {
    PyErr_Format(PyExc_RuntimeError, "cannot construct object of type %s: unknown exception caught", s_lpinteriorpointshortstep_str);
    return -1;
  }
  
1045
1046
1047
1048
1049
1050
  self->parent.base = self->base;

  return 0;

}

André Anjos's avatar
André Anjos committed
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
static int PyBobMathLpInteriorPointShortstep_init(PyBobMathLpInteriorPointShortstepObject* self, PyObject* args, PyObject* kwds) {

  Py_ssize_t nargs = args?PyTuple_Size(args):0 + kwds?PyDict_Size(kwds):0;

  switch (nargs) {

    case 1:
      return PyBobMathLpInteriorPointShortstep_init1(self, args, kwds);
      break;

    case 4:
      return PyBobMathLpInteriorPointShortstep_init4(self, args, kwds);
      break;

    default:

      PyErr_Format(PyExc_RuntimeError, "number of arguments mismatch - %s requires 1 or 4 arguments, but you provided %" PY_FORMAT_SIZE_T "d (see help)", s_lpinteriorpointshortstep_str, nargs);

  }

  return -1;

}

1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
static void PyBobMathLpInteriorPointShortstep_delete (PyBobMathLpInteriorPointShortstepObject* self) {
  
  delete self->base;
  self->parent.base = 0;
  self->base = 0;
  self->parent.ob_type->tp_free((PyObject*)self);

}

PyDoc_STRVAR(s_theta_str, "theta");
PyDoc_STRVAR(s_theta_doc,
"The value theta used to define a V2 neighborhood"
);

static PyObject* PyBobMathLpInteriorPointShortstep_getTheta (PyBobMathLpInteriorPointShortstepObject* self, void* /*closure*/) {
  return Py_BuildValue("d", self->base->getTheta());
}

static int PyBobMathLpInteriorPointShortstep_setTheta (PyBobMathLpInteriorPointShortstepObject* self,
    PyObject* o, void* /*closure*/) {

  double e = PyFloat_AsDouble(o);
  if (PyErr_Occurred()) return -1;

  try {
    self->base->setTheta(e);
  }
  catch (std::exception& ex) {
    PyErr_SetString(PyExc_RuntimeError, ex.what());
    return -1;
  }
  catch (...) {
André Anjos's avatar
André Anjos committed
1107
    PyErr_Format(PyExc_RuntimeError, "cannot reset `theta' of %s: unknown exception caught", s_lpinteriorpointshortstep_str);
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
    return -1;
  }

  return 0;

}

static PyGetSetDef PyBobMathLpInteriorPointShortstep_getseters[] = {
    {
      s_theta_str, 
      (getter)PyBobMathLpInteriorPointShortstep_getTheta,
      (setter)PyBobMathLpInteriorPointShortstep_setTheta,
      s_theta_doc,
      0
    },
    {0}  /* Sentinel */
};

static PyObject* PyBobMathLpInteriorPointShortstep_RichCompare
André Anjos's avatar
André Anjos committed
1127
1128
1129
1130
1131
1132
1133
1134
1135
(PyBobMathLpInteriorPointShortstepObject* self, PyObject* other, int op) {

  if (!PyBobMathLpInteriorPointShortstep_Check(other)) {
    PyErr_Format(PyExc_TypeError, "cannot compare `%s' with `%s'",
        s_lpinteriorpointshortstep_str, other->ob_type->tp_name);
    return 0;
  }
  
  PyBobMathLpInteriorPointShortstepObject* other_ = reinterpret_cast<PyBobMathLpInteriorPointShortstepObject*>(other);
1136
1137
1138

  switch (op) {
    case Py_EQ:
André Anjos's avatar
André Anjos committed
1139
      if (*(self->base) == *(other_->base)) Py_RETURN_TRUE;
1140
1141
1142
      Py_RETURN_FALSE;
      break;
    case Py_NE:
André Anjos's avatar
André Anjos committed
1143
      if (*(self->base) != *(other_->base)) Py_RETURN_TRUE;
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
      Py_RETURN_FALSE;
      break;
    default:
      Py_INCREF(Py_NotImplemented);
      return Py_NotImplemented;
  }

}

PyTypeObject PyBobMathLpInteriorPointShortstep_Type = {
    PyObject_HEAD_INIT(0)
    0,                                                          /*ob_size*/
    s_lpinteriorpointshortstep_str,                             /*tp_name*/
    sizeof(PyBobMathLpInteriorPointShortstepObject),            /*tp_basicsize*/
    0,                                                          /*tp_itemsize*/
    (destructor)PyBobMathLpInteriorPointShortstep_delete,       /*tp_dealloc*/
    0,                                                          /*tp_print*/
    0,                                                          /*tp_getattr*/
    0,                                                          /*tp_setattr*/
    0,                                                          /*tp_compare*/
    0,                                                          /*tp_repr*/
    0,                                                          /*tp_as_number*/
    0,                                                          /*tp_as_sequence*/
    0,                                                          /*tp_as_mapping*/
    0,                                                          /*tp_hash */
    0,                                                          /*tp_call*/
    0,                                                          /*tp_str*/
    0,                                                          /*tp_getattro*/
    0,                                                          /*tp_setattro*/
    0,                                                          /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                   /*tp_flags*/
    s_lpinteriorpointshortstep_doc,                             /* tp_doc */
    0,		                                                      /* tp_traverse */
    0,		                                                      /* tp_clear */
    (richcmpfunc)PyBobMathLpInteriorPointShortstep_RichCompare, /* tp_richcompare */
    0,		                                                      /* tp_weaklistoffset */
    0,		                                                      /* tp_iter */
    0,		                                                      /* tp_iternext */
    0,                                                          /* tp_methods */
    0,                                                          /* tp_members */
    PyBobMathLpInteriorPointShortstep_getseters,                /* tp_getset */
    0,                                                          /* tp_base */
    0,                                                          /* tp_dict */
    0,                                                          /* tp_descr_get */
    0,                                                          /* tp_descr_set */
    0,                                                          /* tp_dictoffset */
    (initproc)PyBobMathLpInteriorPointShortstep_init,           /* tp_init */
    0,                                                          /* tp_alloc */
    0,                                                          /* tp_new */
1193
1194
1195
};

/**
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
static bool is_in_vinf(bob::math::LPInteriorPointLongstep& op,
  bob::python::const_ndarray x, bob::python::const_ndarray mu,
  const double gamma)
{
  return op.isInV(x.bz<double,1>(), mu.bz<double,1>(), gamma);
}


void bind_math_lp_interiorpoint()
{
  class_<bob::math::LPInteriorPointShortstep, boost::shared_ptr<bob::math::LPInteriorPointShortstep>, bases<bob::math::LPInteriorPoint> >("LPInteriorPointShortstep", "A Linear Program solver based on a short step interior point method", init<const size_t, const size_t, const double, const double>((arg("self"), arg("M"), arg("N"), arg("theta"), arg("epsilon")), "Constructs a new LPInteriorPointShortstep solver"))
    .def(init<const bob::math::LPInteriorPointShortstep&>((arg("self"), arg("solver")), "Copy constructs a solver"))
    .def(self == self)
    .def(self != self)
    .add_property("theta", &bob::math::LPInteriorPointShortstep::getTheta, &bob::math::LPInteriorPointShortstep::setTheta, "The value theta used to define a V2 neighborhood")
  ;

  class_<bob::math::LPInteriorPointPredictorCorrector, boost::shared_ptr<bob::math::LPInteriorPointPredictorCorrector>, bases<bob::math::LPInteriorPoint> >("LPInteriorPointPredictorCorrector", "A Linear Program solver based on a predictor-corrector interior point method", init<const size_t, const size_t, const double, const double, const double>((arg("self"), arg("M"), arg("N"), arg("theta_pred"), arg("theta_corr"), arg("epsilon")), "Constructs a new LPInteriorPointPredictorCorrector solver"))
    .def(init<const bob::math::LPInteriorPointPredictorCorrector&>((arg("self"), arg("solver")), "Copy constructs a solver"))
    .def(self == self)
    .def(self != self)
    .add_property("theta_pred", &bob::math::LPInteriorPointPredictorCorrector::getThetaPred, &bob::math::LPInteriorPointPredictorCorrector::setThetaPred, "The value theta_pred used to define a V2 neighborhood")
    .add_property("theta_corr", &bob::math::LPInteriorPointPredictorCorrector::getThetaCorr, &bob::math::LPInteriorPointPredictorCorrector::setThetaCorr, "The value theta_corr used to define a V2 neighborhood")
  ;

  class_<bob::math::LPInteriorPointLongstep, boost::shared_ptr<bob::math::LPInteriorPointLongstep>, bases<bob::math::LPInteriorPoint> >("LPInteriorPointLongstep", "A Linear Program solver based on a ong step interior point method", init<const size_t, const size_t, const double, const double, const double>((arg("self"), arg("M"), arg("N"), arg("gamma"), arg("sigma"), arg("epsilon")), "Constructs a new LPInteriorPointLongstep solver"))
    .def(init<const bob::math::LPInteriorPointLongstep&>((arg("self"), arg("solver")), "Copy constructs a solver"))
    .def(self == self)
    .def(self != self)
    .def("is_in_v", &is_in_vinf, (arg("self"), arg("x"), arg("mu"), arg("gamma")), "Check if a primal-dual point (x,lambda,mu) belongs to the V-inf neighborhood of the central path")
    .add_property("gamma", &bob::math::LPInteriorPointLongstep::getGamma, &bob::math::LPInteriorPointLongstep::setGamma, "The value gamma used to define a V-inf neighborhood")
    .add_property("sigma", &bob::math::LPInteriorPointLongstep::getSigma, &bob::math::LPInteriorPointLongstep::setSigma, "The value sigma used to define a V-inf neighborhood")
  ;
}
1230
**/