formalang/include/NFA/NFAGraph.hpp

75 lines
1.8 KiB
C++
Raw Normal View History

2021-09-27 20:13:02 +00:00
#pragma once
#include <map>
#include <vector>
2021-10-03 13:42:51 +00:00
#include <set>
2021-09-27 20:13:02 +00:00
#include <memory>
namespace NFA {
2021-10-05 13:11:24 +00:00
class NFAGraph {
2021-09-27 20:13:02 +00:00
public:
class Vertex {
public:
2021-10-05 13:11:24 +00:00
Vertex(NFAGraph* owner);
2021-09-27 20:13:02 +00:00
bool IsFinal() const;
bool IsStart() const;
2021-10-03 13:42:51 +00:00
size_t GetNumber() const;
2021-09-27 20:13:02 +00:00
2021-10-05 12:01:30 +00:00
const std::map<char, std::set<size_t>>& GetTransitions() const;
const std::map<char, std::set<size_t>>& GetBackTransitions() const;
void AddEdge(char, size_t);
void RemoveEdge(char, size_t);
2021-10-05 13:11:24 +00:00
void SetOwner(NFAGraph* owner);
2021-10-05 12:01:30 +00:00
void SetFinal(bool status);
void SetStart(bool status);
2021-09-27 20:13:02 +00:00
private:
2021-10-05 13:11:24 +00:00
NFAGraph* owner_;
2021-10-05 12:01:30 +00:00
std::map<char, std::set<size_t>> transitions_;
std::map<char, std::set<size_t>> back_transitions_;
2021-10-03 13:42:51 +00:00
size_t number_;
2021-09-27 20:13:02 +00:00
bool is_final_ = false;
bool is_start_ = false;
2021-10-03 13:42:51 +00:00
2021-10-05 13:11:24 +00:00
friend class NFAGraph;
2021-09-27 20:13:02 +00:00
};
2021-10-05 13:11:24 +00:00
NFAGraph() = default;
NFAGraph(const NFAGraph&) = delete;
NFAGraph(NFAGraph&&);
2021-10-03 13:42:51 +00:00
2021-10-05 13:11:24 +00:00
NFAGraph& operator=(const NFAGraph&) = delete;
NFAGraph& operator=(NFAGraph&&);
2021-10-03 13:42:51 +00:00
size_t AddNewVertex();
void AddFinalVertex(size_t number);
void AddStartVertex(size_t number);
void RemoveVertex(size_t number);
void RemoveFinalVertex(size_t number);
void RemoveStartVertex(size_t number);
2021-10-05 13:11:24 +00:00
void Composition(NFAGraph&&,
2021-10-03 13:42:51 +00:00
std::vector<size_t> start_vertexes,
std::vector<size_t> final_vertexes);
2021-10-10 18:08:13 +00:00
Vertex& GetVertex(size_t number);
bool NotExistVertex(size_t number);
2021-10-03 13:42:51 +00:00
size_t GetCountVertexes() const;
2021-10-10 22:13:50 +00:00
size_t GetReallyCountVertexes() const;
2021-10-03 13:42:51 +00:00
const std::vector<size_t>& GetFinalVertexes() const;
const std::vector<size_t>& GetStartVertexes() const;
2021-09-27 20:13:02 +00:00
2021-10-03 13:42:51 +00:00
void Print() const;
2021-10-05 17:41:05 +00:00
void CreateDotFile(const std::string& filename) const;
2021-09-27 20:13:02 +00:00
private:
2021-10-03 13:42:51 +00:00
size_t count_vertexes_ = 0;
2021-10-10 18:08:13 +00:00
std::map<size_t, Vertex> vertexes_;
2021-10-03 13:42:51 +00:00
std::vector<size_t> final_vertexes_;
std::vector<size_t> start_vertexes_;
2021-09-27 20:13:02 +00:00
};
}