123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /**
- * @file tests/multithreading/lifegame/graph_manager.cpp
- * @author The ARTIS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * ARTIS - the multimodeling and simulation environment
- * This file is a part of the ARTIS environment
- *
- * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef TESTS_MULTITHREADING_LIFEGAME_GRAPH_MANAGER_HPP
- #define TESTS_MULTITHREADING_LIFEGAME_GRAPH_MANAGER_HPP 1
- #include <tests/multithreading/lifegame/models.hpp>
- #include <artis-star/kernel/pdevs/multithreading/Coordinator.hpp>
- #include <artis-star/kernel/pdevs/GraphManager.hpp>
- #include <artis-star/kernel/pdevs/Simulator.hpp>
- namespace artis {
- namespace tests {
- namespace multithreading {
- namespace lifegame {
- struct GridGraphManagerParameters {
- unsigned int column_number;
- unsigned int line_number;
- };
- class FlatGraphManager
- : public artis::pdevs::GraphManager<common::DoubleTime, CellParameters, GridGraphManagerParameters> {
- public:
- enum submodels {
- CELL
- };
- FlatGraphManager(common::Coordinator<common::DoubleTime>* coordinator,
- const CellParameters& parameters,
- const GridGraphManagerParameters& graph_parameters)
- :
- artis::pdevs::GraphManager<common::DoubleTime, CellParameters, GridGraphManagerParameters>(
- coordinator, parameters, graph_parameters)
- {
- for (unsigned int i = 0; i < graph_parameters.column_number; ++i) {
- for (unsigned int j = 0; j < graph_parameters.line_number; ++j) {
- std::ostringstream ss;
- ss << "C_" << (i + 1) << "_" << (j + 1);
- Simulator* cell = new Simulator(ss.str(), parameters);
- _cells.push_back(cell);
- add_children(CELL, cell);
- }
- }
- for (int i = 0; i < (int)graph_parameters.column_number; ++i) {
- for (int j = 0; j < (int)graph_parameters.line_number; ++j) {
- int index = i * graph_parameters.line_number + j;
- // south
- if (j - 1 >= 0) {
- out({_cells[index], Cell::OUT})
- >> in({_cells[i * graph_parameters.line_number + j - 1], Cell::IN});
- }
- // north
- if (j + 1 < (int)graph_parameters.line_number) {
- out({_cells[index], Cell::OUT})
- >> in({_cells[i * graph_parameters.line_number + j + 1], Cell::IN});
- }
- // west
- if (i - 1 >= 0) {
- out({_cells[index], Cell::OUT})
- >> in({_cells[(i - 1) * graph_parameters.line_number + j], Cell::IN});
- }
- // east
- if (i + 1 < (int)graph_parameters.column_number) {
- out({_cells[index], Cell::OUT})
- >> in({_cells[(i + 1) * graph_parameters.line_number + j], Cell::IN});
- }
- }
- }
- }
- ~FlatGraphManager() override
- {
- std::for_each(_cells.begin(), _cells.end(), std::default_delete<Simulator>());
- }
- private:
- typedef pdevs::Simulator<common::DoubleTime, Cell, CellParameters> Simulator;
- typedef std::vector<Simulator*> Simulators;
- Simulators _cells;
- };
- }
- }
- }
- } // namespace artis tests multithreading lifegame
- #endif
|