Exemple #1
0
nn *buildGraph(int a)
{
    nn *temp = new nn;
    if (root == NULL)
        root = temp;
    temp->v = a;
    temp->lchild = NULL;
    temp->parent = NULL;
    temp->rbro = NULL;
    graph[a] = temp;
    node *n = nodes[a]->next;
    if (n != NULL)
    {
        deleteNode(n->v, a);
        temp->lchild = buildGraph(n->v);
        nn *tt = temp->lchild;
        graph[n->v] = tt;
        tt->parent = temp;
        n = n->next;
        while (n != NULL)
        {
            deleteNode(n->v, a);
            tt->rbro = buildGraph(n->v);
            tt = tt->rbro;
            tt->parent = temp;
            graph[n->v] = tt;
            n = n->next;
        }
    }
    return temp;
}
Exemple #2
0
int main(int argc, char * argv[]) {
    if (argc != 2) {
        std::cerr << "Invalid number of arguments; expecting 1 for file name" << std::endl;
        exit(1);
    }

    std::ifstream input (argv[1], std::ios::in);

    Graph<int> g;

    if (!buildGraph(g, input)) {
        std::cerr << "Unable to build graph, please check graph format" << std::endl;
        exit(1);
    }

    std::list<std::set<int> > sccs = scc(g);
    std::cout << "SCC groupings:" << std::endl;
    for(auto it = sccs.begin(); it != sccs.end(); it++) {
        for(auto it_comp = (*it).begin(); it_comp != (*it).end(); it_comp++) {
            std::cout << (*it_comp) << " ";
        }
        std::cout << "\n";
    }

    return 0;
}
void EtGcSegmentRgb::segment(image<rgb> *im, image<rgb>*dest, float sigma, float c, int minSize,  std::string sortingMethod){
	EtTimer tmr;

	//smooth each color channel  
	#pragma omp parallel for
	for (int y = 0; y < imgH; y++) {
		for (int x = 0; x < imgW; x++) {
			imRef(this->r, x, y) = imRef(im, x, y).r;
			imRef(this->g, x, y) = imRef(im, x, y).g;
			imRef(this->b, x, y) = imRef(im, x, y).b;
		}
	}

	if( doPreprocess ){
	    tmr.start();

		preprocess(sigma);
	    
		tmr.stop();
		std::cout << im->width() << " " << im->height() << " Preprocess " << tmr.getElapsedTime() << endl; 
	}

    tmr.start();

	buildGraph( );

	tmr.stop();
	std::cout << im->width() << " " << im->height() << " BuildGraph " << tmr.getElapsedTime() << endl; 

    //EtGcSegment::segment( im, dest, sigma, c, minSize, sortingMethod );
	EtGcSegment::segment( dest, c, minSize, sortingMethod );
}
void FlowBasedGlobalConstraint::initStructure() {
    
    if (!hasConfigOrganized) {                
        organizeConfig();
        hasConfigOrganized = true;
    }

	if (graph == NULL) {
		size_t graphSize = GetGraphAllocatedSize();
		graph = new Graph(graphSize, arity_, wcsp->getStore());
		
		if (zeroEdges == NULL) {
			zeroEdges = new bool*[graph->size()];
			for (int i=0;i<graph->size();i++) zeroEdges[i] = new bool[graph->size()];
		}
		for (int i=0;i<graph->size();i++) {
			for (int j=0;j<graph->size();j++) {	
				zeroEdges[i][j] = false;
			}
		}
	
		buildGraph(*graph);
		cost = constructFlow(*graph);
	
	}
	
	propagate();
		
}
  FootstepPlanner::FootstepPlanner(ros::NodeHandle& nh):
    as_(nh, nh.getNamespace(),
        boost::bind(&FootstepPlanner::planCB, this, _1), false)
  {
    srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (nh);
    typename dynamic_reconfigure::Server<Config>::CallbackType f =
      boost::bind (&FootstepPlanner::configCallback, this, _1, _2);
    srv_->setCallback (f);
    pub_text_ = nh.advertise<jsk_rviz_plugins::OverlayText>(
      "text", 1, true);
    pub_close_list_ = nh.advertise<sensor_msgs::PointCloud2>(
      "close_list", 1, true);
    pub_open_list_ = nh.advertise<sensor_msgs::PointCloud2>(
      "open_list", 1, true);
    srv_project_footprint_ = nh.advertiseService(
      "project_footprint", &FootstepPlanner::projectFootPrintService, this);
    srv_project_footprint_with_local_search_ = nh.advertiseService(
      "project_footprint_with_local_search", &FootstepPlanner::projectFootPrintWithLocalSearchService, this);
    {
      boost::mutex::scoped_lock lock(mutex_);
      if (!readSuccessors(nh)) {
        return;
      }

      JSK_ROS_INFO("building graph");
      buildGraph();
      JSK_ROS_INFO("build graph done");
    }
    sub_pointcloud_model_ = nh.subscribe("pointcloud_model", 1, &FootstepPlanner::pointcloudCallback, this);
    as_.start();
  }
            void GraphSegmentationImpl::processImage(InputArray src, OutputArray dst) {

                Mat img = src.getMat();

                dst.create(img.rows, img.cols, CV_32SC1);
                Mat output = dst.getMat();
                output.setTo(0);

                // Filter graph
                Mat img_filtered;
                filter(img, img_filtered);

                // Build graph
                Edge *edges;
                int nb_edges;

                buildGraph(&edges, nb_edges, img_filtered);

                // Segment graph
                PointSet *es;

                segmentGraph(edges, nb_edges, img_filtered, &es);

                // Remove small areas
                filterSmallAreas(edges, nb_edges, es);

                // Map to final output
                finalMapping(es, output);

                free(edges);
                delete es;

            }
 string alienOrder(vector<string>& words) {
     unordered_map<char, unordered_set<char>> graph;
     unordered_map<char, int> mp;
     buildGraph(words, graph, mp);
     string res = topoSort(graph, mp);
     return res;
 }
Exemple #8
0
int main()
{
    int t;
    scanf("%d", &t);
    while (t --)
    {
        root = NULL;
        memset(nodes, NULL, sizeof(nodes));
        memset(graph, NULL, sizeof(graph));
        scanf("%d %d", &n, &q);
        n --;
        while (n --)
        {
            scanf("%d %d", &a, &b);
            insertNode(a, b);
            insertNode(b, a);
        }
        root = buildGraph(1);
        while (q --)
        {
            scanf("%d %d", &a, &b);
            printf("%d\n", find(a, b));
        }
    }
    return 0;
}
Exemple #9
0
int main() {

    int i, j, low, high, mid, value;
    scanf("%d%d%d", &machine_number, &cows_number, &process_number);
    for (i = 1; i <= machine_number + cows_number; i++) {
        for (j = 1; j <= machine_number + cows_number; j++) {
            scanf("%d", &original_map[i][j]);
            if (original_map[i][j] == 0) {
                original_map[i][j] = INF;
            }
        }
    }
    max_distance = min_distance = 0;
    floyd();
    low = min_distance;
    high = max_distance;
    while (low <= high) {
        mid = (low + high) / 2;
        buildGraph(mid);
        value = edmondsKarp();
        if (value == cows_number) {
            high = mid - 1;
        }
        else {
            low = mid + 1;
        }
    }
    printf("%d\n", low);
    return 0;
}
void EtGcSegmentGray::segment(image<unsigned char>*src, image<rgb>*dest, float sigma, float c, int minSize,  std::string sortingMethod){
	EtTimer tmr;

	//smooth each color channel  
	#pragma omp parallel for
	for (int y = 0; y < imgH; y++) {
		for (int x = 0; x < imgW; x++) {
			img->access[y][x] = src->access[y][x];
		}
	}

	if( doPreprocess ){
	    tmr.start();

		preprocess(sigma);
	    
		tmr.stop();
		std::cout << src->width() << " " << src->height() << " Preprocess " << tmr.getElapsedTime() << endl; 
	}

    tmr.start();

	buildGraph( );

	tmr.stop();
	std::cout << src->width() << " " << src->height() << " BuildGraph " << tmr.getElapsedTime() << endl; 

//	EtGcSegment::segment( src, dest, sigma, c, minSize, sortingMethod );
	EtGcSegment::segment( dest, c, minSize, sortingMethod );
}
Exemple #11
0
void ompl::control::Syclop::setup()
{
    base::Planner::setup();
    if (!leadComputeFn)
        setLeadComputeFn(boost::bind(&ompl::control::Syclop::defaultComputeLead, this, _1, _2, _3));
    buildGraph();
    addEdgeCostFactor(boost::bind(&ompl::control::Syclop::defaultEdgeCost, this, _1, _2));
}
PluginDependencyGraph PluginDependencyGraphBuilder::applyFilters(
    const std::map<QString, PluginMetadata> &plugins, std::vector<PluginFilter> filters) const
{
    auto currentPlugins = plugins;
    for (auto filter : filters)
        currentPlugins = applyFilter(currentPlugins, filter);
    return buildGraph(currentPlugins);
}
Exemple #13
0
int test_NarratorEquality(QString)
{
	fillRanks();
	buildGraph(chains);
	NarratorGraph graph(chains);
	NarratorNodeVisitor visitor;
	graph.traverse(visitor);
	return 0;
}
Exemple #14
0
	void CGraphLayeredExt::setGraph(const Mat &potBase, const Mat &potOccl)
	{
		// Assertions
        DGM_ASSERT(!potBase.empty());
		DGM_ASSERT(CV_32F == potBase.depth());
		if (!potOccl.empty()) {
			DGM_ASSERT(potBase.size() == potOccl.size());
			DGM_ASSERT(CV_32F == potOccl.depth());
		}
        if (m_size != potBase.size()) buildGraph(potBase.size());     
        DGM_ASSERT(m_size.height == potBase.rows);
        DGM_ASSERT(m_size.width == potBase.cols);
        DGM_ASSERT(m_size.width * m_size.height * m_nLayers == m_graph.getNumNodes());

		byte nStatesBase = static_cast<byte>(potBase.channels());
		byte nStatesOccl = potOccl.empty() ? 0 : static_cast<byte>(potOccl.channels());
		if (m_nLayers >= 2) DGM_ASSERT(nStatesOccl);
		DGM_ASSERT(nStatesBase + nStatesOccl == m_graph.getNumStates());

#ifdef ENABLE_PPL
		concurrency::parallel_for(0, m_size.height, [&, nStatesBase, nStatesOccl](int y) {
			Mat nPotBase(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
			Mat nPotOccl(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
			Mat nPotIntr(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
			for (byte s = 0; s < nStatesOccl; s++)
				nPotIntr.at<float>(m_graph.getNumStates() - nStatesOccl + s, 0) = 100.0f / nStatesOccl;
#else
		Mat nPotBase(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
		Mat nPotOccl(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
		Mat nPotIntr(m_graph.getNumStates(), 1, CV_32FC1, Scalar(0.0f));
		for (byte s = 0; s < nStatesOccl; s++) 
			nPotIntr.at<float>(m_graph.getNumStates() - nStatesOccl + s, 0) = 100.0f / nStatesOccl;
		for (int y = 0; y < m_size.height; y++) {
#endif
			const float *pPotBase = potBase.ptr<float>(y);
			const float *pPotOccl = potOccl.empty() ? NULL : potOccl.ptr<float>(y);
			for (int x = 0; x < m_size.width; x++) {
				size_t idx = (y * m_size.width + x) * m_nLayers;
				
				for (byte s = 0; s < nStatesBase; s++) 
					nPotBase.at<float>(s, 0) = pPotBase[nStatesBase * x + s];
				m_graph.setNode(idx, nPotBase);
				
				if (m_nLayers >= 2) {
					for (byte s = 0; s < nStatesOccl; s++) 
						nPotOccl.at<float>(m_graph.getNumStates() - nStatesOccl + s, 0) = pPotOccl[nStatesOccl * x + s];
					m_graph.setNode(idx + 1, nPotOccl);
				}
				
				for (word l = 2; l < m_nLayers; l++)
					m_graph.setNode(idx + l, nPotIntr);
			} // x
		} // y
#ifdef ENABLE_PPL	
		);
#endif
	}
Exemple #15
0
TEST_F(CTestInference, inference_exact_weiss)
{
	CGraphWeiss graph(m_nStates);
	buildGraph(graph, m_nNodes);
	fillGraph(graph);
	
	CInferExact inferer(graph);
	testInferer(inferer);
}
Exemple #16
0
TEST_F(CTestInference, inference_LBP)
{
	CGraphPairwise graph(m_nStates);
	buildGraph(graph, m_nNodes);
	fillGraph(graph);
	
	CInferLBP inferer(graph);
	testInferer(inferer);
}
Exemple #17
0
void ompl::control::Syclop::setup()
{
    base::Planner::setup();
    if (!leadComputeFn)
        setLeadComputeFn(std::bind(&ompl::control::Syclop::defaultComputeLead, this,
            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
    buildGraph();
    addEdgeCostFactor(std::bind(&ompl::control::Syclop::defaultEdgeCost, this,
        std::placeholders::_1, std::placeholders::_2));
}
int main() {
  Graph initial, reduced;
  initial = buildGraph();
  Tarjan(initial);
  reduced = reduceGraph(initial, translation);
  printSccGraph(reduced, n_scc);
  freeGraph(reduced);
  freeTarjan();
  return 0;
}
Exemple #19
0
// Constructor
CTestInference::CTestInference(void)
{
	CGraphPairwise graph(m_nStates);
	buildGraph(graph, m_nNodes);
	fillGraph(graph);

	CInferExact exactInferer(graph);
	exactInferer.infer();
	m_vPotExact = exactInferer.getPotentials(0);
}
Exemple #20
0
std::shared_ptr<Graph> ImportIRGraph(const std::string& serialized_graph,
                                     std::vector<at::Tensor>& initializers) {

  pb_istream_t istream = pb_istream_from_buffer(reinterpret_cast<const pb_byte_t *>(serialized_graph.data()), serialized_graph.size());

  auto model = Reader<Model_>::read(&istream);

  auto graph = buildGraph(model.graph, initializers);

  return graph;
}
void MethodLiveness::compute_liveness() {
#ifndef PRODUCT
  if (TraceLivenessGen) {
    tty->print_cr("################################################################");
    tty->print("# Computing liveness information for ");
    method()->print_short_name();
  }

  if (TimeLivenessAnalysis) _time_total.start();
#endif

  {
    TraceTime buildGraph(NULL, &_time_build_graph, TimeLivenessAnalysis);
    init_basic_blocks();
  }
  {
    TraceTime genKill(NULL, &_time_gen_kill, TimeLivenessAnalysis);
    init_gen_kill();
  }
  {
    TraceTime flow(NULL, &_time_flow, TimeLivenessAnalysis);
    propagate_liveness();
  }

#ifndef PRODUCT
  if (TimeLivenessAnalysis) _time_total.stop();

  if (TimeLivenessAnalysis) {
    // Collect statistics
    _total_bytes += method()->code_size();
    _total_methods++;

    int num_blocks = _block_list->length();
    _total_blocks += num_blocks;
    _max_method_blocks = MAX2(num_blocks,_max_method_blocks);

    for (int i=0; i<num_blocks; i++) {
      BasicBlock *block = _block_list->at(i);

      int numEdges = block->_normal_predecessors->length();
      int numExcEdges = block->_exception_predecessors->length();

      _total_edges += numEdges;
      _total_exc_edges += numExcEdges;
      _max_block_edges = MAX2(numEdges,_max_block_edges);
      _max_block_exc_edges = MAX2(numExcEdges,_max_block_exc_edges);
    }

    int numLocals = _bit_map_size_bits;
    _total_method_locals += numLocals;
    _max_method_locals = MAX2(numLocals,_max_method_locals);
  }
#endif
}
std::map<QString, PluginMetadata> PluginDependencyGraphBuilder::applyFilter(
    const std::map<QString, PluginMetadata> &plugins, const PluginFilter &filter) const
{
    auto graph = buildGraph(plugins);
    auto invalid = filter(graph);

    std::map<QString, PluginMetadata> result;
    std::copy_if(
        std::begin(plugins), std::end(plugins), std::inserter(result, result.begin()),
        [&invalid](const std::map<QString, PluginMetadata>::value_type &v) { return !contains(invalid, v.first); });
    return result;
}
main()
{
	struct Vertex *V;
	V=NULL;
	
	wtd=NONWEIGHTED;
	printf("\n**Input Graph**\n");
	buildGraph(&V);
	
	printf("\n***Graph Display***");
	displayGraph(V);
	
	freeGraph(&V);
}
Exemple #24
0
void ompl::control::Syclop::setup()
{
    base::Planner::setup();
    if (!leadComputeFn)
        setLeadComputeFn([this](int startRegion, int goalRegion, std::vector<int> &lead)
                         {
                             defaultComputeLead(startRegion, goalRegion, lead);
                         });
    buildGraph();
    addEdgeCostFactor([this](int r, int s)
                      {
                          return defaultEdgeCost(r, s);
                      });
}
Exemple #25
0
    void PathFinder::buildPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
        const ESM::Pathgrid* pathGrid,float xCell,float yCell)
    {
        int start = getClosestPoint(pathGrid,startPoint.mX - xCell,startPoint.mY - yCell,startPoint.mZ);
        int end = getClosestPoint(pathGrid,endPoint.mX - xCell,endPoint.mY - yCell,endPoint.mZ);

        if(start != -1 && end != -1)
        {
            PathGridGraph graph = buildGraph(pathGrid,xCell,yCell);
            mPath = findPath(start,end,graph);
        }

        mPath.push_back(endPoint);
        mIsPathConstructed = true;
    }
Exemple #26
0
// -----------------------------------------------------------------------------
ArenaGraph::ArenaGraph(const std::string &navmesh, const XMLNode *node)
          : Graph()
{
    loadNavmesh(navmesh);
    buildGraph();
    // Compute shortest distance from all nodes
    for (unsigned int i = 0; i < getNumNodes(); i++)
        computeDijkstra(i);

    setNearbyNodesOfAllNodes();
    if (node && race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
        loadGoalNodes(node);

    loadBoundingBoxNodes();

}   // ArenaGraph
StringGraphGenerator::StringGraphGenerator(const OverlapAlgorithm* pOverlapper, 
                                           const SeqRecord& startRead, 
                                           const SeqRecord& endRead, 
                                           int minOverlap,
                                           EdgeDir startDir,
                                           int maxDistance) : m_pOverlapper(pOverlapper), 
                                                              m_minOverlap(minOverlap), 
                                                              m_pGraph(NULL), 
                                                              m_startDir(startDir), 
                                                              m_maxDistance(maxDistance)
{
    m_pGraph = new StringGraph;

    // Add the start and end vertices to the graph
    m_pStartVertex = addTerminalVertex(startRead);
    m_pEndVertex = addTerminalVertex(endRead);

    // Set the color of the starting node to be UNEXPLORED
    // and the color of the end node to be EXPLORED.
    // This indicates to the subsequent search which vertices
    // should be expanded
    m_pStartVertex->setColor(UNEXPLORED_COLOR);
    m_pEndVertex->setColor(EXPLORED_COLOR);

    // Set up the expansion frontier
    FrontierQueue queue;
    GraphFrontier node;
    node.pVertex = m_pStartVertex;
    node.dir = m_startDir;
    node.distance = m_pStartVertex->getSeqLen();
    queue.push(node);

    buildGraph(queue);

    //m_pGraph->writeDot("local.dot");

    SGDuplicateVisitor dupVisit(true);
    m_pGraph->visit(dupVisit);

    // If the terminal vertices are marked as contained, reset the containment flags so they will not be removed
    resetContainmentFlags(m_pStartVertex);
    resetContainmentFlags(m_pEndVertex);

    SGContainRemoveVisitor containVisit;
    m_pGraph->visit(containVisit);
    //m_pGraph->writeDot("local-final.dot");
}
int main()
{
	FILE * in = fopen("input.txt", "r");

	int numVerticies;
	fscanf(in,"%d", &numVerticies);

	Graph G = newGraph(numVerticies);
	buildGraph(in,G);
	Prim(G, 1);
	fclose(in);

	printf("\n\n\t***** COJ : 1480 - Dota Warlock Power *****\n\n");
	system("PAUSE");
	return 0;

}
Exemple #29
0
    void
    Plan::parse(const std::set<uint16_t>* supported_maneuvers,
                const std::map<std::string, IMC::EntityInfo>& cinfo,
                IMC::PlanStatistics& ps, bool imu_enabled,
                const IMC::EstimatedState* state)
    {
      clear();

      // Build Graph of maneuvers and transitions, if this fails, parse fails
      buildGraph(supported_maneuvers);

      secondaryParse(cinfo, ps, imu_enabled, state);

      m_last_id = m_spec->start_man_id;

      return;
    }
Exemple #30
0
void FacBuilder::buildGraph(string section, string imgDir, string regDir){
	
	string imgPath1 = imgDir + "\\" + section + ".jpg";
	string imgPath2 = imgDir + "\\" + section + ".png";
	string regPath = regDir + "\\" + section + "-label.txt";
	Mat src;
	fs::path fullpath1(imgPath1, fs::native);
	
	if(fs::exists(fullpath1))
		src = imread(imgPath1);//jpg格式
	else
		src = imread(imgPath2);//png格式

	Mat reg;
	Basic_File fileop;
	
	int flag = fileop.LoadData(regPath,reg,src.rows,src.cols);
	buildGraph(section,src,reg);
}