Gröbner basis project
Codebase for research into Gröbner basis computation
skeleton.hpp
1 #ifndef SKELETON_H
2 #define SKELETON_H
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 
30 #include <set>
31 #include <vector>
32 #include <iostream>
33 using std::cout; using std::endl;
34 
35 #include "lp_solver.hpp"
36 #include "polynomial.hpp"
37 
38 #include "system_constants.hpp"
39 
58 class edge {
59 
60 public:
61 
63 
66  edge(const ray &, const ray &);
67 
69  edge(const edge &);
70 
72 
74 
76  ~edge() {}
78 
81 
84  inline ray get_first_ray() const { return first; };
85 
87  inline ray get_second_ray() const { return second; };
88 
90 
92 
100  inline friend bool operator==(const edge &e1, const edge &e2)
101  { return e1.first == e2.first && e1.second == e2.second; }
102 
110  friend bool operator<(const edge &, const edge &);
111 
113 
115 
121  friend ostream & operator<<(ostream &, const edge &);
122 
124 
126 
129  edge & operator=(const edge &);
130 
132 
133 private:
134 
135  ray first, second;
137 };
138 
143 int number_of_common_constraints(bool *, bool *, unsigned);
144 
145 
150 vector<bool> intersections_of_active_constraints(bool *, bool *, unsigned);
151 
156 bool is_first_subset_of_second(bool *, bool *, unsigned);
157 
162 set<edge> union_of_edge_sets(const set<edge> &, const set<edge> &);
163 
178 class skeleton : public LP_Solver {
179 
180 public:
181 
183 
186  void common_initialization(NVAR_TYPE);
187 
197  skeleton(NVAR_TYPE);
198 
210  skeleton(NVAR_TYPE, vector<constraint> &);
211 
213  skeleton(skeleton &);
214 
215  virtual bool copy(const LP_Solver *);
216 
218 
220 
225  virtual ~skeleton();
226 
228 
230 
232  inline NVAR_TYPE get_dimension() const { return dim; };
233 
235  inline unsigned long get_number_of_edges() { return edges.size(); };
236 
238  inline set<edge> get_edges() { return edges; };
239 
241  inline unsigned long get_number_of_constraints() {
242  return constraints.size();
243  };
244 
246  inline const vector<constraint> & get_constraints() { return constraints; };
247 
249  inline constraint get_constraint(int index) { return constraints[index]; };
250 
252 
254 
257  //inline vector<bool> which_constraints_active_at(const ray & u) const {
258  inline void which_constraints_active_at(const ray & u, bool * result) const {
259  static unsigned invocations;
260  //vector<bool> result(constraints.size());
261  for (unsigned i = 0; i < constraints.size(); ++i) {
262  if (u.is_active_at(constraints[i]))
263  result[i] = true;
264  else
265  result[i] = false;
266  }
267  //return result;
268  }
269 
271  inline bool is_consistent(const constraint & c) const
272  {
273  bool inconsistent = true;
274  for (
275  auto riter = rays.begin();
276  inconsistent and riter != rays.end();
277  ++riter
278  ) {
279  if (((*riter) * c) > 0)
280  inconsistent = false;
281  }
282  return not inconsistent;
283  }
284 
286 
288 
305  virtual bool solve(vector<constraint> &);
306 
322  virtual bool solve(constraint &);
323 
328  set<edge> adjacencies_by_graphs(set<ray>);
329 
333  skeleton & operator=(const skeleton &);
334 
336 
338 
341  friend ostream & operator<<(ostream &, const skeleton &);
342 
344 
345 
346 private:
347 
348  int dim;
350  set<edge> edges;
352  vector<constraint> constraints;
354 };
355 
356 #endif
an edge connecting the two rays and
Definition: skeleton.hpp:58
unsigned long get_number_of_edges()
Returns the number of edges defining the skeleton.
Definition: skeleton.hpp:235
constraint get_constraint(int index)
Returns the indicated constraint. Numbering starts at 0.
Definition: skeleton.hpp:249
ray get_first_ray() const
Returns the first ray listed in this edge.
Definition: skeleton.hpp:84
friend bool operator<(const edge &, const edge &)
Compares two edges lexicographically.
Definition: skeleton.cpp:58
void which_constraints_active_at(const ray &u, bool *result) const
returns the set of constraints in the skeleton active at u
Definition: skeleton.hpp:258
a constraint
Definition: lp_solver.hpp:53
skeleton of a polyhedral cone, with methods allowing definition and refinement
Definition: skeleton.hpp:178
set< edge > get_edges()
Returns the edges that define the skeleton.
Definition: skeleton.hpp:238
exact or approximate polyhedral cone solution, with methods allowing definition and refinement ...
Definition: lp_solver.hpp:504
set< edge > union_of_edge_sets(const set< edge > &, const set< edge > &)
Definition: skeleton.cpp:342
~edge()
Definition: skeleton.hpp:76
edge & operator=(const edge &)
Assignment operator.
Definition: skeleton.cpp:77
ray get_second_ray() const
Returns the second ray listed in this edge.
Definition: skeleton.hpp:87
friend ostream & operator<<(ostream &, const edge &)
Output has the form where is the first ray in this edge, etc.
Definition: skeleton.cpp:52
vector< bool > intersections_of_active_constraints(bool *, bool *, unsigned)
bool is_consistent(const constraint &c) const
tests for consistency of a potentially new constraint.
Definition: skeleton.hpp:271
NVAR_TYPE get_dimension() const
Returns the dimension of the underlying vector space.
Definition: skeleton.hpp:232
edge(const ray &, const ray &)
Creates a new edge that joins the two rays.
Definition: skeleton.cpp:39
unsigned long get_number_of_constraints()
Returns the number of constraints defining the skeleton.
Definition: skeleton.hpp:241
bool is_first_subset_of_second(bool *, bool *, unsigned)
Definition: skeleton.cpp:330
bool is_active_at(const constraint &hyperplane) const
Returns true if and only if the hyperplane is active at this ray.
Definition: lp_solver.hpp:279
const vector< constraint > & get_constraints()
Returns the constraints that define the skeleton.
Definition: skeleton.hpp:246
friend bool operator==(const edge &e1, const edge &e2)
Equal if and only if.
Definition: skeleton.hpp:100
a ray defined by nonnegative coordinates
Definition: lp_solver.hpp:190
int number_of_common_constraints(bool *, bool *, unsigned)
Definition: skeleton.cpp:297