Ejemplo n.º 1
0
/** Finds which checklines must be visited before driving on this quad
 *  (useful for rescue)
 */
void QuadGraph::computeChecklineRequirements(GraphNode* node,
                                             int latest_checkline)
{
    for (unsigned int n=0; n<node->getNumberOfSuccessors(); n++)
    {
        const int succ_id = node->getSuccessor(n);

        // warp-around
        if (succ_id == 0) break;

        GraphNode* succ = m_all_nodes[succ_id];
        int new_latest_checkline =
            CheckManager::get()->getChecklineTriggering(node->getCenter(),
                                                        succ->getCenter() );
        if(new_latest_checkline==-1)
            new_latest_checkline = latest_checkline;

        /*
        printf("Quad %i : checkline %i\n", succ_id, new_latest_checkline);

        printf("Quad %i :\n", succ_id);
        for (std::set<int>::iterator it = these_checklines.begin();it != these_checklines.end(); it++)
        {
            printf("    Depends on checkline %i\n", *it);
        }
        */

        if (new_latest_checkline != -1)
            succ->setChecklineRequirements(new_latest_checkline);

        computeChecklineRequirements(succ, new_latest_checkline);
    }
}   // computeChecklineRequirements
void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) {

	String prev_name = blend_tree->get_node_name(p_node);
	ERR_FAIL_COND(prev_name == String());
	GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name));
	ERR_FAIL_COND(!gn);

	String new_name = p_text;

	ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1)

	ERR_FAIL_COND(new_name == prev_name);

	String base_name = new_name;
	int base = 1;
	String name = base_name;
	while (blend_tree->has_node(name)) {
		base++;
		name = base_name + " " + itos(base);
	}

	updating = true;
	undo_redo->create_action("Node Renamed");
	undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
	undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
	undo_redo->add_do_method(this, "_update_graph");
	undo_redo->add_undo_method(this, "_update_graph");
	undo_redo->commit_action();
	updating = false;
	gn->set_name(new_name);
	gn->set_size(gn->get_minimum_size());
}
Ejemplo n.º 3
0
/*
 * BuildCFG()
 *  Build one new CFG by cloning the input CFGs and then connecting them. The
 *  original CFG is not changed.
 */
void BuildCFG(CodeInfo *Parent, SuccMap &SMap, Node2Map &NodeMapping,
        int &Version)
{
    GraphNode *ChildCFG;
    
    CloneCFG(Parent->CFG, NodeMapping);

    CodeVec &Successor = SMap[Parent];
    int NumSucc = Successor.size();
    if (NumSucc == 0)
        return;

    for (int i = 0; i < NumSucc; i++)
    {
        CodeInfo *Child = Successor[i];
        if (Child->Version > Version)
            Version = Child->Version;

        if (NodeMapping.count(Child->CFG) == 0)
            BuildCFG(Child, SMap, NodeMapping, Version);
        
        ChildCFG = NodeMapping[Child->CFG];

        NodeVec &Links = Parent->getLink(Child->GuestPC);
        int NumLinks = Links.size();
        for (int j = 0; j < NumLinks; j++)
        {
            if (NodeMapping.find(Links[j]) == NodeMapping.end())
               DM->Error("%s: fatal error on %x.\n", __func__, Child->GuestPC);

            GraphNode *LinkNode = NodeMapping[Links[j]];
            LinkNode->setSuccessor(ChildCFG);
        }
    }
}
Ejemplo n.º 4
0
    void GraphValidator::verify_output_socket_satisfied(const GraphNode &node, const InputSocket& input_socket, ValidationResults &results) const
    {
        auto possible_connection = input_socket.connection();
        if(!possible_connection)
        {
            if(!(node.is_graph_internal_node() && input_socket.optional()))
            {
                std::string text = boost::str(boost::format("Output node %1% is missing an input connection.") % node.display_name());
                results.add(text);
                return;
            }

            if(graph_.get_input_buffer(node.name()))
                return;

            std::string text = boost::str(boost::format("Output node %1% is missing an input connection, or is missing data being set directly on the Graph.") % node.display_name());
            results.add(text);
            return;
        }

        const Connection& connection = possible_connection->get();
        const OutputSocket& output = connection.output();

        if(output.parent() == nullptr)
            throw std::logic_error("Output socket did not have a parent! Internal error!");

        verify_node_satisfied(*output.parent(), results);
    }
Ejemplo n.º 5
0
void Graph :: drawnodes(bool treedee, double sz){
	if (treedee) {
		for (int n=0; n< adjlist.size(); n++) {
			
			GraphNode * gn = adjlist.at(n);
			
			vec3d point = gn->getPos();
				
			glPushMatrix();
			glTranslatef(point.x, point.y, point.z);
			glScalef(sz, sz, sz);
			drawsphere (10, 10);
			glPopMatrix();
			
		}
	}
	else 
	{
		
		glPointSize(sz);
		glBegin(GL_POINTS);
		for (int n=0; n< adjlist.size(); n++) 
		{
			GraphNode * gn = adjlist.at(n);
			vec3d point = gn->getPos();
			glVertex3d(point.x, point.y, point.z);
			
		}
		glEnd();
		
		pointsz = sz;
		
	}

}
Ejemplo n.º 6
0
void Graph :: normalizeinitpos(){
	//we want to normalize graph node positions between 0.0 and 1.0
	
	double minx=0.0;
	double maxx = 1.0;
	double miny=0.0;
	double maxy = 1.0;

	for (int a=0; a<adjlist.size(); a++) {
		GraphNode * nd = adjlist.at(a);
		vec3d place = nd->getPos();
		
		minx = min(place.x, minx); 
		maxx = max(place.x, maxx); 
		
		miny = min(place.y, miny); 
		maxy = max(place.y, maxy); 
		
	}
	
	//printf("min max %f, %f, %f, %f \n", minx, maxx, miny, maxy);
	
	double yrange = maxy - miny;
	double xrange = maxx - minx;
	
	for (int a=0; a<adjlist.size(); a++) {
		GraphNode * nd = adjlist.at(a);
		vec3d place = nd->getPos();
		place.x = (place.x - minx) / xrange;
		place.y = (place.y - miny) / yrange;
		
		nd -> setPos(place);
		//printf("place of node %f, %f \n", place.x, place.y);
	}
}
Ejemplo n.º 7
0
void Graph::move(vec3d amount){
	if (selectednodes.size() > 0) {
		int selectednodeindex = selectednodes.back();
		GraphNode * selected = adjlist.at(selectednodeindex);
		selected->visited(true);
		vector<GraphNode * > level0  = selected-> nodesvec();
	
		 vector < vector< GraphNode* > > visitednodes;
		 visitednodes.push_back(level0);
		 
		 traverse(visitednodes);
		 
		 //printf("size of visitednodes: %d \n", visitednodes.size());
		 //do the actual move
		
		selected -> move(amount);
		for (int v=0; v<visitednodes.size(); v++) {
			amount = amount * 0.4;
			vector<GraphNode * > lv = visitednodes.at(v);
			for (int n=0; n<lv.size(); n++) {
				GraphNode * g = lv.at(n);
				g->move(amount);
			}
		}
		 
		 //unmark all nodes
		for (int a=0; a<adjlist.size(); a++) {
			adjlist.at(a)->visited(false);
		}
		 
	}
	else printf("Graph:move no valid selected node \n");
}
Ejemplo n.º 8
0
// addMayEdge
// Adds the edge F -> T with weight Weight.
void IneqGraph::addMayEdge(Value *F, Value *T, APInt Weight) {
  DEBUG(dbgs() << "IneqGraph: addMayEdge: " << *F << " == " << Weight
                << " ==> " << *T << "\n");
  GraphNode *FN = getOrCreateNode(F);
  GraphNode *TN = getOrCreateNode(T);
  FN->addMayEdgeTo(TN, Weight);
}
Ejemplo n.º 9
0
bool Graph::SearchDFS(GraphNode* start, GraphNode* end)
{
	ResetVisited();

	std::stack<GraphNode*> nodeStack;
	nodeStack.push(start);

	//keep looping until the stack is empty. 
	//This will only happen once we've checked every node. 
	while (!nodeStack.empty())
	{
		//the rest of the algorithm goes in here
		GraphNode* current = nodeStack.top();
		nodeStack.pop();

		if (!current->GetIsVisited())
		{
			current->SetIsVisited(true);

			if (current == end)
			{
				return true;
			}

			for (int i = 0; i < int(current->GetEdgeList().size()); ++i)
			{
				nodeStack.push(current->GetEdgeList()[i]->GetEnd());
			}
		}
		return false;
	}

	return false;
}
Ejemplo n.º 10
0
bool Graph::SearchBFS(GraphNode* start, GraphNode* end)
{
	ResetVisited();

	std::queue<GraphNode*> nodeQueue;
	nodeQueue.push(start);

	//keep looping until the stack is empty. 
	//This will only happen once we've checked every node. 
	while (!nodeQueue.empty())
	{
		GraphNode* current = nodeQueue.front();

		if (!current->GetIsVisited())
		{
			current->SetIsVisited(true);

			if (current == end)
			{
				return true;
			}

			for (int i = 0; i < int(current->GetEdgeList().size()); ++i)
			{
				nodeQueue.push(current->GetEdgeList()[i]->GetEnd());
			}
		}

		nodeQueue.pop();

		return false;
	}

	return false;
}
void Graph::inset(long key) {
  srand(time(NULL));
  GraphNode *n = new GraphNode(key);
  nodes[numOfNodes] = n;
  int connectCount = 0;
  int connectSpot;
  int connectedSpot[5];
  bool alreadyConnected = false;
  for(int i = 0; i < 5; i++) connectedSpot[i] = -1;
  if(numOfNodes <= 5) {
    for(int i = 0; i < numOfNodes; i++) {
      nodes[i]->connect(n);
      n->connect(nodes[i]);
    }
  }
  else {
    while(connectCount <= 4) {
      connectSpot = rand() % numOfNodes;
      for(int i = 0; i < connectCount; i++)
        if(connectedSpot[i] == connectSpot) alreadyConnected = true;
      if(!alreadyConnected) {
        nodes[connectSpot]->connect(n);
	n->connect(nodes[connectSpot]);
	connectedSpot[connectCount] = connectSpot;
	connectCount++;
      }
      alreadyConnected = false;
    }
  }
  numOfNodes++;
  if(numOfNodes == capacity) doubleNodes();
  //connect();
}
Ejemplo n.º 12
0
Archivo: DFS.cpp Proyecto: kirkor93/15
void DFS::Solve(GraphNode *startNode, int maxIterations)
{
	StartTimer();
	stack<GraphNode*> nodesStack;

	GraphNode *node = new GraphNode(startNode);
	elements.push_back(node);
	nodesStack.push(node);
	node->visited = true;
	int iterations = 0;
	while (!node->IsSolution())
	{
		node->visited = true;
		node->FindNeighbours(elements);
		node->PushNeighbours(nodesStack);
		node = nodesStack.top();
		while ((node = nodesStack.top())->visited)
		{
			nodesStack.pop();
		}
		iterations++;
		if (iterations > maxIterations)
		{
			ShowResult(false, iterations);
			StopTimer();
			return;
		}
	}
	StopTimer();
	ShowResult(true, iterations, node);
}
Ejemplo n.º 13
0
DoubleLinkedList<GraphNode *> Dijkstra(GraphNode *Start, GraphNode * End)
{
	Map<GraphNode *, DijkstraHelperNode *> NodeHelperMap;
	DoubleLinkedList<DijkstraHelperNode *> Visited;
	MinHeap<DijkstraHelperNode *> OpenHeap;
	DijkstraHelperNode *NewHelper = new DijkstraHelperNode();
	NewHelper->m_Node = Start;
	NewHelper->m_Cost = 0;
	NodeHelperMap.Insert(Start, NewHelper);
	OpenHeap.Insert(NewHelper);
	while(!OpenHeap.IsEmpty())
	{
		DijkstraHelperNode *CurrentHelperNode = OpenHeap.PopTop();
		assert(CurrentHelperNode != NULL);
		GraphNode *CurrentGraphNode = CurrentHelperNode->m_Node;
		assert(CurrentGraphNode != NULL);
		DoubleLinkedList<GraphEdge *> *CurrendEdges = CurrentGraphNode->GetEdges();
		DoubleListNode<GraphEdge *> *CurrentEdge = CurrentEdges.GetHead();
		while(CurrentEdge != NULL)
		{
			GraphNode *OtherNode = CurrentEdge->m_End;
			if(OtherNode == CurrentGraphNode)
			{
				OtherNode = CurrentEdge->m_Start;
			}
			assert(OtherNode != CurrentGraphNode);
			DijkstraHelperNode *NodeHelper = NodeHelperMap.GetValue(OtherNode);
			if(NodeHelper == NULL)
			{
 				NodeHelper = new DijkstraHelperNode();
				NodeHelper->m_Node = OtherNode;
				NodeHelperMap.Insert(OtherNode, NodeHelper);		
				OpenHeap.Insert(NodeHelper);
			}
			int CostToNode = CurrentHelperNode->m_Cost + CurrentEdge->m_Cost;
			if(CostToNode < NodeHelper->m_Cost)
			{		
				NodeHelper->m_Cost = CostToNode;
				NodeHelper->m_Previous = CurrentGraphNode;
				OpenHeap.Update(NodeHelper);
			}
			if(OtherNode == End)
			{
				break;
			}
		}
	}

	DoubleLinkedList<GraphNode *> Path;
	DijkstraHelperNode *EndHelper = NodeHelperMap.GetValue(End);
	if(EndHelper != NULL)
	{
		DijkstraHelperNode *CurrentHelper = EndHelper;
		while(CurrentHelper != NULL)
		{
			Path.AddFront(CurrentHelper->m_Node);
			CurrentHelper = CurrentHelper->m_Previous;
		}
	}
}
Ejemplo n.º 14
0
void GraphNode :: printAdjacentNodes(){
	for (int a =0; a< adjacents.size(); a++){
		GraphNode * tmp = adjacents.at(a);
		printf("neighbors %i 'th id is: %i \n", a, tmp->getnodeid());
	}
	
	
}
Ejemplo n.º 15
0
void GraphEdit::remove_child_notify(Node *p_child) {

	top_layer->call_deferred("raise"); //top layer always on top!
	GraphNode *gn = p_child->cast_to<GraphNode>();
	if (gn) {
		gn->disconnect("offset_changed",this,"_graph_node_moved");
		gn->disconnect("raise_request",this,"_graph_node_raised");
	}
}
Ejemplo n.º 16
0
 void addEdge(int A, int B) {
     GraphNode *tmp;
     tmp = new GraphNode(B);
     tmp->setNext(list[A]);
     list[A] = tmp; 
     tmp = new GraphNode(A);
     tmp->setNext(list[B]);
     list[B] = tmp;
 }
Ejemplo n.º 17
0
/*
 * LinkCompactCFG()
 *  Connecting multiple compact CFGs. No copy of original CFG is performed and
 *  the original CFGs are changed.
 */
void LinkCompactCFG(CompactInfo &CI)
{
    for (NPSet::iterator I = CI.NPair.begin(), E = CI.NPair.end(); I != E; I++)
    {
        GraphNode *Src = I->first;
        GraphNode *Dest = I->second;
        Src->setSuccessor(Dest);
    }
}
Ejemplo n.º 18
0
void GraphViewer::addNode (GenericEditor* editor)
{
    GraphNode* gn = new GraphNode (editor, this);
    addAndMakeVisible (gn);
    availableNodes.add (gn);
    
    gn->setBounds (20, 20, 150, 50);
    updateNodeLocations();
}
Ejemplo n.º 19
0
Archivo: Bond.cpp Proyecto: dtbinh/dgl
Bond::Bond(GraphNode& origin,
           GraphNode& partner,
           float strength,
           sf::RenderWindow& w):
    m_strength(strength),
    m_control(new sf::Vector2f(w.getSize().x/2, w.getSize().y/2)),
    m_origin(&origin),
    m_partner(&partner),
    m_graphic(new QuadraticBezier(origin.getPos(), *m_control, partner.getPos(), w))
{}
Ejemplo n.º 20
0
void GraphEdit::add_child_notify(Node *p_child) {

	top_layer->call_deferred("raise"); //top layer always on top!
	GraphNode *gn = p_child->cast_to<GraphNode>();
	if (gn) {
		gn->connect("offset_changed",this,"_graph_node_moved",varray(gn));
		gn->connect("raise_request",this,"_graph_node_raised",varray(gn));
		_graph_node_moved(gn);
		gn->set_stop_mouse(false);
	}
}
//--------------------------------------------
// Function: insertNode()					 *
// Purpose: Insert nodes in node array		 *
// Returns: void							 *
//--------------------------------------------
	void Prog3Graph::insertNode(int ID, char *data, int edges)
	{
		
		GraphNode *newNode = new GraphNode();
        newNode->setNodeID(ID);
        newNode->setNodeData(data);
		newNode->setNumberOfEdges(edges);
        Nodes[nodesInserted] = *newNode;
        nodesInserted++;
		
	}
Ejemplo n.º 22
0
void GraphEdit::set_selected(Node *p_child) {

	for (int i = get_child_count() - 1; i >= 0; i--) {

		GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
		if (!gn)
			continue;

		gn->set_selected(gn == p_child);
	}
}
Ejemplo n.º 23
0
	void SceneGraph::Remove(GraphNode aGameObject)
	{
		if (aGameObject == nullptr || m_Top == nullptr)
		{
			return;
		}

		if (aGameObject->GetParent() == m_Top)
		{
			aGameObject->SetParent(nullptr);
		}
	}
Ejemplo n.º 24
0
	void SceneGraph::Insert(GraphNode aGameObject)
	{
		if (aGameObject == nullptr || m_Top == nullptr)
		{
			return;
		}
		if (aGameObject->GetParent() == nullptr)
		{
			aGameObject->SetParent(m_Top);
		}

	}
Ejemplo n.º 25
0
void GraphEdit::remove_child_notify(Node *p_child) {

	Control::remove_child_notify(p_child);
	if (is_inside_tree()) {
		top_layer->call_deferred("raise"); //top layer always on top!
	}
	GraphNode *gn = Object::cast_to<GraphNode>(p_child);
	if (gn) {
		gn->disconnect("offset_changed", this, "_graph_node_moved");
		gn->disconnect("raise_request", this, "_graph_node_raised");
	}
}
Ejemplo n.º 26
0
void PlygonDrawer::resetGraph() {
	GraphNodeVisitorGraph grp_vis;
	for (grp_vis.begin(m_graph->m_rows, m_graph->m_cols); ! grp_vis.end(); ++grp_vis)
		if (m_graph->check_bdy_enable(grp_vis.m_ptCur)) {
			GraphNode* pNode = m_graph->get_node(grp_vis.m_ptCur);
			auto categ = pNode->get_category();
			categ.spec  = CHESS_CATEGORY_NORM;
			categ.color = (enNodeColor)(rand()%NODE_COLOR_SPEC);
			m_tileMap->changeCell(grp_vis.m_ptCur, &categ);
			pNode->set_category(categ);
		}
}
void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {

	GraphNode *gn = Object::cast_to<GraphNode>(p_node);
	ERR_FAIL_COND(!gn);

	String name = gn->get_name();

	Ref<AnimationNode> anode = blend_tree->get_node(name);
	ERR_FAIL_COND(!anode.is_valid());

	EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
}
Ejemplo n.º 28
0
void DualGraph::saveGraph(const char *filename) {
    std::ofstream output(filename);
    for (NodeIter nit(this); !nit.end(); ++nit) {
        GraphNode *node = *nit;
		output << "v " << node->id() << "\n";
	}

    for (EdgeIter eit(this); !eit.end(); ++eit) {
        GraphEdge *edge = *eit;
        output << "e " << edge->from()->id() << " " << edge->to()->id() << "\n";
	}
    output.close();
}
Ejemplo n.º 29
0
		/** Removes a node and all its dependents from the graph. */
		void removeDependencyPath (const T &key) {
			auto it = _nodeMap.find(key);
			if (it != _nodeMap.end()) {
				for (GraphNode *node = it->second.get(); node;) {
					GraphNode *dependent = node->dependent;
					node->unlinkDependees();
					if (dependent)
						dependent->unlinkDependee(node);
					_nodeMap.erase(node->key);
					node = dependent;
				}
			}
		}
Ejemplo n.º 30
0
void GraphEdit::_update_scroll() {

	if (updating)
		return;

	updating = true;

	set_block_minimum_size_adjust(true);

	Rect2 screen;
	for (int i = 0; i < get_child_count(); i++) {

		GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
		if (!gn)
			continue;

		Rect2 r;
		r.position = gn->get_offset() * zoom;
		r.size = gn->get_size() * zoom;
		screen = screen.merge(r);
	}

	screen.position -= get_size();
	screen.size += get_size() * 2.0;

	h_scroll->set_min(screen.position.x);
	h_scroll->set_max(screen.position.x + screen.size.x);
	h_scroll->set_page(get_size().x);
	if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
		h_scroll->hide();
	else
		h_scroll->show();

	v_scroll->set_min(screen.position.y);
	v_scroll->set_max(screen.position.y + screen.size.y);
	v_scroll->set_page(get_size().y);

	if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
		v_scroll->hide();
	else
		v_scroll->show();

	set_block_minimum_size_adjust(false);

	if (!awaiting_scroll_offset_update) {
		call_deferred("_update_scroll_offset");
		awaiting_scroll_offset_update = true;
	}

	updating = false;
}