Gröbner basis project
Codebase for research into Gröbner basis computation
glpk_solver.hpp
1 #ifndef __GLPK_SOLVER_HPP_
2 #define __GLPK_SOLVER_HPP_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <glpk.h>
22 
23 #include "system_constants.hpp"
24 
25 #include "lp_solver.hpp"
26 
37 class GLPK_Solver : public LP_Solver {
38 public:
40 
42  GLPK_Solver(NVAR_TYPE n);
44  GLPK_Solver(const GLPK_Solver &);
45  virtual bool copy(const LP_Solver *);
47 
48  virtual ~GLPK_Solver();
51 
52  virtual NVAR_TYPE get_dimension() const { return n; }
54  virtual unsigned long get_number_of_rays() {
55  unsigned long result;
56  if (dirty) result = get_rays().size();
57  else result = rays.size();
58  return result;
59  }
60  virtual const set<ray> & get_rays();
61  virtual unsigned long get_number_of_constraints() { return m; }
63 
64  virtual bool solve(constraint &);
66  virtual bool solve(vector<constraint> &);
68 
69 
71  virtual inline bool makes_consistent_constraint(
72  const Monomial & t, const Monomial & u, bool show_data = false
73  ) {
74  bool inconsistent = true;
75  for (
76  auto riter = rays.begin();
77  inconsistent and riter != rays.end();
78  ++riter
79  ) {
80  int d = 0;
81  for (int i = 0; i < riter->get_dimension(); ++i)
82  d += (*riter)[i] * (t.degree(i) - u.degree(i));
83  if (d > 0)
84  inconsistent = false;
85  if (show_data) {
86  cout << d << ' ';
87  if (!inconsistent) cout << *riter << endl;
88  }
89  }
90  if (show_data) cout << endl;
91  return not inconsistent;
92  }
94 private:
95  glp_prob * lp;
96  glp_smcp smcp;
97  double * row_data;
98  int * row_indx;
99  RAYENT_TYPE * ray_data;
100  int m;
101  int n;
102  bool dirty;
103 };
104 
105 #endif
virtual bool copy(const LP_Solver *)
performs a deep copy, similar to a copy constructor
Definition: glpk_solver.cpp:58
set< ray > rays
Definition: lp_solver.hpp:602
virtual bool makes_consistent_constraint(const Monomial &t, const Monomial &u, bool show_data=false)
tests for consistency of a constraint generated by two monomials.
Definition: glpk_solver.hpp:71
virtual NVAR_TYPE get_dimension() const
Returns the dimension of the underlying vector space.
Definition: glpk_solver.hpp:53
approximate skeleton of a polyhedral cone, using GLPK linear solver
Definition: glpk_solver.hpp:37
virtual unsigned long get_number_of_rays()
Returns the number of rays defining the skeleton.
Definition: glpk_solver.hpp:54
a constraint
Definition: lp_solver.hpp:53
exact or approximate polyhedral cone solution, with methods allowing definition and refinement ...
Definition: lp_solver.hpp:504
GLPK_Solver(NVAR_TYPE n)
initializes solver for variables
Definition: glpk_solver.cpp:27
Implementation of monomials.
Definition: monomial.hpp:69
virtual const set< ray > & get_rays()
Returns the rays that define the skeleton.
DEG_TYPE degree(NVAR_TYPE i) const
Degree of th variable.
Definition: monomial.cpp:183
virtual bool solve(constraint &)
Adds the indicated constraint (singular!) and re-computes the solution.