26 unsigned short numNodes = 0;
27 for (
size_t j = 0; j < nodes_list->
size; j++) {
31 graph->
nodes[numNodes].
y = curr->
y;
32 graph->
nodes[numNodes].
x = curr->
x;
38 unsigned short numEdges = 0;
40 for (
size_t i = 0; i < edges_list->
size ; i++) {
43 unsigned short src = current_edge->
src;
44 unsigned short dest = current_edge->
dest;
77 for (
size_t i = 0; i < nodes->
size; i++) {
79 for (
size_t j = i + 1; j < nodes->
size; j++) {
87 edges[z].
weight = (float) sqrt(pow(fabs(node_src->
x - node_dest->
x), 2) +
88 pow(fabs(node_src->
y - node_dest->
y), 2));
113 printf(
"\nCost: %lf\n", G->
cost);
116 double dim = (log(G->
num_nodes) / log(10) + 1) * 2 + 7;
117 for (
unsigned short j = 0; j < G->
num_edges; j++) {
118 char edge_print [(int) dim] ;
119 char edge_print_dest [(int) (dim-7)/2] ;
121 sprintf(edge_print,
"%i", curr.
src);
122 strcat(edge_print,
" <--> ");
123 sprintf(edge_print_dest,
"%i", curr.
dest);
124 strcat(edge_print, edge_print_dest);
126 printf(
"Edge%i:\t%s\tweight = %.*f\tprob = %.*f\n",
void print_graph(const Graph *G)
Print Nodes, Edges and other information of the Graph.
void create_graph(Graph *graph, List *nodes_list, List *edges_list, GraphKind kind)
Create a new instance of a Graph with all the needed parameters.
void create_euclidean_graph(Graph *graph, List *nodes)
Create a new instance of an euclidean graphs only the Nodes are necessary.
The data structures to model the Graph.
GraphKind
Enum to specify the kind of the Graph.
@ WEIGHTED_GRAPH
The Graph is weighted.
void add_elem_list_bottom(List *list, void *element)
Adds an DllElem to the bottom of the List.
void del_list(List *list)
Delete an instance of a List.
List * new_list(void)
Create a new instance of a List.
void * get_list_elem_index(List *list, size_t index)
Retrieves a pointer to an DllElem from the List.
void * list_iterator_get_next(ListIterator *iterator)
Method that retrieves the current DllElem of an ListIterator and moves the pointer to the next object...
ListIterator * create_list_iterator(List *list)
Used for the creation of a new ListIterator.
void delete_list_iterator(ListIterator *iterator)
Delete the ListIterator given.
The declaration of the functions to manipulate the ListIterator.
#define MAX_EDGES_NUM
The maximum number of edges in the Graph.
unsigned short dest
ID of the destination vertex.
unsigned short src
ID of the source vertex.
double prob
Probability of the Edge to be in an optimal tour.
double weight
Weight of the Edge, 1 if the data_structures is not weighted.
unsigned short symbol
Symbol of the Edge, i.e. its unique ID.
unsigned short positionInGraph
Position of the Edge in the list of Edges of the Graph.
Edge edges_matrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]
Adjacency matrix of the Graph.
unsigned short num_edges
Number of Edges in the Graph.
bool orderedEdges
True if the Edges are ordered by weight, false otherwise.
Edge edges[MAX_EDGES_NUM]
Array of Edges.
GraphKind kind
Type of the Graph.
Node nodes[MAX_VERTEX_NUM]
Array of Nodes.
double cost
Sum of the weights of the Edges in the Graph.
unsigned short num_nodes
Number of Nodes in the Graph.
The iterator for the List.
size_t size
The current size of the List.
double x
x coordinate of the Node.
double y
y coordinate of the Node.
unsigned short num_neighbours
Number of neighbours of the Node.
unsigned short positionInGraph
Position of the Node in the list of Nodes of the Graph, i.e. its unique ID.
unsigned short neighbours[MAX_VERTEX_NUM - 1]
Array of IDs of the Node's neighbors.