BayesNet/bayesnet/utils/Mst.h

40 lines
1.4 KiB
C
Raw Normal View History

2024-04-11 16:02:49 +00:00
// ***************************************************************
// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
// SPDX-FileType: SOURCE
// SPDX-License-Identifier: MIT
// ***************************************************************
#ifndef MST_H
#define MST_H
#include <vector>
#include <string>
2024-03-08 21:20:54 +00:00
#include <torch/torch.h>
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);
void insertElement(std::list<int>& variables, int variable);
std::vector<std::pair<int, int>> reorder(std::vector<std::pair<float, std::pair<int, int>>> T, int root_original);
2023-11-08 17:45:35 +00:00
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;
};
class Graph {
public:
2023-07-29 17:38:42 +00:00
explicit Graph(int V);
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;
};
}
#endif