|
| 1 | +/** |
| 2 | + * Copyright 2024, SRI International. |
| 3 | + * |
| 4 | + * This file is part of LibPoly. |
| 5 | + * |
| 6 | + * LibPoly is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * LibPoly is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with LibPoly. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +#include "poly.h" |
| 23 | +#include "integer.h" |
| 24 | +#include <stdbool.h> |
| 25 | + |
| 26 | +#ifdef __cplusplus |
| 27 | +extern "C" { |
| 28 | +#endif |
| 29 | + |
| 30 | +/** |
| 31 | + * Set of disjoint intervals representing an algebraic set, ordered from |
| 32 | + * left to right (-inf to +inf). |
| 33 | + */ |
| 34 | +struct lp_feasibility_set_int_struct { |
| 35 | + /** The ring in which the feasibility set lives. */ |
| 36 | + lp_int_ring_t *K; |
| 37 | + |
| 38 | + /** If true, set represents K \setminus elements */ |
| 39 | + bool inverted; |
| 40 | + |
| 41 | + /** Number of elements */ |
| 42 | + size_t size; |
| 43 | + |
| 44 | + /** |
| 45 | + * Vector feasibility elements |
| 46 | + * Values are normalized wrt to K, kept sorted and unique |
| 47 | + */ |
| 48 | + lp_integer_t* elements; |
| 49 | +}; |
| 50 | + |
| 51 | +/** |
| 52 | + * Create a new feasibility set K. |
| 53 | + */ |
| 54 | +lp_feasibility_set_int_t* lp_feasibility_set_int_new_full(lp_int_ring_t *K); |
| 55 | + |
| 56 | +/** |
| 57 | + * Create a new feasibility set {}. |
| 58 | + */ |
| 59 | +lp_feasibility_set_int_t* lp_feasibility_set_int_new_empty(lp_int_ring_t *K); |
| 60 | + |
| 61 | +/** |
| 62 | + * Construct a copy. |
| 63 | + */ |
| 64 | +lp_feasibility_set_int_t* lp_feasibility_set_int_new_copy(const lp_feasibility_set_int_t* set); |
| 65 | + |
| 66 | +/** |
| 67 | + * Construct from integers. |
| 68 | + */ |
| 69 | +lp_feasibility_set_int_t* lp_feasibility_set_int_new_from_integer(lp_int_ring_t *K, const lp_integer_t* integers, size_t integers_size, bool inverted); |
| 70 | + |
| 71 | +/** |
| 72 | + * Delete the given feasibility set. |
| 73 | + */ |
| 74 | +void lp_feasibility_set_int_delete(lp_feasibility_set_int_t* set); |
| 75 | + |
| 76 | +/** |
| 77 | + * Assignment. |
| 78 | + */ |
| 79 | +void lp_feasibility_set_int_assign(lp_feasibility_set_int_t* set, const lp_feasibility_set_int_t* from); |
| 80 | + |
| 81 | +/** |
| 82 | + * Swap. |
| 83 | + */ |
| 84 | +void lp_feasibility_set_int_swap(lp_feasibility_set_int_t* s1, lp_feasibility_set_int_t* s2); |
| 85 | + |
| 86 | +/** |
| 87 | + * Check if the given set is empty. |
| 88 | + */ |
| 89 | +int lp_feasibility_set_int_is_empty(const lp_feasibility_set_int_t* set); |
| 90 | + |
| 91 | +/** |
| 92 | + * Check if the given set is full. |
| 93 | + */ |
| 94 | +int lp_feasibility_set_int_is_full(const lp_feasibility_set_int_t* set); |
| 95 | + |
| 96 | +/** |
| 97 | + * Check if the set is a point {a}. |
| 98 | + */ |
| 99 | +int lp_feasibility_set_int_is_point(const lp_feasibility_set_int_t* set); |
| 100 | + |
| 101 | +/** |
| 102 | + * assigns the size of the set to out |
| 103 | + */ |
| 104 | +void lp_feasibility_set_int_size(const lp_feasibility_set_int_t *set, lp_integer_t *out); |
| 105 | + |
| 106 | +/** |
| 107 | + * returns the size; guaranteed to be correct if it fits in long |
| 108 | + */ |
| 109 | +size_t lp_feasibility_set_int_size_approx(const lp_feasibility_set_int_t *set); |
| 110 | + |
| 111 | +/** |
| 112 | + * Check if the given value belongs to the set. |
| 113 | + */ |
| 114 | +int lp_feasibility_set_int_contains(const lp_feasibility_set_int_t* set, const lp_integer_t* value); |
| 115 | + |
| 116 | +/** |
| 117 | + * Pick a value from the feasible set (must be non-empty). |
| 118 | + */ |
| 119 | +void lp_feasibility_set_int_pick_value(const lp_feasibility_set_int_t* set, lp_integer_t* value); |
| 120 | + |
| 121 | +/** |
| 122 | + * Get intersection of the two sets. |
| 123 | + * s1 and s2 must be over the same ring K. |
| 124 | + */ |
| 125 | +lp_feasibility_set_int_t* lp_feasibility_set_int_intersect(const lp_feasibility_set_int_t* s1, const lp_feasibility_set_int_t* s2); |
| 126 | + |
| 127 | +/** |
| 128 | + * Get union of the two sets. |
| 129 | + * s1 and s2 must be over the same ring K. |
| 130 | + */ |
| 131 | +lp_feasibility_set_int_t* lp_feasibility_set_int_union(const lp_feasibility_set_int_t* s1, const lp_feasibility_set_int_t* s2); |
| 132 | + |
| 133 | +typedef enum { |
| 134 | + LP_FEASIBILITY_SET_INT_S1, |
| 135 | + LP_FEASIBILITY_SET_INT_S2, |
| 136 | + LP_FEASIBILITY_SET_INT_NEW, |
| 137 | + LP_FEASIBILITY_SET_INT_EMPTY |
| 138 | +} lp_feasibility_set_int_status_t; |
| 139 | + |
| 140 | +/** |
| 141 | + * Get intersection of the two sets, returns the status in the given variable. |
| 142 | + * The set s1 is given precedence so LP_FEASIBILITY_SET_S2 is the |
| 143 | + * status only if the intersect is not s1. |
| 144 | + * s1 and s2 must be over the same ring K. |
| 145 | + */ |
| 146 | +lp_feasibility_set_int_t* lp_feasibility_set_int_intersect_with_status(const lp_feasibility_set_int_t* s1, const lp_feasibility_set_int_t* s2, lp_feasibility_set_int_status_t * status); |
| 147 | + |
| 148 | +/** |
| 149 | + * Get union of the two sets, returns the status in the given variable. |
| 150 | + * The set s1 is given precedence so LP_FEASIBILITY_SET_S2 is the |
| 151 | + * status only if the union is not s1. |
| 152 | + * s1 and s2 must be over the same ring K. |
| 153 | + */ |
| 154 | +lp_feasibility_set_int_t* lp_feasibility_set_int_union_with_status(const lp_feasibility_set_int_t* s1, const lp_feasibility_set_int_t* s2, lp_feasibility_set_int_status_t* status); |
| 155 | + |
| 156 | +/** |
| 157 | + * Add one set to another, i.e. s = s \cup from. |
| 158 | + */ |
| 159 | +void lp_feasibility_set_int_add(lp_feasibility_set_int_t* s, const lp_feasibility_set_int_t* from); |
| 160 | + |
| 161 | +/** |
| 162 | + * Returns true if both sets are equal |
| 163 | + */ |
| 164 | +bool lp_feasibility_set_int_eq(const lp_feasibility_set_int_t* s1, const lp_feasibility_set_int_t* s2); |
| 165 | + |
| 166 | +/** |
| 167 | + * Print the set. |
| 168 | + */ |
| 169 | +int lp_feasibility_set_int_print(const lp_feasibility_set_int_t* set, FILE* out); |
| 170 | + |
| 171 | +/** |
| 172 | + * Return the string representation of the set. |
| 173 | + */ |
| 174 | +char* lp_feasibility_set_int_to_string(const lp_feasibility_set_int_t* set); |
| 175 | + |
| 176 | +#ifdef __cplusplus |
| 177 | +} /* close extern "C" { */ |
| 178 | +#endif |
0 commit comments