struct listnode
shortest_path (int v, int s, int t, int *dist)
{

  int distance[v], accepted_vertice[v], predecessor[v], i;

  for (i = 0; i != v; ++i) {
    distance[i] = INFNTY;
    predecessor[i] = NOVERTEX;
    accepted_vertice[i] = FALSE;
  }
  distance[s] = 0;
  int allowed_size;

  /* discover start vertex, and its adjacent vertices */
  for (allowed_size = 0; allowed_size != v; ++allowed_size) {

    int next = get_next_vertex (v, accepted_vertice, distance);
    if (next == INFNTY)
      break;
    accepted_vertice[next] = TRUE;
    get_adjacent_vertice (next, v, accepted_vertice, dist, distance,
			  predecessor);
  }

  int is_false = 0;
  int vertex_on_path = t;
  struct listnode short_path = { NULL, s };	/* got start vertex */

  /* get path to destination vertex */
  while (predecessor[vertex_on_path] != s) {

    struct listnode *node
      = (struct listnode *) malloc (sizeof (struct listnode));

    if (shortest_path == NULL)
      perror ("ERROR: allocating dynamic memory with malloc() ");

    if (is_false++ == 0)
      node->vertexnumber = vertex_on_path;
    else {
      node->vertexnumber = predecessor[vertex_on_path];
      vertex_on_path = predecessor[vertex_on_path];
    }
    node->next = short_path.next;
    short_path.next = node;
  }
  return short_path;
}
Beispiel #2
0
void Radar::compute_bezier_from_aframe() {
  // From the aframe points, compute the bezier segments
  // place bezier structs into bezier_segments vector
  bezier_segments.clear();

  ofPoint start = get_next_vertex(-1);
  for (int i = 0; i < aframe_points.size(); i++) {
    ofPoint a1 = get_aframe_point(i);
    ofPoint a2 = get_aframe_point(i+1);
    ofPoint c1 = intermediate_point(a1, a2, 1/3.0);
    ofPoint c2 = intermediate_point(a1, a2, 2/3.0);
    ofPoint end = get_next_vertex(i);

    bezier b = bezier();
    b.start = start;
    b.c1 = c1;
    b.c2 = c2;
    b.end = end;

    bezier_segments.push_back(b);

    start = end;
  }
}
Beispiel #3
0
bool GRAPH::is_equal(GRAPH & g)
{
	if (get_vertex_num() != g.get_vertex_num() ||
		get_edge_num() != g.get_edge_num()) {
		return false;
	}
	
	BITSET vs;
	INT c;
	for (VERTEX * v1 = get_first_vertex(c); 
		 v1 != NULL; v1 = get_next_vertex(c)) {
		VERTEX * v2 = g.get_vertex(VERTEX_id(v1));
		if (v2 == NULL) {
			return false; 
		}

		vs.clean();
		EDGE_C * el = VERTEX_out_list(v1);		
		EDGE * e = NULL;
		UINT v1_succ_n = 0;
		if (el == NULL) {
			if (VERTEX_out_list(v2) != NULL) {
				return false;
			}
			continue;
		}
		for (e = EC_edge(el); e != NULL; el = EC_next(el), 
			 e = el ? EC_edge(el) : NULL) {
			vs.bunion(VERTEX_id(EDGE_to(e)));
			v1_succ_n++;
		}

		UINT v2_succ_n = 0;
		el = VERTEX_out_list(v2);
		for (e = EC_edge(el); e != NULL; el = EC_next(el), 
			 e = el ? EC_edge(el) : NULL) {
			v2_succ_n++;
			if (!vs.is_contain(VERTEX_id(EDGE_to(e)))) {
				return false;
			}			
		}
		
		if (v1_succ_n != v2_succ_n) { 
			return false; 
		}
	}
	return true;
}
Beispiel #4
0
/*
Perform DFS to seek for unreachable node.
Return true if some nodes removed.
*/
bool DGRAPH::remove_unreach_node(UINT entry_id)
{
	if (get_vertex_num() == 0) return false;
	bool removed = false;
	BITSET visited;
	_remove_unreach_node(entry_id, visited);
	INT c;
	for (VERTEX * v = get_first_vertex(c); 
		 v != NULL; v = get_next_vertex(c)) {
		if (!visited.is_contain(VERTEX_id(v))) {
			remove_vertex(v);
			removed = true;
		}
	}
	return removed;
}
Beispiel #5
0
//
//START CDG
//
void CDG::dump()
{
	dump_vcg("graph_cd_tree.vcg");
	if (g_tfile == NULL) return;
	fprintf(g_tfile, "\n==---- DUMP Control Dependence ----==");
	INT c;
	for (VERTEX * v = get_first_vertex(c);
		 v != NULL; v = get_next_vertex(c)) {
		EDGE_C * in = VERTEX_in_list(v);
		if (in == NULL) {
			fprintf(g_tfile, "\nBB%d has NO ctrl BB", VERTEX_id(v));
			continue;
		}
		fprintf(g_tfile, "\nBB%d ctrl BB is: ", VERTEX_id(v));
		while (in != NULL) {
			VERTEX * pred = EDGE_from(EC_edge(in));
			fprintf(g_tfile, "%d,", VERTEX_id(pred));
			in = EC_next(in);
		}
	}
	fprintf(g_tfile, "\n");
	fflush(g_tfile);
}
Beispiel #6
0
/*
Vertexs should have been sorted in topological order.
And we access them by reverse-topological order.
'vlst': compute dominator for vertices in vlst if it 
	is not empty or else compute all graph.
'uni': universe.	
*/
bool DGRAPH::compute_dom(IN LIST<VERTEX*> * vlst, BITSET const* uni)
{
	LIST<VERTEX*> tmpvlst;
	LIST<VERTEX*> * pvlst = &tmpvlst;
	if (vlst != NULL) {
		pvlst = vlst;
	} else {
		INT c;
		for (VERTEX * u = get_first_vertex(c); 
			 u != NULL; u = get_next_vertex(c)) {
			pvlst->append_tail(u);
		}
	}

	BITSET const* luni = NULL;
	if (uni != NULL) {
		luni = uni;
	} else {
		BITSET * x = new BITSET();	
		for (VERTEX * u = pvlst->get_head(); 
			 u != NULL; u = pvlst->get_next()) {
			x->bunion(VERTEX_id(u));		
		}
		luni = x;
	}

	//Initialize dom-set for each BB.	
	for (VERTEX * v = pvlst->get_head();
		 v != NULL; v = pvlst->get_next()) {
		if (is_graph_entry(v)) {
			BITSET * dom = get_dom_set(v);
			dom->clean();
			dom->bunion(VERTEX_id(v));
		} else {
			get_dom_set(v)->copy(*luni);
		}
	}
	
	/*
	DOM[entry] = {entry}
	DOM[n] = {n} ¡È { ¡É(DOM[pred] of predecessor of 'n') }	
	*/
	bool change = true;
	BITSET tmp;
	UINT count = 0;
	while (change && count < 10) {
		count++;
		change = false;
		for (VERTEX * v = pvlst->get_head(); 
			 v != NULL; v = pvlst->get_next()) {
			UINT vid = VERTEX_id(v);
			if (is_graph_entry(v)) {
				continue;
			} else {
				//Access each preds
				EDGE_C * ec = VERTEX_in_list(v);
				while (ec != NULL) {
					VERTEX * pred = EDGE_from(EC_edge(ec));
					if (ec == VERTEX_in_list(v)) {
						tmp.copy(*m_dom_set.get(VERTEX_id(pred)));		
					} else {
						tmp.intersect(*m_dom_set.get(VERTEX_id(pred)));
					}
					ec = EC_next(ec);
				}
				tmp.bunion(vid);

				BITSET * dom = m_dom_set.get(VERTEX_id(v));
				if (!dom->is_equal(tmp)) {
					dom->copy(tmp);
					change = true;
				}				
			} //end else
		} //end for
	}//end while
	IS_TRUE0(!change);
	if (uni == NULL && luni != NULL) {
		delete luni;
	}
	return true;
}
Beispiel #7
0
//Vertexs should have been sorted in topological order.
//And we access them by reverse-topological order.
bool DGRAPH::compute_pdom(IN LIST<VERTEX*> * vlst, BITSET const* uni)
{
	LIST<VERTEX*> tmpvlst;
	LIST<VERTEX*> * pvlst = &tmpvlst;
	if (vlst != NULL) {
		pvlst = vlst;
	} else {
		INT c;
		for (VERTEX * v = get_first_vertex(c); 
			 v != NULL; v = get_next_vertex(c)) {
			pvlst->append_tail(v);
		}
	}
	
	BITSET const* luni = NULL;
	if (uni != NULL) {
		luni = uni;
	} else {
		BITSET * x = new BITSET();	
		for (VERTEX * u = pvlst->get_head();
			 u != NULL; u = pvlst->get_next()) {
			x->bunion(VERTEX_id(u));		
		}
		luni = x;
	}

	//Initialize pdom for each bb
	for (VERTEX * v = pvlst->get_head(); 
		 v != NULL; v = pvlst->get_next()) {
		if (is_graph_exit(v)) {
			BITSET * pdom = get_pdom_set(v);
			pdom->clean();
			pdom->bunion(VERTEX_id(v));
		} else {
			get_pdom_set(v)->copy(*luni);
		}
	}

	/*
	PDOM[exit] = {exit} 
	PDOM[n] = {n} U {¡É(PDOM[succ] of each succ of n)}	
	*/
	bool change = true;
	BITSET tmp;
	UINT count = 0;
	while (change && count < 10) {
		count++;
		change = false;
		for (VERTEX * v = pvlst->get_head(); 
			 v != NULL; v = pvlst->get_next()) {
			UINT vid = VERTEX_id(v);			
			if (is_graph_exit(v)) {
				continue;
			} else {
				tmp.clean();	
				//Access each succs
				EDGE_C * ec = VERTEX_out_list(v);
				while (ec != NULL) {
					VERTEX * succ = EDGE_to(EC_edge(ec));
					if (ec == VERTEX_out_list(v)) {
						tmp.copy(*m_pdom_set.get(VERTEX_id(succ)));	
					} else {
						tmp.intersect(*m_pdom_set.get(VERTEX_id(succ)));
					}
					ec = EC_next(ec);
				}
				tmp.bunion(vid);
				
				BITSET * pdom = m_pdom_set.get(VERTEX_id(v));
				if (!pdom->is_equal(tmp)) {
					pdom->copy(tmp);
					change = true;
				}
			}			
		} //end for
	}// end while
	IS_TRUE0(!change);
	if (uni == NULL && luni != NULL) {
		delete luni;
	}
	return true;
}