Jul 27, 2012 at 4:23pm UTC
hi, I get problem with c++ STL, it is always Segmentation fault: 11. is that because i use vector<int> Sp, and Sp.clear(), then Sp actions too many times(1e3)? thanks for reply!
Jul 27, 2012 at 4:30pm UTC
Without seeing your code it is impossible to say why you get the segmentation fault.
Jul 27, 2012 at 6:09pm UTC
for (int run=0; run<runtime; run++ )
{
SpeciesAge.clear();
/////initial condition
for ( int i=0; i<Species; i++ )
{
SpeciesNum.push_back( Population/Species);
SpeciesAge.push_back(1);
}
for ( int it=1; it<maxtime; it++ )
{
cout<<endl<<"time "<<it<<endl;
for (int i=0;i<SpeciesNum.size(); i++ )
{
SpeciesNumtemp.push_back( SpeciesNum[i] );
}
//////////1first check all of the population node
for ( int i=0; i<SpeciesNum.size(); i++ )
{
if ( SpeciesNum[i]!=0)
{
if ( tt800_single( )<p )
{
SpeciesNumtemp.push_back(1);
}
else
{
SpeciesNumtemp[i]= SpeciesNumtemp[i]+1;
}
}
}//end for check all the N node
/////////2big killing
int total=accumulate(SpeciesNumtemp.begin(), SpeciesNumtemp.end(),0 );
int killnum=total-Population;
// cout<<"killnum "<<killnum<<endl;
if ( killnum>0 )
{
allsum.clear();
for ( int i=0; i<total; i++ )
{
allsum.push_back(i+1);
}
cout<<" ???0"<<endl;
randomSet.clear();
random_shuffle( allsum.begin(), allsum.end() );
for ( int i=0; i<allsum.size(); i++ )
{
randomSet.push_back( allsum[i]);
}
killset.clear();
cout<<"randomSet.size() "<<randomSet.size() <<endl;
for ( int i=0; i<killnum; i++ )
{
cout<<"randomSet "<<randomSet[i]<<endl;
killset.push_back( randomSet[i] );// .push_back(randomSet[i]);
cout<<i<<endl;
cout<<killset[i]<<endl;
}
cout<<"killset size "<<killset.size()<<endl;
killpool.clear();
for ( int i=0; i<SpeciesNumtemp.size(); i++ ) // vtr=SpeciesNumtemp.begin(); vtr!=SpeciesNumtemp.end(); vtr++ )
{
int co=0;
for ( int j=0;j<=i; j++)
{
co=co+SpeciesNumtemp[j];
}
killpool.push_back( co );
}
for ( int i=0; i<killset.size(); i++ )
{
vtr=find_if(killpool.begin(), killpool.end(), bind2nd(greater_equal<int>(), killset[i] ));
SpeciesNumtemp[ vtr-killpool.begin() ]=SpeciesNumtemp[ vtr-killpool.begin() ]-1;
if ( SpeciesNumtemp[ vtr-killpool.begin()]==0 && it > startime )
{
SpeciesLife.push_back( SpeciesAge[ vtr-killpool.begin() ]);
SpeciesAgefile<<SpeciesAge[ vtr-killpool.begin() ]<<endl;
SpeciesAge[ vtr-killpool.begin() ]=0;
}
}
}// if killnum >0
SpeciesNum.clear();
for ( int i=0; i<SpeciesNumtemp.size(); i++ )
{
SpeciesNum.push_back( SpeciesNumtemp[i] );
}
SpeciesNumtemp.clear();
int ccnum=0;
for ( int i=0; i<SpeciesNum.size(); i++ )
{
if (SpeciesNum[i]!=0)
{
ccnum=ccnum+1;
}
if (it > startime && it%step==0 )
{
SpeciesAbufile<<SpeciesNum[i]<<endl;
}
if (it > startime )
{
SpeciesEvrfile<<i+1<<setw(10)<<SpeciesNum[i]<<endl;
}
if ( SpeciesAge[i]!=0 )
{
SpeciesAge[i]=SpeciesAge[i]+1;
}
}
SpeciesEvofile<<ccnum<<endl;
}//for maxtime run
}// for runtime