2024-04-11 16:02:49 +00:00
|
|
|
// ***************************************************************
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
|
|
|
// SPDX-FileType: SOURCE
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// ***************************************************************
|
|
|
|
|
2023-07-15 16:31:50 +00:00
|
|
|
#ifndef MST_H
|
|
|
|
#define MST_H
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2024-03-08 21:20:54 +00:00
|
|
|
#include <torch/torch.h>
|
2023-07-15 16:31:50 +00:00
|
|
|
namespace bayesnet {
|
|
|
|
class MST {
|
|
|
|
public:
|
|
|
|
MST() = default;
|
2023-11-08 17:45:35 +00:00
|
|
|
MST(const std::vector<std::string>& features, const torch::Tensor& weights, const int root);
|
|
|
|
std::vector<std::pair<int, int>> maximumSpanningTree();
|
2024-04-11 15:29:46 +00:00
|
|
|
private:
|
|
|
|
torch::Tensor weights;
|
|
|
|
std::vector<std::string> features;
|
|
|
|
int root = 0;
|
2023-07-15 16:31:50 +00:00
|
|
|
};
|
|
|
|
class Graph {
|
|
|
|
public:
|
2023-07-29 17:38:42 +00:00
|
|
|
explicit Graph(int V);
|
2023-07-15 16:31:50 +00:00
|
|
|
void addEdge(int u, int v, float wt);
|
|
|
|
int find_set(int i);
|
|
|
|
void union_set(int u, int v);
|
|
|
|
void kruskal_algorithm();
|
2023-11-08 17:45:35 +00:00
|
|
|
std::vector <std::pair<float, std::pair<int, int>>> get_mst() { return T; }
|
2024-04-11 15:29:46 +00:00
|
|
|
private:
|
|
|
|
int V; // number of nodes in graph
|
|
|
|
std::vector <std::pair<float, std::pair<int, int>>> G; // std::vector for graph
|
|
|
|
std::vector <std::pair<float, std::pair<int, int>>> T; // std::vector for mst
|
|
|
|
std::vector<int> parent;
|
2023-07-15 16:31:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|