void FlatUCBMod::expand(Node* node, int UCTPlayer) { if (getUntriedChildren(node).size() > 0) { Node* randomNode = getRandomNode(getUntriedChildren(node)); rollout(randomNode, randomNode->currentState, randomNode->playerPlaying); } else { if (node->currentState.gameFinished()) { rollout(node, node->currentState, node->playerPlaying); } else { //createAllChildren(node); Node* randomNode = getRandomNode(node->childrenPtrs); rollout(randomNode, randomNode->currentState, randomNode->playerPlaying); } } }
void CLARANSClustering::startClustering(const ClusterMethodParameters* pParameters, Document *pDocument, ClusteringResult *pClusteringResult) { mpDocument = pDocument; mpClusteringResult = pClusteringResult; this->mpDocument->setDistanceType(pParameters->dataType); // retrieve parameters: const CLARANSParameters *pParams = (const CLARANSParameters*)(pParameters); std::cout << "CLARANS parameters: numClust = " << pParams->numClust << ", numLocal = " << pParams->numLocal << ", maxNeighbor = " << pParams->maxNeighbor << std::endl; mpClusteringResult->deleteClustering(); // delete probably old clustering result const int nSamples = this->mpDocument->nParsedImages(); const int nClusts = pParams->numClust; if (nSamples < 2) { throw NoDataException("No data found for clustering!"); } if (pParameters->dataType == FEATURES_BASED && this->mpDocument->nFeatures() < 2) { throw NoDataException("No features found for clustering!"); } // get pointer to image chars: std::vector<ImageChar*> *imageCharVecPointer = this->mpDocument->getImageCharsVecPointer(); // INITIALIZATION: // srand(time(NULL)); // FIXME!!!!!!!!!!!!! double minCost = 1e32f; minCost = 1e32f; double actCost = 0.0f; double newCost = 0.0f; std::vector<int> currentNode; getRandomNode(nSamples, nClusts, currentNode); actCost = getNodeCost(nSamples, currentNode); std::cout << "Starting node: "; printNode(currentNode); // LOOP: int j = 1; j=1; std::vector<int> neighborNode; getRandomNeighbor(nSamples, currentNode, neighborNode); // determine a random neighbor node newCost = getNodeCost(nSamples, neighborNode); std::cout << "Finished CLARANS clustering!" << std::endl; return; } // end startClustering(...)
/** * \brief Plans a path on a grid map using RRT. * \param[in] startNode The start node of the path. * \param[in] goalNode The goal node where the path should end up. * \param[in] map The occupancy grid map of the environment. * \param[in] maxIterations The maximum number of iterations. * \return The planned path, or an empty path in case the algorithm exceeds the maximum number of iterations. */ std::deque<AbstractNode *> RRT::planPath(AbstractNode * const startNode, AbstractNode * const goalNode, const GridMap& map, const size_t& maxIterations) { std::deque<AbstractNode *> result; std::vector<AbstractNode *> startList; std::vector<AbstractNode *> goalList; // Add the start and goal nodes to the corresponding lists: startList.push_back(startNode); goalList.push_back(goalNode); /* TODO: Expand trees from both the start node and the goal node at the same time * until they meet. When extendClosestNode() returns a connection node, then call * constructPath() to find the complete path and return it. */ int iter = 0; while(iter < maxIterations) { AbstractNode * Qrand; Qrand = getRandomNode(map,startList,goalList.back() ); AbstractNode * Qclosest= getClosestNodeInList(Qrand,startList); AbstractNode * Qconnection = extendClosestNode(Qrand,Qclosest,startList,map,goalList); if (Qconnection->getConnection() !=goalNode) { startList.push_back(Qconnection); startList.swap(goalList); iter++; } else { result = constructPath(Qconnection,startNode,goalNode); return result; } } return result; }