first commit
This commit is contained in:
86
src/Graphe.h
Normal file
86
src/Graphe.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
struct Edge;
|
||||
|
||||
struct Vertex {
|
||||
std::vector<float> m_Values;
|
||||
std::vector<Edge*> m_Edges;
|
||||
|
||||
std::size_t getWeight() {
|
||||
return m_Edges.size();
|
||||
}
|
||||
|
||||
std::string m_Name;
|
||||
};
|
||||
|
||||
struct Edge {
|
||||
Vertex* m_Start;
|
||||
Vertex* m_End;
|
||||
std::vector<float> m_Values;
|
||||
};
|
||||
|
||||
using VertexMap = std::map<std::string, Vertex*>;
|
||||
|
||||
using Path = std::vector<Vertex*>;
|
||||
|
||||
class Graphe {
|
||||
private:
|
||||
VertexMap m_VertexMap;
|
||||
std::vector<Vertex> m_Vertecies;
|
||||
std::vector<Edge> m_Edges;
|
||||
|
||||
std::string file_name;
|
||||
std::string comment;
|
||||
bool directed;
|
||||
int nb_vertices;
|
||||
int nb_edges;
|
||||
int nb_values_by_vertex;
|
||||
int nb_values_by_edge;
|
||||
|
||||
public:
|
||||
Graphe(const std::string& fileName);
|
||||
|
||||
std::vector<Vertex>& getVertecies() {
|
||||
return m_Vertecies;
|
||||
}
|
||||
|
||||
Vertex* getVertex(const std::string& name) {
|
||||
return m_VertexMap.at(name);
|
||||
}
|
||||
|
||||
std::vector<Edge>& getEdges() {
|
||||
return m_Edges;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Graphe& graphe);
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const Path& p) {
|
||||
os << "[";
|
||||
for (size_t i = 0; i < p.size(); i++) {
|
||||
os << p[i]->m_Name;
|
||||
if (i < p.size() - 1) {
|
||||
os << ", ";
|
||||
}
|
||||
}
|
||||
return os << "]";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& os, const std::vector<T>& value) {
|
||||
os << "[";
|
||||
for (size_t i = 0; i < value.size(); i++)
|
||||
{
|
||||
os << value[i];
|
||||
if (i < value.size() - 1) {
|
||||
os << ", ";
|
||||
}
|
||||
}
|
||||
os << "]";
|
||||
return os;
|
||||
}
|
||||
Reference in New Issue
Block a user