本文整理汇总了C++中shawn::SimulationController::world_w方法的典型用法代码示例。如果您正苦于以下问题:C++ SimulationController::world_w方法的具体用法?C++ SimulationController::world_w怎么用?C++ SimulationController::world_w使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shawn::SimulationController
的用法示例。
在下文中一共展示了SimulationController::world_w方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tok
// ----------------------------------------------------------------------
void
TreeCreationTask::
create_tree_from_file( shawn::SimulationController& sc,
routing::tree::TreeRouting& routing_instance,
const std::string& filename )
throw()
{
double now = sc.world().current_time();
ifstream file_in;
file_in.open(filename.c_str(),ifstream::in);
if(!file_in)
{
ERROR(this->logger(),"Unable to open file " + filename + "!");
abort();
}
string buf;
while( getline(file_in,buf) )
{
StrTok tok(buf,"\t ");
double line[6];
int i = 0;
for(StrTok::iterator it = tok.begin(); it != tok.end(); ++it)
{
line[i++] = conv_string_to_double(*it);
}
shawn::Node* node = sc.world_w().find_node_by_id_w( (int)line[0] );
shawn::Node* sink = sc.world_w().find_node_by_id_w( (int)line[1] );
shawn::Node* neighbor = sc.world_w().find_node_by_id_w( (int)line[2] );
int hops_to_sink = (int)line[3];
double node_x = line[4];
double node_y = line[5];
double node_real_pos_x = conv_string_to_double(conv_double_to_string(node->real_position().x()));
double node_real_pos_y = conv_string_to_double(conv_double_to_string(node->real_position().y()));
if( !( node && sink && neighbor ) )
{
ERROR(this->logger(),"Error while reading file!");
abort();
}
if( node_x != node_real_pos_x ||
node_y != node_real_pos_y )
{
ERROR(this->logger(),"Position mismatch! Read x: "
+ conv_double_to_string(node_x)
+ ", y: " + conv_double_to_string(node_y)
+ " Real position x: " + conv_double_to_string(node_real_pos_x)
+ ", y: " + conv_double_to_string(node_real_pos_y));
abort();
}
routing_instance.tree_routing_table_update(*node,*sink,TreeRoutingTableInfo(*neighbor,hops_to_sink,now));
}
INFO(this->logger(),"Reading from file: " + filename + " succeeded!");
}
示例2: file_op
// ----------------------------------------------------------------------
void
TreeCreationTask::
create_tree_in_file( shawn::SimulationController& sc,
const std::string& filename,
const shawn::Node& sink,
int max_hops )
throw()
{
// Avoid appending
bool append = sc.environment().optional_bool_param("append",false);
if(!append)
{
remove( filename.c_str() );
}
// Init stuff
// double now = sink.current_time();
NodesToExamineMap nodes_to_examine;
TreeCreationHopsToSinkResult& result = *( new TreeCreationHopsToSinkResult( sc.world_w() ) );
ofstream file_op(filename.c_str(),ios::app);
// Treat the sink
file_op << sink.id() << "\t"
<< sink.id() << "\t"
<< sink.id() << "\t"
<< 0 << "\t"
<< sink.real_position().x() << "\t"
<< sink.real_position().y() << endl;
result[sink].hops_ = 0;
nodes_to_examine.insert( NodesToExamineMapValueType(0,&sink) );
// Main loop
while( ! nodes_to_examine.empty() )
{
NodesToExamineMapIterator min_it = nodes_to_examine.begin();
const shawn::Node* min_node = min_it->second;
nodes_to_examine.erase( min_it );
for( World::const_adjacency_iterator adj_it = min_node->begin_adjacent_nodes();
adj_it != min_node->end_adjacent_nodes(); ++adj_it )
{
int hops = result[*min_node].hops_ + 1;
if( hops < result[*adj_it].hops_ )
{
assert( result[*adj_it].hops_ == INT_MAX );
result[*adj_it].hops_ = hops;
file_op << adj_it->id() << "\t"
<< sink.id() << "\t"
<< min_node->id() << "\t"
<< hops << "\t"
<< adj_it->real_position().x() << "\t"
<< adj_it->real_position().y() << endl;
if( hops < max_hops )
{
nodes_to_examine.insert( NodesToExamineMapValueType( hops, &(*adj_it) ) );
}
}
}
}
file_op.clear();
file_op.close();
delete &result;
}
示例3:
// ----------------------------------------------------------------------
void
TreeCreationTask::
run( shawn::SimulationController& sc )
throw( std::runtime_error )
{
require_world( sc );
bool tree_routing_set = false;
bool filename_set = false;
string tree_routing_instance = sc.environment().optional_string_param("routing_instance","",&tree_routing_set);
string filename = sc.environment().optional_string_param("tree_creation_filename","",&filename_set);
TreeRouting* routing_instance = NULL;
if( tree_routing_set )
{
RoutingBaseHandle rbh = routing::routing_keeper_w(sc).find_w(tree_routing_instance);
routing_instance = dynamic_cast<TreeRouting*>( rbh.get() );
if( ! routing_instance )
{
ERROR(this->logger(),"The given routing is no TreeRouting!");
abort();
}
routing_instance->init( sc.world_w() );
}
if( tree_routing_set && filename_set )
{
create_tree_from_file(sc,*routing_instance,filename);
return;
}
int sink_id = sc.environment().required_int_param("sink_id");
const Node* sink = sc.world().find_node_by_id( sink_id );
if( tree_routing_set && ( ! filename_set ) )
{
create_tree_in_tree_routing( *routing_instance, *sink );
return;
}
if( ( ! tree_routing_set ) && filename_set )
{
int max_hops = sc.environment().optional_int_param("max_hops",INT_MAX);
create_tree_in_file( sc, filename, *sink, max_hops );
return;
}
}
示例4: GroupElement
// ----------------------------------------------------------------------
void
VisualizationTaskCreate::
run( shawn::SimulationController& sc )
throw( std::runtime_error )
{
Visualization* vis;
require_world(sc);
std::string name = sc.environment().optional_string_param( "vis", "visualization" );
visualization_keeper_w(sc).add(vis=new Visualization(name));
std::string type = sc.environment().optional_string_param( "node_type", "default" );
DrawableNodeFactoryHandle dnfh = sc.keeper_by_name_w<DrawableNodeKeeper>("DrawableNodeKeeper")
->find_w(sc.environment().optional_string_param("drawable_nodes", type));
sc.world_w().add_node_change_listener(*vis);
vis->set_world( sc.world() );
vis->init();
DEBUG( logger(),
"created visualization '" << name << "'" );
GroupElement* ge =
new GroupElement( "all.nodes" );
ge->init();
vis->add_element(ge);
for( shawn::World::const_node_iterator
it = sc.world().begin_nodes();
it != sc.world().end_nodes();
++it )
{
DrawableNode *dn = dnfh->create(*it);
dn->init();
vis->add_element(dn);
ge->add_element(*dn);
}
}