// ----------------------------------------------------------------------
   // ----------------------------------------------------------------------
   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);
   }
Esempio n. 2
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;
						}
                    }
            }
        }
    }
Esempio n. 3
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 );
   }
Esempio n. 4
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"));
   }
Esempio n. 5
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();
   }
Esempio n. 6
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 );
   }
Esempio n. 7
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;
   }