Graph Convolutional Branch and Bound v1.0.0
A TSP solver that combines a graph convolutional network with a 1-Tree branch-and-bound.
Loading...
Searching...
No Matches
Functions
mfset.c File Reference

This file contains the implementation of the Merge-Find Set datastructure for the Minimum Spanning Tree problem. More...

#include "mfset.h"

Go to the source code of this file.

Functions

void create_forest_constrained (Forest *forest, const Node *nodes, unsigned short num_nodes, unsigned short candidateId)
 Create a new Forest with n Sets, each Set containing a Node, with constraints.
 
void create_forest (Forest *forest, const Node *nodes, unsigned short num_nodes)
 Create a new Forest with n Sets, each Set containing a Node, without constraints.
 
Setfind (Set *set)
 Find the root of a Set.
 
void merge (Set *set1, Set *set2)
 Merge two Sets in the Forest if they are not already in the same Set.
 
void print_forest (const Forest *forest)
 Print all the Forest.
 

Detailed Description

This file contains the implementation of the Merge-Find Set datastructure for the Minimum Spanning Tree problem.

Author
Lorenzo Sciandra
Version
1.0.0 @data 2024-05-1

Repo: https://github.com/LorenzoSciandra/GraphConvolutionalBranchandBound

Definition in file mfset.c.

Function Documentation

◆ create_forest()

void create_forest ( Forest forest,
const Node nodes,
unsigned short  num_nodes 
)

Create a new Forest with n Sets, each Set containing a Node, without constraints.

Parameters
nodesPointer to the List of Nodes.
num_nodesNumber of Nodes in the List.
forestPointer to the Forest to be initialized.

Definition at line 31 of file mfset.c.

◆ create_forest_constrained()

void create_forest_constrained ( Forest forest,
const Node nodes,
unsigned short  num_nodes,
unsigned short  candidateId 
)

Create a new Forest with n Sets, each Set containing a Node, with constraints.

The candidateId Node is not added to the Forest because for the 1-tree I need a MST on the remaining Nodes.

Parameters
nodesPointer to the List of Nodes.
num_nodesNumber of Nodes in the List.
candidateIdId of the Node in the List to be excluded from the Forest.
forestPointer to the Forest to be initialized.

Definition at line 17 of file mfset.c.

◆ find()

Set * find ( Set set)

Find the root of a Set.

Complexity: O(log n), only a path in the tree is traversed. The parent Set of all the Nodes in the path are updated to point to the root, to reduce the complexity of the next find operations.

Parameters
setPointer to the Set.
Returns
Pointer to the root of the Set.

Definition at line 44 of file mfset.c.

◆ merge()

void merge ( Set set1,
Set set2 
)

Merge two Sets in the Forest if they are not already in the same Set.

The Set with the highest rank is the parent of the other. This is done to let the find operation run in O(log n) time. Complexity: O(log n_1 + log n_2)

Parameters
set1Pointer to the first Set.
set2Pointer to the second Set.

Definition at line 53 of file mfset.c.

◆ print_forest()

void print_forest ( const Forest forest)

Print all the Forest.

Used for debugging purposes.

Parameters
forestPointer to the Forest.

Definition at line 72 of file mfset.c.