Pagini recente » Cod sursa (job #2080172) | Cod sursa (job #2144907) | Cod sursa (job #734203) | Cod sursa (job #3189549) | Cod sursa (job #1711359)
/* ========================================================================
$Creator: Emanuel Truta $
$Notice: (C) Copyright 2016 by Emanuel Truta. All Rights Reserved. $
======================================================================== */
#include <vector>
#include <queue>
#include <stdlib.h>
#include <stdio.h>
#include "manu_header.h"
#include "graph.cpp"
int main()
{
printf("===========================\n");
graph Graph = {};
Graph.Directed = 1;
Graph.StartIndex = 0;
Graph.ProvideReverse = 1;
// Reading a graph from a file.
char *GraphInputFile = "graph1k.txt";
Graph.Read(GraphInputFile);
printf("Graph read from file: %s\n", GraphInputFile);
// Get Graph Size.
printf("Size of graph: %d\n", Graph.Size);
// Check if edge exists.
u32 Node1 = 1;
u32 Node2 = 2;
printf("Edge between %d and %d: %d\n", Node1, Node2, Graph.HasEdge(Node1, Node2));
// GetOutDeggee of vertex.
Node1 = 1;
printf("Out degree of %d is: %d: \n", Node1, Graph.Out[Node1].size());
// GetInDeggee of vertex.
Node1 = 1;
printf("In degree of %d is: %d: \n", Node1, Graph.In[Node1].size());
// GetOutboundNeighbours
Node1 = 1;
printf("Outbound neighbours of %d: ", Node1);
for (graph::iter it = Graph.Out[Node1].begin(); it != Graph.Out[Node1].end(); ++it)
{
printf("%d ", it->Node);
}
printf("\n");
// GetInboundNeighbours
Node1 = 1;
printf("Inbound neighbours of %d: ", Node1);
for (graph::iter it = Graph.In[Node1].begin(); it != Graph.In[Node1].end(); ++it)
{
printf("%d ", it->Node);
}
printf("\n");
// GetCost
Node1 = 1;
Node2 = 4;
printf("Cost of edge %d %d is: %d\n", Node1, Node2, Graph.GetCost(Node1, Node2));
// SetCost
Node1 = 1;
Node2 = 2;
u32 Cost = 1;
Graph.SetCost(Node1, Node2, Cost);
printf("Changed cost of edge %d %d is now: %d\n", Node1, Node2, Graph.GetCost(Node1, Node2));
// GetDistanceForwardBFS
Node1 = 1;
Node2 = 999;
printf("GetDistanceForwardBFS(%d, %d): %d\n", Node1, Node2, Graph.GetDistanceForwardBFS(Node1, Node2));
// GetDistanceBackwardBFS
Node1 = 1;
Node2 = 999;
printf("GetDistanceBackwardBFS(%d, %d): %d\n", Node1, Node2, Graph.GetDistanceBackwardBFS(Node1, Node2));
// GetDistanceDijkstra
Node1 = 1;
Node2 = 5;
printf("GetDistanceDijkstra(%d, %d): %d\n", Node1, Node2, Graph.GetDistanceDijkstra(Node1, Node2));
// std::vector<u32> Dist = Graph.DoForwardBFS(1);
// FILE* OutFile = fopen("dijkstra.out", "w");
// for (u32 I = 2; I < Dist.size(); I++)
// {
// if (Dist[I] == 0x3f3f3f3f) Dist[I] = 0;
// fprintf(OutFile, "%d ", Dist[I]);
// }
// fprintf(OutFile, "\n");
printf("\n");
return 0;
}