123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * @file Simulator.cpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.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 <devs/Coordinator.hpp>
- #include <devs/Simulator.hpp>
- #include <cassert>
- #include <stdexcept>
- namespace paradevs { namespace devs {
- Simulator::Simulator(Dynamics* dynamics) :
- Model(dynamics->get_name()), _dynamics(dynamics)
- { }
- Simulator::~Simulator()
- { delete _dynamics; }
- common::Time Simulator::i_message(common::Time t)
- {
- _tl = t;
- _tn = _tl + _dynamics->start();
- return _tn;
- }
- common::Time Simulator::s_message(common::Time t)
- {
- std::cout << "[" << get_name() << "] at " << t << ": BEFORE - s_message => "
- << "tl = " << _tl << " ; tn = " << _tn << std::endl;
- assert(t == _tn);
- common::Messages msgs = _dynamics->lambda();
- if (not msgs.empty()) {
- for (common::Messages::iterator it = msgs.begin(); it != msgs.end(); ++it) {
- it->set_model(this);
- }
- dynamic_cast < Coordinator* >(get_parent())->y_message(msgs, t);
- }
- _dynamics->dint(t);
- _tl = t;
- _tn = t + _dynamics->ta();
- std::cout << "[" << get_name() << "] at " << t << ": AFTER - s_message => "
- << "tl = " << _tl << " ; tn = " << _tn << std::endl;
- return _tn;
- }
- common::Time Simulator::x_message(const common::Message& msg, common::Time t)
- {
- std::cout << "[" << get_name() << "] at " << t << ": BEFORE - x_message => "
- << "tl = " << _tl << " ; tn = " << _tn << std::endl;
- assert(_tl <= t and t <= _tn);
- common::Time e = t - _tl;
- _dynamics->dext(e, msg);
- _tl = t;
- _tn = _tl + _dynamics->ta();
- std::cout << "[" << get_name() << "] at " << t << ": AFTER - x_message => "
- << "tl = " << _tl << " ; tn = " << _tn << std::endl;
- return _tn;
- }
- void Simulator::observation(std::ostream &file) const
- { _dynamics->observation(file); }
- } } // namespace paradevs devs
|