|
@@ -29,7 +29,9 @@
|
|
#include <artis-star/common/RootCoordinator.hpp>
|
|
#include <artis-star/common/RootCoordinator.hpp>
|
|
#include <artis-star/common/observer/Iterator.hpp>
|
|
#include <artis-star/common/observer/Iterator.hpp>
|
|
|
|
|
|
|
|
+#include <fstream>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
+#include <boost/archive/binary_oarchive.hpp>
|
|
|
|
|
|
using namespace artis::tests::qss;
|
|
using namespace artis::tests::qss;
|
|
|
|
|
|
@@ -70,29 +72,22 @@ void test_parabola()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-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<artis::common::DoubleTime> {
|
|
|
|
- public:
|
|
|
|
- View()
|
|
|
|
- {
|
|
|
|
- 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});
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+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});
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
|
|
- artis::common::context::Context<artis::common::DoubleTime> context(0, 100);
|
|
|
|
|
|
+void run_predator_prey(artis::common::context::Context<artis::common::DoubleTime>& context,
|
|
|
|
+ const PreyPredatorGraphManagerParameters& parameters)
|
|
|
|
+{
|
|
artis::common::RootCoordinator<
|
|
artis::common::RootCoordinator<
|
|
artis::common::DoubleTime, artis::pdevs::Coordinator<
|
|
artis::common::DoubleTime, artis::pdevs::Coordinator<
|
|
artis::common::DoubleTime,
|
|
artis::common::DoubleTime,
|
|
@@ -100,13 +95,20 @@ void test_predator_prey()
|
|
PreyPredatorGraphManagerParameters>
|
|
PreyPredatorGraphManagerParameters>
|
|
> rc(context, "root", parameters, artis::common::NoParameters());
|
|
> rc(context, "root", parameters, artis::common::NoParameters());
|
|
|
|
|
|
- rc.attachView("Value", new View());
|
|
|
|
|
|
+ rc.attachView("Value", new PredatorPreyView());
|
|
|
|
|
|
rc.run(context);
|
|
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(
|
|
artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> it(
|
|
- rc.observer().view("Value").get("PredatorView"), 0, 0.1);
|
|
|
|
|
|
+ rc.observer().view("Value").get("PredatorView"), context.begin(), 0.1);
|
|
|
|
|
|
while (it.has_next()) {
|
|
while (it.has_next()) {
|
|
double v;
|
|
double v;
|
|
@@ -118,7 +120,7 @@ void test_predator_prey()
|
|
}
|
|
}
|
|
{
|
|
{
|
|
artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> it(
|
|
artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> it(
|
|
- rc.observer().view("Value").get("PreyView"), 0, 0.1);
|
|
|
|
|
|
+ rc.observer().view("Value").get("PreyView"), context.begin(), 0.1);
|
|
|
|
|
|
while (it.has_next()) {
|
|
while (it.has_next()) {
|
|
double v;
|
|
double v;
|
|
@@ -128,6 +130,26 @@ void test_predator_prey()
|
|
++it;
|
|
++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()
|
|
int main()
|