//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // MAIN PROGRAM START //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int main() { Attr test; test.Load(); test.Attrs1(); AStar(); }
//============================================================================ // A-Star-Search Algorithm // ---Start--- //============================================================================ void AStar() { priority_queue<tracker, vector<tracker>, gTracker> CloseList; priority_queue<tracker, vector<tracker>, gTracker> OpenList; priority_queue<tracker, vector<tracker>, gTracker> TempOpenList; priority_queue<tracker, vector<tracker>, gTracker> TempCloseList; int begin; int last; int top; int temp; int values; int sTemp1 = 0; int sTemp2 = 0; int frontier = 0; bool rNext = false; bool closeCheck = false; tracker tracking; tracker closeT; tracker checkT; tracker tempT; vector<tracker> trackTemp; vector<float> lFind; Attr dist; begin = attrs[0].letters[0].value; for(int r = 0; r <= attrs.size()-1; r++) { for(int c = 0; c <= attrs[r].letters.size()-1; c++) lFind.push_back(attrs[r].letters[c].value); } sort(lFind.begin(),lFind.end(),compare()); last = lFind[0]; cout<<"The goal is: "<<last<<endl; cout<<"The begin is: "<<begin<<endl; cout<<"Euclidean distance: "<<dist.Euclidean(begin,last)<<endl; tracking.asci = begin; tracking.gS = dist.Euclidean(0, begin); tracking.hS = dist.Euclidean(last, begin); tracking.fN = tracking.gS + tracking.hS; OpenList.push(tracking); while(!OpenList.empty()) { tempT = OpenList.top(); cout<<"tempT is: "<<tempT.asci<<endl; if(frontier < OpenList.size()) frontier = OpenList.size(); OpenList.pop(); //First I am obtaining the blocks that are next to tempT.asci //FIX: Iterator in order to move to the next row if it is available for(int s1 = 0; s1 <= tempAttr.size()-1; s1++) { for(int s2 = 0; s2 <= tempAttr[s1].letters.size()-1; s2++) { if(tempT.asci == tempAttr[s1].letters[s2].value) { sTemp1 = s1; sTemp2 = s2; dist.Attrs1(); //vector<Attr> tempAttr(3); if(tempAttr[s1].letters[s2].id == 0) { if(s2 == 0 && tempAttr[s1].letters[sTemp2+1].value != 0) { //no left neighbor temp = tempAttr[s1].letters[sTemp2+1].value; //remove letter from temp adj list //tempAttr.erase(remove(tempAttr.begin(), tempAttr.end(), temp), tempAttr.end()); //tempAttr.resize(tempAttr.size()); cout<<"the right 3 neighbor is: "<<temp<<endl; tracking.asci = temp; tracking.gS = dist.Euclidean(temp,tempT.asci); cout<<"the right 3 neighbor gS is: "<<tracking.gS<<endl; tracking.hS = dist.Euclidean(temp,last); cout<<"the right 3 neighbor hS is: "<<tracking.hS<<endl; tracking.fN = tracking.gS + tracking.hS; cout<<"the right 3 neighbor fN is: "<<tracking.fN<<endl; OpenList.push(tracking); trackTemp.push_back(tracking); cin.get(); } else if(tempAttr[s1].letters[sTemp2-1].value != 0) { //there is a left neighbor temp = tempAttr[s1].letters[sTemp2-1].value; //remove letter from temp adj list //tempAttr.erase(remove(tempAttr.begin(), tempAttr.end(), temp), tempAttr.end()); //tempAttr.resize(tempAttr.size()); cout<<"the right 2 neighbor is: "<<temp<<endl; tracking.asci = temp; tracking.gS = dist.Euclidean(temp,tempT.asci); cout<<"the right 2 neighbor gS is: "<<tracking.gS<<endl; tracking.hS = dist.Euclidean(temp,last); cout<<"the right 2 neighbor hS is: "<<tracking.hS<<endl; tracking.fN = tracking.gS + tracking.hS; cout<<"the right 2 neighbor fN is: "<<tracking.fN<<endl; OpenList.push(tracking); trackTemp.push_back(tracking); cin.get(); if(tempAttr[s1].letters[sTemp2+1].value != 0) { //there is a left neighbor temp = tempAttr[s1].letters[sTemp2+1].value; //remove letter from temp adj list //tempAttr.erase(remove(tempAttr.begin(), tempAttr.end(), temp), tempAttr.end()); //tempAttr.resize(tempAttr.size()); cout<<"the right 1 neighbor is: "<<temp<<endl; tracking.asci = temp; tracking.gS = dist.Euclidean(temp,tempT.asci); cout<<"the right 1 neighbor gS is: "<<tracking.gS<<endl; tracking.hS = dist.Euclidean(temp,last); cout<<"the right 1 neighbor hS is: "<<tracking.hS<<endl; tracking.fN = tracking.gS + tracking.hS; cout<<"the right 1 neighbor fN is: "<<tracking.fN<<endl; OpenList.push(tracking); trackTemp.push_back(tracking); cin.get(); } else cout<<"The right neighbor does not exist"<<endl; } } s1 = tempAttr.size(); s2 = tempAttr[s1].letters.size()-1; }//if statement }//column for loop }//row for loop }//while loop }