unsigned ClusterAlg::getDist(ClusterAlg* other) { // construct graph MGraph<ClusterAlg*, unsigned> *graph (constructGraph ( other )); // calc dist if (graph) { unsigned dist; if (graph->isGraphConnected ()) { dist = graph->getDist( this, other ); } else { delete graph; graph = constructGraph (other, 1); if (graph) { if (graph->isGraphConnected ()) dist = graph->getDist( this, other ); else { delete graph; graph = constructGraph (other, 2); if (graph) { if (graph->isGraphConnected ()) dist = graph->getDist( this, other ); else { delete graph; graph = constructGraph (other, 3); if (graph) { if (graph->isGraphConnected ()) dist = graph->getDist( this, other ); else { delete graph; graph = constructGraph (other, 4); if (graph) { if (graph->isGraphConnected ()) dist = graph->getDist( this, other ); else { delete graph; graph = NULL; dist = std::numeric_limits<unsigned>::max(); } } } } } } } } } // tidy up if (graph) delete graph; return dist; } return 0; }
int main(int argc, char** argv) { if (argc==1) { constructGraph(5, 2); return (EXIT_SUCCESS); } else if (argc==3) { int n = atoi(argv[1]); int k = atoi(argv[2]); constructGraph(n, k); return (EXIT_SUCCESS); } else { fprintf(stderr,"%s [n k]\n",argv[0]); return EXIT_FAILURE; } }
vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) { vector<int> courses; if (numCourses <= 0) { return courses; } vector<DirectedGraphNode*> nodes = constructGraph(numCourses, prerequisites); queue<DirectedGraphNode*> q; for (int i = 0; i < nodes.size(); i++) { if (nodes[i]->indegree == 0) { q.push(nodes[i]); } } while (!q.empty()) { DirectedGraphNode* node = q.front(); q.pop(); courses.push_back(node->label); for (const auto& neighbor: node->neighbors) { nodes[neighbor]->indegree--; if (nodes[neighbor]->indegree == 0) { q.push(nodes[neighbor]); } } } if (courses.size() != numCourses) { return vector<int>(); } return courses; }
int main(int argc, char** argv) { if (argc==2) { int order = atoi(argv[1]); constructGraph(order); return (EXIT_SUCCESS); } else { fprintf(stderr,"%s n\n",argv[0]); return EXIT_FAILURE; } }
int main(int argc, char** argv) { if (argc==3) { int vertices = atoi(argv[1]); int edgeMultiplicity = atoi(argv[2]); constructGraph(vertices, edgeMultiplicity); return (EXIT_SUCCESS); } else { fprintf(stderr,"%s n m\n",argv[0]); return EXIT_FAILURE; } }
int main(int argc, char** argv) { if (argc==3) { int internalDegree = atoi(argv[1]); int depth = atoi(argv[2]); constructGraph(internalDegree, depth); return (EXIT_SUCCESS); } else { fprintf(stderr,"%s degree depth\n",argv[0]); return EXIT_FAILURE; } }
//============================================================================== void UGenPlugin::prepareToPlay (double sampleRate, int samplesPerBlock) { // do your pre-playback setup stuff here.. // create filters here... for example since we now have the sample rate UGen::prepareToPlay(sampleRate, samplesPerBlock); inputBuffer = Buffer::newClear(samplesPerBlock, getNumInputChannels(), true); int numChannels = getNumInputChannels(); DBG(String("numChannels = ")+String(numChannels)); inputUGen = AudioIn::AR(numChannels);//getNumInputChannels()); outputUGen = constructGraph(inputUGen); }
void PlannerPRM::initialize(Sampler* sampler_, const RoboCompCommonBehavior::ParameterList ¶ms) { sampler = sampler_; //////////////////////// /// Initialize RRTplaner //////////////////////// plannerRRT.initialize(sampler); //////////////////////// /// Check if graph already exists //////////////////////// if( QFile(graphFileName).exists()) { qDebug() << __FUNCTION__ << "Graph file exits. Loading"; readGraphFromFile(graphFileName); } else { try { nPointsInGraph = std::stoi(params.at("PlannerGraphPoints").value); nNeighboursInGraph = std::stoi(params.at("PlannerGraphNeighbours").value); maxDistToSearchmm = std::stof(params.at("PlannerGraphMaxDistanceToSearch").value); robotRadiusmm = std::stof(params.at("RobotRadius").value); } catch(...) { qFatal("Planner-Initialize. Aborting. Some Planner graph parameters not found in config file"); } qDebug() << __FUNCTION__ << "No graph file found. Creating with " << nPointsInGraph << "nodes and " << nNeighboursInGraph << "neighboors"; QList<QVec> pointList = sampler->sampleFreeSpaceR2(nPointsInGraph); if( pointList.size() < nNeighboursInGraph ) qFatal("Planner-Initialize. Aborting. Could not find enough free points to build de graph"); qDebug() << __FUNCTION__ << "Creating with " << nPointsInGraph << "nodes and " << nNeighboursInGraph << "neighboors"; constructGraph(pointList, nNeighboursInGraph, maxDistToSearchmm, robotRadiusmm); ///GET From IM ---------------------------------- qDebug() << __FUNCTION__ << "Graph constructed with " << pointList.size() << "points"; writeGraphToFile(graphFileName); } graphDirtyBit = true; }
static PyObject *maxflow(PyObject *self, PyObject *args) { PyObject *edges; int numVertices; FlowGraph graph; float maxflowVal; if(!PyArg_ParseTuple(args, "Oi", &edges, &numVertices)) return NULL; if(!PyList_Check(edges)) return NULL; graph = constructGraph(edges, numVertices); Py_BEGIN_ALLOW_THREADS maxflowVal = Graph_maxflow(graph); Py_END_ALLOW_THREADS copyFlowsToPython(graph, edges); Graph_free(graph); return Py_BuildValue("f", maxflowVal); }
FactorGraph* BayesBall::getMinimalFactorGraph (const VarIds& queryIds) { assert (fg_.bayesianFactors()); Scheduling scheduling; for (size_t i = 0; i < queryIds.size(); i++) { assert (dag_.getNode (queryIds[i])); BBNode* n = dag_.getNode (queryIds[i]); scheduling.push (ScheduleInfo (n, false, true)); } while (!scheduling.empty()) { ScheduleInfo& sch = scheduling.front(); BBNode* n = sch.node; n->setAsVisited(); if (n->hasEvidence() == false && sch.visitedFromChild) { if (n->isMarkedAbove() == false) { n->markAbove(); scheduleParents (n, scheduling); } if (n->isMarkedBelow() == false) { n->markBelow(); scheduleChilds (n, scheduling); } } if (sch.visitedFromParent) { if (n->hasEvidence() && n->isMarkedAbove() == false) { n->markAbove(); scheduleParents (n, scheduling); } if (n->hasEvidence() == false && n->isMarkedBelow() == false) { n->markBelow(); scheduleChilds (n, scheduling); } } scheduling.pop(); } FactorGraph* fg = new FactorGraph(); constructGraph (fg); return fg; }
vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) { vector<int> courses(numCourses, -1); if (numCourses <= 0) { return courses; } vector<DirectedGraphNode*> nodes = constructGraph(numCourses, prerequisites); vector<int> visited(numCourses, 0); current_pos = numCourses - 1; for (int i = 0; i < nodes.size(); i++) { DirectedGraphNode* node = nodes[i]; if (visited[node->label] == 0) { if (DFS(nodes, visited, node, courses) == false) { return vector<int>(); } } } return courses; }
int main(int argc, char *argv[]) { if(argc != 5) { cout << "Not enough parameters" << endl; return -1; } const string videoLocation = argv[1]; const string outputLocation = argv[2]; const string haarCascadeXML = argv[3]; const string finalFacesLocation = argv[4]; // Extract faces from the movie // extractFaces(videoLocation, outputLocation, haarCascadeXML); // Filter faces in a given range of size and make them of same size //filterFaces(finalFacesLocation); // Pose alignment of the faces // Build the list of all selected faces //buildListOfSelectedFaces(finalFacesLocation); // Build the graph out of all the facesBuildListOfSelectedFaces.cpp constructGraph(outputLocation); // Find the interesting routes to come up with interesting sequences // Stage 2: Build a cube out of one particular expression sequence and find how another actor looks if he gives similar sort of sequence of expressions waitKey(50); return 0; }
unsigned ClusterAlg::getDist(ClusterAlg* other) { // construct graph MGraph<ClusterAlg*, unsigned> *graph (constructGraph ( other )); // compute path(s) std::list<ClusterAlg*> path0, path1, path2; unsigned dist0 (graph->getPathsAndDist ( this, other, path0, path1, path2 )); unsigned dist1(std::numeric_limits<unsigned>::max()), dist2(dist1), tmp_dist; delete graph; // *** first level refinement // compute refined graph for path0 unsigned max_depth (depth), refine_level(3); getMaxDepth(max_depth); if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path0); // choose a new src and target node in the new graph // starting from old src and target ClusterAlg*src (*path0.begin()), *target (*(--path0.end())); getNode (refine_level, src); other->getNode (refine_level, target); // compute distance in refined graph std::list<ClusterAlg*> path00, path01, path02; tmp_dist = graph->getPathsAndDist ( src, target, path00, path01, path02 ); if (tmp_dist < dist1) dist1 = tmp_dist; // tidy up if (graph) delete graph; // *** second level refinement // *** refinement path p00 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3) { refine_level += depth; graph = constructRefinedGraph(refine_level, path00); // choose a new src and target node in the new graph // starting from old src and target src = *path00.begin(); target = *(--path00.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path000, path001, path002; tmp_dist = graph->getPathsAndDist ( src, target, path000, path001, path002 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p01 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path01.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path01); // choose a new src and target node in the new graph // starting from old src and target src = *path01.begin(); target = *(--path01.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path010, path011, path012; tmp_dist = graph->getPathsAndDist ( src, target, path010, path011, path012 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p02 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path02.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path02); // choose a new src and target node in the new graph // starting from old src and target src = *path02.begin(); target = *(--path02.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path020, path021, path022; tmp_dist = graph->getPathsAndDist ( src, target, path020, path021, path022 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } } // *** first level refinement // compute refined graph for path1 refine_level=3; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && path1.size() > 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path1); // choose a new src and target node in the new graph // starting from old src and target ClusterAlg *src (*path1.begin()), *target (*(--path1.end())); other->getNode (refine_level, target); getNode (refine_level, src); // std::cout << "\033[32m |p1| " << dist << " \033[0m" << std::flush; // compute distance in refined graph std::list<ClusterAlg*> path10, path11, path12; tmp_dist = graph->getPathsAndDist ( src, target, path10, path11, path12 ); if (tmp_dist < dist1) dist1 = tmp_dist; // tidy up if (graph) delete graph; // *** second level refinement // *** refinement path p10 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3) { refine_level += depth; graph = constructRefinedGraph (refine_level, path10); // choose a new src and target node in the new graph // starting from old src and target src = *path10.begin(); target = *(--path10.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path100, path101, path102; tmp_dist = graph->getPathsAndDist ( src, target, path100, path101, path102 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p11 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path11.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path11); // choose a new src and target node in the new graph // starting from old src and target src = *path11.begin(); target = *(--path11.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path110, path111, path112; tmp_dist = graph->getPathsAndDist ( src, target, path110, path111, path112 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p12 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path12.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path12); // choose a new src and target node in the new graph // starting from old src and target src = *path12.begin(); target = *(--path12.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path120, path121, path122; tmp_dist = graph->getPathsAndDist ( src, target, path120, path121, path122 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } } // *** first level refinement // compute refined graph for path2 refine_level=3; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && path2.size() > 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path2); // choose a new src and target node in the new graph // starting from old src and target ClusterAlg *src (*path2.begin()), *target (*(--path2.end())); other->getNode (refine_level, target); getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path20, path21, path22; tmp_dist = graph->getPathsAndDist ( src, target, path20, path21, path22 ); if (tmp_dist < dist1) dist1 = tmp_dist; // tidy up if (graph) delete graph; // *** second level refinement // *** refinement path p20 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3) { refine_level += depth; graph = constructRefinedGraph (refine_level, path20); // choose a new src and target node in the new graph // starting from old src and target src = *path20.begin(); target = *(--path20.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path200, path201, path202; tmp_dist = graph->getPathsAndDist ( src, target, path200, path201, path202 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p21 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path21.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path21); // choose a new src and target node in the new graph // starting from old src and target src = *path21.begin(); target = *(--path21.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path210, path211, path212; tmp_dist = graph->getPathsAndDist ( src, target, path210, path211, path212 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } // *** refinement path p22 refine_level=6; if (max_depth - depth < refine_level) refine_level = max_depth - depth; if (refine_level != 0 && refine_level > 3 && path22.size() != 0) { refine_level += depth; graph = constructRefinedGraph (refine_level, path22); // choose a new src and target node in the new graph // starting from old src and target src = *path22.begin(); target = *(--path22.end()); getNode (refine_level, target); other->getNode (refine_level, src); // compute distance in refined graph std::list<ClusterAlg*> path220, path221, path222; tmp_dist = graph->getPathsAndDist ( src, target, path220, path221, path222 ); if (tmp_dist < dist2) dist2 = tmp_dist; // tidy up if (graph) delete graph; } } if (dist2 < std::numeric_limits<unsigned>::max()) return dist2; if (dist1 < std::numeric_limits<unsigned>::max()) return dist1; return dist0; }