Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow){    
    ui->setupUi(this);
    createActions();
    createMenus();
    initVectors();
    initListeners();
    muteEvent=false;
    ClickedClear();
    sqlite = new SQLite();
    openSet(true);
    sqlite->startDriver();
}
Exemplo n.º 2
0
vector<point> BlockAStar::startProcess()
{
	////////////////////////////////////////////////////////////////////////////
	//initialize variables
	point start(0,0);
	point goal(gridSize[0]-1,gridSize[1]-1);
	int nodepointer = 0;

	int currentIdx;
	point current(0,0);

	int neighborIdx;
	point neighbor(0,0);

	int i;
	FLOAT tentativeScore; //helper variables

	int gridElements = gridSize[0]*gridSize[1];
	int allocSize = (int)floor(PREALLOC_FACTOR*gridElements);

	//G.create(size[0],size[1]);				//contains the accumulated values
	G.create(size[0],size[1],blockSize);				//contains the accumulated values
	nodeMap.create(-1,gridSize[0],gridSize[1]);	//matrix that contains the index
			
	updated[0] = new Matrix<bool>(false,gridSize[0]+1,gridSize[1]+1); //update flags
	updated[1] = new Matrix<bool>(false,gridSize[0]+1,gridSize[1]+1); //+1, so that no border check necessary
	updated[2] = new Matrix<bool>(false,gridSize[0]+1,gridSize[1]+1);

	nodes.reserve(allocSize);
	cameFrom.reserve(allocSize);
	gScore.reserve(allocSize);
	//fScore.reserve(allocSize);

	MinHeap<FLOAT> openSet((int)(allocSize/PREALLOC_FACTOR));			//openset - priority queue
	#ifdef USE_CLOSEDSET
	Matrix<bool> closedSet(gridSize[0],gridSize[1]);	///closedset - matrix
	#endif //USE_CLOSEDSET

	////////////////////////////////////////////////////////////////////////////
	//intialize start values
	nodes.push_back(start);
	cameFrom.push_back(-1);
	FLOAT tempGS = getRealCost(start,-1);
	gScore.push_back(tempGS);
	nodeMap.set(start,nodepointer);
	openSet.push(tempGS+getHeuristicCost(start,goal),nodepointer);

	////////////////////////////////////////////////////////////////////////////
	//start iterations
	while (!openSet.empty())
	{
		//get node with lowest cost
		currentIdx = openSet.pop(); 
		current = nodes[currentIdx];

		//check if we are at goal
		if (current==goal) {
			break;
		}

		#ifdef USE_CLOSEDSET
		///add to closed set
		closedSet.set(current,1);
		#endif //USE_CLOSEDSET
			
		//evaluate each neighbor
		for (i=0;i<3;i++)
		{
			neighbor = current + move[i];

			//border check
			if ((neighbor.first >= gridSize[0]) || (neighbor.second >= gridSize[1])){
				continue;
			}

			//check mask
			if (useMask) {
				if (mask.get(neighbor)==0) {
					continue;
				}
			}

			#ifdef USE_CLOSEDSET
			///check closed set
			if (closedSet.get(neighbor) == 1) {
				continue; //do nothing for this neighbor
			}
			#endif //USE_CLOSEDSET
			neighborIdx = nodeMap.get(neighbor);
 			tentativeScore = getRealCost(neighbor,neighborIdx);

			if (neighborIdx == -1) //unwalked coordinates - not in the openlist
			{
				nodepointer++,
				neighborIdx = nodepointer;
				nodeMap.set(neighbor,neighborIdx);	
				nodes.push_back(neighbor);
				cameFrom.push_back(currentIdx);                          
				gScore.push_back(tentativeScore);

				cout << "\r" << nodepointer+1 << " Blocks of maximal " <<gridElements<< " calculated";

				//add to openlist
				openSet.push(tentativeScore + getHeuristicCost(neighbor, goal),neighborIdx);
			}
			else if (tentativeScore < gScore[neighborIdx]) //new value is better than old one
			{
				nodes[neighborIdx] = neighbor;
				cameFrom[neighborIdx] = currentIdx;                          
				gScore[neighborIdx] = tentativeScore;

				//update value in openlist
				openSet.push(tentativeScore + getHeuristicCost(neighbor, goal),neighborIdx);           
			}
		}


	}
	
	cout <<  "\r" << nodepointer+1 << " Blocks of maximal " <<gridElements<< " calculated\n";
	LOG_totalBlocks = gridElements;
	LOG_calcBlocks = nodepointer+1;

	////////////////////////////////////////////////////////////////////////////
	//Backtrack

	vector<point> path = backtrack();
	return path;
};