24 #include <unordered_map>
25 #include <unordered_set>
115 apply_modifications();
132 m_modifications.clear();
133 m_states = std::move(
states);
141 m_modifications.clear();
157 std::vector<graph_state>&
states() {
return m_states; }
170 const std::vector<graph_state>&
states()
const {
return m_states; }
189 unsigned m_last_node_id = 0;
190 unsigned m_last_edge_id = 0;
192 std::vector<graph_state> m_states;
193 std::vector<std::vector<std::function<void(
graph_state&)>>> m_modifications;
196 void add_modification(
unsigned time, std::function<
void(
graph_state&)> operation) {
197 if (time >= m_modifications.size()) {
198 m_modifications.resize(time + 1);
200 m_modifications[time].push_back(operation);
203 void apply_modifications() {
204 m_states.reserve(m_modifications.size());
205 for (
const auto& mod : m_modifications) {
206 graph_state new_state;
207 if (!m_states.empty()) {
208 new_state = m_states.back();
210 for (
const auto& operation : mod) {
211 operation(new_state);
213 m_states.push_back(std::move(new_state));
216 m_modifications.clear();
219 void recalculate_ids() {
220 auto id_comp = [](
const auto& a,
const auto& b){
return a.id() < b.id(); };
221 auto max_id = [id_comp](
auto begin,
auto end){
222 return std::max_element(begin, end, id_comp)->id().value;
224 for (
const auto& state : m_states) {
225 if (!state.nodes().empty()) {
226 m_last_node_id = std::max(m_last_node_id,
227 max_id(state.nodes().begin(), state.nodes().end()) + 1);
229 if (!state.edges().empty()) {
230 m_last_edge_id = std::max(m_last_edge_id,
231 max_id(state.edges().begin(), state.edges().end()) + 1);
236 void set_bool_values() {
237 for (
unsigned i = 0; i < m_states.size(); ++i) {
238 for (
auto& node : m_states[i].nodes()) {
239 node.is_old((i < m_states.size() - 1)
240 && !m_states[i + 1].node_exists(node.id()));
242 && !m_states[i - 1].node_exists(node.id()));
244 for (
auto& edge : m_states[i].edges()) {
245 edge.is_old((i < m_states.size() - 1)
246 && !m_states[i + 1].edge_exists(edge.id()));
248 && !m_states[i - 1].edge_exists(edge.id()));