Esempio n. 1
0
/*Cancel last assignment*/
int CSP::goBack(int *chosen_cell)
{
    if(assigned_variables.size() > 0)
    {
        int cur_id = assigned_variables.top(); /*Remove last options*/
        assigned_variables.pop(); //pop out last option
        int y = cur_id / 9;
        int x = cur_id % 9;
        
        variables[y][x].assignement = 0; //assign the cell to zero
        cur_state.values[y][x] = 0; //update the assignment
        *chosen_cell = cur_id;
        
       // printf("(%d, %d)\n", y, x);
        if(alg_opt == 2)
        {
            updateDomain(cur_state);
        }
        else if (alg_opt == 3)
        {
            arcConsistency(cur_state);
        }
        
    }
    
    return goalCheck(cur_state);
    
}
Esempio n. 2
0
/*!
	Set the range control expressions.
*/
void DynaRangeCtlVarVf::setDynaRangeX(Fss const theFss, Prm const & LeftValue, Prm const & RightValue)
{
	EvalTblFlt const & tPxtTbl = EvalTblFlt::refc(this->mTermSys.SysHdl);

	mDynaLeftTerm = this->mTermSys.ptrmTerm(LeftValue.TermGen, LeftValue.TermHdl);

	Loc const tLeftLoc = getPxLoc(theFss, mDynaLeftTerm, LeftValue.PrmSpec);
	mDynaLeftRec = tPxtTbl.ptrcEvalRec(tLeftLoc);

	mDynaRightTerm = this->mTermSys.ptrmTerm(RightValue.TermGen, RightValue.TermHdl);
	Loc const tRightLoc = getPxLoc(theFss, mDynaRightTerm, RightValue.PrmSpec);
	mDynaRightRec = tPxtTbl.ptrcEvalRec(tRightLoc);
	if (!mTermSys.chkExecMode(NullComp))
		updateDomain();
}
Esempio n. 3
0
Profile::Profile(const QString &username) :
    _username(username),
    _uuid(),
    _lastDomain(),
    _lastPosition(0.0, 0.0, 0.0),
 	_faceModelURL()
{
    if (!_username.isEmpty()) {
        // we've been given a new username, ask the data-server for profile
        DataServerClient::getClientValueForKey(DataServerKey::UUID);
        
        // send our current domain server to the data-server
        updateDomain(NodeList::getInstance()->getDomainHostname());
    }
}
Esempio n. 4
0
Profile::Profile(const QString &username) :
    _username(),
    _uuid(),
    _lastDomain(),
    _lastPosition(0.0, 0.0, 0.0),
    _lastOrientationSend(0)
{
    if (!username.isEmpty()) {
        setUsername(username);
        
        // we've been given a new username, ask the data-server for profile
        DataServerClient::getValueForKeyAndUserString(DataServerKey::UUID, getUserString(), this);
        
        // send our current domain server to the data-server
        updateDomain(NodeList::getInstance()->getDomainHostname());
    }
}
Esempio n. 5
0
/*Forward Checking algorithm*/
bool CSP::forwardCheckingOrder(int *chosen_cell)
{

    updateDomain(cur_state); //the first step is based on current setting to update the domain
    
    
    
    /*First go through all the variables and do backtrack whether there is an empty domain */
    for(int i = 0; i < 81; i++)
    {
        int y = i / 9;
        int x = i % 9;
        
        if(cur_state.values[y][x] == 0 && variables[y][x].domain.size() == 0)
        {
            int available_assignemnt = 0; //an indicatior whether there are possible possible varaibles to be re-assigned
            while (available_assignemnt == 0) {
                int cur_id = assigned_variables.top();
                int y = cur_id / 9;
                int x = cur_id % 9;
                variables[y][x].assignement = 0;
                cur_state.values[y][x] = 0;
                updateDomain(cur_state);
                for(int i = 0; i < variables[y][x].domain.size(); i++)
                {
                    State temp_state;
                    temp_state = cur_state;
                    temp_state.values[y][x] = variables[y][x].domain[i];
                    if (std::find(repeating_list.begin(), repeating_list.end(), temp_state)==repeating_list.end()) //if not in the repeating list
                    {
                        cur_state = temp_state;
                        variables[y][x].assignement = variables[y][x].domain[i];
                        repeating_list.push_back(temp_state);
                        available_assignemnt = 1;
                        *chosen_cell = cur_id;
                        updateDomain(cur_state);
                        return false; //get out of the current varaible assignment
                    }
                }
                
                if(available_assignemnt == 0) //if all the domain values have been tried for current variable
                {
                    variables[y][x].assignement = 0;
                    cur_state.values[y][x] = 0;
                    assigned_variables.pop();
                    
                }
            }
            
        }
    }
    
    
    int count = 0;
    while (count < 81)
    {
        /*Find the index of minimum number of domain*/
        int min_idx = 0;
        int min_num = 10; //because the maximum number of domain is 10
        for(int i = 0; i < 81; i++)
        {
            int y = i / 9;
            int x = i % 9;
            if(cur_state.values[y][x] == 0 && variables[y][x].domain.size() > 0)
            {
                if (variables[y][x].domain.size() < min_num) {
                    min_idx = i;
                    min_num = variables[y][x].domain.size();
                }
            }
        }
        
        int y = min_idx / 9;
        int x = min_idx % 9;
        
        /*If there is any varable has not been assigned yet, assign it and return it*/
        if(cur_state.values[y][x] == 0 && variables[y][x].domain.size() > 0)
        {
            /*Find the smalles number in domain to assign it. Here no update domain for bracktrack*/
            int id_min = 0;
            cur_state.values[y][x] = variables[y][x].domain[id_min];
            variables[y][x].assignement = variables[y][x].domain[id_min];
            assigned_variables.push(min_idx); //push the variable into stack, which will be used for backtrack (or DFS)
            repeating_list.push_back(cur_state); //make this state into the repeat_list
            *chosen_cell = 9 * y + x;
            
            updateDomain(cur_state); //Every time modify the assignment update the domain
            
            return false;
        }
        
        count++;
    }
    
    if(goalCheck(cur_state))
    {
        printf("find the goal\n");
        return true;
    }
	else
	{
		int available_assignemnt = 0; //an indicatior whether there are possible varaibles to be re-assigned
		while (available_assignemnt == 0) {
			int cur_id = assigned_variables.top();
			int y = cur_id / 9;
			int x = cur_id % 9;
			variables[y][x].assignement = 0;
			cur_state.values[y][x] = 0;
			updateDomain(cur_state);
			for(int i = 0; i < variables[y][x].domain.size(); i++)
			{
				State temp_state;
				temp_state = cur_state;
				temp_state.values[y][x] = variables[y][x].domain[i];
				if (std::find(repeating_list.begin(), repeating_list.end(), temp_state)==repeating_list.end()) //if not in the repeating list
				{
					cur_state = temp_state;
					variables[y][x].assignement = variables[y][x].domain[i];
					repeating_list.push_back(cur_state);
					available_assignemnt = 1;
					*chosen_cell = cur_id;
					break; //get out of the current varaible assignment
				}
			}

			if(available_assignemnt == 0) //if all the domain values have been tried for current variable
			{

				assigned_variables.pop();

			}
		}

		return false;
	}

    return false;
    
}
Esempio n. 6
0
/*Arc consistency use*/
void CSP::arcConsistency(const State state)
{
    updateDomain(state);
    queue<Arrow> q;
    for (int i=0; i<81; i++) {
        int row=i/9;
        int col=i%9;
        for (int j=0; j<9; j++) {
            if (j!=row) {
                Arrow temp=Arrow(i, 9*j+col);
                q.push(temp);
            }
            if (j!=col) {
                Arrow temp=Arrow(i,9*row+j);
                q.push(temp);
            }
        }
        int tempRow = row / 3 * 3;
        int tempCol = col / 3 * 3;
        for(int l = tempRow; l < tempRow + 3;l++){
            for(int k = tempCol; k < tempCol + 3; k++){
                if (l!=row&&k!=col) {
                    Arrow temp=Arrow(i, l*9+k);
                    q.push(temp);
                    }
                }
            }
        }
    //cout<<q.size()<<endl;
    while (!q.empty()) {
        Arrow arrow=q.front();
        q.pop();
        bool delete_sign=0;
        int row_tail=arrow.tail/9;
        int col_tail=arrow.tail%9;
        int row_head=arrow.head/9;
        int col_head=arrow.head%9;
        if (state.values[row_tail][col_tail]==0) {
            for (int x=0;x<variables[row_tail][col_tail].domain.size();x++)
            {
                int avail=0;
                for (int y=0;y<variables[row_head][col_head].domain.size();
                     y++) {
                    if (variables[row_tail][col_tail].domain[x]!=variables[row_head][col_head].domain[y]) {
                        avail=1;
                        break;
                    }
                }
                if ( avail==0) {
                    delete_sign=1;
                    variables[row_tail][col_tail].domain.erase(std::find(variables[row_tail][col_tail].domain.begin(), variables[row_tail][col_tail].domain.end(), variables[row_tail][col_tail].domain[x]));
                    x--;
                }

        }
        if (delete_sign==1) {
            for (int j=0; j<9; j++) {
                if (j!=row_tail) {
                    Arrow temp=Arrow( arrow.tail,9*j+col_tail);
                    q.push(temp);
                }
                if (j!=col_tail) {
                    Arrow temp=Arrow(arrow.tail,9*row_tail+j);
                    q.push(temp);
                }
                int tempRow = row_tail / 3 * 3;
                int tempCol = col_tail / 3 * 3;
                for(int l = tempRow; l < tempRow + 3;l++){
                    for(int k = tempCol; k < tempCol + 3; k++){
                        if (l!=row_tail&&k!=col_tail) {
                            Arrow temp=Arrow( arrow.tail,l*9+k);
                            q.push(temp);
                        }
                    }
                }
            }
        }
    }
}
}