Exemple #1
0
void AddAgentActions(int num_actions, VariablesInfo* admissible_actions) {
    Variable* temp;
    string action_name("Action_");
    temp = new Variable(action_name.append(1,'R'),1.0,GRID_SIZE);		// Right ( value = 0)
    if (temp == NULL) {
        cerr << "main:AddAgentActions (R action) was NULL!" << endl;
        exit(NO_MEM_AVAILABLE);
    }
    temp->SetVarValue(0);
    admissible_actions->AddVariable(temp->Clone());
    delete temp;
    action_name.clear();
    action_name = "Action_";
    temp = new Variable(action_name.append(1,'L'),1.0,GRID_SIZE);		// Left (value = 1)
    if (temp == NULL) {
        cerr << "main:AddAgentActions (L action) was NULL!" << endl;
        exit(NO_MEM_AVAILABLE);
    }
    temp->SetVarValue(1);
    admissible_actions->AddVariable(temp->Clone());
    delete temp;
    action_name.clear();
    action_name = "Action_";
    temp = new Variable(action_name.append(1,'U'),1.0,GRID_SIZE);		// Up (value = 2)
    if (temp == NULL) {
        cerr << "main:AddAgentActions (U action) was NULL!" << endl;
        exit(NO_MEM_AVAILABLE);
    }
    temp->SetVarValue(2);
    admissible_actions->AddVariable(temp->Clone());
    delete temp;
    action_name.clear();
    action_name = "Action_";
    temp = new Variable(action_name.append(1,'D'),1.0,GRID_SIZE);		// Down (value = 3)
    if (temp == NULL) {
        cerr << "main:AddAgentActions (D action) was NULL!" << endl;
        exit(NO_MEM_AVAILABLE);
    }
    temp->SetVarValue(3);
    admissible_actions->AddVariable(temp->Clone());
    delete temp;
}
Exemple #2
0
bool VariablesInfo::SetVarValue(string varName, float varValue) {
	Variable* var = NULL;
	unsigned i;
	for (i = 0; i < mVariables.size() && var == NULL; i++) {
		if (mVariables[i]->GetVarName() == varName) var = mVariables[i];
	}
	if (var != NULL) {
		var->SetVarValue(varValue);
		return true;
	}
	return false;
}
Exemple #3
0
// Add agents (for the grid environment)
VariablesInfo* SetInitialState(unsigned NUM_AGENTS) {
    string name;
//	bool grid[GRID_SIZE][GRID_SIZE];
    unsigned i;
//	unsigned j;
    /*	for (i = 0; i < GRID_SIZE; i++)
    		for (j = 0; j < GRID_SIZE; j++)
    			grid[i][j] = false;*/
    unsigned c;
    unsigned r;
    VariablesInfo* initial_state = new VariablesInfo();

//	vector<string>::iterator it = agent_names->begin();
    for (i = 0; i < NUM_AGENTS; i++) {
        std::ostringstream stream;
        stream<<i;
        //c = rand()%GRID_SIZE; // columns
        //r = rand()%GRID_SIZE; // rows
        if(i == 0) {
            r = 2;
            c = 0;
        }
        else {
            r = 2;
            c = 2;
        }
//		grid[r][c] = true;
        name = "Row_";
        Variable* state = new Variable(name.append(stream.str()),0.0,GRID_SIZE-1);
        state->SetVarValue(r);			// Random row
        initial_state->AddVariable(state->Clone());
        delete state;
        name = "Col_";
        state = new Variable(name.append(stream.str()),0.0,GRID_SIZE-1);
        state->SetVarValue(c);			// Random column
        initial_state->AddVariable(state->Clone());
        delete state;
    }
    return initial_state;
}
Exemple #4
0
// Add tokens (for the grid environment)
VariablesInfo* AppendToInitialState(VariablesInfo* AgentPositions, unsigned NUM_AGENTS) {
    // now it receives the environment description which contains ONLY the position of all agents
    string counter;
    string token;
    unsigned c;
    unsigned r;
    unsigned i = 0;
    unsigned j = 0;
    bool grid[GRID_SIZE][GRID_SIZE];
    for (i = 0; i < GRID_SIZE; i++)
        for (j = 0; j < GRID_SIZE; j++)
            grid[i][j] = false;
    Sgi::hash_map<int, Variable*> state;
    AgentPositions->GetVariableList(state);
    Sgi::hash_map<int, Variable*>::iterator it = state.begin();
    while (it != state.end()) {
        r = (int) (it->second->GetVarValue()); // row
        it++;
        c = (int) (it->second->GetVarValue()); // column
        grid[r][c] = true;
        it++;
    }
    VariablesInfo* initial_state = new VariablesInfo();
    for (i = 0; i < NUM_TOKENS_A; i++) {
        token = "token_";
        counter = i;
        //r = rand()%GRID_SIZE; // row
        //c = rand()%GRID_SIZE; // column
        r = 0;
        c = 2;
        /*	while (grid[r][c]) {
        	r = rand()%GRID_SIZE;
        	c = rand()%GRID_SIZE;
        	}*/
        grid[r][c] = true;
        token.append("Row").append("0").append(string(counter));
        Variable* state = new Variable(token,0.0,GRID_SIZE);
        state->SetVarValue(r);		// row
        initial_state->AddVariable(state->Clone());
        delete state;
        token = "token_";
        token.append("Col").append("0").append(string(counter));
        state = new Variable(token,0.0,GRID_SIZE);
        state->SetVarValue(c);		// column
        initial_state->AddVariable(state->Clone());
        delete state;
        //cout << "appended token " << i << " for agent A" << endl;
    }

    for (i = 0; i < NUM_TOKENS_B; i++) {
        token = "token_";
        counter = i;
        //r = rand()%GRID_SIZE; // row
        //c = rand()%GRID_SIZE; // column
        r = 0;
        c = 0;
        /*	while (grid[r][c]) {
        	r = rand()%GRID_SIZE;
        	c = rand()%GRID_SIZE;
        	}*/
        grid[r][c] = true;
        token.append("Row").append("1").append(string(counter));
        Variable* state = new Variable(token,0.0,GRID_SIZE);
        state->SetVarValue(r);		// row
        initial_state->AddVariable(state->Clone());
        delete state;
        token = "token_";
        token.append("Col").append("1").append(string(counter));
        state = new Variable(token,0.0,GRID_SIZE);
        state->SetVarValue(c);		//column
        initial_state->AddVariable(state->Clone());
        delete state;
        //cout << "appended token " << i << " for agent B" << endl;
    }
    return initial_state;
}