14 #ifndef OR_TOOLS_LP_DATA_PERMUTATION_H_
15 #define OR_TOOLS_LP_DATA_PERMUTATION_H_
17 #include "absl/random/random.h"
43 template <
typename IndexType>
50 IndexType
size()
const {
return IndexType(perm_.
size()); }
65 const IndexType
operator[](IndexType i)
const {
return perm_[i]; }
103 template <
typename IndexType,
typename ITIVectorType>
105 const ITIVectorType&
b, ITIVectorType* result);
109 template <
typename IndexType,
typename ITIVectorType>
111 const ITIVectorType&
b, ITIVectorType* result);
115 template <
typename RowIndexedVector>
118 RowIndexedVector temp_v = *v;
122 template <
typename RowIndexedVector>
125 RowIndexedVector* tmp) {
134 template <
typename IndexType>
136 const size_t size = inverse.perm_.
size();
138 for (IndexType i(0); i < size; ++i) {
139 perm_[inverse[i]] = i;
143 template <
typename IndexType>
145 const size_t size = perm_.size();
146 perm_.resize(size, IndexType(0));
147 for (IndexType i(0); i < size; ++i) {
152 template <
typename IndexType>
154 PopulateFromIdentity();
155 std::shuffle(perm_.begin(), perm_.end());
158 template <
typename IndexType>
160 const size_t size = perm_.size();
162 for (IndexType i(0); i < size; ++i) {
163 if (perm_[i] < 0 || perm_[i] >= size) {
166 visited[perm_[i]] =
true;
168 for (IndexType i(0); i < size; ++i) {
176 template <
typename IndexType>
178 const size_t size = perm_.size();
182 for (IndexType i(0); i < size; ++i) {
191 if ((cycle_size & 1) == 0) {
192 signature = -signature;
199 template <
typename IndexType,
typename ITIVectorType>
201 const ITIVectorType&
b, ITIVectorType* result) {
203 const IndexType size(perm.
size());
209 DCHECK_EQ(size.value(),
b.size().value());
210 result->resize(
b.size(),
b.back());
211 for (IndexType i(0); i < size; ++i) {
212 const typename ITIVectorType::IndexType ith_index(i.value());
213 const typename ITIVectorType::IndexType permuted(perm[i].
value());
214 (*result)[permuted] =
b[ith_index];
218 template <
typename IndexType,
typename ITIVectorType>
220 const ITIVectorType&
b, ITIVectorType* result) {
222 const IndexType size(perm.
size());
228 DCHECK_EQ(size.value(),
b.size().value());
229 result->resize(
b.size(),
b.back());
230 for (IndexType i(0); i < size; ++i) {
231 const typename ITIVectorType::IndexType ith_index(i.value());
232 const typename ITIVectorType::IndexType permuted(perm[i].
value());
233 (*result)[ith_index] =
b[permuted];
void assign(size_type n, const value_type &val)
void resize(size_type new_size)
void resize(IndexType size, IndexType value)
IndexType & operator[](IndexType i)
const IndexType operator[](IndexType i) const
int ComputeSignature() const
void PopulateFromIdentity()
Permutation(IndexType size)
void assign(IndexType size, IndexType value)
void PopulateFromInverse(const Permutation &inverse)
void ApplyInversePermutation(const Permutation< IndexType > &perm, const ITIVectorType &b, ITIVectorType *result)
Permutation< ColIndex > ColumnPermutation
void ApplyPermutation(const Permutation< IndexType > &perm, const ITIVectorType &b, ITIVectorType *result)
void ApplyColumnPermutationToRowIndexedVector(const Permutation< ColIndex > &col_perm, RowIndexedVector *v)
Permutation< RowIndex > RowPermutation
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
Collection of objects used to extend the Constraint Solver library.
#define RETURN_IF_NULL(x)