24 for (
unsigned short i = 0; i < num_nodes; i++) {
30 for (
unsigned short j = i; j < num_nodes; j++) {
40 unsigned short src = edge->
src;
41 unsigned short dest = edge->
dest;
71 printf(
"\nMST or 1-Tree with cost: %lf and validity = %s\n", tree->
cost, tree->
isValid ?
"TRUE" :
"FALSE");
73 double dim = (log(tree->
num_nodes) / log(10) + 1) * 2 + 7;
74 for (
unsigned short i = 0; i < tree->
num_edges; i++) {
75 char edge_print [(int) dim] ;
76 char edge_print_dest [(int) (dim-7)/2] ;
78 sprintf(edge_print,
"%i", curr->
src);
79 strcat(edge_print,
" <--> ");
80 sprintf(edge_print_dest,
"%i", curr->
dest);
81 strcat(edge_print, edge_print_dest);
82 printf(
"Edge%i:\t%s\tweight = %lf\tprob = %lf\n",
93 printf(
"\nMST or 1-Tree with cost: %f and validity = %s\n", tree->
cost, tree->
isValid ?
"TRUE" :
"FALSE");
95 double dim = (log(tree->
num_nodes) / log(10) + 1) * 2 + 7;
96 for (
unsigned short i = 0; i < tree->
num_edges; i++) {
97 char edge_print [(int) dim] ;
98 char edge_print_dest [(int) (dim-7)/2] ;
100 sprintf(edge_print,
"%i", curr->
src);
101 strcat(edge_print,
" <--> ");
102 sprintf(edge_print_dest,
"%i", curr->
dest);
103 strcat(edge_print, edge_print_dest);
104 printf(
"Edge%i: %s weight = %f prob = %f\n",
void add_edge(MST *tree, const Edge *edge)
Add an Edge to the MST.
void print_mst(const MST *tree)
Print the MST, printing all the information it contains.
void create_mst(MST *mst, const Node *nodes, unsigned short num_nodes)
Create a Minimum Spanning Tree from a set of Nodes.
void print_mst_original_weight(const MST *tree, const Graph *graph)
Print the MST, printing all the information it contains.
This file contains the declaration of the Minimum Spanning Tree datastructure.
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.
Minimum Spanning Tree, or MST, and also a 1-Tree.
unsigned short num_nodes
The number of Nodes in the MST.
short edges_matrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]
-1 if there is no Edge between the two Nodes, otherwise the index of the Edge in the MST.
double prob
The probability of the MST, i.e. the average of the probabilities of its Edges.
Edge edges[MAX_VERTEX_NUM]
The set of Edges in the MST, these are |V| because the MST can be a 1-Tree.
Node nodes[MAX_VERTEX_NUM]
The set of Nodes in the MST.
unsigned short num_edges
The number of Edges in the MST.
bool isValid
True if the MST has the correct number of Edges, false otherwise.
double cost
The total cost of the MST, i.e. the sum of the weights of the Edges.
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.