예제 #1
0
puck_event ()
{
    State *ps = (State *) myState;
    int totMsgs;
    register int i, msg_i;
    char cannedMsgs[MAX_NUMBER_OF_MESSAGES];




    int tst_i;

    totMsgs = numMsgs;
    ps->now1 = now;
    
    canTheMsgs ( cannedMsgs, ps, totMsgs );
/*
 *	Now we process all of the un-cancelled puck messages
 */

			 
    for (msg_i = 0; msg_i < totMsgs; msg_i++)
    {

	if ( cannedMsgs[msg_i] )
	    continue;

	switch (msgSelector (msg_i))
	{
	case CONFIG_MSG:
	case PUCK_START:
	    puckStart ( msg_i, ps );
	    break;

	case NEW_TRAJECTORY:
	    newTrajectory ( msg_i, ps );
	    break;

	case COLLIDE_CUSHION:
	    collideCush ( msg_i, ps );
	    ps->Total_Cushion_Collisions++;
	    break;

	case COLLIDE_PUCK:
	    collidePuck ( msg_i, ps );
	    ps->Total_Puck_Collisions++;
	    break;

	case ENTER_SECTOR:
	    enterSector ( msg_i, ps );
	    ps->Total_Enter_Sectors++;
	    break;

	case DEPART_SECTOR:
	    departSector ( msg_i, ps );
	    ps->Total_Depart_Sectors++;
	    break;

	case UPDATE_SELF:
#ifdef AUTO_UPDATE
	    do_it_update ();
#endif AUTO_UPDATE
	    break;

	default:
/*???PJH
	    tw_printf ("%s Received an UNKNOWN msg type\n", ps->my_name );
	    Dump_Pool_Msg ( msg_i );
*/
	    break;

	}
    }
}
예제 #2
0
AlphaList 
MCGS_improve( AlphaList **projections, PomdpSolveParams param ) {

  Trajectory trajectory, t;
  int trajectory_count = 0;
  AlphaList old_vector_list;
  AlphaList new_vector_list;
  double gen_time, prune_time;
  double tot_gen_time = 0.0, tot_prune_time = 0.0;
  int m, num_new_points = 0;

  /* FIXME: Need to rethink how this works before making it
	available. */
  Abort( "MCGS method not yet available. Sorry.");
 
  if ( param->opts->verbose == POMDP_SOLVE_OPTS_Verbose_mcgs ) {
    fprintf( param->report_file, 
             "<<Monte Carlo Gauss Seidel Approximation>>\n" );
  } /* if verbose */

  /* Use an old and a new and periodically merge them. */
  old_vector_list = newAlphaList();
  new_vector_list = newAlphaList();

  trajectory = newTrajectory( param->opts->mcgs_traj_length );

  if ( param->opts->verbose == POMDP_SOLVE_OPTS_Verbose_mcgs )
    fprintf( param->report_file,
             "Using trajectory length %d.\n", 
             param->opts->mcgs_traj_length );

  while ( (! gInterrupt) 
          && param->opts->mcgs_num_traj > trajectory_count ) {

    /* Generate a trajectory of length N from starting state,
       accumulating a set of N points. Uses random selection for the
       policy (the NULL parameter specifies this). */
    generateTrajectory( trajectory, gInitialBelief, NULL );
    trajectory_count++;

    if ( param->opts->verbose == POMDP_SOLVE_OPTS_Verbose_mcgs )
      fprintf( param->report_file,
               "Trajectory %d.\n", trajectory_count );
    
    /* Loop over this set of points M times. */
    for( m = 0; m < param->opts->mcgs_traj_iter_count; m++ ) {

      /* Loop over the points from the trajectory. */
      for ( t = trajectory; t != NULL; t = t->next ) {

        if ( gInterrupt )
          goto END_MCGS;

        /* For each point, and the current alpha vector list, generate the
           vector for this point. This routine also adds the vector to
           the list (if it is not already in the list. */
        makeAlphaVector( new_vector_list,
                         projections,
                         t->belief,
                         SMALLEST_PRECISION );

	   /* FIXME: On review, this does not look right to me.  Seems
		 like we would only want to increment *if* the new vector is
		 added, and further, this is a count of new *value function
		 facets* not points. Also, seems like we can just look at
		 the size of the new list to determine whether it is time to
		 merge and prune. */
        num_new_points++;

        if ( param->opts->mcgs_prune_freq == num_new_points ) {
        
          num_new_points = 0;

          if ( param->opts->verbose == POMDP_SOLVE_OPTS_Verbose_mcgs ) {
            fprintf( param->report_file,
                     "Changing value function..." );
            fflush(  param->report_file );
          } /* if versboe */

          /* First merge the two sets... */
          unionTwoAlphaLists( old_vector_list, new_vector_list );

          /* ... create a new list ... */
          new_vector_list = newAlphaList();

          if ( param->opts->verbose == POMDP_SOLVE_OPTS_Verbose_mcgs )
            fprintf( param->report_file,
                     "%d vectors -> ", sizeAlphaList( old_vector_list ) );

          /* ... then prune this set */
          normalPrune( old_vector_list, param );

          /* Clear the old projection set ... */
          clearAllProjections( projections );

          /* ... and create the new projection set */
          setAllProjections( projections, old_vector_list );

          if ( gVerbose[V_APPROX_MCGS] )
            fprintf( param->report_file,
                     "%d vectors.\n", sizeAlphaList( old_vector_list ) );

        } /* if time to prune */

      } /* for n */

    } /* for m */

  } /* while not done */

  END_MCGS:

  destroyAlphaList( new_vector_list );
  freeTrajectory( trajectory );
  freeAllProjections( projections );

  return ( old_vector_list );

}  /* MCGS_improve */