cprover
ilp.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: ILP structure
4 
5 Author: Vincent Nimal
6 
7 \*******************************************************************/
8 
11 
12 #ifdef HAVE_GLPK
13 #include <glpk.h>
14 #endif
15 
16 #include <vector>
17 
18 #ifndef CPROVER_MUSKETEER_ILP_H
19 #define CPROVER_MUSKETEER_ILP_H
20 
21 #ifdef HAVE_GLPK
22 class ilpt
23 {
24 protected:
25  template <class T>
26  class my_vectort: public std::vector<T>
27  {
28  public:
29  T *to_array()
30  {
31  /* NOTE: not valid if T==bool */
32  return &(*this)[0];
33  }
34  };
35 
36  glp_iocp parm;
37  unsigned matrix_size;
38 
39 public:
40  glp_prob *lp;
41 
42  my_vectort<int> imat;
43  my_vectort<int> jmat;
44  my_vectort<double> vmat;
45 
46  ilpt()
47  {
48  glp_init_iocp(&parm);
49  parm.msg_lev=GLP_MSG_OFF;
50  parm.presolve=GLP_ON;
51 
52  lp=glp_create_prob();
53  glp_set_prob_name(lp, "fence optimisation");
54  glp_set_obj_dir(lp, GLP_MIN);
55  }
56 
57  ~ilpt()
58  {
59  glp_delete_prob(lp);
60  }
61 
62  void set_size(unsigned mat_size)
63  {
64  matrix_size=mat_size;
65  imat.resize(mat_size+1);
66  jmat.resize(mat_size+1);
67  vmat.resize(mat_size+1);
68  }
69 
70  void solve()
71  {
72  glp_load_matrix(lp, matrix_size, imat.to_array(),
73  jmat.to_array(), vmat.to_array());
74  glp_intopt(lp, &parm);
75  }
76 };
77 #else
78 class ilpt {};
79 #endif
80 
81 #endif // CPROVER_MUSKETEER_ILP_H
Definition: ilp.h:78