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;
126 template <
typename IndexType>
128 const size_t size = inverse.perm_.
size();
130 for (IndexType i(0); i < size; ++i) {
131 perm_[inverse[i]] = i;
135 template <
typename IndexType>
137 const size_t size = perm_.size();
138 perm_.resize(size, IndexType(0));
139 for (IndexType i(0); i < size; ++i) {
144 template <
typename IndexType>
146 PopulateFromIdentity();
147 std::shuffle(perm_.begin(), perm_.end());
150 template <
typename IndexType>
152 const size_t size = perm_.size();
154 for (IndexType i(0); i < size; ++i) {
155 if (perm_[i] < 0 || perm_[i] >= size) {
158 visited[perm_[i]] =
true;
160 for (IndexType i(0); i < size; ++i) {
168 template <
typename IndexType>
170 const size_t size = perm_.size();
174 for (IndexType i(0); i < size; ++i) {
183 if ((cycle_size & 1) == 0) {
184 signature = -signature;
191 template <
typename IndexType,
typename ITIVectorType>
193 const ITIVectorType&
b, ITIVectorType* result) {
195 const IndexType size(perm.
size());
196 if (size == 0)
return;
198 result->resize(
b.size(),
b.back());
199 for (IndexType i(0); i < size; ++i) {
200 const typename ITIVectorType::IndexType ith_index(i.value());
201 const typename ITIVectorType::IndexType permuted(perm[i].
value());
202 (*result)[permuted] =
b[ith_index];
206 template <
typename IndexType,
typename ITIVectorType>
208 const ITIVectorType&
b, ITIVectorType* result) {
210 const IndexType size(perm.
size().value());
211 if (size == 0)
return;
213 result->resize(
b.size(),
b.back());
214 for (IndexType i(0); i < size; ++i) {
215 const typename ITIVectorType::IndexType ith_index(i.value());
216 const typename ITIVectorType::IndexType permuted(perm[i].
value());
217 (*result)[ith_index] =
b[permuted];
#define DCHECK(condition)
#define DCHECK_EQ(val1, val2)
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
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
#define RETURN_IF_NULL(x)