1 /* Copyright (c) 2003-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/plugins/battery.hpp"
7 #include "simgrid/s4u.hpp"
9 #include <simgrid/s4u/Actor.hpp>
11 XBT_LOG_NEW_DEFAULT_CATEGORY(battery_degradation, "Messages specific for this s4u example");
15 auto battery = simgrid::plugins::Battery::init("Battery", 0.8, -200, 200, 0.9, 0.9, 10, 100);
17 battery->set_load("load", 100);
19 auto handler1 = battery->schedule_handler(0.2, simgrid::plugins::Battery::DISCHARGE, true, [battery]() {
20 XBT_INFO("%f,%f,SoC", simgrid::s4u::Engine::get_clock(), battery->get_state_of_charge());
21 XBT_INFO("%f,%f,SoH", simgrid::s4u::Engine::get_clock(), battery->get_state_of_health());
22 battery->set_load("load", -100);
25 std::shared_ptr<simgrid::plugins::Battery::Handler> handler2;
26 handler2 = battery->schedule_handler(0.8, simgrid::plugins::Battery::CHARGE, true, [battery, handler1, handler2]() {
27 XBT_INFO("%f,%f,SoC", simgrid::s4u::Engine::get_clock(), battery->get_state_of_charge());
28 XBT_INFO("%f,%f,SoH", simgrid::s4u::Engine::get_clock(), battery->get_state_of_health());
29 if (battery->get_state_of_health() < 0.1) {
30 battery->delete_handler(handler1);
31 battery->delete_handler(handler2);
33 battery->set_load("load", 100);
37 int main(int argc, char* argv[])
39 simgrid::s4u::Engine e(&argc, argv);
40 e.load_platform(argv[1]);
42 simgrid::s4u::Actor::create("manager", e.host_by_name("MyHost1"), manager);