/** * @file pdevs/tests.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 . */ #include #include #include using namespace artis::tests::qss; void test_parabola() { artis::pdevs::qss::QSSParameters parameters = {{0.5}, {true, true, 0.001, 3}, {0.2}}; class View : public artis::observer::View { public: View() { selector("Value", {OnlyOneParabolaGraphManager::A, ParabolaGraphManager::S_Integrator, artis::pdevs::qss::Integrator::VALUE}); } }; artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, OnlyOneParabolaGraphManager, artis::pdevs::qss::QSSParameters> > rc(0, 5, "root", parameters, artis::common::NoParameters()); rc.attachView("Value", new View()); rc.run(); const View::Values& values = rc.observer().view("Value").get("Value"); for (const auto& value: values) { double v; value.second(v); std::cout << value.first << ": " << v << std::endl; } } void test_predator_prey() { PreyPredatorGraphManagerParameters parameters = {{{45.}, {true, true, 0.1, 3}, {0.5, 0.01, 0.01, 0.2}}, {{5000.}, {true, true, 1, 3}, {0.5, 0.01, 0.01, 0.2}}}; class View : public artis::observer::View { public: View() { selector("PredatorView", {PreyPredatorGraphManager::PREDATOR, PredatorGraphManager::S_Integrator, artis::pdevs::qss::Integrator::VALUE}); selector("PreyView", {PreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator, artis::pdevs::qss::Integrator::VALUE}); } }; artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, PreyPredatorGraphManager, PreyPredatorGraphManagerParameters> > rc(0, 100, "root", parameters, artis::common::NoParameters()); rc.attachView("Value", new View()); rc.run(); { artis::observer::DiscreteTimeIterator it( rc.observer().view("Value").get("PredatorView"), 0, 0.1); while (it.has_next()) { double v; (*it).second(v); std::cout << (*it).first << ";" << v << std::endl; ++it; } } { artis::observer::DiscreteTimeIterator it( rc.observer().view("Value").get("PreyView"), 0, 0.1); while (it.has_next()) { double v; (*it).second(v); std::cout << (*it).first << ";" << v << std::endl; ++it; } } } int main() { // test_parabola(); test_predator_prey(); }