void AlgMultiArranque::recuperarCentroides () { for (unsigned int i = 0; i < getClusters().size(); ++i) { for (int j = 0; j < getDimension(); ++j) { getClusters()[i]->getCaracteristicas()[j] = _centroidesFin[i][j]; } } }
//kernel code identification int kdi(unsigned startVirtualAddr, Mem * mem, int pageSize, unsigned cr3Pages[], int *kdi_time, int *allPages) { struct timeval earlier; struct timeval later; if (gettimeofday(&earlier, NULL)) { perror("gettimeofday() error"); exit(1); } //generate step 1 clusters unsigned cluster_index = getClusters(startVirtualAddr, mem, pageSize, allPages); print_clusters(cluster_index); findKernelCodePageByCr3(startVirtualAddr, mem, pageSize, cr3Pages); if (gettimeofday(&later, NULL)) { perror("gettimeofday() error"); exit(1); } (*kdi_time) = timeval_diff(NULL, &later, &earlier) / 1000; printf ("step1,all pages: %d, cluster: %d,kdi time cost is %d milliseconds\n", *allPages, cluster_index, (*kdi_time)); return cluster_index; }
AlgMultiArranque::AlgMultiArranque(vector<Cluster*>& clusters, vector<Objeto*>& objetos) { setNombreAlgoritmo(" Técnica MultiArranque "); setObjetos(objetos); setClusters(clusters); setDimension(getClusters()[0]->getDimension()); int* sol = new int [getObjetos().size()]; _solActual = new int [getObjetos().size()]; _mejorSol = new int [getObjetos().size()]; for (unsigned int i = 0; i < getObjetos().size(); ++i) { sol[i] = -1; } setSolucion(sol); delete [] sol; _tecnicaLocal = NULL; _centroidesFin = new int *[getClusters().size()]; for (unsigned int i = 0; i < getClusters().size(); ++i) _centroidesFin[i] = new int[getDimension()]; }
std::vector<Database::IdType> getSimilarTracks(Wt::Dbo::Session& session, const std::set<Database::IdType>& trackIds, std::size_t maxCount) { std::vector<Database::IdType> res; Wt::Dbo::Transaction transaction(session); std::vector<Database::IdType> clusterIds; for (auto trackId : trackIds) { auto track = Database::Track::getById(session, trackId); if (!track) continue; auto clusters = track->getClusters(); if (clusters.empty()) continue; for (const auto& cluster : clusters) clusterIds.push_back(cluster.id()); } std::vector<Database::IdType> sortedClusterIds; uniqueAndSortedByOccurence(clusterIds.begin(), clusterIds.end(), std::back_inserter(sortedClusterIds)); for (auto clusterId : clusterIds) { auto cluster = Database::Cluster::getById(session, clusterId); if (!cluster) continue; std::set<Database::IdType> clusterTrackIds = cluster->getTrackIds(); std::set<Database::IdType> candidateTrackIds; std::set_difference(clusterTrackIds.begin(), clusterTrackIds.end(), trackIds.begin(), trackIds.end(), std::inserter(candidateTrackIds, candidateTrackIds.end())); if (candidateTrackIds.empty()) continue; for (auto trackId : candidateTrackIds) { if (res.size() >= maxCount) break; res.push_back(trackId); } if (res.size() >= maxCount) break; } return res; }
int* AlgMultiArranque::busquedaLocal (enum TIPO_TECN_LOCAL tipo) { int* resultado = NULL; switch (tipo) { case VORAZ: if (_tecnicaLocal) delete _tecnicaLocal; _tecnicaLocal = new AlgVoraz(getClusters().size(), getObjetos()); _tecnicaLocal->ejecutarAgrupamiento(); resultado = _tecnicaLocal->getSolucion(); break; case GRASP: if (_tecnicaLocal) delete _tecnicaLocal; _tecnicaLocal = new AlgGRASP(getClusters(), getObjetos(), 2); // Nº candidatos LRC !! _tecnicaLocal->ejecutarAgrupamiento(); resultado = _tecnicaLocal->getSolucion(); break; /* IGNORAR */ case GRAVITACION: if (_tecnicaLocal) delete _tecnicaLocal; _tecnicaLocal = new AlgGravitacion (getClusters(), getObjetos()); _tecnicaLocal->ejecutarAgrupamiento(); resultado = _tecnicaLocal->getSolucion(); break; /* IGNORAR */ default: cerr << "ERROR: ASIGNE UN TIPO DE TÉCNICA COMO BÚSQUEDA LOCAL!!" << endl; } return resultado; }
void AlgMultiArranque::ejecutarAgrupamiento () { int contadorMejora = 0, tipo = 0; double desvMejor = 0.0; TIPO_TECN_LOCAL tecnicaLocal; cout << " Elija técnica local: 0 = LOCAL VORAZ, 1 = LOCAL GRASP " << endl; cin >> tipo; tecnicaLocal = (TIPO_TECN_LOCAL) tipo; // ****** Inicialización ****** generarCentroides(); _solActual = busquedaLocal(tecnicaLocal); desvMejor = calcularDesvAgrup(_solActual); guardarCentroides (getClusters()); copiarSolucion (_solActual, _mejorSol); // origen, destino // ****** Procedimiento MultiArranque ****** do { _solActual = busquedaLocal(tecnicaLocal); if (calcularDesvAgrup(_solActual) < desvMejor) { desvMejor = calcularDesvAgrup(_solActual); copiarSolucion(_solActual, _mejorSol); contadorMejora = 0; guardarCentroides(getClusters()); } ++contadorMejora; generarCentroides(); } while (hayMejora(contadorMejora)); // ****** Asignación de soluciones ****** setSolucion(_mejorSol); // Asigne la sol. global del problema recuperarCentroides (); // Recupera los centroides de la solución que mejoró la actual mejor asignarClusters (); // Asigne a cada objeto su clasificación final }
vector<vector<int> > kmeansModule::clusterData(float** data, int M, vector<int>& pts) { clusterMemberships = vector<int>(pts.size(),-1); for (int i = 1; i < maxIt; i++) { bool change = computeClustMemberships(data, M, pts); computeCentroids(data, M, pts); if (!change) break; } //check and fix degenerate clusters handleDegenerateClusters(); return getClusters(data, M, pts); }
void HpaMap::draw() { for (size_t i = 0; i < getClusters().count(); ++i) { const fdkgame::findpath::HpaCluster& cluster = *getClusters().raw_data()[i]; CellCoord topLeftCellCoord; topLeftCellCoord.x = cluster.getClusterCoord().x*getMaxClusterSize().x; topLeftCellCoord.y = cluster.getClusterCoord().y*getMaxClusterSize().y; g_HGE.FrameRect(topLeftCellCoord.x*CELL_SIZE_X, topLeftCellCoord.y*CELL_SIZE_Y, (topLeftCellCoord.x+cluster.getRange().width())*CELL_SIZE_X, (topLeftCellCoord.y+cluster.getRange().height())*CELL_SIZE_Y, ARGB(255, 45, 151, 128), 2); } const AbstractGraph::Nodes& nodes = getAbstractGraph().getNodes(); for (AbstractGraph::Nodes::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { const AbstractNode* node = *it; if (node->getInfo().lowLevelNodeID == getLowLevelMap().toNodeID(g_Game.getStartCoord()) || node->getInfo().lowLevelNodeID == getLowLevelMap().toNodeID(g_Game.getTargetCoord())) { continue; } CellCoord cellCoord = getLowLevelMap().toNodeCoord(node->getInfo().lowLevelNodeID); util::fillCell(cellCoord, ARGB(255, 210, 248, 207)); if (g_Option.isOn(Option::Toggle_ShowPortID)) { g_Font.printf(cellCoord.x*CELL_SIZE_X+2, cellCoord.y*CELL_SIZE_Y+2, HGETEXT_LEFT, "%d", node->getID()); } } const AbstractGraph::Edges& edges = getAbstractGraph().getEdges(); for (AbstractGraph::Edges::const_iterator it = edges.begin(); it != edges.end(); ++it) { const AbstractEdge* edge = *it; if (edge->getInfo().bIntra && !g_Option.isOn(Option::Toggle_ShowIntraEdge)) { continue; } CellCoord startCellCoord = getLowLevelMap().toNodeCoord(edge->getStartNode().getInfo().lowLevelNodeID); CellCoord targetCellCoord = getLowLevelMap().toNodeCoord(edge->getTargetNode().getInfo().lowLevelNodeID); g_HGE->Gfx_RenderLine( startCellCoord.x*CELL_SIZE_X+CELL_SIZE_X/2, startCellCoord.y*CELL_SIZE_X+CELL_SIZE_X/2, targetCellCoord.x*CELL_SIZE_X+CELL_SIZE_X/2, targetCellCoord.y*CELL_SIZE_X+CELL_SIZE_X/2, ARGB(255, 57, 92, 145) ); } if (g_Option.isOn(Option::Toggle_ShowIntraEdge)) { g_Font.printf(20, 20, HGETEXT_LEFT, "total edges: %d", edges.size()); } if (g_Option.isOn(Option::Toggle_ShowClusterCoord)) { for (size_t i = 0; i < getClusters().count(); ++i) { const fdkgame::findpath::HpaCluster& cluster = *getClusters().raw_data()[i]; CellCoord topLeftCellCoord; topLeftCellCoord.x = cluster.getClusterCoord().x*getMaxClusterSize().x; topLeftCellCoord.y = cluster.getClusterCoord().y*getMaxClusterSize().y; g_Font.printf(topLeftCellCoord.x*CELL_SIZE_X+2, topLeftCellCoord.y*CELL_SIZE_Y+2, HGETEXT_LEFT, "%d,%d", cluster.getClusterCoord().x, cluster.getClusterCoord().y); } } }
/// post construction initialization to perform before simulation void TileNew::PreSimInit() { for(int cluster = 0; cluster < rigel::CLUSTERS_PER_TILE; cluster++) { getClusters()[cluster]->getProfiler()->start_sim(); } };
void AlgMultiArranque::generarCentroides () { for (unsigned int i = 0; i < getClusters().size(); ++i) { for (int j = 0; j < getClusters()[i]->getDimension(); ++j) getClusters()[i]->getCaracteristicas()[j] = rand () % 10; } }