File: LPinterface.hh

package info (click to toggle)
topcom 1.1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 31,784 kB
  • sloc: cpp: 37,616; sh: 4,262; makefile: 497; ansic: 49
file content (108 lines) | stat: -rw-r--r-- 2,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
////////////////////////////////////////////////////////////////////////////////
// 
// LPinterface.hh 
//
//    produced: 2001/10/21 jr
// last change: 2020/04/02 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef LPINTERFACE_HH
#define LPINTERFACE_HH

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <mutex>

#include "Vector.hh"
#include "Matrix.hh"
#include "LabelSet.hh"
#include "Rational.h"

#include "setoper.h"
#include "cdd.h"

namespace topcom {

  // we can use three variants of arithmetics in cddlib:

  // the following preprocessor magic is necessary because the word `Rational'
  // is used in an enum type in the cddlib:
  
#if defined GMPRATIONAL // GMP Rational
  
  inline void dd_set_R(mytype& a, const Rational& b) {
    mpq_set(a, b.get_mpq_t());
  }

#endif

  class LPinterface {
  private:
    dd_ErrorType      _err;
    dd_LPSolverType   _solver;
    dd_LPPtr          _lpptr;
    dd_LPSolutionPtr  _solptr; 
    dd_rowrange       _m;
    dd_colrange       _n;
    dd_MatrixPtr      _matrixptr;
    const LabelSet    _support;
    static bool       _is_initialized;
    static std::mutex _init_mutex;
  private:
    LPinterface();
  public:
    // constructors:
    LPinterface(const Matrix&, const LabelSet&);
    LPinterface(const LPinterface&) = delete;
    const LPinterface& operator=(const LPinterface&) = delete;

    // destructor:
    inline ~LPinterface();

    // cdd must be initialized and terminated,
    // which is best done only once:
    inline static void init();
    inline static void term();

    // functions:
    bool has_interior_point(Vector* heightsptr);
  };

  inline LPinterface::~LPinterface() {

    // Free allocated spaces:
    if (_solptr) {
      dd_FreeLPSolution(_solptr);
    }
    dd_FreeLPData    (_lpptr);
    dd_FreeMatrix    (_matrixptr);
  }

  // cdd must be initialized and terminated,
  // which is best done only once:
  inline void LPinterface::init() {
    std::lock_guard<std::mutex> init_lock(_init_mutex);
    if (_is_initialized) {
      return;
    }
    dd_set_global_constants();
    _is_initialized = true;
  }

  inline void LPinterface::term() {
    std::lock_guard<std::mutex> init_lock(_init_mutex);
    if (!_is_initialized) {
      return;
    }
    dd_free_global_constants();
    _is_initialized = false;
  }

}; // namespace topcom

#endif

// eof LPinterface.hh