当前位置: 首页>>代码示例>>C++>>正文


C++ Strategy::setRandomStrategy方法代码示例

本文整理汇总了C++中Strategy::setRandomStrategy方法的典型用法代码示例。如果您正苦于以下问题:C++ Strategy::setRandomStrategy方法的具体用法?C++ Strategy::setRandomStrategy怎么用?C++ Strategy::setRandomStrategy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Strategy的用法示例。


在下文中一共展示了Strategy::setRandomStrategy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {

  int genCounter = 0;
  int populationCount = 0;
  int sessionScores = 0;
  int fieldMatrix [ 10 ] [ 10 ];
  int c;
  int nr_generations = 1000;
  int nr_steps = 200;
     
       while (1)
         {
           static struct option long_options[] =
             {
//               {"Number of agents",     required_argument,       0, 'a'},
//               {"Number of cleaning sessions",  required_argument,       0, 'c'},
               {"Number of generations",    required_argument, 0, 'g'},
//               {"Number of survivors",  required_argument, 0, 'n'},
               {"Number of steps in each cleaning session",  required_argument, 0, 's'},
               {0, 0, 0, 0}
             };
           /* getopt_long stores the option index here. */
           int option_index = 0;
     
           c = getopt_long (argc, argv, "g:s:",
                            long_options, &option_index);
     
           /* Detect the end of the options. */
           if (c == -1)
             break;
     
           switch (c)
             {
             case 0:
               printf ("option %s", long_options[option_index].name);
               if (optarg)
                 printf (" with arg %s", optarg);
               printf ("\n");
               break;
             case 'g':
               printf ("option -%c with value `%s'\n", c, optarg);     
               nr_generations = (int) atol(optarg);
               break;
             case 's':
               printf ("option -%c with value `%s'\n", c, optarg);     
               nr_steps = (int) atol(optarg);
               break;
//             case 'a':
//             case 'n':      
//             case 'c':
//               printf ("option -%c with value `%s'\n", c, optarg);     
//               break;
             case '?':
               /* getopt_long already printed an error message. */
//               break;
     
             default:
               abort ();
             }
         }
         
  srand ( time ( NULL ) );

  // initialize agents
  
  Robby agentArray [ NR_AGENTS ];
  
  for ( int agent = 0; agent < NR_AGENTS; agent++ ) {
    s.setRandomStrategy ( );
    agentArray [ agent ].setStrategy ( s );
  }

  while ( genCounter < nr_generations ) {

    for ( int agent = 0; agent < NR_AGENTS; agent++ ) {

      agentArray [ agent ].resetStatistics ( );

      for ( int session = 0; session < SESSIONS; session++ ) {
	
	agentArray [ agent ].setPos ( 0 , 0 );
	agentArray [ agent ].initializeField ( fieldMatrix ) ;
	agentArray [ agent ].resetStatistics ( );

	for ( int steps = 0; steps < nr_steps; steps++ ) {

	  // make one step by figuring out current context, getting the index for that context, getting the action for that index 

	  agentArray [ agent ].updateContext( );
	  agentArray [ agent ].makeMove ( agentArray [ agent ].getStrategy( ).getAction ( agentArray [ agent ].getContext( ).getCoding( ) ), false );

	} // end steps

	// register score for this session

	sessionScores  += agentArray [ agent ].getPoints ( );

      } // END SESSIONS(k): all sessions for an agent done

      int sessionAvg = 0;
//.........这里部分代码省略.........
开发者ID:Avi2011class,项目名称:genetic,代码行数:101,代码来源:run_genetic.cpp


注:本文中的Strategy::setRandomStrategy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。