/** * @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 #include #include #include #include using namespace artis::tests::qss; void test_parabola() { artis::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::qss::Integrator::VALUE}); } }; artis::common::context::Context context(0, 5); artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, OnlyOneParabolaGraphManager, artis::qss::QSSParameters> > rc(context, "root", parameters, artis::common::NoParameters()); rc.attachView("Value", new View()); rc.run(context); 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; } } class PredatorPreyView : public artis::observer::View { public: PredatorPreyView() { selector("PredatorView", {PreyPredatorGraphManager::PREDATOR, PredatorGraphManager::S_Integrator, artis::qss::Integrator::VALUE}); selector("PreyView", {PreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator, artis::qss::Integrator::VALUE}); } }; void run_predator_prey(artis::common::context::Context& context, const PreyPredatorGraphManagerParameters& parameters) { artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, PreyPredatorGraphManager, PreyPredatorGraphManagerParameters> > rc(context, "root", parameters, artis::common::NoParameters()); rc.attachView("Value1", new PredatorPreyView()); rc.run(context); rc.save(context); std::ofstream os("state"); boost::archive::binary_oarchive oa(os); oa << context; { artis::observer::DiscreteTimeIterator it( rc.observer().view("Value").get("PredatorView"), context.begin(), 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"), context.begin(), 0.1); while (it.has_next()) { double v; (*it).second(v); std::cout << (*it).first << ";" << v << std::endl; ++it; } } } 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}}}; artis::common::context::Context context(0, 100); run_predator_prey(context, parameters); artis::common::context::Context new_context(context); new_context.end(200); run_predator_prey(new_context, parameters); } class PredatorPreySmartGardenerView : public artis::observer::View { public: PredatorPreySmartGardenerView() { selector("PredatorView", {PreyPredatorSmartGardenerGraphManager::PREY_PREDATOR, PreyPredatorGraphManager::PREDATOR, PredatorGraphManager::S_Integrator, artis::qss::Integrator::VALUE}); selector("PreyView", {PreyPredatorSmartGardenerGraphManager::PREY_PREDATOR, PreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator, artis::qss::Integrator::VALUE}); } }; void test_predator_prey_smart_gardener() { PreyPredatorSmartGardenerGraphManagerParameters 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}}}, {2000, 0.25, 0.75, 5}}; artis::common::context::Context context(0, 100); artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, PreyPredatorSmartGardenerGraphManager, PreyPredatorSmartGardenerGraphManagerParameters> > rc(context, "root", parameters, artis::common::NoParameters()); rc.attachView("Value2", new PredatorPreySmartGardenerView()); rc.run(context); artis::observer::Output output(rc.observer()); output(0, 100, 0.1); } class MixedPredatorPreyView : public artis::observer::View { public: MixedPredatorPreyView() { selector("PredatorView", {MixedPreyPredatorGraphManager::PREDATOR, DiscretePredatorGraphManager::PREDATOR, DiscretePredator::VALUE}); selector("PreyView", {MixedPreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator, artis::qss::Integrator::VALUE}); } }; void test_mixed_predator_prey() { MixedPreyPredatorGraphManagerParameters parameters = {{0.0001, 45., 0.5, 0.01, 0.01, 0.2}, {{5000.}, {true, true, 1, 3}, {0.5, 0.01, 0.01, 0.2}}}; artis::common::context::Context context(0, 100); artis::common::RootCoordinator< artis::common::DoubleTime, artis::pdevs::Coordinator< artis::common::DoubleTime, MixedPreyPredatorGraphManager, MixedPreyPredatorGraphManagerParameters> > rc(context, "root", parameters, artis::common::NoParameters()); rc.attachView("Value3", new MixedPredatorPreyView()); rc.run(context); artis::observer::Output output(rc.observer()); output(0, 100, 0.1); } int main() { test_parabola(); test_predator_prey(); test_predator_prey_smart_gardener(); test_mixed_predator_prey(); }