本文整理汇总了C++中VertexVector::end方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexVector::end方法的具体用法?C++ VertexVector::end怎么用?C++ VertexVector::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexVector
的用法示例。
在下文中一共展示了VertexVector::end方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calcDistance
double calcDistance(const Graph& g, const EdgeWeightMap& edge_weight_map, const VertexVector& vertices)
{
VertexVector::const_iterator
it(vertices.begin()),
it_end(vertices.end());
--it_end;
EdgeDescriptor edge;
double length = 0;
for (; it != it_end; ++it)
{
length += distance(g, edge_weight_map, *it, *boost::next(it));
}
length += distance(g, edge_weight_map, vertices.back(), vertices.front());
return length;
}
示例2: DoTopologicalSort
void SFUtils::DoTopologicalSort( SLSF::Subsystem subsystem ) {
int vertexIndex = 0;
VertexIndexBlockMap vertexIndexBlockMap;
BlockVertexIndexMap blockVertexIndexMap;
BlockVector blockVector = subsystem.Block_kind_children();
for( BlockVector::iterator blvItr = blockVector.begin(); blvItr != blockVector.end(); ++blvItr, ++vertexIndex ) {
SLSF::Block block = *blvItr;
vertexIndexBlockMap[ vertexIndex ] = block;
blockVertexIndexMap[ block ] = vertexIndex;
std::string blockType = block.BlockType();
if ( blockType == "UnitDelay" ) { // check on other delay blocks as well ...
++vertexIndex; // UnitDelay is vertexed twice - one for outputs (timestep n-1), and one for inputs: vertexIndex is as destination, vertexIndex + 1 is as source
}
}
Graph graph( vertexIndex );
LineSet lineSet = subsystem.Line_kind_children();
for( LineSet::iterator lnsItr = lineSet.begin(); lnsItr != lineSet.end() ; ++lnsItr ) {
SLSF::Line line = *lnsItr;
SLSF::Port sourcePort = line.srcLine_end();
SLSF::Port destinationPort = line.dstLine_end();
SLSF::Block sourceBlock = sourcePort.Block_parent();
SLSF::Block destinationBlock = destinationPort.Block_parent();
if ( sourceBlock == subsystem || destinationBlock == subsystem ) continue;
int sourceBlockVertexIndex = blockVertexIndexMap[ sourceBlock ];
if ( static_cast< std::string >( sourceBlock.BlockType() ) == "UnitDelay" ) {
++sourceBlockVertexIndex;
}
int destinationBlockVertexIndex = blockVertexIndexMap[ destinationBlock ];
boost::add_edge( sourceBlockVertexIndex, destinationBlockVertexIndex, graph );
}
LoopDetector loopDetector( graph );
if ( loopDetector.check() ) {
// TODO: add support for loops involving integrator and other stateful blocks
// Determine what Blocks caused the loop
typedef std::map< Vertex, int > VertexStrongComponentIndexMap;
VertexStrongComponentIndexMap vertexStrongComponentIndexMap;
boost::associative_property_map< VertexStrongComponentIndexMap > apmVertexStrongComponentIndexMap( vertexStrongComponentIndexMap );
strong_components( graph, apmVertexStrongComponentIndexMap );
typedef std::vector< Vertex > VertexVector;
typedef std::map< int, VertexVector > StrongComponentIndexVertexGroupMap;
StrongComponentIndexVertexGroupMap strongComponentIndexVertexGroupMap;
for( VertexStrongComponentIndexMap::iterator vsmItr = vertexStrongComponentIndexMap.begin(); vsmItr != vertexStrongComponentIndexMap.end(); ++vsmItr ) {
strongComponentIndexVertexGroupMap[ vsmItr->second ].push_back( vsmItr->first );
}
std::string error( "Dataflow Graph '" + static_cast< std::string >( subsystem.Name() ) + "' has unhandled loops: " );
for( StrongComponentIndexVertexGroupMap::iterator svmItr = strongComponentIndexVertexGroupMap.begin(); svmItr != strongComponentIndexVertexGroupMap.end(); ++svmItr ) {
VertexVector vertexVector = svmItr->second;
if ( vertexVector.size() <= 1 ) continue;
error.append( "\n" );
for( VertexVector::iterator vtvItr = vertexVector.begin(); vtvItr != vertexVector.end(); ++vtvItr ) {
error.append( blockVector[ *vtvItr ].getPath("/") );
error.append( ", " );
}
error.erase( error.size() - 2 );
}
throw udm_exception(error);
}
typedef std::set< Vertex > VertexSet;
typedef std::map< int, VertexSet > PriorityVertexSetMap;
PriorityVertexSetMap priorityVertexSetMap;
for( BlockVector::iterator blvItr = blockVector.begin() ; blvItr != blockVector.end() ; ++blvItr ) {
SLSF::Block block = *blvItr;
int priority = block.Priority();
if ( priority == 0 ) continue;
Vertex vertex = blockVertexIndexMap[ block ];
priorityVertexSetMap[ priority ].insert( vertex );
}
if ( priorityVertexSetMap.size() > 1 ) {
PriorityVertexSetMap::iterator lstPvmItr = priorityVertexSetMap.end();
--lstPvmItr;
for( PriorityVertexSetMap::iterator pvmItr = priorityVertexSetMap.begin() ; pvmItr != lstPvmItr ; ) {
PriorityVertexSetMap::iterator nxtPvmItr = pvmItr;
++nxtPvmItr;
VertexSet &higherPriorityVertexSet = pvmItr->second;
VertexSet &lowerPriorityVertexSet = nxtPvmItr->second;
for( VertexSet::iterator hvsItr = higherPriorityVertexSet.begin() ; hvsItr != higherPriorityVertexSet.end() ; ++hvsItr ) {
for( VertexSet::iterator lvsItr = lowerPriorityVertexSet.begin() ; lvsItr != lowerPriorityVertexSet.end() ; ++lvsItr ) {
boost::add_edge( *hvsItr, *lvsItr, graph );
LoopDetector loopDetector( graph );
//.........这里部分代码省略.........
示例3: crossover
VertexVector GeneticAlgorithm::crossover(const VertexVector& Parent1,const VertexVector& Parent2,const size_t dot)
{
QString chr;
for (size_t j = 0; j < Parent1.size(); ++j)
{
chr += QString::number(Parent1[j]) + " => ";
}
//qDebug() << "PARENT1: " << chr;
chr.clear();
for (size_t j = 0; j < Parent2.size(); ++j)
{
chr += QString::number(Parent2[j]) + " => ";
}
//qDebug() << "PARENT2: " << chr;
VertexVector::const_iterator it = Parent1.begin();
//it += dot;
VertexVector Child(it, it + dot);
size_t i = dot;
//qDebug() << "dot = " << i << ", parent size = " << Parent1.size() ;
VertexVector::iterator result;
for(; (i<Parent1.size()) && (Child.size() <= Parent1.size() - 1); ++i)
{
result = std::find( Child.begin(), Child.end(), Parent2[i] );
if( result == Child.end())
{
chr.clear();
for (size_t j = 0; j < Child.size(); ++j)
{
chr += QString::number(Child[j]) + " => ";
}
//qDebug() << "Child before adding parent2: " << chr;
//qDebug() << "parent2[" << i << "] = " << Parent2[i];
Child.push_back(Parent2[i]);
QString chr;
for (size_t j = 0; j < Child.size(); ++j)
{
chr += QString::number(Child[j]) + " => ";
}
//qDebug() << "Parent2 added: " << chr;
}
else
{
result = std::find( Child.begin(), Child.end(), Parent1[i] );
if( result == Child.end())
{
Child.push_back(Parent1[i] );
QString chr;
for (size_t j = 0; j < Child.size(); ++j)
{
chr += QString::number(Child[j]) + " => ";
}
//qDebug() << "Parent1 added: " << chr;
}
else
{
VertexVector sortedChild = Child;
VertexVector sortedParent = Parent1;
std::sort(sortedChild.begin(), sortedChild.end());
std::sort(sortedParent.begin(), sortedParent.end());
size_t iter=0;
while((sortedChild[iter]==sortedParent[iter]) && (iter < sortedParent.size()))
{
iter++;
}
//qDebug() << "iter = " << iter;
if (iter<sortedParent.size()) Child.push_back(sortedParent[iter]);
QString chr;
for (size_t j = 0; j < Child.size(); ++j)
{
chr += QString::number(Child[j]) + " => ";
}
//qDebug() << "something added: " << chr;
}
}
}
//.........这里部分代码省略.........