1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| #include "clustering_chaud.h"
#include <iostream>
#include <array>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_set>
#include <functional>
#include <cstdlib>
#include <algorithm>
#include <set>
struct cmp
{
bool operator()(Edge edge, Edge other)
{
return edge.cost < other.cost and !((edge.vertex1 == other.vertex1 and edge.vertex2 == other.vertex2) or (edge.vertex1 == other.vertex2 and edge.vertex2 == other.vertex1));
}
};
Edge::Edge(std::string vertex1_, std::string vertex2_, int cost_) : vertex1(vertex1_), vertex2(vertex2_), cost(cost_)
{
}
typedef std::map<std::string, bool> Vertices;
typedef std::set<Edge, cmp> Graph;
Vertices recuperer_vertices();
Graph get_graph(Vertices vertices);
void flip_bit(char& bit);
int compute_distance(std::string vertex1, std::string vertex2);
int compute_distance(std::string vertex1, std::string vertex2){
int distance(0);
for(size_t i(0); i < vertex1.size(); i++){
if(vertex1[i] != vertex2[i])
distance++;
}
return distance;
}
void flip_bit(char& bit){
if(bit == '0')
bit = '1';
else if(bit == '1')
bit = '0';
else
std::cerr << "Dafuk un bit c'est 0 ou 1" << std::endl;
}
Vertices recuperer_vertices(){
Vertices vertices;
std::string ligne("");
std::ifstream fichier("clustering_big.txt");
if(fichier){
getline(fichier, ligne);
while(getline(fichier, ligne)){
std::string vertex("");
for(size_t i(0); i < 48; i += 2){
vertex += ligne[i];
}
vertices[vertex] = true;
}
}
else
std::cerr << "Impossible d'ouvrir le fichier " << std::endl;
return vertices;
}
int main(int argc, char* argv[]){
Vertices vertices = recuperer_vertices();
Graph g(get_graph(vertices));
std::cout << g.max_size() << std::endl;
Graph s;
s.insert(Edge("1", "3", 12));
s.insert(Edge("4", "1", 10));
s.insert(Edge("9", "7", 8));
s.insert(Edge("3", "1", 9));
s.insert(Edge("10", "3", 9));
s.insert(Edge("3", "10", 12));
/* for(auto& el : g)
std::cout << el.vertex1 << " - " << el.vertex2 << " : " << el.cost << std::endl;
std::array<int, t> cc;
for(size_t i(0); i < t; i++)
cc[i] = i;
*/
return 0;
}
Graph get_graph(Vertices vertices){
Graph graph;
size_t l(0);
for(auto& vertex : vertices){
for(size_t i(0); i < 24; i++){
for(size_t j(i); j < 24; j++){
std::string v(vertex.first);
if(i != j){
flip_bit(v[i]);
flip_bit(v[j]);
}
else
flip_bit(v[i]);
if(vertices.find(v)!= vertices.end()) {
l++;
Edge e(vertex.first, v, compute_distance(vertex.first, v));
graph.insert(e);
if(graph.find(e) != graph.end())
std::cout << l << " eme insertion" << std::endl;
}
}
}
}
return graph;
} |
Partager