34 #include "system_constants.hpp" 37 #include "skeleton.hpp" 40 : first(first_ray), second(second_ray)
47 : first(old_edge.first), second(old_edge.second)
54 ostr <<
"{ " << e.first <<
" , " << e.second <<
" }";
61 if (first.first < second.first)
65 else if (second.first < first.first)
68 if (first.second < second.second)
79 if (!(*
this == other))
82 second = other.second;
92 CONSTR_TYPE * constr_coords =
new CONSTR_TYPE[dim];
93 for (NVAR_TYPE i = 0; i < dim; ++i) constr_coords[i] = 0;
95 for (NVAR_TYPE i = 0; i < dim; ++i)
98 constraints.push_back(
constraint(dim, constr_coords));
101 delete [] constr_coords;
103 for (NVAR_TYPE i = 0; i < dim; ++i)
106 rays.insert(new_ray);
110 for (
auto riter = rays.begin(); riter != rays.end(); ++riter)
111 for (
auto siter = rays.begin(); siter != rays.end(); ++siter)
112 if (*riter != *siter)
114 edge new_edge(*riter, *siter);
115 edges.insert(new_edge);
121 common_initialization(dimension);
127 common_initialization(dimension);
132 : constraints(old_skeleton.constraints),
133 edges(old_skeleton.edges), dim(old_skeleton.dim)
142 if (old_skeleton !=
nullptr) {
143 constraints.clear();
rays.clear(); edges.clear();
144 for (
const constraint & c : old_skeleton->constraints)
145 constraints.push_back(c);
146 for (
const ray & r : old_skeleton->
rays)
148 for (
const edge & e : old_skeleton->edges)
153 dim = old_skeleton->dim;
155 return (old_skeleton !=
nullptr);
166 bool consistent =
true;
168 set<ray> rays_above, rays_below, rays_on;
169 for (
auto riter =
rays.begin(); riter !=
rays.end(); ++riter)
171 DOTPROD_TYPE dp = (*riter) * constraint;
174 rays_above.insert(*riter);
179 rays_below.insert(*riter);
184 ray old_ray = *riter;
185 rays_on.insert(old_ray);
191 if (rays_above.size() == 0)
199 if (consistent and rays_below.size() != 0)
201 set<edge> edges_above, edges_on;
202 for (
auto eiter = edges.begin(); eiter != edges.end(); ++eiter)
209 if ((u*constraint >= 0) and (v*constraint >= 0))
212 edges_above.insert(e);
215 for (
auto eiter = edges.begin(); eiter != edges.end(); ++eiter)
220 DOTPROD_TYPE a = u*constraint;
221 DOTPROD_TYPE b = v*constraint;
229 edges_on.insert(
edge(u,w));
232 else if (b > 0 and a < 0)
237 edges_on.insert(
edge(v,w));
243 for (
auto riter = rays_above.begin(); riter != rays_above.end(); ++riter)
249 for (
auto riter = rays_on.begin(); riter != rays_on.end(); ++riter)
259 constraints.push_back(constraint);
273 bool consistent =
true;
279 auto nciter = new_constraints.begin();
280 consistent and nciter != new_constraints.end();
299 bool * a,
bool * b,
unsigned m
309 for (
unsigned i = 0; i < m; ++i)
310 if (a[i] and b[i]) ++result;
317 bool * a,
bool * b,
bool * result,
unsigned m
325 for (
unsigned i = 0; i < m; ++i)
326 result[i] = (a[i] and b[i]);
332 bool * a,
bool * b,
unsigned m
337 for (
unsigned i = 0; result and i < m; ++i)
338 if (a[i]) result = b[i];
346 for (
const edge & e : a) result.insert(e);
347 for (
const edge & e : b) result.insert(e);
353 static unsigned long invocations;
355 set<ray> tested_rays;
356 bool * Zu =
new bool [constraints.size()] {
false };
357 bool * Zv =
new bool [constraints.size()] {
false };
358 bool * w_active =
new bool [constraints.size()] {
false };
359 bool * Zuv =
new bool [constraints.size()] {
false };
361 for (
auto riter = new_rays.begin(); riter != new_rays.end(); ++riter)
364 tested_rays.insert(u);
369 for (
auto siter = new_rays.begin(); siter != new_rays.end(); ++siter)
370 if (*riter != *siter)
388 for (
auto diter = D.begin(); diter != D.end(); ++diter)
391 if (tested_rays.find(v) == tested_rays.end())
400 bool can_be_added =
true;
403 auto dditer = D.begin();
404 dditer != D.end() and can_be_added;
414 can_be_added =
false;
422 new_edges.insert(new_edge);
438 ostr <<
"Skeleton defined by constraints" << endl;
440 vector<constraint>::const_iterator citer=skel.constraints.begin();
441 citer != skel.constraints.end();
444 ostr <<
'\t' << *citer << endl;
446 ostr <<
"has " << skel.
rays.size() <<
" rays" << endl;
447 for (
auto riter=skel.
rays.begin(); riter != skel.
rays.end(); ++riter)
448 ostr <<
'\t' << *riter << endl;
450 ostr <<
"connected in " << skel.edges.size() <<
" edges" << endl;
451 for (
auto eiter=skel.edges.begin(); eiter != skel.edges.end(); ++eiter)
452 ostr <<
'\t' << *eiter << endl;
454 ostr <<
"End of skeleton" << endl;
465 auto siter = other.
rays.begin();
466 siter != other.
rays.end();
471 auto eiter = other.edges.begin();
472 eiter != other.edges.end();
475 edges.insert(*eiter);
477 vector<constraint>::const_iterator citer = other.constraints.begin();
478 citer != other.constraints.end();
481 constraints.push_back(*citer);
virtual ~skeleton()
Currently does nothing the compiler wouldn't do.
virtual bool copy(const LP_Solver *)
performs a deep copy, similar to a copy constructor
an edge connecting the two rays and
void common_initialization(NVAR_TYPE)
Initialization common to all constructors.
skeleton & operator=(const skeleton &)
Assignment operator; empties current set & copies from other.
virtual bool solve(vector< constraint > &)
Adds the indicated constraints (plural!) and re-computes the skeleton.
ray get_first_ray() const
Returns the first ray listed in this edge.
set< edge > adjacencies_by_graphs(set< ray >)
Re-computes the edges in the skeleton using Zolotych's GraphAdj algorithm and returns the result...
friend bool operator<(const edge &, const edge &)
Compares two edges lexicographically.
void which_constraints_active_at(const ray &u, bool *result) const
returns the set of constraints in the skeleton active at u
void swap(ray &)
Swap two rays of equal dimension by swapping their data, avoiding memory reallocation.
skeleton of a polyhedral cone, with methods allowing definition and refinement
exact or approximate polyhedral cone solution, with methods allowing definition and refinement ...
set< edge > union_of_edge_sets(const set< edge > &a, const set< edge > &b)
friend ostream & operator<<(ostream &, const skeleton &)
prints out the constraints, then the rays, then the edges.
edge & operator=(const edge &)
Assignment operator.
ray get_second_ray() const
Returns the second ray listed in this edge.
friend ostream & operator<<(ostream &, const edge &)
Output has the form where is the first ray in this edge, etc.
skeleton(NVAR_TYPE)
Constructs a basic skeleton in the given number of dimensions, initialized to the axes...
vector< bool > intersections_of_active_constraints(bool *, bool *, unsigned)
bool is_consistent(const constraint &c) const
tests for consistency of a potentially new constraint.
edge(const ray &, const ray &)
Creates a new edge that joins the two rays.
void simplify_ray()
Simplifies the ray by dividing its components by the least common denominator.
bool is_first_subset_of_second(bool *a, bool *b, unsigned m)
a ray defined by nonnegative coordinates
int number_of_common_constraints(bool *a, bool *b, unsigned m)