Example #1
0
 SharkValue* local(int index) {
   SharkValue *value = current_state()->local(index);
   assert(value != NULL, "shouldn't be");
   assert(value->is_one_word() ||
          (index + 1 < max_locals() &&
           current_state()->local(index + 1) == NULL), "should be");
   return value;
 }
Example #2
0
 SharkValue* xstack(int slot) {
   SharkValue *value = current_state()->stack(slot);
   assert(value != NULL, "shouldn't be");
   assert(value->is_one_word() ||
          (slot > 0 &&
           current_state()->stack(slot - 1) == NULL), "should be");
   return value;
 }
Example #3
0
int
make1( TARGET *t )
{
	state *pState;

	memset( (char *)counts, 0, sizeof( *counts ) );

	/* Recursively make the target and its dependents */
	push_state(&state_stack, t, NULL, T_STATE_MAKE1A);

	do
	{
		while((pState = current_state(&state_stack)) != NULL)
		{
            if (intr) 
                pop_state(&state_stack);

			switch(pState->curstate)
			{
			case T_STATE_MAKE1A:
				make1a(pState);
				break;
			case T_STATE_MAKE1ATAIL:
				make1atail(pState);
				break;
			case T_STATE_MAKE1B:
				make1b(pState);
				break;
			case T_STATE_MAKE1C:
				make1c(pState);
				break;
			case T_STATE_MAKE1D:
				make1d(pState);
				break;
			default:
				break;
			}
		}
	

	/* Wait for any outstanding commands to finish running. */
	} while( execwait() );

	clear_state_freelist();

	/* Talk about it */
	if( counts->failed )
	    printf( "...failed updating %d target%s...\n", counts->failed,
		        counts->failed > 1 ? "s" : "" );

	if( DEBUG_MAKE && counts->skipped )
	    printf( "...skipped %d target%s...\n", counts->skipped,
		        counts->skipped > 1 ? "s" : "" );

	if( DEBUG_MAKE && counts->made )
	    printf( "...updated %d target%s...\n", counts->made,
		        counts->made > 1 ? "s" : "" );

	return counts->total != counts->made;
}
Example #4
0
void StatesClassification::compute()             
{
    if (Status>=Computed) return;
    IndexSize = IndexInfo.getIndexSize();
    StateSize = 1<<IndexSize;
    std::vector<boost::shared_ptr<Operator> > sym_op = Symm.getOperations();
    int NOperations=sym_op.size();
    BlockNumber block_index=0;
    for (QuantumState FockStateIndex=0; FockStateIndex<StateSize; ++FockStateIndex) {
        FockState current_state(IndexSize,FockStateIndex);
        QuantumNumbers QNumbers(Symm.getQuantumNumbers());
        for (int n=0; n<NOperations; ++n) {
            MelemType Value=sym_op[n]->getMatrixElement(current_state, current_state);
            QNumbers.set(n,Value);
        }
        std::map<QuantumNumbers, BlockNumber>::iterator map_pos=QuantumToBlock.find(QNumbers);
        if (map_pos==QuantumToBlock.end()) {
//            DEBUG("Adding " << current_state << " to block " << block_index << " with QuantumNumbers " << QNumbers << ".");
            QuantumToBlock[QNumbers]=block_index;
            BlockToQuantum.insert(std::make_pair(block_index, QNumbers)); // Needed not to invoke an empty constructor.
            StatesContainer.push_back(std::vector<FockState>(0));
            StatesContainer[block_index].push_back(current_state);
            StateBlockIndex.push_back(block_index);
            block_index++;
            }
         else {
//            DEBUG("Adding " << current_state << " to block " << map_pos->second << " with QuantumNumbers " << QNumbers << ".");
            StatesContainer[map_pos->second].push_back(current_state);
            StateBlockIndex.push_back(map_pos->second);
            };
        }
    Status = Computed;
}
void camel_test_nonfatal (const gchar *what, ...)
{
	struct _stack *node;
	va_list ap;
	gchar *text;
	struct _state *s;

	CAMEL_TEST_LOCK;

	s = current_state ();

	va_start (ap, what);
	text = g_strdup_vprintf (what, ap);
	va_end (ap);

	if (camel_test_verbose > 3)
		printf("Start nonfatal: %s\n", text);

	node = g_malloc (sizeof (*node));
	node->what = text;
	node->next = s->state;
	node->fatal = 0;
	s->nonfatal++;
	s->state = node;

	CAMEL_TEST_UNLOCK;
}
Example #6
0
/*
Additional timer event
*/
void timer_event()
{
	if (event_mode == MANUAL_MODE)
	return;
	
	// for pwm time dependent events - always keep up to date
	current_state();
}
Example #7
0
 SharkValue* pop() {
   int size = current_state()->stack(0) == NULL ? 2 : 1;
   if (size == 2)
     xpop();
   SharkValue *value = xpop();
   assert(value && value->size() == size, "should be");
   return value;
 }
Example #8
0
/** \brief StateReturn StateMachine( const StateTransition *table, \
 *                                   int table_size, \
 *                                   StateFunction starting_state, \
 *                                   StateFunction exit_state)
 * \param const StateTransition *table
 * \param int table_size
 * \param StateFunction starting_state
 * \param StateFunction exit_state
 * \return StateReturn
 */
StateReturn StateMachine( const StateTransition *table, \
                          int table_size, \
                          StateFunction starting_state, \
                          StateFunction exit_state){
  StateReturn return_code = 0;
  StateFunction current_state = starting_state;

  while(current_state != NULL){
    return_code = current_state();
    if( current_state == exit_state){
      return return_code;
    }
    current_state = _LookupTransition(table, table_size, current_state, return_code);
  }
  for(;;){}; // catch error in lookup table
}
Example #9
0
int make1( TARGET * const t )
{
    state * pState;

    memset( (char *)counts, 0, sizeof( *counts ) );

    /* Recursively make the target and its dependencies. */
    push_state( &state_stack, t, NULL, T_STATE_MAKE1A );

    while ( 1 )
    {
        while ( ( pState = current_state( &state_stack ) ) )
        {
            if ( intr )
                pop_state( &state_stack );

            switch ( pState->curstate )
            {
                case T_STATE_MAKE1A: make1a( pState ); break;
                case T_STATE_MAKE1B: make1b( pState ); break;
                case T_STATE_MAKE1C: make1c( pState ); break;
                default:
                    assert( !"make1(): Invalid state detected." );
            }
        }
        if ( !cmdsrunning )
            break;
        /* Wait for outstanding commands to finish running. */
        exec_wait();
    }

    clear_state_freelist();

    /* Talk about it. */
    if ( counts->failed )
        printf( "...failed updating %d target%s...\n", counts->failed,
            counts->failed > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->skipped )
        printf( "...skipped %d target%s...\n", counts->skipped,
            counts->skipped > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->made )
        printf( "...updated %d target%s...\n", counts->made,
            counts->made > 1 ? "s" : "" );

    return counts->total != counts->made;
}
Example #10
0
void load_events()
{
	// initialize random number generator; it has to be done only once (after reset)
	srand(current_time());
	
	events_count = eeprom_read_byte(&events_count_ee);
	
	// initialize - for testing purposes
	/*
	if (events_count == 0)
	{
	send_string("add_default\r\n");
	add_default_events();
	}
	*/
	
	if (events_count == 0)
	{
		send_line("No events => MANUAL_MODE");
		event_mode = MANUAL_MODE;
		return;
	}
	
	// load events into ram
	eeprom_read_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// prepare
	prepare_actual_events();
	
	// print events
	print_events();
	
	// check current state of pins
	// if the device is power off, and later power on - it doesn't know what should be current state of pins
	
	int32_t time = current_time();
	send_string(" start time: ");
	
	char formatted_date[30];
	timeToString(time, formatted_date);
	send_string(formatted_date);
	send_enter();
	
	current_state();
}
Example #11
0
void camel_test_start (const gchar *what)
{
	struct _state *s;

	CAMEL_TEST_LOCK;

	s = current_state ();

	if (!setup)
		camel_test_init (0, 0);

	ok = 1;

	s->test = g_strdup (what);

	if (camel_test_verbose > 0) {
		printf("Test: %s ... ", what);
		fflush (stdout);
	}

	CAMEL_TEST_UNLOCK;
}
Example #12
0
void camel_test_pull (void)
{
	struct _stack *node;
	struct _state *s;

	CAMEL_TEST_LOCK;

	s = current_state ();

	g_assert (s->state);

	if (camel_test_verbose > 3)
		printf("Finish step: %s\n", s->state->what);

	node = s->state;
	s->state = node->next;
	if (!node->fatal)
		s->nonfatal--;
	g_free (node->what);
	g_free (node);

	CAMEL_TEST_UNLOCK;
}
Example #13
0
bool strategy_formulation_with_rca::do_play_stage()
{
	// Make general "offense" or "defense" decision for current turn.
	LOG_AI_TESTING_SF_WITH_RCA << "------Analyze started------" << std::endl;

	int ticks = SDL_GetTicks();

	DBG_AI_TESTING_SF_WITH_RCA << "Clear strategy flag at the beginning of do_play_stage()" << std::endl;
	clear_strategy();

	// Find optimal strategy.
	// First calculate the state of current turn.
	boost::shared_ptr<turn_state> current_state(new turn_state(this->get_side(), 0, *resources::units, *resources::teams));
	states_.push(*current_state);

	// Second calculate decisions based on current state.
	simulate_states_ahead();

	// Finally figure out the optimal strategy for the total
	// three turns and set the flag for CA to use.
	set_optimal_strategy();

	// Clean the queue.
	while(!states_.empty())
		states_.pop();

	int time_taken = SDL_GetTicks() - ticks;
	LOG_AI_TESTING_SF_WITH_RCA <<"Took " << time_taken <<" ticks on decision making." << std::endl;

	LOG_AI_TESTING_SF_WITH_RCA << "------Analyze completed------\n" << std::endl;

	rca_->do_play_stage();

	clear_strategy();

	return false;
}
Example #14
0
void camel_test_failv (const gchar *why, va_list ap)
{
	gchar *text;
	struct _state *s;

	CAMEL_TEST_LOCK;

	s = current_state ();

	text = g_strdup_vprintf (why, ap);

	if ((s->nonfatal == 0 && camel_test_verbose > 0)
	    || (s->nonfatal && camel_test_verbose > 1)) {
		printf("Failed.\n%s\n", text);
		camel_test_break ();
	}

	g_free (text);

	if ((s->nonfatal == 0 && camel_test_verbose > 0)
	    || (s->nonfatal && camel_test_verbose > 2)) {
		g_hash_table_foreach (info_table, (GHFunc)dump_action, 0);
	}

	if (s->nonfatal == 0) {
		exit (1);
	} else {
		ok=0;
		if (camel_test_verbose > 1) {
			printf("Known problem (ignored):\n");
			dump_action (CAMEL_TEST_ID, s, 0);
		}
	}

	CAMEL_TEST_UNLOCK;
}
Example #15
0
bool game::initial() const
{
  return current_state() == state_initial;
}
Example #16
0
bool game::beginning_end() const
{
  return current_state() == state_beginning_end;
}
Example #17
0
 SharkValue* xpop() {
   return current_state()->pop();
 }
Example #18
0
 void xpush(SharkValue* value) {
   current_state()->push(value);
 }
Example #19
0
int make1( LIST * targets )
{
    state * pState;
    int status = 0;

    memset( (char *)counts, 0, sizeof( *counts ) );
    
    {
        LISTITER iter, end;
        stack temp_stack = { NULL };
        for ( iter = list_begin( targets ), end = list_end( targets );
              iter != end; iter = list_next( iter ) )
            push_state( &temp_stack, bindtarget( list_item( iter ) ), NULL, T_STATE_MAKE1A );
        push_stack_on_stack( &state_stack, &temp_stack );
    }

    /* Clear any state left over from the past */
    quit = 0;

    /* Recursively make the target and its dependencies. */

    while ( 1 )
    {
        while ( ( pState = current_state( &state_stack ) ) )
        {
            if ( quit )
                pop_state( &state_stack );

            switch ( pState->curstate )
            {
                case T_STATE_MAKE1A: make1a( pState ); break;
                case T_STATE_MAKE1B: make1b( pState ); break;
                case T_STATE_MAKE1C: make1c( pState ); break;
                default:
                    assert( !"make1(): Invalid state detected." );
            }
        }
        if ( !cmdsrunning )
            break;
        /* Wait for outstanding commands to finish running. */
        exec_wait();
    }

    clear_state_freelist();

    /* Talk about it. */
    if ( counts->failed )
        printf( "...failed updating %d target%s...\n", counts->failed,
            counts->failed > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->skipped )
        printf( "...skipped %d target%s...\n", counts->skipped,
            counts->skipped > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->made )
        printf( "...updated %d target%s...\n", counts->made,
            counts->made > 1 ? "s" : "" );

    /* If we were interrupted, exit now that all child processes
       have finished. */
    if ( intr )
        exit( 1 );

    {
        LISTITER iter, end;
        for ( iter = list_begin( targets ), end = list_end( targets );
              iter != end; iter = list_next( iter ) )
        {
            /* Check that the target was updated and that the
               update succeeded. */
            TARGET * t = bindtarget( list_item( iter ) );
            if (t->progress == T_MAKE_DONE)
            {
                if (t->status != EXEC_CMD_OK)
                    status = 1;
            }
            else if ( ! ( t->progress == T_MAKE_NOEXEC_DONE && globs.noexec ) )
            {
                status = 1;
            }
        }
    }
    return status;
}
Example #20
0
bool game::player_sweeping() const
{
  return current_state() == state_player_sweeping;
}
Example #21
0
 void make_move(Move move) {
   history.push(State(current_state()));
   current_state().make_move(move);
 }
Example #22
0
Scrollbar::Thumb::State Scrollbar::Thumb::GetState() const
{
  auto stateMachine = (SmScrollbar::StateMachine*) _stateMachine;
  return (State) stateMachine->current_state()[0];
}
Example #23
0
bool game::player_ending_shot() const
{
  return current_state() == state_player_ending_shot;
}
Example #24
0
int main()
{
	//learning factor
	const double alpha = 0.5;
	//discount factor
	const double gamma = 0.5;
	
	const double deltatime = 0.05;
	const double mass = 0.5;
	const double length = 0.08;
	const int angle_bins = 100;
	const int velocity_bins = 50;
	const int torque_bins = 9;
	const double max_angle = M_PI;
	const double max_velocity = 10;
	const double max_torque = 4;
	
	Environment* env = new Environment(0, 0, 0, max_torque, 0, deltatime, mass, length, gamma);
	
	//seed rng
	std::srand(static_cast<unsigned int>(std::time(NULL)));
	
	//create the possible actions as well as the chosen action
	float chosen_action = 1;	// rip f
	float actions[torque_bins];
	for (int i = 0; i < (max_torque*2)+1 ; ++i)
	{
		actions[i] = static_cast<float>(-max_torque+i);
	}
	
	//create a priority queue to copy to all the state space priority queues
	PriorityQueue<float, double> initiator_queue(MAX);
	for (int i = 0; i < torque_bins; ++i)
	{
		initiator_queue.enqueueWithPriority(actions[i], 0);
	}
	
	//create the state space
	StateSpace space(initiator_queue, angle_bins, velocity_bins, torque_bins, max_angle, max_velocity, max_torque);
	
	//state objects
	State current_state(0, 0, 0);
	State old_state(0, 0, 0);
	
//	std::ofstream file("output.txt");
//	file.precision(16);
	
//	file << "Trialno" << "	" << "Time" << "		" << "Theta" << "	" << "Thetadot" << "		" << "Torque" << std::endl;
	
	double trialno = 1;
	unsigned long i=0;
	while (true)
	{
		current_state.theta = env->getTheta();
		current_state.theta_dot = env->getThetadot();
		current_state.torque = env->getTorque();
		
		std::cout << "State Read" << std::endl;
		
		updateQ(space, chosen_action, old_state, current_state, alpha, gamma);

		if (std::abs(current_state.theta_dot) > 5)
		{
			env->resetPendulum();
			std::cout<<"->unsuccessful trial\n";
			trialno++;
			i = 0;
			continue;
		}
		
		old_state = current_state;
		
		chosen_action = selectAction(space[current_state],i);
		std::cout << "Action Selected" << std::endl;
		env->setTorque(chosen_action);
		
		env->propagate();
		std::cout << "Environment Propagated\n" << std::endl;

//		file << trialno << "	  " << env->getTime() << "	  " << current_state.theta << "	  " << current_state.theta_dot << "	   " << current_state.torque << std::endl;
		++i;
	}

//	file.close();
	
	delete env;
	
	return 1;
}
Example #25
0
Knob::State Knob::GetState() const
{
  auto stateMachine = (SmKnob::StateMachine*) _stateMachine;
  return (State) stateMachine->current_state()[0];
}
Example #26
0
bool game::player_delivering() const
{
  return current_state() == state_player_delivering;
}
Example #27
0
 void set_local(int index, SharkValue* value) {
   assert(value != NULL, "shouldn't be");
   current_state()->set_local(index, value);
   if (value->is_two_word())
     current_state()->set_local(index + 1, NULL);
 }
Example #28
0
bool game::ending_game() const
{
  return current_state() == state_ending_game;
}
Example #29
0
 int xstack_depth() {
   return current_state()->stack_depth();
 }
Example #30
0
 Color color_to_move() {
   return current_state().us;
 }