/
serge.balakshiy
/
idef0_model_cpp
Обзор
Документация
Войти
/
serge.balakshiy
/
idef0_model_cpp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
IDEF0Model.cpp
188 строк
7 KB
sergebn
Начало проекта
09 май 2026, 02:21
09 май 2026, 02:21
c6a5429
Код
Авторство
О чём код?
#include "IDEF0Model.h" #include <sstream> bool IDEF0Model::load_from_json(const std::string& filename) { try { std::ifstream file(filename); if (!file.is_open()) { std::cout << "Ошибка: не удалось открыть файл " << filename << "\n"; return false; } std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); json::value jv = json::parse(content); json::object model = jv.as_object(); std::string model_name = model["model_name"].as_string().c_str(); std::cout << "Загружена модель: " << model_name << "\n"; json::array functions_array = model["functions"].as_array(); for (const auto& func_obj : functions_array) { json::object func = func_obj.as_object(); std::string id = func["id"].as_string().c_str(); std::string name = func["name"].as_string().c_str(); auto func_ptr = std::make_shared<Function>(id, name); add_function(func_ptr); if (func.contains("inputs")) { json::array inputs = func["inputs"].as_array(); for (const auto& input_val : inputs) { std::string input_name = input_val.as_string().c_str(); auto flow = std::make_shared<Flow>(input_name, FlowType::INPUT); flows[input_name] = flow; func_ptr->add_input(flow); } } if (func.contains("outputs")) { json::array outputs = func["outputs"].as_array(); for (const auto& output_val : outputs) { std::string output_name = output_val.as_string().c_str(); auto flow = std::make_shared<Flow>(output_name, FlowType::OUTPUT); flows[output_name] = flow; func_ptr->add_output(flow); } } if (func.contains("controls")) { json::array controls = func["controls"].as_array(); for (const auto& control_val : controls) { std::string control_name = control_val.as_string().c_str(); auto flow = std::make_shared<Flow>(control_name, FlowType::CONTROL); flows[control_name] = flow; func_ptr->add_control(flow); } } if (func.contains("mechanisms")) { json::array mechanisms = func["mechanisms"].as_array(); for (const auto& mech_val : mechanisms) { std::string mech_name = mech_val.as_string().c_str(); auto flow = std::make_shared<Flow>(mech_name, FlowType::MECHANISM); flows[mech_name] = flow; func_ptr->add_mechanism(flow); } } } return true; } catch (const std::exception& e) { std::cout << "Ошибка парсинга JSON: " << e.what() << "\n"; return false; } } void IDEF0Model::print_hierarchy() const { std::cout << "Иерархия модели:\n"; for (const auto& [id, func] : functions) { std::cout << " Функция " << id << ": " << func->get_name() << "\n"; // Входы std::cout << " Входы: "; for (const auto& input : func->get_inputs()) { std::cout << input->get_name() << " "; } std::cout << "\n"; // Выходы std::cout << " Выходы: "; for (const auto& output : func->get_outputs()) { std::cout << output->get_name() << " "; } std::cout << "\n"; // Управление std::cout << " Управление: "; for (const auto& control : func->get_controls()) { std::cout << control->get_name() << " "; } std::cout << "\n"; // Механизмы std::cout << " Механизмы: "; for (const auto& mechanism : func->get_mechanisms()) { std::cout << mechanism->get_name() << " "; } std::cout << "\n"; } } bool IDEF0Model::validate_decomposition(const std::string& func_id) const { auto it = functions.find(func_id); if (it != functions.end()) { std::cout << "Валидация для " << func_id << ": OK\n"; return true; } return false; } std::map<std::string, std::map<std::string, int>> IDEF0Model::build_incidence_matrix(const std::string& func_id) const { auto it = functions.find(func_id); if (it == functions.end()) { return {}; } const auto& func = it->second; std::map<std::string, std::map<std::string, int>> matrix; // Заполняем матрицу для входов for (const auto& input : func->get_inputs()) { matrix[func_id][input->get_name()] = 1; } // Заполняем матрицу для выходов for (const auto& output : func->get_outputs()) { matrix[func_id][output->get_name()] = 1; } // Заполняем матрицу для управления for (const auto& control : func->get_controls()) { matrix[func_id][control->get_name()] = 1; } // Заполняем матрицу для теханизмов for (const auto& mechanism : func->get_mechanisms()) { matrix[func_id][mechanism->get_name()] = 1; } // Добавьте обработку outputs, controls, mechanisms return matrix; } void IDEF0Model::print_all_connections() const { std::cout << "Список связей (источник → приёмник):\n"; for (const auto& [func_id, func_ptr] : functions) { // Входы: поток → функция for (const auto& input : func_ptr->get_inputs()) { std::cout << " " << input->get_name() << ", " << "[Тип: " << flow_type_to_string(input->get_type()) << "] → " << func_id << " (" << func_ptr->get_name() << ")\n"; } // Выходы: функция → поток for (const auto& output : func_ptr->get_outputs()) { std::cout << " " << func_id << " (" << func_ptr->get_name() << ")" << "[Тип: " << flow_type_to_string(output->get_type()) << "] → " << output->get_name() << "\n"; } // Управления: поток → функция for (const auto& control : func_ptr->get_controls()) { std::cout << " " << control->get_name() << "[Тип: " << flow_type_to_string(control->get_type()) << "] → " << func_id << " (" << func_ptr->get_name() << ")\n"; } // Механизмы: поток → функция for (const auto& mechanism : func_ptr->get_mechanisms()) { std::cout << " " << mechanism->get_name() << "[Тип: " << flow_type_to_string(mechanism->get_type()) << "] → " << func_id << " (" << func_ptr->get_name() << ")\n"; } } }