本文整理汇总了C++中Permutation类的典型用法代码示例。如果您正苦于以下问题:C++ Permutation类的具体用法?C++ Permutation怎么用?C++ Permutation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permutation类的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: Exception_SizesDoNotMatch
void
DateSet::permute(const Permutation& p)
{
if (p.size() != size())
throw Exception_SizesDoNotMatch();
p.permute(data_.data());
}
示例3: calculateKendall
float Permutation::calculateKendall(const Permutation & compare) const
{
float score=0;
vector<int> compareArray = compare.getArray();
if (getLength() != compare.getLength()) {
cerr << "1stperm: " << getLength() << " 2ndperm: " << compare.getLength() << endl;
throw runtime_error("Length of permutations not equal");
}
if (getLength() == 0) {
cerr << "Empty permutation" << endl;
return 0;
}
for (size_t i=0; i<getLength(); i++) {
for (size_t j=0; j<getLength(); j++) {
if ((m_array[i] < m_array[j]) && (compareArray[i] > compareArray[j])) {
score++;
}
}
}
score = (score / ((getLength()*getLength() - getLength()) /2 ) );
//Adjusted Kendall's tau correlates better with human judgements
score = sqrt (score);
score = 1 - score;
return score;
}
示例4: getRank
Word ThRightNormalForm::getShortWord( ) const
{
Word result;
Permutation omega = Permutation::getHalfTwistPermutation( getRank( ) );
int power = getPower( );
if( power<0 ) {
const list< Permutation >& decomp = getDecomposition( );
list<Permutation>:: const_iterator it = decomp.begin( );
for( int j=0 ; it!=decomp.end( ) ; ++it, ++j ) {
int n = j - decomp.size( ) - power;
if( n<0 ) {
vector< int > gd = (*it).geodesic();
for( size_t t=0 ; t<gd.size() ; ++t )
result.push_back( gd[t]+1 );
} else {
Permutation p = ( n%2 == 1 ? (*it).inverse() * omega : omega * (*it).inverse() );
vector<int> gd = p.geodesic();
for( int t=gd.size( )-1 ; t>=0 ; --t )
result.push_back( -gd[t]-1 );
}
}
Word omega_w = Word(omega.geodesicWord( ));
omega_w = -omega_w;
for( int j=decomp.size( ) ; j<-power ; ++j )
result = omega_w*result;
} else
result = getWord( );
return result;
}
示例5: load_format_trec
pair<std::vector<Permutation<element_type, rank_type>* >, std::map<string, int> > load_format_trec(string qresult){
std::string line;
std::map<string, int> map_queries;
std::vector<Permutation<element_type, rank_type>* > rankings;
ifstream infile;
infile.open(qresult.c_str());
while(infile.good() && std::getline( infile, line )){
std::vector<std::string> strs = split(line, ' ');
element_type elem = atoi(&(strs[2]).c_str()[0]);
rank_type pos = atoi(&(strs[3]).c_str()[0]);
std::map<string, int>::iterator it = map_queries.find(strs[0]);
if(it != map_queries.end()){
rankings[it->second]->addElement(elem, pos);
}else{
Permutation<element_type, rank_type>* p = new perm_imp_type();
p->addElement(elem, pos);
rankings.push_back(p);
map_queries[strs[0]] = map_queries.size() - 1;
}
}
infile.close();
return make_pair(rankings, map_queries);
}
示例6: getWord
Word ThLeftNormalForm::getReducedWord() const {
if (theOmegaPower >= 0 || theDecomposition.size() == 0)
return getWord();
const auto p = -theOmegaPower;
const auto d = theDecomposition.size();
const auto a = p < d ? p : d;
Word result;
// 1. Process omega
const Permutation omega = Permutation::getHalfTwistPermutation(theRank);
Word omegaWord = Word(omega.geodesicWord());
omegaWord = -omegaWord;
result = omegaWord.power(p - a);
// 2. Cancel omega^-1 with positive permutations
auto it = theDecomposition.begin();
for (int i = 0; i < a; ++i, ++it) {
auto perm = (-(*it)) * omega;
if ((a - i - 1) % 2 != 0)
perm = perm.flip();
result *= -Word(perm.geodesicWord());
}
// 3. process the rest of positive permutations
for (; it != theDecomposition.end(); ++it) {
result *= Word((*it).geodesicWord());
}
return result;
}
示例7: 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;
}
示例8: union_perm
void union_perm(Permutation<element_type, rank_type> &sigma, Permutation<element_type, rank_type> &tau){
for (typename Permutation<element_type, rank_type>::iterator it = tau.begin(); it != tau.end(); ++it)
{
sigma.addElement(it->first, sigma(it->first));
}
}
示例9: getWord
Word ThRightNormalForm::getWord( ) const
{
Word result;
vector< int > decomposition;
vector< int > geodesic;
list<Permutation>::const_iterator it = theDecomposition.begin( );
for( ; it!=theDecomposition.end( ) ; ++it ) {
geodesic = (*it).geodesic( );
for( size_t j=0 ; j<geodesic.size( ) ; ++j )
result.push_back( geodesic[j]+1 );
}
if( theOmegaPower==0 )
return result;
Word omegaWord;
const Permutation omega = Permutation::getHalfTwistPermutation( theRank );
geodesic = omega.geodesic( );
for( size_t i=0 ; i<geodesic.size( ) ; ++i )
omegaWord.push_back( geodesic[i]+1 );
if( theOmegaPower<0 )
omegaWord = -omegaWord;
for( int i=0 ; i<abs(theOmegaPower) ; ++i )
result *= omegaWord;
return result;
}
示例10: 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_);
}
示例11: TEST
TEST(PermutationTest, Inverse) {
Permutation p = Permutation(create_image(3, 1, 2, 0));
Permutation inverse = p.inverse();
EXPECT_EQ(2, inverse(0));
EXPECT_EQ(0, inverse(1));
EXPECT_EQ(1, inverse(2));
}
示例12: permDiff
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;
}
示例13: applyTo
void KRMB::applyTo(Permutation &p)
{
for (size_t i = 1; i <= k; ++i)
{
if (param.c[i] < param.d[i]) {
p.applyReversal(param.c[i], param.d[i]);
}
}
if (param.a < param.b) {
p.applyReversal(param.a, param.b);
}
}
示例14: 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];
}
}
示例15: ThLeftNormalForm
pair< ThLeftNormalForm , ThLeftNormalForm > ThLeftNormalForm::cycle( ) const
{
if( theDecomposition.empty( ) )
return pair< ThLeftNormalForm , ThLeftNormalForm >( *this , ThLeftNormalForm( theRank ) );
ThLeftNormalForm result = *this;
Permutation first = *(theDecomposition.begin( ));
if( theOmegaPower%2!=0 )
first = first.flip( );
result.theDecomposition.push_back( first );
result.theDecomposition.pop_front( );
result.adjust( );
return pair< ThLeftNormalForm , ThLeftNormalForm >( result , ThLeftNormalForm(first) );
}