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 | Variables
main Namespace Reference

Functions

def compute_prob (net, config, dtypeLong, dtypeFloat)
 
def write_adjacency_matrix (graph, y_probs, x_edges_values, nodes_coord, filepath, num_nodes, kmedoids_labels=None)
 
def add_dummy_cities (num_nodes, model_size)
 
def create_temp_file (num_nodes, str_grap)
 
def cluster_nodes (graph, k)
 
def fix_instance_size (graph, num_nodes, model_size=100)
 
def get_instance (num_nodes)
 
def main (filepath, num_nodes, model_size)
 

Variables

 category
 
sys filepath = sys.argv[1]
 
int num_nodes = int(sys.argv[2])
 
int model_size = int(sys.argv[3])
 

Detailed Description

    @file main.py
    @author Lorenzo Sciandra
    @brief A recombination of code take from: https://github.com/chaitjo/graph-convnet-tsp.
    Some functions were created for the purpose of the paper.
    @version 1.0.0
    @data 2024-05-1
    @copyright Copyright (c) 2024, license MIT
    Repo: https://github.com/LorenzoSciandra/GraphConvolutionalBranchandBound

Function Documentation

◆ add_dummy_cities()

def main.add_dummy_cities (   num_nodes,
  model_size 
)
This function adds dummy cities to the graph instance. The dummy cities are randomly generated are
added to the graph instance and the new instance is saved in a temporary file.
Args:
    num_nodes: The number of nodes of the graph instance.
    model_size: The size of the Graph Convolutional Network to use.

Definition at line 199 of file main.py.

◆ cluster_nodes()

def main.cluster_nodes (   graph,
  k 
)
Applies the k-medoids clustering to the graph.
Args:
    graph: The graph to cluster.
    k: The number of clusters to create.
Returns:
    medoids_str: The medoids of the clusters.
    kmedoids.labels_: The labels of the clusters.

Definition at line 269 of file main.py.

◆ compute_prob()

def main.compute_prob (   net,
  config,
  dtypeLong,
  dtypeFloat 
)
This function computes the probability of the edges being in the optimal tour, by running the GCN.
Args:
    net: The Graph Convolutional Network.
    config: The configuration file, from which the parameters are taken.
    dtypeLong: The data type for the long tensors.
    dtypeFloat: The data type for the float tensors.
Returns:
    y_probs: The probability of the edges being in the optimal tour.
    x_edges_values: The distance between the nodes.

Definition at line 37 of file main.py.

◆ create_temp_file()

def main.create_temp_file (   num_nodes,
  str_grap 
)
Creates a temporary file with the graph instance.
Args:
    num_nodes: The number of nodes of the graph instance.
    str_grap: The graph instance.

Definition at line 253 of file main.py.

◆ fix_instance_size()

def main.fix_instance_size (   graph,
  num_nodes,
  model_size = 100 
)
The function that fixes the instance size with clustering.
It applies the k-medoids clustering to the graph and creates a new instance with the medoids as the new nodes.
Args:
    graph: The graph to fix.
    num_nodes: The number of nodes of the graph instance.
    model_size: The size of the Graph Convolutional Network to use.

Definition at line 287 of file main.py.

◆ get_instance()

def main.get_instance (   num_nodes)
The function that reads the current instance from the file.
Args:
    num_nodes: The number of nodes of the graph instance.
Returns:
    graph: The graph instance.

Definition at line 312 of file main.py.

◆ main()

def main.main (   filepath,
  num_nodes,
  model_size 
)
The function that runs the Graph Convolutional Network and writes the adjacency matrix to a file
for the given input instance.
Args:
    filepath: The path to the file where the adjacency matrix will be written.
    num_nodes: The number of nodes in the TSP instance.
    model_size: The size of the Graph Convolutional Network to use.

Definition at line 345 of file main.py.

◆ write_adjacency_matrix()

def main.write_adjacency_matrix (   graph,
  y_probs,
  x_edges_values,
  nodes_coord,
  filepath,
  num_nodes,
  kmedoids_labels = None 
)
This function writes the adjacency matrix to a file.
The file is in the format:
        cities: (x1, y1);(x2, y2);...;(xn, yn)
        adjacency matrix:
        (0.0, 0.0);(0.23, 0.9);...;(0.15, 0.56)
        ...
        (0.23, 0.9);(0.3, 0.59);...;(0.0, 0.0)
        where each entry is (distance, probability)
If needed adjusts the size of the graph when the model size is different from the number of nodes in the instance.
Args:
    graph: The set of nodes in the graph.
    y_probs: The probability of the edges being in the optimal tour.
    x_edges_values: The weight of the edges.
    nodes_coord: The nodes coordinates used in the GCN.
    filepath: The path to the file where the adjacency matrix will be written.
    num_nodes: The number of nodes in the TSP instance.
    kmedoids_labels: The labels of the k-medoids clustering.

Definition at line 115 of file main.py.

Variable Documentation

◆ category

main.category

Definition at line 24 of file main.py.

◆ filepath

sys main.filepath = sys.argv[1]

Definition at line 421 of file main.py.

◆ model_size

int main.model_size = int(sys.argv[3])

Definition at line 423 of file main.py.

◆ num_nodes

int main.num_nodes = int(sys.argv[2])

Definition at line 422 of file main.py.