14#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_ELEMENTAL_DIFFERENCER_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_ELEMENTAL_DIFFERENCER_H_
22#include "absl/container/flat_hash_set.h"
33absl::flat_hash_set<T>
IntersectSets(
const absl::flat_hash_set<T>& first,
34 const absl::flat_hash_set<T>& second);
45 const absl::flat_hash_set<T>& second);
86 template <
typename AttrType>
138 return elements_[
static_cast<int>(e)];
142 return elements_[
static_cast<int>(e)];
145 template <
typename AttrType>
150 template <
typename AttrType>
159 model_name_different_ = value;
163 return primary_objective_name_different_;
166 primary_objective_name_different_ = value;
170 bool model_name_different_ =
false;
171 bool primary_objective_name_different_ =
false;
172 std::array<ElementDifference, kNumElements> elements_;
174 using StorageForAttr = AttributeDifference<AllAttrs::Type<i>>;
183absl::flat_hash_set<T>
IntersectSets(
const absl::flat_hash_set<T>& first,
184 const absl::flat_hash_set<T>& second) {
185 absl::flat_hash_set<T> result;
186 for (
const T& f : first) {
187 if (second.contains(f)) {
196 const absl::flat_hash_set<T>& first,
const absl::flat_hash_set<T>& second) {
197 for (
const T& f : first) {
198 if (!second.contains(f)) {
202 for (
const T& s : second) {
203 if (!first.contains(s)) {
204 only_in_second.insert(s);
209template <
typename AttrType>
210std::vector<typename ElementalDifference::AttributeDifference<AttrType>::Key>
212 std::vector<Key> result;
214 result.push_back(key);
216 for (Key key : keys.only_in_second) {
217 result.push_back(key);
219 for (Key key : different_values) {
220 result.push_back(key);
222 absl::c_sort(result);
226template <
typename AttrType>
228 return keys.Empty() && different_values.empty();
const AttributeDifference< AttrType > & attr_difference(const AttrType a) const
bool model_name_different() const
bool primary_objective_name_different() const
AttributeDifference< AttrType > & mutable_attr_difference(const AttrType a)
static ElementalDifference Create(const Elemental &first, const Elemental &second, const ElementalDifferenceOptions &options={})
Returns the difference between two Elementals.
ElementDifference & mutable_element_difference(const ElementType e)
void set_primary_objective_name_different(bool value)
ElementalDifference()=default
const ElementDifference & element_difference(const ElementType e) const
static std::string Describe(const Elemental &first, const Elemental &second, const ElementalDifference &difference)
static std::string DescribeDifference(const Elemental &first, const Elemental &second, const ElementalDifferenceOptions &options={})
Returns a string describing the difference between two models.
void set_model_name_different(bool value)
An object oriented wrapper for quadratic constraints in ModelStorage.
AttrKey< AttrTypeDescriptorT< AttrType >::kNumKeyElements, typename AttrTypeDescriptorT< AttrType >::Symmetry > AttrKeyFor
The type of the AttrKey for attribute type AttrType.
absl::flat_hash_set< T > IntersectSets(const absl::flat_hash_set< T > &first, const absl::flat_hash_set< T > &second)
Returns the elements in both first and second.
bool Empty() const
Indicates that there are no differences for this attribute.
SymmetricDifference< Key > keys
AttrKeyFor< AttrType > Key
std::vector< Key > AllKeysSorted() const
absl::flat_hash_set< Key > different_values
The difference for an ElementType.
bool next_id_different
The value of next_id for this ElementType differs.
bool Empty() const
Indicates there are no differences for this ElementType.
SymmetricDifference< int64_t > ids
Element ids in one elemental but not in the other.
absl::flat_hash_set< int64_t > different_names
Element ids in both elementals where the element names disagree.
SymmetricDifference()=default
absl::flat_hash_set< T > only_in_second
absl::flat_hash_set< T > only_in_first