void OpenSteer::PolylineSegmentedPath::movePoints( size_type startIndex, size_type numOfPoints, Vec3 const newPoints[] ) { assert( ( startIndex < ( pointCount() - ( isCyclic() ? 1 : 0 ) ) ) && "startIndex must be inside index range." ); assert( ( ( startIndex + numOfPoints ) <= ( pointCount() - ( isCyclic() ? 1 : 0 ) ) ) && "The max. index of a point to set must be inside the index range." ); // Update the point positions. // @todo Remove this line size_type const pathPointCount = pointCount(); for ( size_type i = 0; i < numOfPoints; ++i ) { points_[ startIndex + i ] = newPoints[ i ]; } // If the first point is changed and the path is cyclic also change the // last point, which is just a copy of the first point. if ( isCyclic() && ( 0 == startIndex ) ) { points_.back() = points_.front(); } // Recalculate the tangents and lengths. updateTangentsAndLengths( points_, segmentTangents_, segmentLengths_, startIndex, numOfPoints, isCyclic() ); assert( adjacentPathPointsDifferent( points_.begin(), points_.end(), isCyclic() ) && "Adjacent path points must be different." ); }
std::string Problem061::get_answer() { std::vector<unsigned int> triangleNumbers, squareNumbers, pentagonalNumbers, hexagonalNumbers, heptagonalNumbers, octagonalNumbers; for (unsigned int i = 1000; i <= 9999; ++i) { if (isNgonal(3, i)) triangleNumbers.push_back(i); if (isNgonal(4, i)) squareNumbers.push_back(i); if (isNgonal(5, i)) pentagonalNumbers.push_back(i); if (isNgonal(6, i)) hexagonalNumbers.push_back(i); if (isNgonal(7, i)) heptagonalNumbers.push_back(i); if (isNgonal(8, i)) octagonalNumbers.push_back(i); } std::vector<std::vector<unsigned int>> typeLists = {triangleNumbers, squareNumbers, pentagonalNumbers, hexagonalNumbers, heptagonalNumbers}; for (auto &x1 : typeLists) { for (auto &val1 : octagonalNumbers) { for (auto &val2 : x1) { if (!this->isCyclic(val1, val2)) continue; for (auto &x2 : typeLists) { if (x2 == x1) continue; for (auto &val3 : x2) { if (!isCyclic(val2, val3)) continue; for (auto &x3 : typeLists) { if (x3 == x2 || x2 == x1) continue; for (auto &val4 : x3) { if (!isCyclic(val3, val4)) continue; for (auto &x4 : typeLists) { if (x4 == x3 || x4 == x2 || x4 == x1) continue; for (auto &val5 : x4) { if (!isCyclic(val4, val5)) continue; for (auto &x5 : typeLists) { if (x5 == x4 || x5 == x3 || x5 == x2 || x5 == x1) continue; for (auto &val6 : x5) { if (!isCyclic(val5, val6) || !isCyclic(val6, val1)) continue; int answer = val1 + val2 + val3 + val4 + val5 + val6; return std::to_string(answer); } } } } } } } } } } } return ""; }
int32 MoveSpline::currentPathIdx() const { int32 point = point_Idx_offset + point_Idx - spline.first() + (int)Finalized(); if (isCyclic()) point = point % (spline.last()-spline.first()); return point; }
//All cycle check function //Check cycle exist on graphs with connected componentsd bool Cyclic::isCyclic(bool connected_flag){ bool return_value=false ; int size=countConnected(); for(size_t index=0;index<size;index++){ return_value=return_value||isCyclic(bfs_roots[index]); } return return_value; }
LayoutSpringRefPtr SpringLayout::getDecycledSpring(LayoutSpringRefPtr s) const { if(isCyclic(s)) { return _CyclicDummySpring; } else { return s; } }
static Edge getNextEdge(Edge* e, int size, int current){ // Tant que nous n'avons pas testés toutes les arêtes while (caseActuelleEnsemble<tailleEnsemble){ // Si l'ajout d'une nouvelle arête ne fait pas de cycle if (!isCyclic(e, current, size, 10, ensemble[caseActuelleEnsemble])){ // On fournit l'arête qui est considérée comme correcte caseActuelleEnsemble++; return ensemble[caseActuelleEnsemble-1]; } caseActuelleEnsemble++; } return NULL; }
int DL_detect::detect_cycle(uint64_t txnid) { if (g_no_dl) return 0; uint64_t starttime = get_sys_clock(); INC_GLOB_STATS(cycle_detect, 1); bool deadlock = false; int thd = get_thdid_from_txnid(txnid); DetectData * detect_data = (DetectData *) mem_allocator.alloc(sizeof(DetectData), thd); detect_data->visited = (bool * ) mem_allocator.alloc(sizeof(bool) * V, thd); detect_data->recStack = (bool * ) mem_allocator.alloc(sizeof(bool) * V, thd); for(int i = 0; i < V; i++) { detect_data->visited[i] = false; detect_data->recStack[i] = false; } detect_data->min_lock_num = 1000; detect_data->min_txnid = -1; detect_data->loop = false; if ( isCyclic(txnid, detect_data) ){ deadlock = true; INC_GLOB_STATS(deadlock, 1); int thd_to_abort = get_thdid_from_txnid(detect_data->min_txnid); if (dependency[thd_to_abort].txnid == (SInt64) detect_data->min_txnid) { txn_man * txn = glob_manager->get_txn_man(thd_to_abort); txn->lock_abort = true; } } mem_allocator.free(detect_data->visited, sizeof(bool)*V); mem_allocator.free(detect_data->recStack, sizeof(bool)*V); mem_allocator.free(detect_data, sizeof(DetectData)); uint64_t timespan = get_sys_clock() - starttime; INC_GLOB_STATS(dl_detect_time, timespan); if (deadlock) return 1; else return 0; }
void aiContext::getTimeSampling(int i, aiTimeSamplingData& dst) { auto ts = m_archive.getTimeSampling(i); auto tst = ts->getTimeSamplingType(); dst.numTimes = (int)ts->getNumStoredTimes(); if (tst.isUniform() || tst.isCyclic()) { int numCycles = int(m_archive.getMaxNumSamplesForTimeSamplingIndex(i) / tst.getNumSamplesPerCycle()); dst.type = tst.isUniform() ? aiTimeSamplingType_Uniform : aiTimeSamplingType_Cyclic; dst.interval = (float)tst.getTimePerCycle(); dst.startTime = (float)ts->getStoredTimes()[0]; dst.endTime = dst.startTime + dst.interval * (numCycles - 1); dst.numTimes = (int)ts->getNumStoredTimes(); dst.times = const_cast<double*>(&ts->getStoredTimes()[0]); } else if (tst.isAcyclic()) { dst.type = aiTimeSamplingType_Acyclic; dst.startTime = (float)ts->getSampleTime(0); dst.endTime = (float)ts->getSampleTime(ts->getNumStoredTimes() - 1); dst.numTimes = (int)ts->getNumStoredTimes(); dst.times = const_cast<double*>(&ts->getStoredTimes()[0]); } }
int main() { Graph *graph = Graph::create(9); graph_info info; info.source = 0; info.destination = 0; graph->addEdge(0, 1, 4); graph->addEdge(0, 7, 8); graph->addEdge(1, 2, 8); graph->addEdge(1, 7, 11); graph->addEdge(2, 3, 7); graph->addEdge(2, 8, 2); graph->addEdge(2, 5, 4); graph->addEdge(3, 4, 9); graph->addEdge(3, 5, 14); graph->addEdge(4, 5, 10); graph->addEdge(5, 6, 2); graph->addEdge(6, 7, 1); graph->addEdge(6, 8, 6); graph->addEdge(7, 8, 7); // DFS LOG("======== DFS start========"); DFS *dfs = DFS::create(graph, info); dfs->compute(); delete(dfs); LOG("======== DFS end========"); // BFS LOG("======== BFS start========"); BFS *bfs = BFS::create(graph, info); bfs->compute(); delete(bfs); LOG("======== BFS end========"); // dijkstra LOG("======== dijkstra start========"); dijkstra *dijkstra = dijkstra::create(graph, info); dijkstra->compute(); delete(bfs); LOG("======== dijkstra end========"); // PrimMST LOG("======== PrimMST start========"); PrimMST *prim = PrimMST::create(graph, info); prim->compute(); delete(prim); LOG("======== PrimMST end========"); // BellmanFord LOG("======== BellmanFord start========"); BellmanFord *bellman_ford = BellmanFord::create(graph, info); bellman_ford->compute(); delete(bellman_ford); LOG("======== BellmanFord end========"); // ShortestPath LOG("======== ShortestPath start========"); ShortestPath *shortest_path = ShortestPath::create(graph, info); shortest_path->compute(); delete(shortest_path); LOG("======== ShortestPath end========"); // Detect Cycle LOG("======== Detect Cycle start========"); isCyclic(graph, info); LOG("======== Detect Cycle end========"); // Detect Cycle using Disjoint set LOG("======== Detect Cycle using Disjoint set start========"); LOG(isCyclicUsingDisjointSet(graph, info)); LOG("======== Detect Cycle using Disjoint set end========"); // Graph Coloring LOG("======== Graph Coloring start========"); GraphColoring *graph_color = GraphColoring::create(graph, info); graph_color->color(); graph_color->print(); LOG("======== Graph Coloring end========"); // Hamilton Cycle LOG("======== Hamilton Cycle start========"); HamiltonCycle *hamiton = HamiltonCycle::create(graph, info); hamiton->checkHamiltonCycle(); LOG("======== Hamilton Cycle end========"); delete graph; // Directed Graph graph = Graph::create(6); graph->addDirectedEdge(0, 1); graph->addDirectedEdge(0, 5); graph->addDirectedEdge(1, 2); graph->addDirectedEdge(1, 3); graph->addDirectedEdge(1, 4); graph->addDirectedEdge(2, 3); graph->addDirectedEdge(2, 4); graph->addDirectedEdge(3, 4); graph->addDirectedEdge(5, 2); LOG("======== Topological Sort start========"); TopologicalSort *tsort = TopologicalSort::create(graph, info); tsort->sort(); tsort->print(); LOG("======== Topological Sort end========"); return 0; }