APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_lincons1.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_lincons1.hh
3 *
4 * APRON Library / C++ class wrappers
5 *
6 * Copyright (C) Antoine Mine' 2007
7 *
8 */
9/* This file is part of the APRON Library, released under LGPL license
10 with an exception allowing the redistribution of statically linked
11 executables.
12
13 Please read the COPYING file packaged in the distribution.
14*/
15
16#ifndef __APXX_LINCONS1_HH
17#define __APXX_LINCONS1_HH
18
19#include "ap_lincons1.h"
20#include "apxx_environment.hh"
21#include "apxx_lincons0.hh"
22#include "apxx_linexpr1.hh"
23
24
25namespace apron {
26
27
28/* ================================= */
29/* lincons1 */
30/* ================================= */
32
36
37 * Internally, a lincons1 wraps together a lincons0 (memory managed) and an environment (holding a
38 * reference count).
39 */
40class lincons1 : public use_malloc {
41
42protected:
43
44 ap_lincons1_t l;
45
47 lincons1(ap_lincons1_t p);
48
49
50 friend class lincons1_array;
51
52public:
53
54
55 /* constructors */
56 /* ============ */
60
61
62 * incremented) associating names to dimensions in lincons0.
63 */
64 lincons1(const environment& e, const lincons0& x);
65
66
67 *
68 * The auxiliary scalar is not created (has_modulo returns false).
69 * The linear expression is created sparse and empty (has_linexpr returns true).
70 * \arg \c e associates a variable name to each dimension (reference counter incremented).
71 * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, or \c AP_CONS_DISEQ (but not \c AP_CONS_EQMOD).
72 */
73 lincons1(const environment& e, ap_constyp_t constyp=AP_CONS_SUPEQ);
74
77
80 lincons1(ap_constyp_t constyp, const linexpr1& lin);
81
82 /*! \brief Creates a new constraint from a linear expression and a modulo scalar (both copied).
83 *
84 * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ.
85 */
86 lincons1(ap_constyp_t constyp, const linexpr1& lin, const scalar& modulo);
87
89 lincons1(const environment& e, unsat x);
90
91 //! (Deep) copy of a constraint.
92 lincons1(const lincons1& x);
93
98 lincons1(const lincons1& x, const environment& e);
101
102
103 /* destructor */
104 /* ========== */
105
106
107 //@{
108
111
113
115
116
117 /* assignment */
118 /* ========== */
119
121 //@{
122
124 lincons1& operator= (const lincons1& x);
125
128
131
134 void set_modulo(const scalar& c);
135
136 /*! \brief Sets the underlying linear expression to c (copied).
137 *
138 * Does not fail as get_linexpr can: if the constraint was created without an underlying expression,
139 * it is created.
140 *
141 * \warning assumes that c and *this have equal environments (unchecked).
142 */
143 void set_linexpr(const linexpr1& c);
144
145
147
148 /* dimension operations */
149 /* ==================== */
150
151 /** @name Dimension operations */
153
155
156 * \throw std::invalid_argument if e is not a super-environment of that of *this.
157 */
158 void extend_environment(const environment& e);
159
160
162
163 /* access */
164 /* ====== */
165
166 /** @name Accesses, size */
168
173 const lincons0& get_lincons0() const;
174
175
182 size_t size() const;
188 ap_constyp_t& get_constyp();
189
190 /*! \brief Returns a reference to the constraint type.
191 *
192 * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ.
193 */
194 const ap_constyp_t& get_constyp() const;
195
197 bool has_modulo() const;
204 bool has_linexpr() const;
211
212 /*! \brief Returns a reference to the auxiliary scalar.
213 *
214 * \throw std::invalid_argument if no valid auxiliary scalar has been defined.
215 */
216 const scalar& get_modulo() const;
217
222 linexpr1 get_linexpr() const;
228 coeff& get_cst();
229
233
234 const coeff& get_cst() const;
235
238 * \throw std::invalid_argument if the variable name is not present in the environment.
239 * \throw std::invalid_argument if no valid linear expression has been defined.
240 */
241 coeff& operator[](const var& v);
242
248 const coeff& operator[](const var& v) const;
249
250
252
253 /* print */
254 /* ===== */
255
258
260 friend std::ostream& operator<< (std::ostream& os, const lincons1& s);
261
263 void print(FILE* stream=stdout) const;
264
265 //@}
266
267
268 /* tests */
269 /* ===== */
273
274
278
279 bool is_unsat() const;
280
283
284 */
285 bool is_linear() const;
286
288
292 bool is_quasilinear() const;
293
294 // TODO: equal, compare (currently not in ap_lincons1.h) ???
295
297
298
299 /* TODO: evaluation, linearization, intelligent constructors */
300
302 /* C-level compatibility */
303 /* ===================== */
307
309 const ap_lincons1_t* get_ap_lincons1_t() const;
310
311
312 ap_lincons1_t* get_ap_lincons1_t();
313
315};
316
318
319/* ================================= */
320/* lincons1_array */
321/* ================================= */
322
323
324
326 * Level 1 version of linear constraint arrays.
327 * Internally, a lincons1_array wraps together a lincons0_array (memory managed) and an environment
328 * (holding a reference count).
329 * Please note that all constraints share the same environment!
330 */
332
333protected:
335 ap_lincons1_array_t a;
336
338 lincons1_array(ap_lincons1_array_t& a);
339
340 friend class abstract1;
341
342public:
344 /* constructors */
345 /* ============ */
346
349
352
353 lincons1_array(const environment& e, const lincons0_array& x);
354
357 * has_modulo and has_linexpr will return false on all elements of the array.
358 * \arg \c e associates a variable name to each dimension (reference count incremented).
359 */
360 lincons1_array(const environment& e, size_t size);
361
364
367 * \throw std::invalid_argument if e is not a super-environment of that of x.
368 */
369 lincons1_array(const lincons1_array& x, const environment& e);
370
376 lincons1_array(size_t size, const lincons1 x[]);
377
378 /*! \brief Creates a lincons1_array from an vector (of size >0) of constraints of the given size (copied).
379 *
380 * \warning assumes that all constraints have the same environment (unchecked).
381 * \throw std::invalid_argument if vector size<1.
382 */
383 lincons1_array(const std::vector<lincons1>& x);
384
386
387
388 /* destructor */
389 /* ========== */
390
393
398
400
401
402 /* assignment */
403 /* ========== */
404
405
407
414
415 */
417
422 lincons1_array& operator= (const std::vector<lincons1>& x);
423
425
426
427 /* dimension operations */
428 /* ==================== */
429
431
434 void resize(size_t size);
435
436
438 * \throw std::invalid_argument if e is not a super-environment of that of *this.
439 */
440 void extend_environment(const environment& e);
441
442 //@}
443
444
445 /* access */
446 /* ====== */
450
452 size_t size() const;
453
454 //! Returns the environment shared by all constraints (with incremented reference count).
456
458 const lincons0_array& get_lincons0_array() const;
459
462
466 */
467 lincons1 get(size_t i) const;
468
474 void set(size_t i, const lincons1& x);
475
477
478
479 /* conversion */
480 /* ========== */
481
482 /** @name Conversion */
484
486 operator std::vector<lincons1>() const;
487
489
490
491 /* print */
492 /* ===== */
493
495
496
500 * auxiliary scalar is missing (for modulo constraint).
501 */
502 friend std::ostream& operator<< (std::ostream& os, const lincons1_array& s);
503
504
505 void print(FILE* stream=stdout) const;
506
508
509
510 /* C-level compatibility */
511 /* ===================== */
512
515
517 const ap_lincons1_array_t* get_ap_lincons1_array_t() const;
518
520 ap_lincons1_array_t* get_ap_lincons1_array_t();
521
523
524};
525
526
528
529}
530
531#endif /* __APXX_LINCONS1_HH */
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
Level 1 environment (ap_environment_t wrapper).
Definition apxx_environment.hh:51
Array of linear constraints (ap_lincons0_array_t wrapper).
Definition apxx_lincons0.hh:341
Level 0 linear constraint (ap_lincons0_t wrapper).
Definition apxx_lincons0.hh:43
void set(size_t i, const lincons1 &x)
Changes the constraint at index i.
Definition apxx_lincons1.hh:454
const lincons0_array & get_lincons0_array() const
Returns a reference to the underlying lincons0_array.
Definition apxx_lincons1.hh:437
void extend_environment(const environment &e)
Extends the environment of all expressions in array.
Definition apxx_lincons1.hh:415
ap_lincons1_array_t a
Structure managed by APRON.
Definition apxx_lincons1.hh:335
void resize(size_t size)
Resizes the array.
Definition apxx_lincons1.hh:410
const ap_lincons1_array_t * get_ap_lincons1_array_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons1.hh:500
friend std::ostream & operator<<(std::ostream &os, const lincons1_array &s)
Printing.
Definition apxx_lincons1.hh:482
lincons1_array(ap_lincons1_array_t &a)
Internal use only. Shallow copy (no copy of lincons0_array or environment).
Definition apxx_lincons1.hh:301
environment get_environment() const
Returns the environment shared by all constraints (with incremented reference count).
Definition apxx_lincons1.hh:432
~lincons1_array()
Frees the space used by the array and all its constraints, and decrements the reference count of the ...
Definition apxx_lincons1.hh:357
ap_lincons1_array_t * get_ap_lincons1_array_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons1.hh:505
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_lincons1.hh:491
lincons1_array & operator=(const lincons1_array &x)
(Deep) copy.
Definition apxx_lincons1.hh:366
friend class abstract1
Definition apxx_lincons1.hh:340
size_t size() const
Returns the size of the array.
Definition apxx_lincons1.hh:427
lincons1 get(size_t i) const
Returns a copy of the constraint at index i.
Definition apxx_lincons1.hh:447
Level 1 linear constraint (ap_lincons1_t wrapper).
Definition apxx_lincons1.hh:40
void set_linexpr(const linexpr1 &c)
Sets the underlying linear expression to c (copied).
Definition apxx_lincons1.hh:112
const ap_lincons1_t * get_ap_lincons1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons1.hh:279
bool is_linear() const
Whether the underlying linear expression has only scalar coefficients.
Definition apxx_lincons1.hh:265
size_t size() const
Returns the size of the underlying linear expression.
Definition apxx_lincons1.hh:151
bool has_modulo() const
Whether the constraint has a valid auxiliary scalar (used in modulo constraints).
Definition apxx_lincons1.hh:166
environment get_environment() const
Returns the environment of the constraint (with incremented reference count).
Definition apxx_lincons1.hh:136
void set_modulo(const scalar &c)
Sets the auxiliary scalar modulo to c (copied).
Definition apxx_lincons1.hh:107
void extend_environment(const environment &e)
Extends the environment of the expression.
Definition apxx_lincons1.hh:121
lincons1 & operator=(const lincons1 &x)
Makes a (deep) copy.
Definition apxx_lincons1.hh:91
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name.
Definition apxx_lincons1.hh:212
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_lincons1.hh:251
ap_lincons1_t l
Structure managed by APRON.
Definition apxx_lincons1.hh:44
friend std::ostream & operator<<(std::ostream &os, const lincons1 &s)
Printing.
Definition apxx_lincons1.hh:238
bool is_quasilinear() const
Whether the underlying linear expression has only scalar coefficients, except maybe for the constant ...
Definition apxx_lincons1.hh:270
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_lincons1.hh:156
lincons1(ap_lincons1_t p)
Internal use only. Shallow copy (no copy of lincons0 or environment).
Definition apxx_lincons1.hh:28
const lincons0 & get_lincons0() const
Returns a reference to the underlying lincons0.
Definition apxx_lincons1.hh:141
linexpr1 get_linexpr() const
Returns a copy of the underlying linear expression.
Definition apxx_lincons1.hh:190
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_lincons1.hh:198
scalar & get_modulo()
Returns a (modifiable) reference to the auxiliary scalar.
Definition apxx_lincons1.hh:176
bool has_linexpr() const
Whether the constraint has a valid linear expression.
Definition apxx_lincons1.hh:171
friend class lincons1_array
Definition apxx_lincons1.hh:50
~lincons1()
Frees all space for the expression and coefficients, and decrements the reference count of the enviro...
Definition apxx_lincons1.hh:82
bool is_unsat() const
Whether the constraint is unsatisfiable.
Definition apxx_lincons1.hh:260
Level 1 linear expression (ap_linexpr1_t wrapper).
Definition apxx_linexpr1.hh:39
Scalar (ap_scalar_t wrapper).
Definition apxx_scalar.hh:89
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
Definition apxx_abstract0.hh:27
Unsatisfiable constraint, to simplify initialisations and assignments.
Definition apxx_lincons0.hh:28
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69