本文整理汇总了C++中shawn::SimulationController::world方法的典型用法代码示例。如果您正苦于以下问题:C++ SimulationController::world方法的具体用法?C++ SimulationController::world怎么用?C++ SimulationController::world使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shawn::SimulationController
的用法示例。
在下文中一共展示了SimulationController::world方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
// ----------------------------------------------------------------------
void
ExampleTask::
run( shawn::SimulationController& sc )
throw( std::runtime_error )
{
require_world( sc );
double count = 0;
for( shawn::World::const_node_iterator
it = sc.world().begin_nodes();
it != sc.world().end_nodes();
++it )
{
count++;
}
INFO( logger(), "visited " << count << " nodes" );
}
示例2: 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!");
}
示例3: 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);
}
}
示例4:
// ----------------------------------------------------------------------
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;
}
}