本文整理汇总了C++中Permutation::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Permutation::size方法的具体用法?C++ Permutation::size怎么用?C++ Permutation::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permutation
的用法示例。
在下文中一共展示了Permutation::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addSolution
void addSolution(const Permutation& sol)
{
permutations.push_back(sol);
D_ASSERT(sol.size() == orbit_mins.size());
debug_out(3, "SS", "Old orbit_mins:" << orbit_mins);
for(int i : range1(sol.size()))
{
if(sol[i] != i)
{
int val1 = walkToMinimum(i);
int val2 = walkToMinimum(sol[i]);
int orbit_min = -1;
if(comparison(val1, val2))
orbit_min = val1;
else
orbit_min = val2;
update_orbit_mins(orbit_min, val1);
update_orbit_mins(orbit_min, val2);
update_orbit_mins(orbit_min, i);
update_orbit_mins(orbit_min, sol[i]);
}
}
debug_out(1, "SS", "Solution found");
debug_out(3, "SS", "Sol:" << sol);
debug_out(3, "SS", "New orbit_mins:" << orbit_mins);
}
示例2: operator
Permutation operator()(Permutation lhs, Permutation rhs) const {
assert(lhs.size() == rhs.size());
value_type result(lhs.size());
for (size_t i = 0; i < lhs.size(); ++i)
result[i] = rhs[lhs[i]];
return result;
}
示例3: assert
set<Upair<size_t> >
permDiff(const Permutation& p1, const Permutation& p2)
{
set<Upair<size_t> > ret;
assert(p1.size() == p2.size());
for (size_t i = 0; i < p1.size(); ++i)
if (p1[i] != p2[i])
ret.insert(Upair<size_t>(p1[i], p2[i]));
return ret;
}
示例4: permuteInPlace
/* ************************************************************************* */
void Ordering::permuteInPlace(const Permutation& selector, const Permutation& permutation) {
if(selector.size() != permutation.size())
throw invalid_argument("Ordering::permuteInPlace (partial permutation version) called with selector and permutation of different sizes.");
// Create new index the size of the permuted entries
OrderingIndex newIndex(selector.size());
// Permute the affected entries into the new index
for(size_t dstSlot = 0; dstSlot < selector.size(); ++dstSlot)
newIndex[dstSlot] = orderingIndex_[selector[permutation[dstSlot]]];
// Put the affected entries back in the new order and fix the indices
for(size_t slot = 0; slot < selector.size(); ++slot) {
orderingIndex_[selector[slot]] = newIndex[slot];
orderingIndex_[selector[slot]]->second = selector[slot];
}
}
示例5: applyInverse
Permutation Permutation::applyInverse(Permutation const &b)const
{
IntVector ret(size());
assert(size()==b.size());
for(int i=0;i<size();i++)ret[(*this)[i]]=b[i];
return Permutation(ret);
}
示例6: permute
ColumnPtr ColumnFixedString::permute(const Permutation & perm, size_t limit) const
{
size_t col_size = size();
if (limit == 0)
limit = col_size;
else
limit = std::min(col_size, limit);
if (perm.size() < limit)
throw Exception("Size of permutation is less than required.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
if (limit == 0)
return ColumnFixedString::create(n);
auto res = ColumnFixedString::create(n);
Chars_t & res_chars = res->chars;
res_chars.resize(n * limit);
size_t offset = 0;
for (size_t i = 0; i < limit; ++i, offset += n)
memcpySmallAllowReadWriteOverflow15(&res_chars[offset], &chars[perm[i] * n], n);
return std::move(res);
}
示例7: Exception_SizesDoNotMatch
void
DateSet::permute(const Permutation& p)
{
if (p.size() != size())
throw Exception_SizesDoNotMatch();
p.permute(data_.data());
}
示例8: Exception
void
StringSet::permute(const Permutation& p)
{
if (size() != p.size())
throw Exception("Permutation and data are not of the same size");
p.permute(data_);
}
示例9: swap_rows_inverted
void swap_rows_inverted(Permutation const& P, vector_expression<V>& v) {
for(std::size_t i = P.size(); i != 0; --i) {
std::size_t k = i-1;
if(k != P(k)) {
using std::swap;
swap(v()(k),v()(P(k)));
}
}
}
示例10:
Permutation::Permutation(const Permutation &other)
{
const size_t dim=other.size();
if(dim==0) P=NULL;
else {
P=gsl_permutation_alloc(dim);
gsl_permutation_memcpy(P,other.P);
}
}
示例11:
/**
* Composition operator ie (P1*P2)[k] = P1[P2[k]]
**/
Permutation operator*(const Permutation & P2) const
{
MTOOLS_INSURE(_perm.size() == P2.size());
const int l = (int)_perm.size();
Permutation R;
R._perm.resize(l); R._invperm.resize(l);
for (int i = 0;i < l;i++) { R._perm[i] = _perm[P2._perm[i]]; R._invperm[i] = P2._invperm[_invperm[i]]; }
return R;
}
示例12: generatePermutations
void
generatePermutations(const size_t n, const size_t k,
Permutation perm,
vector<Permutation>& rPerms)
{
if (perm.size() == k){
rPerms.push_back(perm);
return;
}
perm.push_back(0);
for (size_t i = 0; i < n; ++i){
bool used = false;
for (size_t m = 0; m + 1 < perm.size(); ++m)
if (perm[m] == i){
used = true;
break;
}
if (!used){
perm.back() = i;
generatePermutations(n, k, perm, rPerms);
}
}
}
示例13: permute
ColumnPtr ColumnString::permute(const Permutation & perm, size_t limit) const
{
size_t size = offsets.size();
if (limit == 0)
limit = size;
else
limit = std::min(size, limit);
if (perm.size() < limit)
throw Exception("Size of permutation is less than required.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
if (limit == 0)
return std::make_shared<ColumnString>();
std::shared_ptr<ColumnString> res = std::make_shared<ColumnString>();
Chars_t & res_chars = res->chars;
Offsets_t & res_offsets = res->offsets;
if (limit == size)
res_chars.resize(chars.size());
else
{
size_t new_chars_size = 0;
for (size_t i = 0; i < limit; ++i)
new_chars_size += sizeAt(perm[i]);
res_chars.resize(new_chars_size);
}
res_offsets.resize(limit);
Offset_t current_new_offset = 0;
for (size_t i = 0; i < limit; ++i)
{
size_t j = perm[i];
size_t string_offset = j == 0 ? 0 : offsets[j - 1];
size_t string_size = offsets[j] - string_offset;
memcpySmallAllowReadWriteOverflow15(&res_chars[current_new_offset], &chars[string_offset], string_size);
current_new_offset += string_size;
res_offsets[i] = current_new_offset;
}
return res;
}
示例14: handlePossibleSolution
// Checks a solution satisfies all the constraints, and
// adds to the solutionStore if it is. Returns true if
// the solution is real
bool handlePossibleSolution(Problem* p, SolutionStore* ss, RBase* rbase)
{
D_ASSERT(p->p_stack.cellCount() == p->p_stack.domainSize());
Permutation perm = getRawPermutation(p->p_stack.domainSize());
for(int i = 1 ; i <= perm.size(); ++i)
{
perm.raw(rbase->initial_permstack->val(i)) = p->p_stack.val(i);
}
D_ASSERT(perm.validate());
if(!p->con_store.verifySolution(perm))
return false;
info_out(1, "Solution: " << perm);
ss->addSolution(perm);
return true;
}
示例15: generateCombinations
void
generateCombinations(const size_t n, const size_t k,
Permutation perm,
vector<Permutation>& rPerms)
{
if (perm.size() == k){
rPerms.push_back(perm);
return;
}
perm.push_back(0);
for (size_t i = 0; i < n; ++i){
perm.back() = i;
generateCombinations(n, k, perm, rPerms);
}
}