本文整理汇总了C++中VectorOf::length方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorOf::length方法的具体用法?C++ VectorOf::length怎么用?C++ VectorOf::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorOf
的用法示例。
在下文中一共展示了VectorOf::length方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: G
AbelianEquationsSolver::AbelianEquationsSolver( const AbelianGroup& a ,
const VectorOf<Word>& v ,
int numOfVar )
: rawA( a ),
A( FPGroup() ),
rawSystem( v ),
system( v.length() ),
b( v.length() ),
x( numOfVar ),
torsion( numOfVar ),
params( numOfVar ),
numberOfVariables( numOfVar ),
sysRank( 0 ),
haveSol( -1 )
{
FPGroup G( a.getFPGroup() );
VectorOf<Chars> q( G.numberOfGenerators() - numberOfVariables );
for( int i = numberOfVariables ; i < G.numberOfGenerators() ; i++ )
q[ i - numberOfVariables ] = (G.namesOfGenerators())[i];
if( G.getRelators().cardinality() )
{
SetOf<Word> s = G.getRelators();
SetIterator<Word> I(s);
SetOf<Word> news;
while( !I.done() )
{
Word w = I.value();
for( int j = 0 ; j < w.length() ; j++ )
{
int p = Generator( w[j] ).hash();
if( p > 0 )
w[j] = Generator( p - numberOfVariables );
else
w[j] = Generator( p + numberOfVariables );
}
news.adjoinElement( w );
I.next();
}
FPGroup G1( q , news );
A = AbelianGroup( G1 );
}
else
A = AbelianGroup( FPGroup(q) );
}
示例2: main
int main( )
{
FPGroup G;
cout << "Enter nilpotentcy class first then group ";
int NilpotentcyClass;
cin >> NilpotentcyClass;
Chars errMsg = cin >> G;
if (errMsg.length()>0)
return 1;
NilpotentGroup ng(G.namesOfGenerators(),
NilpotentcyClass,makeVectorOf(G.getRelators()));
ng.initialize();
VectorOf<Word> vw;
Word w;
for (int i=1;true;i++){
cout << endl << "Enter the "<<i<<" generator of subgroup"<< endl;
cout << "Empty word to finish: ";
w = G.readWord(cin,errMsg);
if (w.length()==0)
break;
if (errMsg.length()>0)
return 1;
vw.append(w);
}
SGOfNilpotentGroup sg(ng,vw);
sg.initBasis();
sg.printBasis(cout);
cout << "The Hirsch number :" << sg.theHirschNumber() << endl;
cout << "Index in parent group :" << sg.index() << endl;
cout << "Is Trivial :" << sg.isTrivial() << endl;
cout << "Is Central :" << sg.isCentral() << endl;
cout << "Is normal :" << sg.isNormal() << endl;
cout << "Is abelian :" << sg.isAbelian() << endl;
cout << "Subgroup class :" << sg.subgroupClass() << endl;
cout << "Generators of normal closure :" << endl;
vw = sg.normalClosureGens();
for (int i=0;i<vw.length();i++){
G.printWord(cout,vw[i]);
cout << endl;
}
PresentationForSNG sgp = sg.makePresentation();
cout << "Presentation of subgroup :" << endl;
sgp.print(cout);
cout << endl << "Enter the word :";
errMsg = "";
w = G.readWord(cin,errMsg);
if (errMsg.length()>0){
cout << errMsg;
return 1;
}
cout << endl << "Does subgroup contain the word :" << sg.contains(w) << endl;
PolyWord result;
if (sg.decompose(ng.decompose(w),result))
cout << "Decomposition in sg basis :" << sg.asDecomposition(result);
else
cout << "Subgroup does not contain this word";
}
示例3: root
// can be invoced only after the cyclic decomposition has been computed
bool AbelianEquationsSolver::root( Word& w , int n ) const
{
AbelianGroup A1 = A.getCanonicalSmithPresentation();
FPGroup G = A1.getFPGroup();
AbelianWord nw = A.oldInAbelianForm( w );
nw = A.oldToNewGens( nw );
Word ans;
VectorOf<Integer> powers = nw.getPowers();
for( int i = 0 ; i < powers.length() ; i++ )
{
Generator g( i + 1 );
int ord = A1.orderOfElt( g ).as_long();
int pow = powers[i].as_long();
if( pow )
if( !ord )
{
if( pow % n )
return no;
else
for( int j = 0 ; j < abs(pow / n) ; j++ )
ans *= ( (pow / n) > 0 ) ? g : inv(g);
}
else
if( pow % n )
{
ord = ( ord > 0 ) ? ord : -ord;
int x;
for( x = -ord ; x < ord ; x++ )
if( ! ( (n * x - pow) % ord ) )
break;
for( int j = 0 ; j < abs( x ) ; j++ )
ans *= ( x > 0 ) ? g : inv(g);
}
else
for( int j = 0 ; j < abs(pow / n) ; j++ )
ans *= ( (pow / n) > 0 ) ? g : inv(g);
}
nw = AbelianWord( G.numberOfGenerators() , ans );
nw = A.newToOldGens( nw );
w = nw.getWord();
return yes;
}
示例4: look
Subgroup& Subgroup::deleteGenerator( const Word& w ) {
VectorOf<Word> theGenerators = look()->theGenerators;
int i = theGenerators.indexOf(w);
if ( i == -1 )
error("attempt to delete nonexistent word in Subgroup::deleteGenerator");
else {
int len = theGenerators.length();
VectorOf<Word> temp(len - 1);
int k = 0;
for( int j = 0; j < len; ++j )
if ( j != i ) temp[k++] = theGenerators[j];
change()->theGenerators = temp;
enhance()->theOrder = -1;
// @stc not yet correct: the order does not necessarily become unknown
return *this;
}
}
示例5: makeFile
void AbelianSGPresentationRep::makeFile( )
{
File file;
VectorOf<AbelianWord> cyclicGens = newToOldGens();
int numofnewgens = cyclicGens.length();
int rank = rankOfFreeAbelianFactor();
char s[10];
Word tmpWord;
file.setColor(titleColor);
file << "New generators of the subgroup expressed in terms of the given generators:" << endl;
file.setColor(mainColor);
for( int i = 0; i < rank; ++i ) {
file << "f" << i+1 << " = ";
tmpWord = fromSGPGensToSGGens(cyclicGens[i].getWord());
theParent.getFPGroup().printWord(file,theParent.oldInAbelianForm(tmpWord).getWord() );
file << endl;
}
for( int i = rank; i < numofnewgens; ++i ) {
file << "t" << i - rank + 1 << " = ";
tmpWord = fromSGPGensToSGGens(cyclicGens[i].getWord());
theParent.getFPGroup().printWord(file,theParent.oldInAbelianForm(tmpWord).getWord() );
file << endl;
}
file << endl;
file.setColor(titleColor);
file << "Given generators expressed in terms of the generators for the canonical decomposition of the subgroup:" << endl;
file.setColor(mainColor);
for( int i = 0; i < theSGGens.length(); ++i ) {
theParent.getFPGroup().printWord( file,theSGGens[i] );
file << " = ";
if (fromSGGensToSGPGens(theSGGens[i],tmpWord))
printWordInNewGens(file,oldToNewGens(oldInAbelianForm(tmpWord)));
file << endl;
}
file << end;
theFileName = file.getFileName();
}
示例6: newBasis
VectorOf<Word> SGOfFreeNilpotentGroupRep::normalClosureBasis() const {
//@ep I have found that the process is slower with the full basis,
// so I form it from the scratch.
MalcevSet newBasis(theGenerators, theParentGroup.collector());
newBasis.makeNormalClosure();
// The basis is found. Now we try to reduce it to make further
// processing easier.
VectorOf<Word> basis = newBasis.getCommutatorWords();
// First, we reduce words in terms of basic commutators.
// We could proceed without this step, but it helps
// to reduce the second one greatly.
FreeGroup F( theParentGroup.theHirschNumber() );
basis = F.nielsenBasis(basis);
// Convert words in terms of basic commutators to group
// generators.
for(int i = 0; i < basis.length(); i++) {
PolyWord pw = basis.val(i);
basis[i] = theParentGroup.commutators().wordForm().toWord(pw);
}
// Now reduce this vector
FreeGroup F1( theParentGroup.numberOfGenerators() );
basis = F1.nielsenBasis(basis);
return basis;
}
示例7: findSolutions
//@njz:default value removed. defined in .h file
//void AbelianEquationsSolver::findSolutions( File& file , bool out = true )
void AbelianEquationsSolver::findSolutions( File& file , bool out)
//
{
haveSol = 0;
if( !A.haveCyclicDecomposition() )
A.computeCyclicDecomposition();
if( !A.havePrimaryDecomposition() )
A.findPrimaryBasis();
if( !rawA.haveCyclicDecomposition() )
rawA.computeCyclicDecomposition();
if( !rawA.havePrimaryDecomposition() )
rawA.findPrimaryBasis();
makeSystem();
if( out )
{
if( system.length() > 1 )
file << "The system of equations: " << endl << endl;
else
file << "The equation: " << endl << endl;
printRawSystem( file );
file << endl << "can be transformed to the one: " << endl << endl;
printSystem( file );
if( system.length() > 1 )
file << endl << "Finding solutions of this system ..." << endl << endl;
else
file << endl << "Finding solutions of this equation ..." << endl << endl;
}
//@njz
// int **matrix = new (int*)[ system.length() ];
int **matrix = new int*[ system.length() ];
//
int i,j,k,i1,j1;
for( i = 0 ; i < system.length() ; i++ )
{
matrix[i] = new int[ numberOfVariables ];
for( j = 0 ; j < numberOfVariables ; j++ )
{
Integer u = (AbelianWord( numberOfVariables , system[i] ))[j];
matrix[i][j] = u.as_long();
}
}
VectorOf< VectorOf<int> > transform;
VectorOf<int> trans(3);
// diagonalization of the matrix
sysRank = 0;
for( i = 0 ; ( i < numberOfVariables && i < system.length() ) ; i++ )
{
bool flag = false;
for( j = i ; j < system.length() ; j++ )
{
for( k = i ; k < numberOfVariables ; k++ )
if( matrix[j][k] )
{
flag = true;
break;
}
if( flag ) break;
}
if( k == numberOfVariables && j == system.length() )
{
if( sysRank )
break;
int q;
for( q = 0 ; q < b.length() ; q++ )
if( !A.isTrivial( Word( b[q] ) ) )
{
haveSol = -1;
if( out )
if( system.length() > 1 )
file << "while computing the canonical form of the system it was found that this system has no solutions." << endl;
else
file << "while computing the canonical form of the equation it was found that this equation has no solutions." << endl;
return;
}
//.........这里部分代码省略.........
示例8: main
int main ( )
{
Chars errMsg;
GHNConfig c;
//cout << c << endl;
ifstream in("../wp.in");
in >> c;
cout << c << endl;
int numOfVars;
cout << "Enter the number of variables: ";
cin >> numOfVars;
cout << endl;
FreeGroup G;
cout << "Enter a free group: ";
errMsg = cin >> G;
if( errMsg.length() > 0 ) {
cout << errMsg;
exit(0);
}
cout << endl;
VectorOf<Chars> v = G.namesOfGenerators();
int numOfConst = v.length();
int rLen = v.length() + numOfVars;
VectorOf<Chars> r(rLen);
int j;
for( j = 0; j < v.length(); ++j )
if( v[j][0] != 'x' && v[j][0] != 'X' )
r[j] = v[j];
else
error("x is reserved for variables\n");
char s[3] = {0,0,0};
s[0] = 'x';
for( int i = j; i < rLen; ++i ) {
s[1] = i-j+1+48;
r[i] = s;
}
FreeGroup F(r);
cout << "Enter an equation (a word) with variables x1 ... x"
<< numOfVars << ": ";
Word w;
w = F.readWord(cin,errMsg);
if( errMsg.length() > 0 ) {
cout << errMsg;
exit(0);
}
cout << endl;
VectorOf<Word> im(rLen);
for( int i = 0; i < rLen; ++i )
im[i] = Word(Generator(i+1));
Map M(F,F,im);
int popSize = c.populationSize();
GAWord pop[numOfVars][popSize],newPop[numOfVars][popSize];
for( int k = 0; k < numOfVars; ++k )
for( int i = 0; i < popSize; ++i ) {
pop[k][i] = GAWord(numOfConst,Word());
}
int fit[popSize];
// the main loop
int numOfGens = c.numOfGenerations();
//bool bHaveFitnessScaling = c.haveFitnessScaling();
float crossRate = c.chanceOfCrossover();
float mutRate = c.chanceOfMutation();
UniformRandom devgen;
int max, min, minInd, g;
// create the original random populations
for( int k = 0; k < numOfVars; ++k )
for( int i = 0; i < popSize; ++i ) {
pop[k][i] = pop[k][i].randomWord();
}
for( g = 0; g < numOfGens || numOfGens == -1; ++g ) {
min = MAXINT; max = 0; minInd = -1;
// compute fitness values
for( int i = 0; i < popSize; ++i ) {
for( int k = 0; k < numOfVars; ++k )
M.setGeneratingImages(numOfConst+k,(pop[k][i]).getWord());
fit[i] = M.imageOf(w).freelyReduce().length();
if( fit[i] < min ) {
min = fit[i];
minInd = i;
//.........这里部分代码省略.........
示例9: isBasis
// put the words to the set
MalcevSet::MalcevSet(const VectorOf<Word>& v, const NGCollector& nc)
: isBasis(false), isNormal(dontknow), theCollector(nc)
{
for(int i = 0; i < v.length(); i++)
addWord( v.val(i) );
}