123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /**
- * @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 <http://www.gnu.org/licenses/>.
- */
- #include <tests/qss/graph_manager.hpp>
- #include <artis-star/common/RootCoordinator.hpp>
- #include <artis-star/common/observer/Iterator.hpp>
- #include <fstream>
- #include <iostream>
- #include <boost/archive/binary_oarchive.hpp>
- using namespace artis::tests::qss;
- void test_parabola()
- {
- artis::pdevs::qss::QSSParameters<ParabolaParameters> parameters = {{0.5},
- {true, true, 0.001, 3},
- {0.2}};
- class View : public artis::observer::View<artis::common::DoubleTime> {
- public:
- View()
- {
- selector("Value", {OnlyOneParabolaGraphManager::A, ParabolaGraphManager::S_Integrator,
- artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
- }
- };
- artis::common::context::Context<artis::common::DoubleTime> context(0, 5);
- artis::common::RootCoordinator<
- artis::common::DoubleTime, artis::pdevs::Coordinator<
- artis::common::DoubleTime,
- OnlyOneParabolaGraphManager,
- artis::pdevs::qss::QSSParameters<ParabolaParameters>>
- > 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<artis::common::DoubleTime> {
- public:
- PredatorPreyView()
- {
- selector("PredatorView",
- {PreyPredatorGraphManager::PREDATOR, PredatorGraphManager::S_Integrator,
- artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
- selector("PreyView",
- {PreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator,
- artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
- }
- };
- void run_predator_prey(artis::common::context::Context<artis::common::DoubleTime>& 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("Value", new PredatorPreyView());
- rc.run(context);
- rc.save(context);
- std::ofstream os("state");
- boost::archive::binary_oarchive oa(os);
- oa << context;
- {
- artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> 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<artis::common::DoubleTime> 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<artis::common::DoubleTime> context(0, 100);
- run_predator_prey(context, parameters);
- artis::common::context::Context<artis::common::DoubleTime> new_context(context);
- new_context.end(200);
- run_predator_prey(new_context, parameters);
- }
- int main()
- {
- // test_parabola();
- test_predator_prey();
- }
|