Exemplo n.º 1
0
void agent_init(const char* task_spec)
{
	/*Struct to hold the parsed task spec*/
	taskspec_t *ts=(taskspec_t*)malloc(sizeof(taskspec_t));
	int decode_result = decode_taskspec( ts, task_spec );
	if(decode_result!=0){
		printf("Could not decode task spec, code: %d for task spec: %s\n",decode_result,task_spec);
		exit(1);
	}
	this_action=allocateRLStructPointer(getNumIntAct(ts),getNumDoubleAct(ts),0);
}
Exemplo n.º 2
0
void agent_init(const char* task_spec)
{
	/*Struct to hold the parsed task spec*/
	taskspec_t *ts=(taskspec_t*)malloc(sizeof(taskspec_t));
	int decode_result = decode_taskspec( ts, task_spec );
	if(decode_result!=0){
		printf("Could not decode task spec, code: %d for task spec: %s\n",decode_result,task_spec);
		exit(1);
	}
	
	/* Lots of assertions to make sure that we can handle this problem.  */
	assert(getNumIntObs(ts)==1);
	assert(getNumDoubleObs(ts)==0);
	assert(isIntObsMax_special(ts,0)==0);
	assert(isIntObsMin_special(ts,0)==0);

	
	numStates=getIntObsMax(ts,0)+1;

	assert(getNumIntAct(ts)==1);
	assert(getNumDoubleAct(ts)==0);
	assert(isIntActMax_special(ts,0)==0);
	assert(isIntActMin_special(ts,0)==0);

	numActions=getIntActMax(ts,0)+1;

	free_taskspec_struct(ts); /* Make the taskspec struct a "blank slate" */
	free(ts); /* Free the structure itself */
	/*Here is where you might allocate storage for parameters (value function or policy, last action, last observation, etc)*/
	
	/*Here you would parse the task spec if you felt like it*/
	
	/*Allocate memory for a one-dimensional integer action using utility functions from RLStruct_util*/
	allocateRLStruct(&this_action,1,0,0);
	allocateRLStruct(&last_action,1,0,0);
	/* That is equivalent to:
			 this_action.numInts     =  1;
			 this_action.intArray    = (int*)calloc(1,sizeof(int));
			 this_action.numDoubles  = 0;
			 this_action.doubleArray = 0;
			 this_action.numChars    = 0;
			 this_action.charArray   = 0;
	*/

	/*Allocate memory for a one-dimensional integer observation using utility functions from RLStruct_util*/
	last_observation=allocateRLStructPointer(1,0,0);
	
	/*Later we will parse this from the task spec, but for now*/
	value_function=(double *)calloc(numActions*numStates,sizeof(double));
	
}
Exemplo n.º 3
0
void agent_init(const char* task_spec)
{
	srand(time(0));

	/*Struct to hold the parsed task spec*/
	taskspec_t *ts = (taskspec_t*)malloc(sizeof(taskspec_t));
	int decode_result = decode_taskspec(ts, task_spec);
	if (decode_result != 0){
		printf("Could not decode task spec, code: %d for task spec: %s\n", decode_result, task_spec);
		exit(1);
	}

	possibleActions = getIntActMax(ts,0)-1;
	allocateRLStruct(&currentAction, 1, 0, 0);
	
	//load();
}
Exemplo n.º 4
0
int main( int argc, char **argv )
{
	FILE *test_fp;
	char *cp;
	char test_str[BUF_SIZE];
	taskspec_t ts;
	int dec_result;

	/* attempt to open the file of test task spec strings */
	if (argc == 1) {
		test_fp = fopen( "test_cases.txt", "r" );
	} else if (argc == 2) {
		if (strlen(argv[1]) == 1 && argv[1][0] == '-')
			test_fp = stdin;
		else
			test_fp = fopen( argv[1], "r" );
	} else {
		printf( "Usage: %s [test-strings-file]\n", argv[0] );
		return 1;
	}
	if (test_fp == NULL) {
		perror( "main, fopen" );
		return -1;
	}

	/* the read, test loop */
	while (!feof( test_fp )) {

		if (fgets( test_str, BUF_SIZE, test_fp ) == NULL)
			break;

		/* strip read line of a new-line character, if present */
		if ((cp = strchr( test_str, '\n' )) != NULL)
			*cp = '\0';

		printf( "Test string:      %s\n", test_str );
		dec_result = decode_taskspec( &ts, test_str );
		switch( dec_result ) {

		case 0:
			printf( "taskspec_t accessor method results:\n" );
			test_accessors( &ts );
			free_taskspec_struct( &ts );
			printf( "\n" );
			break;

		case 1:
			printf( "Unrecognized or unsupported task spec string version.\n\n" );
			break;

		case -1:
			fprintf( stderr, "decode_taskspec (task spec string parsing) failed.\n\n" );
			break;

		default:
			fprintf( stderr, "decode_taskspec returned: %d\n\n", dec_result );
			break;

		}

	}

	if (test_fp != stdin)
		fclose( test_fp );

	return 0;
}