Hello everone,
                      I'm trying to solve n-queens problem by a new approach(actually , it's quite old) called Contraint Programming, It is basically backtracking combined with notions of local consistancy. My basic algo is this

bool findsol(ChessBoard *ptboard, int row)
{// Basic Backtracking procedure
    static int times=1;
    if(ptboard->propogate()==false)
        return false;

    for(int col=0; col<n; col++)
    {
        if(ptboard->place(row,col))
            if(row==n-1)
            {
                ptboard->dispboard();
                cout<<endl<<"Soln No. "<<times++<<".\n";
                return true;
            }
            else if(findsol(ptboard,row+1))
                return true;
            else
                undomoves();
    }
    return false;
}
Basically i have variables that keep track of the domain each var(queens pos in n rows) can take now the propogate procedure restricts the domain of each unassigned var. according to the values the assigned variables have taken.
                       My  trouble is with writing the undo procedure that requires i put the domains back to the same state it was before the propogate() procedure of this call was invoked. Anyone has any idea on i could write this?


--
Well," said Owl, "the customary procedure in such cases is as follows."
"What does Crustimoney Proseedcake mean?" said Pooh. "For I am a Bear of Very Little Brain, and long words Bother me."
"It means the Thing to Do."
"As long as it means that, I don't mind," said Pooh humbly.

Reply via email to