1 #ifndef __LP_SOLVER_CPP_ 2 #define __LP_SOLVER_CPP_ 21 #include "lp_solver.hpp" 25 nvars = num_variables;
26 coefficients =
new CONSTR_TYPE[nvars];
27 for (NVAR_TYPE i = 0; i < nvars; ++i)
28 coefficients[i] = coeffs[i];
33 nvars = coeffs.size();
34 coefficients =
new CONSTR_TYPE[nvars];
35 for (NVAR_TYPE i = 0; i < nvars; ++i)
36 coefficients[i] = coeffs[i];
41 nvars = old_constraint.nvars;
42 coefficients =
new CONSTR_TYPE[nvars];
43 for (NVAR_TYPE i = 0; i < nvars; ++i)
44 coefficients[i] = old_constraint.coefficients[i];
50 bool result = !(first == second);
51 bool checking = result;
52 for (NVAR_TYPE i = 0; checking and i < first.nvars; ++i)
53 if (first[i] != second[i])
56 result = first[i] < second[i];
65 if (first[i] != second[i])
75 if (first[i] != second[i])
85 for (NVAR_TYPE i = 0; i < c.nvars; ++i)
89 if (first) { ostr <<
'-'; first =
false; }
else ostr <<
"- ";
91 ostr << -c[i] <<
'x' << i <<
' ';
93 ostr <<
'x' << i <<
' ';
97 if (first) { first =
false; }
else ostr <<
"+ ";
99 ostr << c[i] <<
'x' << i <<
' ';
101 ostr <<
'x' << i <<
' ';
113 delete [] coefficients;
124 unsigned invocations = 0;
126 inline DEG_TYPE * ray_data_allocation(NVAR_TYPE n) {
136 coords = ray_data_allocation(dim);
137 for (NVAR_TYPE i = 0; i < dim; ++i) coords[i] = 0;
138 if (direction >= 0) {
139 coords[direction] = 1;
143 ray::ray(NVAR_TYPE dimension,
const RAYENT_TYPE entries [])
147 coords = ray_data_allocation(dim);
148 for (NVAR_TYPE i = 0; i < dim; ++i)
149 coords[i] = entries[i];
152 ray::ray(NVAR_TYPE dimension,
const EXP_TYPE entries [])
156 coords = ray_data_allocation(dim);
157 for (NVAR_TYPE i = 0; i < dim; ++i)
158 coords[i] = entries[i];
163 dim = entries.size();
165 coords = ray_data_allocation(dim);
166 for (NVAR_TYPE i = 0; i < dim; ++i)
167 coords[i] = entries[i];
174 static unsigned long invocations;
175 coords = ray_data_allocation(dim);
176 for (RAYENT_TYPE i = 0; i < dim; ++i)
177 coords[i] = old_ray.coords[i];
188 RAYENT_TYPE * w = coords;
196 RAYENT_TYPE r = (gcd < w[i] ? gcd : w[i]);
197 RAYENT_TYPE s = (gcd < w[i] ? w[i] : gcd);
200 RAYENT_TYPE t = s % r;
214 DOTPROD_TYPE result = 0;
215 const CONSTR_TYPE * coeffs = hyperplane.
coeffs();
216 for (NVAR_TYPE i = 0; i < dim; ++i)
218 result += coords[i] * coeffs[i];
226 RAYENT_TYPE *coords = ray_data_allocation(d);
227 for (NVAR_TYPE i = 0; i < d; ++i)
229 ray result(d, coords);
237 RAYENT_TYPE result = 0;
239 result += r1[i]*r2[i];
245 RAYENT_TYPE result = 0;
247 result += r1[i]*r2[i];
253 RAYENT_TYPE result = 0;
254 for (NVAR_TYPE i = 0; i < r1.size(); ++i)
255 result += r1[i]*r2[i];
262 RAYENT_TYPE * coords = ray_data_allocation(d);
263 for (NVAR_TYPE i = 0; i < d; ++i)
264 coords[i] = r1[i] + r2[i];
265 ray result(d, coords);
273 RAYENT_TYPE *coords = ray_data_allocation(d);
274 for (NVAR_TYPE i = 0; i < d; ++i)
275 coords[i] = r1[i] - r2[i];
276 ray result(d, coords);
284 RAYENT_TYPE *coords =
nullptr;
285 for (
auto riter = rs.begin(); riter != rs.end(); ++riter)
288 if (coords ==
nullptr)
291 coords = ray_data_allocation(d);
292 for (NVAR_TYPE i = 0; i < d; ++i) coords[i] = 0;
294 for (NVAR_TYPE i = 0; i < d; ++i)
299 ray result(d, coords);
307 for (NVAR_TYPE i = 0; result and i < r1.
get_dimension(); ++i)
308 result = r1[i] == r2[i];
315 for (NVAR_TYPE i = 0; result and i < r1.
get_dimension(); ++i)
316 result = r1[i] == r2[i];
324 for (i = 0; i < r.dim - 1; ++i)
325 ostr << r[i] <<
", ";
326 ostr << r[i] <<
" )";
332 if (!(*
this == other))
335 if (dim != other.dim)
341 coords = ray_data_allocation(dim);
344 for (NVAR_TYPE i = 0; i < dim; ++i)
345 coords[i] = other.coords[i];
353 for (NVAR_TYPE i = 0; i < dim; ++i)
356 coords[i] = other.coords[i];
357 other.coords[i] = tmpval;
366 while (equal and i < first_ray.dim)
368 if (first_ray[i] != second_ray[i])
371 result = first_ray[i] < second_ray[i];
375 return result and (not equal);
ray ray_sum(const set< ray > &rs)
Add all the rays in a set.
special memory pool allocator for Grevlex_Order_Data and WGrevlex_Order_Data
ray operator-(const ray &r1, const ray &r2)
Subtract the two rays.
friend bool operator<(const ray &, const ray &)
Lexicographic comparison of rays.
ray operator+(ray &r1, ray &r2)
Add the two rays.
TYPE * get_new_block()
allocates and returns a block of memory
friend bool operator!=(const constraint &a, const constraint &b)
check for constraint inequality
Grading_Order_Data_Allocator< DEG_TYPE > * doda
memory manager for ray entries
virtual const set< ray > & get_rays()
Returns the rays that define the skeleton.
friend bool operator<(const constraint &a, const constraint &b)
Lexicographic comparison of constraints.
~constraint()
Deletes memory allocated by the constructor.
friend ostream & operator<<(ostream &, const constraint &)
print a representation of the constraint to the stream
ray operator*(RAYENT_TYPE a, ray &r)
Multiply every coordinate in the given ray by the given scalar.
constraint(NVAR_TYPE, CONSTR_TYPE [])
Initialize constraint to the given coefficients.
DOTPROD_TYPE obtain_dot_product(const constraint &) const
Convenience function to compute dot product between ray and the given constraint. ...
NVAR_TYPE get_number_of_variables() const
Returns the number of variables in the constraint.
friend bool operator==(const ray &, const ray &)
Indicates whether the two rays are equal.
void swap(ray &)
Swap two rays of equal dimension by swapping their data, avoiding memory reallocation.
~ray()
Deletes memory allocated by the constructor.
friend bool operator==(const constraint &a, const constraint &b)
check for constraint equality
ray(NVAR_TYPE, long=-1)
Creates a ray with the given number of variables, all set to 0.
const CONSTR_TYPE * coeffs() const
Returns the coefficients that determine this constraints.
NVAR_TYPE get_dimension() const
Returns the dimension of this ray.
ray & operator=(const ray &)
Assignment operator; assigns the value of other to this.
friend ostream & operator<<(ostream &, const ray &)
Output is of the form .
void return_used_block(TYPE *freed_block)
returns a block of memory that is no longer needed to the pool
friend bool operator!=(const ray &, const ray &)
Indicates whether the two rays are unequal.
void simplify_ray()
Simplifies the ray by dividing its components by the least common denominator.
a ray defined by nonnegative coordinates