Beispiel #1
0
void readFiles(Graph<int> &g, int scenario, int index) {

	GraphViewer *gv = new GraphViewer(600, 600, false);

	gv->createWindow(600, 600);

	gv->defineEdgeColor("blue");
	gv->defineVertexColor("yellow");

	stringstream file;

	file << "tests/scenario" << scenario << "/nos" << index << ".txt";

	readVertex(g,gv,file.str());

	file.str("");

	file << "tests/scenario" << scenario << "/arestas" << index << ".txt";

	readEdges(g,gv,file.str());

	file.str("");
	file << "tests/scenario" << scenario << "/pedidos" << index << ".txt";

	readRequests(g,file.str());

	file.str("");
	file << "tests/scenario" << scenario << "/details" << index << ".txt";

	readDetails(g,file.str());

	gv->rearrange();
}
Beispiel #2
0
void exercicio1(){
	GraphViewer *gv = new GraphViewer(600, 600, true);
	gv->createWindow(600, 600);
	gv->defineVertexColor("blue");
	gv->defineEdgeColor("black");
	gv->addNode(0);
	gv->addNode(1);
	gv->addEdge(0, 0, 1, EdgeType::UNDIRECTED);

	Sleep(100); // use sleep(1) in linux ; Sleep(100) on Windows

	gv->removeEdge(0);
	gv->removeNode(1);
	gv->addNode(2);
	gv->rearrange();

	Sleep(100);

	gv->addEdge(1, 0, 2, EdgeType::UNDIRECTED);
	gv->setVertexLabel(0, "Isto e um no");
	gv->setEdgeLabel(1, "Isto e uma aresta");
	gv->setVertexColor(2, "green");
	gv->setEdgeColor(1, "yellow");
	gv->rearrange();

}
Beispiel #3
0
void printGraph(const Graph<NodeInfo> &graph, const vector<int> &path, const vector<int> &stations)
{
    GraphViewer *gv = new GraphViewer(600, 600, false);
    gv->createWindow(600, 600);
    gv->defineVertexColor("black");
    gv->defineEdgeColor("black");

    vector<Vertex<NodeInfo> *> vertexSet = graph.getVertexSet();
    for (size_t i = 0; i < vertexSet.size(); i++)
    {
        gv->addNode(vertexSet[i]->getInfo().id, vertexSet[i]->getInfo().x, vertexSet[i]->getInfo().y);
        if (vertexSet[i]->getInfo().name == "house")
            gv->setVertexColor(vertexSet[i]->getInfo().id, "red");
    }

    for (size_t i = 0; i < stations.size(); i++)
        gv->setVertexColor(stations[i], "green");

    int edgeID = 0;
    vector<int> edges;
    for (size_t i = 0; i < vertexSet.size(); i++)
    {
        vector<Edge<NodeInfo> > adj = vertexSet[i]->getAdjacentEdges();
        for (size_t j = 0; j < adj.size(); j++)
        {
            int src = vertexSet[i]->getInfo().id;
            int dst = adj[j].getDestination()->getInfo().id;

            if (!edgeExists(edges, src, dst))
            {
                gv->addEdge(edgeID, src, dst, EdgeType::UNDIRECTED);
                stringstream ss;
                ss << adj[j].getWeight();
                gv->setEdgeLabel(edgeID, ss.str());
                edges.push_back(src);
                edges.push_back(dst);
                edgeID++;
            }
        }
    }

    if (path.size() != 0)
    {
        for (size_t i = 0; i < path.size() - 1; i+=2)
        {
            gv->addEdge(edgeID, path[i], path[i + 1], EdgeType::UNDIRECTED);
            gv->setEdgeColor(edgeID, "green");
            gv->setEdgeThickness(edgeID, 2);
            edgeID++;
        }
    }

    cin.clear();
    cin.ignore(100, '\n');
    cout << "\n\tPress enter to continue...";
    cin.get();

    gv->closeWindow();
    delete(gv);
}
Beispiel #4
0
void exercicio1()
{
	GraphViewer *gv = new GraphViewer(600, 600, true);

	gv->setBackground("background.jpg");

	gv->createWindow(600, 600);

	gv->defineEdgeDashed(true);
	gv->defineVertexColor("blue");
	gv->defineEdgeColor("black");

	gv->addNode(0);
	gv->addNode(1);
	gv->addEdge(0, 0, 1, EdgeType::UNDIRECTED);

	Sleep(2000); // use sleep(1) in linux ; Sleep(2000) on Windows

	gv->removeEdge(0);
	gv->removeNode(1);
	gv->addNode(2);

	gv->rearrange();

	Sleep(2000);

	gv->addEdge(1, 0, 2, EdgeType::UNDIRECTED);
	gv->defineEdgeCurved(false);

	gv->setVertexLabel(0, "Isto e um no");
	gv->setEdgeLabel(1, "Isto e uma aresta");

	gv->setVertexColor(2, "green");
	gv->setEdgeColor(1, "yellow");

	gv->setVertexSize(2, 40);
	gv->setVertexIcon(0, "icon.gif");

	gv->setEdgeDashed(1, false);

	gv->rearrange();

}
Beispiel #5
0
void exercicio2()
{
	GraphViewer *gv = new GraphViewer(600, 600, false);

	gv->createWindow(600, 600);

	gv->defineEdgeColor("blue");
	gv->defineVertexColor("yellow");
	gv->addNode(0,300,50);
	gv->addNode(1,318,58);
	gv->addNode(4,300,100);
	gv->addNode(7,282,58);
	gv->addNode(2,325,75);
	gv->addNode(3,318,93);
	gv->addNode(6,275,75);
	gv->addNode(5,282,93);

	gv->addNode(8,150,200);

	gv->setVertexColor(8, "green");
	gv->setVertexColor(9, "blue");
	gv->setVertexColor(10, "green");
	gv->setVertexColor(11, "blue");
	gv->setVertexColor(12, "green");
	gv->setVertexColor(13, "green");
	gv->addNode(9,300,200);
	gv->addNode(10,450,200);
	gv->addNode(11,300,400);

	gv->addNode(12,200,550);
	gv->addNode(13,400,550);

	gv->addEdge(0, 0, 1, EdgeType::UNDIRECTED);
	gv->addEdge(1, 1, 2, EdgeType::UNDIRECTED);
	gv->addEdge(2, 2, 3, EdgeType::UNDIRECTED);
	gv->addEdge(3, 3, 4, EdgeType::UNDIRECTED);
	gv->addEdge(4, 4, 5, EdgeType::UNDIRECTED);
	gv->addEdge(5, 5, 6, EdgeType::UNDIRECTED);
	gv->addEdge(6, 6, 7, EdgeType::UNDIRECTED);
	gv->addEdge(7, 7, 0, EdgeType::UNDIRECTED);

	gv->addEdge(8, 4, 9, EdgeType::UNDIRECTED);
	gv->addEdge(9, 9, 8, EdgeType::UNDIRECTED);
	gv->addEdge(10, 9, 10, EdgeType::UNDIRECTED);
	gv->addEdge(11, 9, 11, EdgeType::UNDIRECTED);
	gv->addEdge(12, 11, 12, EdgeType::UNDIRECTED);
	gv->addEdge(13, 11, 13, EdgeType::UNDIRECTED);


	gv->rearrange();
	bool first=true;

	while(1)
	{
		Sleep(2000);
		if (first)
		{
		  gv->removeNode(12);
		  gv->removeNode(13);
		  first=false;
		}
		else
		{
		  gv->removeNode(20);
		  gv->removeNode(21);
		}
		gv->addNode(14,250,550);
		gv->addNode(15,350,550);
		gv->addEdge(14, 11, 14, EdgeType::UNDIRECTED);
		gv->addEdge(15, 11, 15, EdgeType::UNDIRECTED);
		gv->rearrange();

		Sleep(2000);
		gv->removeNode(14);
		gv->removeNode(15);
		gv->addNode(16,300,550);
		gv->addNode(17,300,550);
		gv->addEdge(16, 11, 16, EdgeType::UNDIRECTED);
		gv->addEdge(17, 11, 17, EdgeType::UNDIRECTED);
		gv->rearrange();
		Sleep(2000);

		gv->removeNode(16);
		gv->removeNode(17);
		gv->addNode(18,250,550);
		gv->addNode(19,350,550);
		gv->addEdge(18, 11, 18, EdgeType::UNDIRECTED);
		gv->addEdge(19, 11, 19, EdgeType::UNDIRECTED);
		gv->rearrange();
		Sleep(2000);

		gv->removeNode(18);
		gv->removeNode(19);
		gv->addNode(20,200,550);
		gv->addNode(21,400,550);
		gv->addEdge(20, 11, 20, EdgeType::UNDIRECTED);
		gv->addEdge(21, 11, 21, EdgeType::UNDIRECTED);
		gv->rearrange();
	}
}
Beispiel #6
0
void exercicio3()
{
	GraphViewer *gv = new GraphViewer(600, 600, false);

	gv->createWindow(600, 600);

	gv->defineEdgeColor("blue");
	gv->defineVertexColor("yellow");

	ifstream inFile;

	//Ler o ficheiro nos.txt
	inFile.open("nos.txt");

	if (!inFile) {
	    cerr << "Unable to open file datafile.txt";
	    exit(1);   // call system to stop
	}

	std::string   line;

	int idNo=0;
	int X=0;
	int Y=0;

	while(std::getline(inFile, line))
	{
	    std::stringstream linestream(line);
	    std::string         data;

	    linestream >> idNo;

	    std::getline(linestream, data, ';');  // read up-to the first ; (discard ;).
	    linestream >> X;
	    std::getline(linestream, data, ';');  // read up-to the first ; (discard ;).
	    linestream >> Y;
	    gv->addNode(idNo,X,Y);

	}

	inFile.close();


	//Ler o ficheiro arestas.txt
	inFile.open("arestas.txt");

		if (!inFile) {
		    cerr << "Unable to open file datafile.txt";
		    exit(1);   // call system to stop
		}

		int idAresta=0;
		int idNoOrigem=0;
		int idNoDestino=0;

		while(std::getline(inFile, line))
		{
		    std::stringstream linestream(line);
		    std::string data;


		    linestream >> idAresta;

		    std::getline(linestream, data, ';');  // read up-to the first ; (discard ;).
		    linestream >> idNoOrigem;
		    std::getline(linestream, data, ';');  // read up-to the first ; (discard ;).
		    linestream >> idNoDestino;
		    gv->addEdge(idAresta,idNoOrigem,idNoDestino, EdgeType::UNDIRECTED);

		}

		inFile.close();

	gv->rearrange();
}
Beispiel #7
0
/**
 *  \brief Prints the given graph
 *  \param grafo Graph to be printed
 */
void showGraph(Graph<Localizacao> &grafo)
{
 	GraphViewer *gv = new GraphViewer(800, 800, true);

 	gv->createWindow(800, 800);


 	gv->defineVertexColor("blue");
 	gv->defineEdgeColor("black");


	unsigned int id1, id2;
 	string s;
 	stringstream ss;


 	for (unsigned int i = 0; i < grafo.getVertexSet().size(); i++) {
 		id1 = grafo.getVertexSet()[i]->getInfo().getId();
 		s = grafo.getVertexSet()[i]->getInfo().getRua();
 		ss << 1;
 		gv->addNode(id1);
 		gv->setVertexLabel(id1, s + " " + ss.str());

 		if(grafo.getVertexSet()[i]->getInfo().getNome() == "Garagem")
 			gv->setVertexColor(id1,"red");
 		else if(grafo.getVertexSet()[i]->getInfo().getNome() == "Escola")
 			gv->setVertexColor(id1,"green");


 		ss.str("");
 	}
 	gv->rearrange();

 	for (unsigned int vert = 0; vert < grafo.getVertexSet().size(); vert++) {
 		for (unsigned int edge = 0; edge < grafo.getVertexSet()[vert]->getAdj().size(); edge++) {
 			id1 = grafo.getVertexSet()[vert]->getInfo().getId();
 			id2 = grafo.getVertexSet()[vert]->getAdj()[edge].getDest()->getInfo().getId();


 			if (grafo.getVertexSet()[vert]->path != NULL && grafo.getVertexSet()[vert]->path->getInfo().getId() == id2) {
 				gv->setEdgeColor(id1*1000 + id2, "green");
 				gv->setEdgeThickness(id1*1000 + id2, 5);
			}


 			gv->addEdge(id1 * 1000 + id2, id1, id2, EdgeType::DIRECTED);

 			gv->setEdgeWeight(id1 * 1000 + id2, grafo.getVertexSet()[vert]->getAdj()[edge].getWeight());
 			ss.str("");
 		}
 	}

 	gv->rearrange();

 #ifdef __linux__
 	sleep(1);
 #else
 	Sleep(100); // use sleep(1) in linux ; Sleep(100) on Windows
 #endif

}
Beispiel #8
0
int main() {


	Graph <VertexInfo> grafo;
	vector <Aviao> avioes;


	VertexInfo inicio={"DKR",Data("09/01/2009 00:00"),1};
	VertexInfo fim={"LIS",Data("09/01/2009 8:00"),2};

	carregarVoos(grafo,inicio,fim);
	carregarAvioes(avioes);

	cout << "Carregado" << endl;
	cout << "Calculando tempo minimo..." << endl;
	grafo.calculateMinTC(inicio);
	cout << "Calculado" << endl;

	GraphViewer *gv;
	int input=-1;
	while (input!=0) {
		cout << "--- GESTOR DE VOOS ---" << endl;
		cout << "| Partida:\t" << printVertexInfo(grafo.getVertex(inicio)->getInfo()) << endl;
		cout << "| Chegada:\t" << printVertexInfo(grafo.getVertex(fim)->getInfo()) << endl;
		cout << "--- MENU ---" << endl;
		cout << "|\t1 - Mostrar caminho mais curto" << endl;
		cout << "|\t2 - Mostrar voos" << endl;
		cout << "|\t3 - Mostrar distribuicao dos avioes" << endl;
		cout << "|\t4 - Mostrar diagrama de Gantt" << endl;
		cout << "|\t-----" << endl;
		cout << "|\t5 - Alterar partida" << endl;
		cout << "|\t6 - Alterar chegada" << endl;
		cout << "|\t-----" << endl;
		cout << "|\t0 - Sair" << endl;
		cout << "\tEscolha:";
		cin >> input;
		VertexInfo newInfo;
		switch (input) {
			case 1:case 2:case 3:
				gv=new GraphViewer(SCREEN_W*MULT_SIZE,SCREEN_H*MULT_SIZE,true);
				break;
			case 4:
				gv=new GraphViewer(SCREEN_W*MULT_SIZE,SCREEN_H*MULT_SIZE,false);
				break;
			case 5:case 6:
				string temp;
				stringstream tempstream;
				cout << "Local:"; cin >> newInfo.local;
				cout << "Dia:"; cin >> temp;
				tempstream << "09/"<< temp <<"/2009 ";
				cout << "Horas(hh:mm):"; cin >> temp;
				tempstream << temp;
				newInfo.data=Data(tempstream.str());
				newInfo.tipo=input-4;
			break;
		}
		if (input>=1 && input<=4) {
			gv->createWindow(SCREEN_W,SCREEN_H);
			gv->defineVertexColor("gray");
			gv->defineEdgeColor("gray");
		}
		switch (input) {
			case 1:
				grafo.showPath(gv);
				break;
			case 2:
				grafo.showTopological(gv);
				break;
			case 3:
				grafo.showAvioes(gv,avioes);
				break;
			case 4:
				grafo.showGantt(gv);
				break;
			case 5:
				inicio=newInfo;
				break;
			case 6:
				fim=newInfo;
				break;
		}
		if (input==5 || input==6) {
			carregarVoos(grafo,inicio,fim);
			cout << "Carregado" << endl;
			cout << "Calculando tempo minimo..." << endl;
			grafo.calculateMinTC(inicio);
			cout << "Calculado" << endl;

		}
	}
	return 0;
}