// ----------------------------------------------------------------------
   // ----------------------------------------------------------------------
   void WisemlLinkDefaultsTask::run(SimulationController &sc) throw()
   {
      WisemlDataKeeper *keeper = 
         sc.keeper_by_name_w<WisemlDataKeeper>("wiseml_data_keeper");
      WisemlSetupCollector &setup = keeper->setup();

      LinkInfo linkdef;
      linkdef.is_encrypted = sc.environment().optional_bool_param(
         "is_encrypted", false);
      linkdef.is_virtual = sc.environment().optional_bool_param(
         "is_virtual", false);

      bool set_type=false, set_unit=false, 
         set_value=false;

      linkdef.rssi_datatype = sc.environment().optional_string_param(
         "rssi_datatype", "", &set_type);
      linkdef.rssi_unit = sc.environment().optional_string_param(
         "rssi_unit", "", &set_unit);
      linkdef.rssi = sc.environment().optional_string_param(
         "rssi_default", "0", &set_value);
      if(!(set_type && set_unit && set_value))
      {
         linkdef.rssi_datatype = "";
         linkdef.rssi_unit = "";
         linkdef.rssi = "";
      }

      setup.set_link_defaults(linkdef);
   }
 // ----------------------------------------------------------------------
 void
     MovementResetTask::
     run( SimulationController& sc )
     throw( std::runtime_error )
 {
    if (sc.environment_w().optional_string_param("reset", "")=="true")
       sc.world_w().reset();
 }
	void 
		init_distance_estimates( SimulationController& sc )
		throw()
	{
		sc.distance_estimate_keeper_w().add( new PerfectDistanceEstimate );
		sc.simulation_task_keeper_w().add( new SimulationTaskRandomizedDistanceEstimate );
		sc.simulation_task_keeper_w().add( new SimulationTaskAbsoluteErrorDistanceEstimate);
		sc.simulation_task_keeper_w().add( new SimulationTaskLQIDistanceEstimate);

	}
示例#4
0
void
init_misc( SimulationController& sc )
throw()
{
    sc.simulation_task_keeper_w().add( new SimulationTaskDegreeSequence );

    sc.simulation_task_keeper_w().add( new SimulationTaskLocalizationAnchorPlacement );
    sc.simulation_task_keeper_w().add( new SimulationTaskDumpLocation );

    init_misc_random(sc);
    init_misc_os(sc);
}
示例#5
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::Results::
   collect_information( SimulationController& sc, const SimulationTaskLocalizationEvaluation& stle )
      throw()
   {
      LocalizationObserver observer;

      if ( sc.world().communication_model().exists_communication_upper_bound() )
         comm_range = sc.world().communication_model().communication_upper_bound();

      set_seed( sc, stle );

      for( World::node_iterator
               it = sc.world_w().begin_nodes_w();
               it != sc.world_w().end_nodes_w();
               ++it )
      {
         Node& v = *it;
         LocalizationProcessor* lp =
            v.get_processor_of_type_w<LocalizationProcessor>();

         if ( lp == NULL || lp->is_anchor() ) continue;
         observer.set_owner( *lp );

         if ( v.has_est_position() )
         {
            ++has_pos_cnt;
            double distance = euclidean_distance( v.real_position(), v.est_position() );

            stat_abs_position += distance;
         }
         else
         {
            ++no_pos_cnt;
         }

         stat_known_anchors += observer.anchor_cnt();
         stat_valid_known_anchors += observer.valid_anchor_cnt();

         observer.fill_stat_rel_anchor_distance(
            stat_real_err_anchor_dist,
            stat_comm_err_anchor_dist );

         observer.fill_stat_rel_neighbor_distance(
            stat_real_neighbor_dist,
            stat_comm_neighbor_dist );

         stat_neighbor_cnt += (double)observer.neighbor_cnt();
      }// for all nodes
   }
示例#6
0
   // ----------------------------------------------------------------------
   // ----------------------------------------------------------------------
   void WisemlWriterTask::run(SimulationController &sc) throw()
   {
      std::string filename = sc.environment().optional_string_param("filename", "simulation.wiseml");
      std::ofstream file;
      file.open(filename.c_str());

      std::string wml;
      WisemlDataKeeper *keeper = 
         sc.keeper_by_name_w<WisemlDataKeeper>("wiseml_data_keeper");
      WisemlSetupCollector &setup = keeper->setup();
      setup.set_timeinfo_duration(sc.world().current_time());
      wml = keeper->generate_xml();
      file << wml;
      file.close();
   }
 // ----------------------------------------------------------------------
 void
 WiselibShawnStandaloneProcessorFactory::
 register_factory( SimulationController& sc )
 throw()
 {
    sc.processor_keeper_w().add( new WiselibShawnStandaloneProcessorFactory );
 }
 void
 HelloworldRandomProcessorFactory::
 register_factory( SimulationController& sc )
    throw()
 {
    sc.processor_keeper_w().add( new HelloworldRandomProcessorFactory(sc) );
 }
 // ----------------------------------------------------------------------
 void
 SimpleAppProcessorFactory::
 register_factory( SimulationController& sc )
    throw()
 {
    sc.processor_keeper_w().add( new SimpleAppProcessorFactory );
 }
		//-----------------------------------------------------------------------
		void
			FloodRoutingProcessorFactory::
			register_factory( SimulationController& sc )
			throw()
		{
			sc.processor_keeper_w().add( new FloodRoutingProcessorFactory );
		}
示例#11
0
    // ----------------------------------------------------------------------
    void
        PermalinkCommunicationModelFactory::
        init_from_tags(const SimulationController& sc, PermalinkCommunicationModel& plcm) 
        const throw()
    {
        /* First look for a group tag named 'permalink'
        Check each tag for the type StringBoolMapTag. Each map will contain the
        neighboring nodes of one node. The name of the map tag corresponds to the 
        node for which neighbor entries are present. Therefore we iterate over all 
        tags instead of a lookup by name.
        */
        ConstTagHandle pl_tag_group = sc.environment().find_tag("permalink");
        const GroupTag* gt = pl_tag_group.is_not_null() ? dynamic_cast<const GroupTag*> (pl_tag_group.get()) : NULL;

        if( gt != NULL )
        {
            for(Tag::tag_iterator it = gt->begin_tags(), end = gt->end_tags(); it!=end; ++it)
            {
				StringBoolMapTag* mt = dynamic_cast<StringBoolMapTag*> (it->second.get());
                if( mt != NULL )
                    for( StringBoolMapTag::Map::const_iterator mit = mt->value().begin(),
                        mend = mt->value().end(); mit!=mend; ++mit )
                    {
                        plcm.add_edge( it->first, mit->first );

						cout << "inserting link " << it->first << " to " << mit->first << endl;

						if( mit->second ) {
                            plcm.add_edge(mit->first, it->first );
							cout << "2nd inserting link " << mit->first << " to " << it->first << endl;
						}
                    }
            }
        }
    }
 // ----------------------------------------------------------------------
 void
 TestqProProcessorFactory::
 register_factory( SimulationController& sc )
    throw()
 {
    sc.processor_keeper_w().add( new TestqProProcessorFactory );
 }
// ----------------------------------------------------------------------
void
IndividualLinkMetricsProcessorFactory::
register_factory( SimulationController& sc )
throw()
{
    sc.processor_keeper_w().add( new IndividualLinkMetricsProcessorFactory );
}
 void
 VisEnergyProcessorFactory::
 register_factory( SimulationController& sc )
    throw()
 {
    sc.processor_keeper_w().add( new VisEnergyProcessorFactory(sc) );
 }
 // ----------------------------------------------------------------------
 void
 WisemlExampleProcessorFactory::
 register_factory( SimulationController& sc )
    throw()
 {
    sc.processor_keeper_w().add( new WisemlExampleProcessorFactory );
 }
示例#16
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::
   write_out( const SimulationController& sc, const HeaderInfo& header, const Results& results )
      const throw( std::runtime_error )
   {
      std::string fname = sc.environment().optional_string_param( "loc_ls_out", "" );
      if ( fname == "" ) return;

      std::string ftype = sc.environment().required_string_param( "loc_ls_type" );
      if ( ftype != "create" && ftype != "append" )
         throw std::runtime_error("Wrong argument for 'loc_ls_type'. Should be 'create' or 'append'");

      if ( ftype == "create" )
         write_header( fname, header );

      write_results( fname, results );
   }
示例#17
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::
   print_ps( const SimulationController& sc, const HeaderInfo& header )
      const throw()
   {
      std::string fname = sc.environment().optional_string_param( "loc_ps_out", "" );
      if ( fname == "" ) return;

      std::ofstream psout( fname.c_str() );
      LocalizationPsWriter psw( psout, false );
      std::string info =
         "Dist: " + header.dist_algo
            + "; Pos: " + header.pos_algo
            + "; Ref: " + header.ref_algo;

      psw.paint_color( sc.world(), info, true );
   }
示例#18
0
 void init_transmission_models( SimulationController& sc ) throw()
 {
    sc.transmission_model_keeper_w().add( new ReliableTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new TracesTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new StatsChainTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new RandomDropTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new AlohaTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new SlottedAlohaTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new MacaTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new CsmaTransmissionModelFactory() );
    sc.transmission_model_keeper_w().add( new ZigbeeCsmaTransmissionModelFactory() );
    
    sc.simulation_task_keeper_w().add( new SimulationTaskChainTransmModel() );
    sc.simulation_task_keeper_w().add( new StatsChainTransmissionModelDumpStats() );
 }
	// ----------------------------------------------------------------------
	DIPostscriptWriter::
		DIPostscriptWriter(std::ostream& psfile, SimulationController& sc) : psfile_(psfile), pageNo_(1), eps_(false)
	{

//		eps ? eps_header() : ps_header();
		ps_header();
		calcOffset(sc.world());
		//newpage();
		setlinewidth2(0.1);


	}
示例#20
0
 void init_communication_models( SimulationController& sc ) throw()
 {
      sc.communication_model_keeper_w().add( new RimCommModelFactory );
      sc.communication_model_keeper_w().add( new ManualCommunicationModelFactory );
      sc.communication_model_keeper_w().add( new DiskGraphCommunicationModelFactory );
      //        sc.communication_model_keeper_w().add( new QuasiDiskGraphCommunicationModelFactory );
      sc.communication_model_keeper_w().add( new MultipleCommunicationModelFactory );
      sc.communication_model_keeper_w().add( new PermalinkCommunicationModelFactory );
      sc.communication_model_keeper_w().add( new LinkProbabilityCommunicationModelFactory );
      sc.communication_model_keeper_w().add( new StochasticCommunicationModelFactory );
 }
void CinderProjectApp::update()
{
    
    if(simulation) {
        
        double currentElapsed = getElapsedSeconds();
        double dt = currentElapsed - lastElapsedSeconds;
        
        simulation->update(currentTime, dt);
        
        lastElapsedSeconds = currentElapsed;
        currentTime += dt;
    }
}
示例#22
0
   void
   init_logging( SimulationController& sc )
      throw()
   {
      sc.simulation_task_keeper_w().add( new SimulationTaskLoggingLoadCfg );
      sc.simulation_task_keeper_w().add( new SimulationTaskLoggingReconfigure );

#if defined ( LOGGER_LOG4CXX )
      log4cxx::LoggerPtr root_logger = log4cxx::Logger::getRootLogger();
      root_logger->addAppender( new log4cxx::ConsoleAppender(
         new log4cxx::PatternLayout( "%c{1} - %m%n" ), "System.Out" ) );

      log4cxx::LoggerPtr user_logger = log4cxx::Logger::getLogger( LOG_USER_NAME );
      user_logger->addAppender( new log4cxx::ConsoleAppender(
         new log4cxx::PatternLayout( "%m%n" ), "System.Out" ) );
      user_logger->setAdditivity( false );
#elif defined ( LOGGER_LOG4CPLUS )
      log4cplus::SharedAppenderPtr root_appender( new log4cplus::ConsoleAppender() );
      log4cplus::SharedAppenderPtr user_appender( new log4cplus::ConsoleAppender() );
      root_appender->setName( "default_root_console" );
      user_appender->setName( "default_user_console" );

      std::auto_ptr<log4cplus::Layout> root_layout =
         std::auto_ptr<log4cplus::Layout>( new log4cplus::PatternLayout( "%c{1} - %m%n" ) );
      std::auto_ptr<log4cplus::Layout> user_layout =
         std::auto_ptr<log4cplus::Layout>( new log4cplus::PatternLayout( "%m%n" ) );

      root_appender->setLayout( root_layout );
      user_appender->setLayout( user_layout );

      log4cplus::Logger root_logger = log4cplus::Logger::getRoot();
      log4cplus::Logger user_logger = log4cplus::Logger::getInstance( LOG_USER_NAME );
      root_logger.addAppender( root_appender );
      user_logger.addAppender( user_appender );
      user_logger.setAdditivity( false );
#endif
   }
示例#23
0
   // ----------------------------------------------------------------------
   // ----------------------------------------------------------------------
   void WisemlTraceTask::run(SimulationController &sc) throw()
   {
      WisemlDataKeeper *keeper = 
         sc.keeper_by_name_w<WisemlDataKeeper>("wiseml_data_keeper");
      if(keeper == NULL)
      {
         cout << "WisemlTraceTask:"
            << " Unable to create trace because WisemlDataKeeper was not"
            << " found. Make shure to run wiseml_setup before this task, or"
            << " to create a WisemlDataKeeper by code." << endl;
         return;
      }

      keeper->add_trace(sc.environment().required_string_param("id"));
   }
示例#24
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskCreateUniform::
   run( SimulationController& sc )
      throw( std::runtime_error )
   {
      UniformRandomVariable* var = new UniformRandomVariable;
      
      try {
         const SimulationEnvironment& se = sc.environment();

         var->set_lower_bound( se.optional_double_param("lower",0.0) );
         var->set_upper_bound( se.optional_double_param("upper",1.0) );
         var->set_lower_bound_inclusive( se.optional_bool_param("lower_incl",true) );
         var->set_upper_bound_inclusive( se.optional_bool_param("upper_incl",false) );
         var->set_name( se.optional_string_param("name","") );
         var->init();
      }
      catch( std::runtime_error& ) {
         delete var;
         throw;
      }
      sc.random_variable_keeper_w().add(var);
      std::cout << "added " << var->name() << std::endl;
   }
示例#25
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::HeaderInfo::
   collect_information( SimulationController& sc, const SimulationTaskLocalizationEvaluation& stle )
      throw()
   {
      LocalizationObserver observer;

      if ( sc.world().communication_model().exists_communication_upper_bound() )
         comm_range = sc.world().communication_model().communication_upper_bound();

      world_width = sc.world().upper_right().x() - sc.world().lower_left().x();
      world_height = sc.world().upper_right().y() - sc.world().lower_left().y();

      set_placement( sc, stle );

      for( World::node_iterator
              it = sc.world_w().begin_nodes_w();
           it != sc.world_w().end_nodes_w();
           ++it )
      {
         Node& v = *it;
         LocalizationProcessor* lp =
            v.get_processor_of_type_w<LocalizationProcessor>();

         if ( lp == NULL ) continue;

         if ( lp->is_anchor() )
            ++anchor_cnt;
         else
            ++unknown_cnt;

         observer.set_owner( *lp );

         startup_anchor_frac = observer.startup_anchor_frac();
         dist_algo = observer.distance_algorithm();
         pos_algo = observer.position_algorithm();
         ref_algo = observer.refinement_algorithm();
         floodlimit = observer.floodlimit();
         idle_time = observer.idle_time();
      }
   }
示例#26
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::Results::
   set_seed( const SimulationController& sc, const SimulationTaskLocalizationEvaluation& stle )
      throw()
   {
      const ConstSimulationTaskHandle& csth =
               sc.simulation_task_keeper().find( "random_seed" );
      if ( csth != NULL )
      {
         const SimulationTaskRandomSeed& strs =
            *dynamic_cast<const SimulationTaskRandomSeed*>( csth.get() );

         DEBUG( stle.logger(), "Results: seed: " << strs.seed() );

         seed = strs.seed();
      }
      else
         seed = 0;
   }
void CinderProjectApp::draw()
{
	// clear out the window with gray
//    float gray = sin(getElapsedSeconds()) * 0.5f + 0.5f;
//	gl::clear( Color( gray, gray, gray ) );
//    
//    if( myImage )
//        gl::draw( myImage, getWindowBounds() );
//    
//    float x = cos( getElapsedSeconds() ) * 100.0f;
//    float y = sin( getElapsedSeconds() ) * 100.0f;
//    gl::drawSolidCircle( Vec2f( x, y ) + getWindowSize() / 2, abs( x ) );
    
    gl::clear( Color( 1.0f, 1.0f, 1.0f ) );
    
    if(simulation) {
        
        simulation->draw();
    }
}
示例#28
0
   // ----------------------------------------------------------------------
   void
   SimulationTaskLocalizationEvaluation::HeaderInfo::
   set_placement( const SimulationController& sc, const SimulationTaskLocalizationEvaluation& stle )
      throw()
   {
      const ConstSimulationTaskHandle& csth =
               sc.simulation_task_keeper().find( "localization_anchor_placement" );
      if ( csth != NULL )
      {
         const SimulationTaskLocalizationAnchorPlacement& stlap =
            *dynamic_cast<const SimulationTaskLocalizationAnchorPlacement*>( csth.get() );

         DEBUG( stle.logger(), "HeaderInfo: placed anchors: " << stlap.anchor_cnt() << "; " << stlap.pl_type() );

         placed_anchor_cnt = stlap.anchor_cnt();
         pl_type = stlap.pl_type();
      }
      else
      {
         placed_anchor_cnt = 0;
         pl_type = "";
      }
   }
示例#29
0
int main(){
	SimulationController * sc = new SimulationController();
	sc->start();
	return 0;
}
示例#30
0
	void 
		init_xml( SimulationController& sc )
		throw()
	{
       sc.simulation_task_keeper_w().add( new shawn::SimulationTaskSaveWorld );
	}