本文整理汇总了C++中Polynomial::AddTerm方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::AddTerm方法的具体用法?C++ Polynomial::AddTerm怎么用?C++ Polynomial::AddTerm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polynomial
的用法示例。
在下文中一共展示了Polynomial::AddTerm方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_Polynomial
//Test Polynomial class
void test_Polynomial()
{
GAParams::SetNumVars( 8 );
Monomial a("1001 0110" );
Monomial b("1111 0000" );
Monomial c("0000 0000" );
// p(x) = 0;
Polynomial p;
p.AddTerm(c);
std::cout << p.ToString( true ) << std::endl;
std::cout << " has max degree = " << (int) p.MaxDegree() << std::endl;
// p(x) = a = x1*x4*x6*x7
p.AddTerm(a);
// p(x) = a + b = x1*x4*x6*x7 + x1*x2*x3*x4
p.AddTerm(b);
// p(x) = a + b + c = x1*x4*x6*x7 + x1*x2*x3*x4 + 1
std::cout << p.ToString( true ) << std::endl;
std::cout << " has max degree = " << (int) p.MaxDegree() << std::endl;
NTuple d("1101 0110" );
std::cout << p.Evaluate(d) << std::endl;
}
示例2: test_poly_mutate
void test_poly_mutate()
{
GAParams::SetNumVars( 8 );
Monomial a("1000 0000" );
Monomial c("0000 0000" );
c.mCoeff = true;
// p(x) = 1;
Polynomial p;
p.AddTerm(c);
std::cout << p.ToString( true ) << std::endl;
p.AddTerm(a);
std::cout << p.ToString( true ) << std::endl;
// Attempt to add a duplicate term
// a.Reset(1);
// p.AddTerm(a);
PolyIter p_iter = p.mPoly.find( c );
if( p_iter != p.mPoly.end( ) )
{
p.mPoly.erase( p_iter );
}
std::cout << p.ToString( true ) << std::endl;
}
示例3: if
Polynomial Polynomial::operator-(Polynomial& p){
Polynomial s;
list<Term>::iterator it1=m_list.begin(),it2=p.m_list.begin();
while(it1!=m_list.end() && it2!=p.m_list.end()){
if(it1->exp>it2->exp){
s.AddTerm(it1->exp,it1->coef);
it1++;
}
else if(it1->exp<it2->exp){
s.AddTerm(it2->exp,-it2->coef);
it2++;
}
else{
if(it1->coef-it2->coef==0){
it1++;
it2++;
continue;
}
s.AddTerm(it1->exp,it1->coef-it2->coef);
it1++;
it2++;
}
}
while(it1!=m_list.end()){
s.AddTerm(it1->exp,it1->coef);
it1++;
}
while(it2!=p.m_list.end()){
s.AddTerm(it2->exp,-it2->coef);
it2++;
}
return s;
}
示例4:
Polynomial Polynomial::operator*(Polynomial& p){
Polynomial s;
list<Term>::iterator it=m_list.begin();
list<Term>::iterator it2;
while(it!=m_list.end()){
it2=p.m_list.begin();
while(it2!=p.m_list.end()){
s.AddTerm(it->exp+it2->exp,it->coef*it2->coef);
it2++;
}
it++;
}
return s;
}
示例5: test_DynSysModel
// Test the DynSysModel class
void test_DynSysModel()
{
// Make a 4 variable model
GAParams::SetNumVars( 4 );
DynSysModel m;
// Create monomial x1, x2, x3, x4, x1*x2, x3*x4, x1*x2*x3*x4
Monomial c0( "0000" ); c0.mCoeff = false;
Monomial c1( "0000" ); c1.mCoeff = true;
Monomial x4( "0001" );
Monomial x3( "0010" );
Monomial x2( "0100" );
Monomial x1( "1000" );
Monomial x34( "0011" );
Monomial x12( "1100" );
Monomial x14( "1001" );
Monomial x1234("1111" );
Polynomial f;
f.AddTerm( c0 );
std::cout << "f = " << f.ToString( true ) << std::endl;
Polynomial g;
g.AddTerm( c1 );
std::cout << "g = " << g.ToString( true ) << std::endl;
// f1(x) = x1 + x2 + x4;
Polynomial f1;
f1.AddTerm( x1 ); f1.AddTerm( x2 ); f1.AddTerm( x4 );
std::cout << "f1 = " << f1.ToString( true ) << std::endl;
Polynomial::mMaxSupport = 2;
m.SetFunction( 1, f );
m.SetFunction( 2, g );
m.SetFunction( 3, f );
m.SetFunction( 4, f1 );
ComplexityMatrix cmplx_mat;
ComplexityMatrixRow row;
cmplx_mat.assign( 4, row );
m.SetPolyComplexities( );
double s;
s = m[1].mComplexityScore;
s = m[2].mComplexityScore;
s = m[3].mComplexityScore;
s = m[4].mComplexityScore;
/*
// f2(x) = x1*x2*x3*x4;
Polynomial f2;
f2.AddTerm( x1234 );
std::cout << "f2 = " << f2.ToString( true ) << std::endl;
// f3(x) = x1*x2 + x3*x4;
Polynomial f3;
f3.AddTerm( x12 );
f3.AddTerm( x34 );
std::cout << "f3 = " << f3.ToString( true ) << std::endl;
// f3'(x) = x1*x4;
Polynomial f3p;
f3p.AddTerm( x14 );
std::cout << "f3p = " << f3p.ToString( true ) << std::endl;
// f4(x) = x3 + x4;
Polynomial f4;
f4.AddTerm( x3 ); f4.AddTerm( x4 );
std::cout << "f4 = " << f4.ToString( true ) << std::endl;
// Assign the functions to the model
m.SetFunction( 1, f1 ); m.SetFunction( 2, f2 );
m.SetFunction( 3, f3p ); m.SetFunction( 4, f4 );
*/
TimeSeries t2;
// t2.push_back( NTuple("1101" ) );
// t2.push_back( NTuple("1011" ) );
t2.push_back( NTuple("1100" ) );
t2.push_back( NTuple("0010" ) );
t2.push_back( NTuple("0001" ) );
t2.push_back( NTuple("1001" ) );
t2.push_back( NTuple("0001" ) );
// Better to pass a reference to the time series for the result
// TimeSeries t3 = m.Iterate( NTuple( "1111" ), 6 );
// Test iteration for only the k'th variable
size_t k = 3;
TimeSeries t4;
size_t h = m.Iterate( t2, k, t4 );
TimeSeriesIter iter = t4.begin();
while( iter != t4.end() )
{
std::cout << *iter++ << std::endl;
//.........这里部分代码省略.........