various adjustments
This commit is contained in:
@ -8,9 +8,10 @@
|
||||
#define LOG_DEBUG_INFO(...)
|
||||
#define LOG_DEBUG_ERROR(...)
|
||||
#else
|
||||
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||
#endif
|
||||
#define VALUE_COUNT (4*24*365)
|
||||
#define VALUE_COUNT ((size_t)(4 * 24 * 365))
|
||||
#define MAX_CONDITIONS 2560
|
||||
|
||||
#endif //CONFIG_H
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 11.03.2025.
|
||||
//
|
||||
|
||||
#ifndef AUT_H
|
||||
#define AUT_H
|
||||
|
||||
namespace Enums::AUT {
|
||||
enum GridLevel {
|
||||
GridLevel1,
|
||||
GridLevel2,
|
||||
GridLevel3,
|
||||
GridLevel4,
|
||||
GridLevel5,
|
||||
GridLevel6,
|
||||
GridLevel7WithP,
|
||||
GridLevel7WithoutP,
|
||||
GridLevel7Interruptable,
|
||||
};
|
||||
enum EegType {
|
||||
GEA,
|
||||
LocalEeg,
|
||||
RegionalEeg,
|
||||
BEG
|
||||
};
|
||||
}
|
||||
|
||||
#endif //AUT_H
|
||||
@ -5,11 +5,9 @@
|
||||
#ifndef CURRY_H
|
||||
#define CURRY_H
|
||||
|
||||
template <typename Func1, typename Func2>
|
||||
auto curry(Func1 f1, Func2 f2)
|
||||
{
|
||||
return [=](auto... args)
|
||||
{
|
||||
template<typename Func1, typename Func2>
|
||||
auto curry(Func1 f1, Func2 f2) {
|
||||
return [=](auto... args) {
|
||||
auto result1 = f1(args...);
|
||||
return f2(result1);
|
||||
};
|
||||
|
||||
@ -1,15 +1,21 @@
|
||||
//
|
||||
// Created by stani on 3/10/2025.
|
||||
//
|
||||
|
||||
#ifndef ICOSTCOMPONENT_H
|
||||
#define ICOSTCOMPONENT_H
|
||||
#include "../model/Community.h"
|
||||
|
||||
class ICostComponent
|
||||
{
|
||||
#include <bitset>
|
||||
#include "../model/Community.h"
|
||||
#include "../Config.h"
|
||||
|
||||
class ICostComponent {
|
||||
public:
|
||||
std::bitset<MAX_CONDITIONS> applicableConditions;
|
||||
|
||||
template<typename... Conditions>
|
||||
ICostComponent(Conditions... conditions) {
|
||||
}
|
||||
|
||||
virtual ~ICostComponent() = default;
|
||||
virtual double apply(std::vector<std::unique_ptr<Community>>& communities) const = 0;
|
||||
|
||||
virtual void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) = 0;
|
||||
};
|
||||
|
||||
#endif //ICOSTCOMPONENT_H
|
||||
|
||||
@ -4,29 +4,141 @@
|
||||
|
||||
#include "Building.h"
|
||||
|
||||
float Building::Cost::special_rate_consumption() const {
|
||||
float Building::Metadata::special_rate_consumption() const {
|
||||
return SpecialRateConsumption;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_consumption(float special_rate_consumption) {
|
||||
void Building::Metadata::set_special_rate_consumption(float special_rate_consumption) {
|
||||
SpecialRateConsumption = special_rate_consumption;
|
||||
}
|
||||
|
||||
float Building::Cost::special_rate_generation() const {
|
||||
float Building::Metadata::special_rate_generation() const {
|
||||
return SpecialRateGeneration;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_generation(float special_rate_generation) {
|
||||
void Building::Metadata::set_special_rate_generation(float special_rate_generation) {
|
||||
SpecialRateGeneration = special_rate_generation;
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::community_coverage() {
|
||||
return CommunityCoverage;
|
||||
std::vector<float> &Building::Simulation_Values::generation_after_community() {
|
||||
return GenerationAfterCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::generation_after_community(const std::vector<float> &generation_after_community) {
|
||||
GenerationAfterCommunity = generation_after_community;
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::consumption_after_community() {
|
||||
return ConsumptionAfterCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::consumption_after_community(const std::vector<float> &consumption_after_community) {
|
||||
ConsumptionAfterCommunity = consumption_after_community;
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::generation_to_community() {
|
||||
return GenerationToCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::generation_to_community(const std::vector<float> &generation_to_community) {
|
||||
GenerationToCommunity = generation_to_community;
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::consumption_from_community() {
|
||||
return ConsumptionFromCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::consumption_from_community(const std::vector<float> &consumption_from_community) {
|
||||
ConsumptionFromCommunity = consumption_from_community;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::con_from_community_relative() const {
|
||||
return this->ConsumptionFromCommunityRelative;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_con_from_community_relative(const float x) {
|
||||
this->ConsumptionFromCommunityRelative = x;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::gen_to_community_relative() const {
|
||||
return this->GenerationToCommunityRelative;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_gen_to_community_relative(float x) {
|
||||
this->GenerationToCommunityRelative = x;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_after_own_coverage_sum() const {
|
||||
return ConsumptionAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_after_own_coverage_sum(const float value) {
|
||||
ConsumptionFromCommunityRelative = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::own_usage_sum() const {
|
||||
return OwnUsageSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_ownUsageSum(const float value) {
|
||||
OwnUsageSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::needed_con_sum() const {
|
||||
return NeededConSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_neededConSum(const float value) {
|
||||
NeededConSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::needed_gen_sum() const {
|
||||
return NeededGenSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_neededGenSum(const float value) {
|
||||
NeededGenSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_after_community_sum() const {
|
||||
return ConsumptionAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_after_community_sum(const float value) {
|
||||
ConsumptionAfterCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::generation_after_community_sum() const {
|
||||
return GenerationAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_generation_after_community_sum(const float value) {
|
||||
GenerationAfterCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_from_community_sum() const {
|
||||
return ConsumptionFromCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_from_community_sum(const float value) {
|
||||
ConsumptionFromCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::generation_to_community_sum() const {
|
||||
return GenerationToCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_generation_to_community_sum(const float values) {
|
||||
GenerationToCommunitySum = values;
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::consumption_after_own_coverage() {
|
||||
return ConsumptionAfterOwnCoverage;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::
|
||||
set_community_coverage(std::vector<float> community_coverage) {
|
||||
CommunityCoverage = std::move(community_coverage);
|
||||
ConsumptionAfterOwnCoverage = std::move(community_coverage);
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::own_usage() {
|
||||
@ -38,11 +150,11 @@ void Building::Simulation_Values::set_own_usage(std::vector<float> own_usage) {
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::needed_con() {
|
||||
return Needed_con;
|
||||
return NeededCon;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_con(std::vector<float> needed_con) {
|
||||
Needed_con = std::move(needed_con);
|
||||
NeededCon = std::move(needed_con);
|
||||
}
|
||||
|
||||
std::vector<float> &Building::Simulation_Values::needed_gen() {
|
||||
@ -68,6 +180,7 @@ float Building::Simulation_Values::relativeSelfGeneration() const {
|
||||
void Building::Simulation_Values::set_relativeSelfGeneration(float const relativeSelfGeneration) {
|
||||
this->RelativeGeneration = relativeSelfGeneration;
|
||||
}
|
||||
|
||||
std::string Building::Metadata::name() const {
|
||||
return Name;
|
||||
}
|
||||
|
||||
@ -4,41 +4,70 @@
|
||||
|
||||
#ifndef BUILDING_H
|
||||
#define BUILDING_H
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Model.h"
|
||||
#include "../Config.h"
|
||||
|
||||
|
||||
namespace Building {
|
||||
class Cost {
|
||||
class CostValues {
|
||||
private:
|
||||
float SpecialRateConsumption;
|
||||
float SpecialRateGeneration;
|
||||
float Consumption{0.0f};
|
||||
float Generation{0.0f};
|
||||
float ConsumptionWithCommunity{0.0f};
|
||||
float GenerationWithCommunity{0.0f};
|
||||
|
||||
public:
|
||||
float special_rate_consumption() const;
|
||||
float consumption() { return Consumption; }
|
||||
void set_consumption(const float consumption) { Consumption = consumption; }
|
||||
float generation() { return Generation; }
|
||||
void set_generation(const float generation) { Generation = generation; }
|
||||
float consumption_with_community() { return ConsumptionWithCommunity; }
|
||||
void set_consumption_with_community(const float consumption) { ConsumptionWithCommunity = consumption; }
|
||||
float generation_with_community() { return Generation; }
|
||||
void set_generation_with_community(const float generation) { GenerationWithCommunity = generation; }
|
||||
};
|
||||
|
||||
void set_special_rate_consumption(float special_rate_consumption);
|
||||
|
||||
float special_rate_generation() const;
|
||||
|
||||
void set_special_rate_generation(float special_rate_generation);
|
||||
class Cost {
|
||||
private:
|
||||
std::shared_ptr<CostValues> CostValuesWith{};
|
||||
std::shared_ptr<CostValues> CostValuesWithOut{};
|
||||
|
||||
public:
|
||||
std::shared_ptr<CostValues> &get_cost_values_with() { return CostValuesWith; }
|
||||
std::shared_ptr<CostValues> &get_cost_values_without() { return CostValuesWithOut; }
|
||||
};
|
||||
|
||||
class Simulation_Values {
|
||||
private:
|
||||
std::vector<float> CommunityCoverage;
|
||||
std::vector<float> OwnUsage;
|
||||
std::vector<float> Needed_con;
|
||||
std::vector<float> NeededGen;
|
||||
std::vector<float> ConsumptionAfterOwnCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> OwnUsage = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> NeededCon = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> NeededGen = std::vector(VALUE_COUNT, 0.0f);
|
||||
float RelativeSelfConsumption{0.0f};
|
||||
float RelativeGeneration{0.0f};
|
||||
std::vector<float> ConsumptionAfterCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> GenerationAfterCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> ConsumptionFromCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> GenerationToCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
float ConsumptionFromCommunityRelative{0.0f};
|
||||
float GenerationToCommunityRelative{0.0f};
|
||||
|
||||
float ConsumptionAfterOwnCoverageSum{0.0f};
|
||||
float OwnUsageSum{0.0f};
|
||||
float NeededConSum{0.0f};
|
||||
float NeededGenSum{0.0f};
|
||||
float ConsumptionAfterCommunitySum{0.0f};
|
||||
float GenerationAfterCommunitySum{0.0f};
|
||||
float ConsumptionFromCommunitySum{0.0f};
|
||||
float GenerationToCommunitySum{0.0f};
|
||||
|
||||
public:
|
||||
std::vector<float> &community_coverage();
|
||||
Simulation_Values() = default;
|
||||
|
||||
std::vector<float> &consumption_after_own_coverage();
|
||||
|
||||
void set_community_coverage(std::vector<float> community_coverage);
|
||||
|
||||
@ -55,24 +84,72 @@ namespace Building {
|
||||
void set_needed_gen(std::vector<float> needed_gen);
|
||||
|
||||
float relativeSelfConsumption() const;
|
||||
|
||||
void set_relativeSelfConsumption(float relativeSelfConsumption);
|
||||
|
||||
float relativeSelfGeneration() const;
|
||||
|
||||
void set_relativeSelfGeneration(float relativeSelfGeneration);
|
||||
|
||||
std::vector<float> &generation_after_community();
|
||||
|
||||
void generation_after_community(const std::vector<float> &generation_after_community);
|
||||
|
||||
std::vector<float> &consumption_after_community();
|
||||
|
||||
void consumption_after_community(const std::vector<float> &consumption_after_community);
|
||||
|
||||
std::vector<float> &generation_to_community();
|
||||
|
||||
void generation_to_community(const std::vector<float> &generation_to_community);
|
||||
|
||||
std::vector<float> &consumption_from_community();
|
||||
|
||||
void consumption_from_community(const std::vector<float> &consumption_from_community);
|
||||
|
||||
float con_from_community_relative() const;
|
||||
|
||||
void set_con_from_community_relative(float x);
|
||||
|
||||
float gen_to_community_relative() const;
|
||||
|
||||
void set_gen_to_community_relative(float x);
|
||||
|
||||
float consumption_after_own_coverage_sum() const;
|
||||
void set_consumption_after_own_coverage_sum(float value);
|
||||
float own_usage_sum() const;
|
||||
void set_ownUsageSum(float value);
|
||||
float needed_con_sum() const;
|
||||
void set_neededConSum(float value);
|
||||
float needed_gen_sum() const;
|
||||
void set_neededGenSum(float value);
|
||||
float consumption_after_community_sum() const;
|
||||
void set_consumption_after_community_sum(float value);
|
||||
float generation_after_community_sum() const;
|
||||
void set_generation_after_community_sum(float value);
|
||||
float consumption_from_community_sum() const;
|
||||
void set_consumption_from_community_sum(float value);
|
||||
float generation_to_community_sum() const;
|
||||
void set_generation_to_community_sum(float values);
|
||||
};
|
||||
|
||||
class Metadata {
|
||||
private:
|
||||
std::string Name;
|
||||
float AnnualConsumption;
|
||||
float AnnualGeneration;
|
||||
std::vector<float> ConsumptionProfile;
|
||||
std::vector<float> GenerationProfile;
|
||||
std::string ConsumptionProfileName;
|
||||
std::string GenerationProfileName;
|
||||
short ConnectionPower;
|
||||
short GridPower;
|
||||
std::string Name{};
|
||||
float AnnualConsumption{0.0f};
|
||||
float AnnualGeneration{0.0f};
|
||||
std::vector<float> ConsumptionProfile = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> GenerationProfile = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::string ConsumptionProfileName{};
|
||||
std::string GenerationProfileName{};
|
||||
short ConnectionPower{0};
|
||||
short GridPower{0};
|
||||
float SpecialRateConsumption{0.0f};
|
||||
float SpecialRateGeneration{0.0f};
|
||||
|
||||
public:
|
||||
Metadata() = default;
|
||||
|
||||
std::string name() const;
|
||||
|
||||
void set_name(const std::string &name);
|
||||
@ -108,13 +185,21 @@ namespace Building {
|
||||
short grid_power() const;
|
||||
|
||||
void set_grid_power(short grid_power);
|
||||
|
||||
float special_rate_consumption() const;
|
||||
|
||||
void set_special_rate_consumption(float special_rate_consumption);
|
||||
|
||||
float special_rate_generation() const;
|
||||
|
||||
void set_special_rate_generation(float special_rate_generation);
|
||||
};
|
||||
|
||||
class Base : public Model<Base> {
|
||||
private:
|
||||
std::unique_ptr<Cost> Cost;
|
||||
std::unique_ptr<Simulation_Values> Values;
|
||||
std::unique_ptr<Metadata> Metadata;
|
||||
std::unique_ptr<Cost> Cost{};
|
||||
std::unique_ptr<Simulation_Values> Values{};
|
||||
std::unique_ptr<Metadata> Metadata{};
|
||||
|
||||
public:
|
||||
std::unique_ptr<Building::Cost> &cost();
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "Community.h"
|
||||
|
||||
#include "../helper/Curry.h"
|
||||
|
||||
std::string Community::name() const {
|
||||
return Name;
|
||||
@ -27,43 +26,44 @@ void Community::set_energy_tariff(const Energy_Tariff &energy_tariff) {
|
||||
energy_Tariff = energy_tariff;
|
||||
}
|
||||
|
||||
std::vector<float> Community::GenerationAvailable() const {
|
||||
return generationAvailable;
|
||||
std::vector<float> &Community::generation_available() {
|
||||
return GenerationAvailable;
|
||||
}
|
||||
|
||||
void Community::set_generation_available(std::vector<float> &generationAvailable) {
|
||||
this->generationAvailable = generationAvailable;
|
||||
this->GenerationAvailable = generationAvailable;
|
||||
}
|
||||
|
||||
std::vector<float> Community::ConsumptionAvailable() const {
|
||||
return consumptionAvailable;
|
||||
std::vector<float> &Community::consumption_available() {
|
||||
return ConsumptionAvailable;
|
||||
}
|
||||
|
||||
void Community::set_consumption_available(std::vector<float> &consumptionAvailable) {
|
||||
this->consumptionAvailable = consumptionAvailable;
|
||||
this->ConsumptionAvailable = consumptionAvailable;
|
||||
}
|
||||
|
||||
std::vector<bool> Community::IsGenBiggerThanCon() const {
|
||||
return isGenBiggerThanCon;
|
||||
std::vector<bool> &Community::is_gen_bigger_than_con() {
|
||||
return IsGenBiggerThanCon;
|
||||
}
|
||||
|
||||
void Community::set_is_gen_bigger_than_con(std::vector<bool> &isGenBiggerThanCon) {
|
||||
this->isGenBiggerThanCon=isGenBiggerThanCon;
|
||||
this->IsGenBiggerThanCon = isGenBiggerThanCon;
|
||||
}
|
||||
|
||||
auto Community::iterateBuildings(
|
||||
std::vector<std::unique_ptr<Community> > &Communities)
|
||||
-> std::function<std::function<void(const std::function<void(
|
||||
Community &, Building::Base &)> &)>(const std::function<void(Community &)> &)> {
|
||||
-> std::function<std::function<void(const std::function<void(Community &, Building::Base &)> &)>(
|
||||
const std::function<void(Community &)> &)> {
|
||||
return [&](const std::function<void(Community &)> &func1) {
|
||||
return [&, func1](const std::function<void(Community &, Building::Base &)> &func2) {
|
||||
iterateVector(Communities, func1);
|
||||
|
||||
iterateVector(Communities, [&](Community &community) {
|
||||
for (auto &building: community.buildings()) {
|
||||
func2(community, *building);
|
||||
for (auto &community: Communities) {
|
||||
func1(*community);
|
||||
for (auto &building: community->buildings()) {
|
||||
func2(*community, *building);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#ifndef COMMUNITY_H
|
||||
#define COMMUNITY_H
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@ -14,7 +15,6 @@
|
||||
|
||||
class Community : public Model<Community> {
|
||||
public:
|
||||
Community():generationAvailable(VALUE_COUNT, 0.0f),consumptionAvailable(VALUE_COUNT,0.0f){};
|
||||
std::string name() const;
|
||||
|
||||
void set_name(const std::string &name);
|
||||
@ -27,29 +27,32 @@ public:
|
||||
|
||||
void set_energy_tariff(const Energy_Tariff &energy_tariff);
|
||||
|
||||
std::vector<float> GenerationAvailable() const;
|
||||
std::vector<float> &generation_available();
|
||||
|
||||
void set_generation_available(std::vector<float> &generationAvailable);
|
||||
|
||||
std::vector<float> ConsumptionAvailable() const;
|
||||
std::vector<float> &consumption_available();
|
||||
|
||||
void set_consumption_available(std::vector<float> &consumptionAvailable);
|
||||
|
||||
std::vector<bool> IsGenBiggerThanCon() const;
|
||||
std::vector<bool> &is_gen_bigger_than_con();
|
||||
|
||||
void set_is_gen_bigger_than_con(std::vector<bool> &isGenBiggerThanCon);
|
||||
|
||||
std::bitset<MAX_CONDITIONS> getConditionsBitmask() const;
|
||||
|
||||
static std::function<std::function<void(const std::function<void(Community &, Building::Base &)> &)>(const std::
|
||||
function<void(
|
||||
Community &)> &)>
|
||||
function<void(
|
||||
Community &)> &)>
|
||||
iterateBuildings(std::vector<std::unique_ptr<Community> > &Communities);
|
||||
|
||||
private:
|
||||
std::string Name;
|
||||
std::vector<std::unique_ptr<Building::Base> > Buildings;
|
||||
std::vector<float> generationAvailable;
|
||||
std::vector<float> consumptionAvailable;
|
||||
std::vector<bool> isGenBiggerThanCon;
|
||||
std::vector<float> GenerationAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> ConsumptionAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<bool> IsGenBiggerThanCon = std::vector(VALUE_COUNT, false);
|
||||
|
||||
|
||||
Energy_Tariff energy_Tariff;
|
||||
};
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
|
||||
|
||||
class Energy_Tariff {
|
||||
public:
|
||||
float consumption_tariff{0.0f};
|
||||
float generation_tariff{0.0f};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -5,15 +5,12 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
template <class T>
|
||||
class Model
|
||||
{
|
||||
template<class T>
|
||||
class Model {
|
||||
public:
|
||||
static void iterateVector(std::vector<std::unique_ptr<T>>& vector,
|
||||
const std::function<void(T&)>& function)
|
||||
{
|
||||
for (auto& item : vector)
|
||||
{
|
||||
static void iterateVector(std::vector<std::unique_ptr<T> > &vector,
|
||||
const std::function<void(T &)> &function) {
|
||||
for (auto &item: vector) {
|
||||
function(*item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,15 +4,25 @@
|
||||
|
||||
#include "CostPipeline.h"
|
||||
|
||||
void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent>& components)
|
||||
{
|
||||
|
||||
void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent> &components) {
|
||||
this->components.push_back(components);
|
||||
}
|
||||
|
||||
void CostPipeline::calculateFinalCost()
|
||||
{
|
||||
for (auto& component : this->components)
|
||||
{
|
||||
component->apply(this->communities);
|
||||
void CostPipeline::calculateFinalCost() {
|
||||
for (auto &component: this->components) {
|
||||
iterateCommunity(component);
|
||||
}
|
||||
}
|
||||
|
||||
void CostPipeline::iterateCommunity(std::shared_ptr<ICostComponent> &component) const {
|
||||
for (auto &community: this->communities) {
|
||||
iterateBuilding(community, component);
|
||||
}
|
||||
}
|
||||
|
||||
void CostPipeline::iterateBuilding(std::unique_ptr<Community> &community, std::shared_ptr<ICostComponent> &component) {
|
||||
for (auto &building: community->buildings()) {
|
||||
component->apply(building, community);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,21 +6,27 @@
|
||||
#define COSTPIPELINE_H
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "NetworkProvider.h"
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
#include "../../model/Community.h"
|
||||
|
||||
class CostPipeline
|
||||
{
|
||||
std::vector<std::unique_ptr<Community>>& communities;
|
||||
std::vector<std::shared_ptr<ICostComponent>> components;
|
||||
class CostPipeline {
|
||||
std::vector<std::unique_ptr<Community> > &communities;
|
||||
std::vector<std::shared_ptr<ICostComponent> > components;
|
||||
|
||||
public:
|
||||
CostPipeline(std::vector<std::unique_ptr<Community>>& communities) : communities(communities)
|
||||
{
|
||||
CostPipeline(std::vector<std::unique_ptr<Community> > &communities) : communities(communities) {
|
||||
}
|
||||
|
||||
void addCostComponent(const std::shared_ptr<ICostComponent>& components);
|
||||
void addCostComponent(const std::shared_ptr<ICostComponent> &components);
|
||||
|
||||
void calculateFinalCost();
|
||||
|
||||
void iterateCommunity(std::shared_ptr<ICostComponent> &component) const;
|
||||
|
||||
|
||||
static void iterateBuilding(std::unique_ptr<Community> &community, std::shared_ptr<ICostComponent> &component);
|
||||
};
|
||||
|
||||
|
||||
|
||||
18
src/services/Cost/NetworkProvider.cpp
Normal file
18
src/services/Cost/NetworkProvider.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 12.03.2025.
|
||||
//
|
||||
|
||||
#include "NetworkProvider.h"
|
||||
|
||||
|
||||
void NetworkProvider::apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) {
|
||||
std::shared_ptr<Building::CostValues> &valuesWith = building->cost()->get_cost_values_with();
|
||||
std::shared_ptr<Building::CostValues> &valuesWithout = building->cost()->get_cost_values_without();
|
||||
|
||||
//Todo tariffs
|
||||
valuesWithout->set_consumption(building->values()->needed_con_sum()*building->metadata()->special_rate_consumption());
|
||||
valuesWithout->set_generation(building->values()->needed_gen_sum()*-building->metadata()->special_rate_generation());
|
||||
|
||||
valuesWithout->set_consumption(building->values()->generation_to_community_sum()*-community->energy_tariff().consumption_tariff);
|
||||
valuesWithout->set_generation(building->values()->consumption_from_community_sum()*-community->energy_tariff().generation_tariff);
|
||||
}
|
||||
19
src/services/Cost/NetworkProvider.h
Normal file
19
src/services/Cost/NetworkProvider.h
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 12.03.2025.
|
||||
//
|
||||
|
||||
#ifndef NETWORKPROVIDER_H
|
||||
#define NETWORKPROVIDER_H
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class NetworkProvider : public ICostComponent {
|
||||
public:
|
||||
NetworkProvider(): ICostComponent() {
|
||||
}
|
||||
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORKPROVIDER_H
|
||||
@ -4,12 +4,6 @@
|
||||
|
||||
#include "TaxComponent.h"
|
||||
|
||||
void TaxComponent::applyCost(std::vector<std::unique_ptr<Community>>& communities)
|
||||
{
|
||||
Community::iterateVector(communities, [&](Community& community)
|
||||
{
|
||||
Building::Base::iterateVector(community.buildings(), [&](Building::Base& building)
|
||||
{
|
||||
});
|
||||
});
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) {
|
||||
|
||||
}
|
||||
|
||||
@ -7,16 +7,14 @@
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class TaxComponent : public ICostComponent
|
||||
{
|
||||
class TaxComponent : public ICostComponent {
|
||||
double taxRate;
|
||||
|
||||
public:
|
||||
TaxComponent(double rate) : taxRate(rate)
|
||||
{
|
||||
TaxComponent(double rate) : ICostComponent(), taxRate(rate) {
|
||||
}
|
||||
|
||||
void applyCost(std::vector<std::unique_ptr<Community>>& communities);
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,69 +1,73 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 10.03.2025.
|
||||
//
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
|
||||
#include "Surplus.h"
|
||||
#include "../model/Building.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
void Surplus::CalculateSurplus() {
|
||||
auto iterateFunc = Community::iterateBuildings(communities);
|
||||
|
||||
auto modifyCommunity = [this](Community &c) {
|
||||
this->consumptionAvailable=std::vector<float>(VALUE_COUNT, 00.f);
|
||||
this->generationAvailable=std::vector<float>(VALUE_COUNT, 00.f);
|
||||
this->isGenBigger=std::vector<bool>(VALUE_COUNT, false);
|
||||
this->consumptionAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||
this->generationAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||
|
||||
assert(!c.name().empty() && "Community name is empty!");
|
||||
LOG_DEBUG_INFO("Calculating Surplus for Community: {}", c.name());
|
||||
};
|
||||
|
||||
|
||||
auto modifyBuildingSurplus = [this](Community &community, Building::Base &building) {
|
||||
assert(building.metadata() != nullptr && "Building metadata is null!");
|
||||
|
||||
LOG_DEBUG_INFO("Calculating Surplus for Building: {} in Community: {}",
|
||||
building.metadata()->name(), community.name());
|
||||
|
||||
CalculateBuildingSurplus(community, building);
|
||||
};
|
||||
auto modifyBuildingSurplusCommunity = [this](Community &community, Building::Base &building) {
|
||||
LOG_DEBUG_INFO("Calculating Surplus for Building: {} in Community: {}",
|
||||
building.metadata()->name(), community.name());
|
||||
CalculateSurplusCommunity(community, building);
|
||||
};
|
||||
iterateFunc(modifyCommunity)(modifyBuildingSurplus);
|
||||
iterateFunc(modifyCommunity)(modifyBuildingSurplusCommunity);
|
||||
auto addCommunityValues = [this](Community &community) {
|
||||
|
||||
community.set_consumption_available(this->consumptionAvailable);
|
||||
community.set_generation_available(this->generationAvailable);
|
||||
community.set_is_gen_bigger_than_con(this->isGenBigger);
|
||||
};
|
||||
iterateFunc(addCommunityValues);
|
||||
|
||||
iterateFunc(modifyCommunity)(modifyBuildingSurplus);
|
||||
|
||||
auto calculateCommunitySurplus = [this](Community &community) {
|
||||
std::vector<bool> isGenBiggerThanCon;
|
||||
std::ranges::transform(
|
||||
consumptionAvailable, generationAvailable,
|
||||
std::back_inserter(isGenBiggerThanCon),
|
||||
[](const float a, const float b) { return a < b; }
|
||||
);
|
||||
community.set_is_gen_bigger_than_con(isGenBiggerThanCon);
|
||||
};
|
||||
|
||||
auto calculateDistribution = [this](Community &community, Building::Base &building) {
|
||||
CalculateSurplusCommunity(community, building);
|
||||
};
|
||||
|
||||
iterateFunc(calculateCommunitySurplus)(calculateDistribution);
|
||||
}
|
||||
|
||||
|
||||
void Surplus::CalculateBuildingSurplus(Community &community, Building::Base &building) {
|
||||
std::vector<float> ownCoverage;
|
||||
std::vector<float> neededConsumption;
|
||||
std::vector<float> neededGeneration;
|
||||
std::vector<float> ownUsage;
|
||||
std::vector<float> ownCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> neededConsumption = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> neededGeneration = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> ownUsage = std::vector(VALUE_COUNT, 0.0f);
|
||||
|
||||
assert(building.metadata() != nullptr && "Building metadata is null!");
|
||||
|
||||
const auto &consumption = building.metadata()->consumption_profile();
|
||||
const auto &generation = building.metadata()->generation_profile();
|
||||
|
||||
ownCoverage.reserve(consumption.size());
|
||||
neededConsumption.reserve(consumption.size());
|
||||
neededGeneration.reserve(consumption.size());
|
||||
ownUsage.reserve(consumption.size());
|
||||
|
||||
size_t i = 0; // Fixed static variable issue
|
||||
std::ranges::for_each(consumption, [&](auto c_ptr) {
|
||||
static size_t i = 0; // Keep track of index
|
||||
const float c = c_ptr ? c_ptr : 0.0f;
|
||||
const float g = (i < generation.size() && generation[i]) ? generation[i] : 0.0f;
|
||||
const float c_community = (i < consumptionAvailable.size() && consumptionAvailable[i])
|
||||
? consumptionAvailable[i]
|
||||
: 0.0f;
|
||||
const float g_community = (i < generationAvailable.size() && generationAvailable[i])
|
||||
? generationAvailable[i]
|
||||
: 0.0f;
|
||||
const float g = i < generation.size() ? generation[i] : 0.0f;
|
||||
const float c_community = (i < consumptionAvailable.size()) ? consumptionAvailable[i] : 0.0f;
|
||||
const float g_community = (i < generationAvailable.size()) ? generationAvailable[i] : 0.0f;
|
||||
|
||||
const auto ownCov = (c - g);
|
||||
const auto neededCons = ((c > 0.0f) ? c : 0.0f);
|
||||
@ -73,13 +77,12 @@ void Surplus::CalculateBuildingSurplus(Community &community, Building::Base &bui
|
||||
const auto communityConsumption = c_community + neededCons;
|
||||
const auto generationConsumption = g_community + neededGen;
|
||||
|
||||
ownCoverage.push_back(ownCov);
|
||||
neededConsumption.push_back(neededCons);
|
||||
neededGeneration.push_back(neededGen);
|
||||
ownUsage.push_back(ownUs);
|
||||
this->consumptionAvailable[i] = communityConsumption;
|
||||
this->generationAvailable[i] = generationConsumption;
|
||||
this->isGenBigger[i] = generationAvailable[i] > consumptionAvailable[i];
|
||||
ownCoverage[i] = ownCov;
|
||||
neededConsumption[i] = neededCons;
|
||||
neededGeneration[i] = neededGen;
|
||||
ownUsage[i] = ownUs;
|
||||
if (i < consumptionAvailable.size()) this->consumptionAvailable[i] = communityConsumption;
|
||||
if (i < generationAvailable.size()) this->generationAvailable[i] = generationConsumption;
|
||||
++i;
|
||||
});
|
||||
|
||||
@ -88,24 +91,92 @@ void Surplus::CalculateBuildingSurplus(Community &community, Building::Base &bui
|
||||
building.values()->set_needed_gen(std::move(neededGeneration));
|
||||
building.values()->set_own_usage(std::move(ownUsage));
|
||||
|
||||
if (building.metadata()->annual_consumption() > 0.0f) {
|
||||
const float totalConsumption = std::accumulate(building.metadata()->consumption_profile().begin(),
|
||||
building.metadata()->consumption_profile().end(), 0.0f);
|
||||
const float totalGeneration = std::accumulate(building.metadata()->generation_profile().begin(),
|
||||
building.metadata()->generation_profile().end(), 0.0f);
|
||||
|
||||
if (totalConsumption > 0.0f) {
|
||||
building.values()->set_relativeSelfConsumption(
|
||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||
std::accumulate(building.metadata()->consumption_profile().begin(),
|
||||
building.metadata()->consumption_profile().end(), 0.0f));
|
||||
totalConsumption);
|
||||
} else {
|
||||
building.values()->set_relativeSelfConsumption(0.0f);
|
||||
}
|
||||
if (building.metadata()->annual_generation() > 0.0f) {
|
||||
|
||||
if (totalGeneration > 0.0f) {
|
||||
building.values()->set_relativeSelfGeneration(
|
||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||
std::accumulate(building.metadata()->generation_profile().begin(),
|
||||
building.metadata()->generation_profile().end(), 0.0f));
|
||||
totalGeneration);
|
||||
} else {
|
||||
building.values()->set_relativeSelfGeneration(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void Surplus::CalculateSurplusCommunity(const Community &community, const Building::Base &base) {
|
||||
void Surplus::CalculateSurplusCommunity(Community &community, Building::Base &base) {
|
||||
const size_t neededGenSize = base.values()->needed_gen().size();
|
||||
const size_t neededConSize = base.values()->needed_con().size();
|
||||
const size_t consumptionAfterCommunitySize = base.values()->consumption_after_community().size();
|
||||
const size_t generationAfterCommunitySize = base.values()->generation_after_community().size();
|
||||
const size_t generationToCommunitySize = base.values()->generation_to_community().size();
|
||||
const size_t consumptionFromCommunitySize = base.values()->consumption_from_community().size();
|
||||
const size_t communityConsumptionSize = community.consumption_available().size();
|
||||
const size_t communityGenerationSize = community.generation_available().size();
|
||||
|
||||
if (neededGenSize != neededConSize ||
|
||||
neededGenSize != consumptionAfterCommunitySize ||
|
||||
neededGenSize != generationAfterCommunitySize ||
|
||||
neededGenSize != generationToCommunitySize ||
|
||||
neededGenSize != consumptionFromCommunitySize ||
|
||||
neededGenSize != communityConsumptionSize ||
|
||||
neededGenSize != communityGenerationSize) {
|
||||
std::cerr << "Size mismatch detected in CalculateSurplusCommunity():\n";
|
||||
std::cerr << "neededGenSize: " << neededGenSize << "\n";
|
||||
std::cerr << "neededConSize: " << neededConSize << "\n";
|
||||
std::cerr << "consumptionAfterCommunitySize: " << consumptionAfterCommunitySize << "\n";
|
||||
std::cerr << "generationAfterCommunitySize: " << generationAfterCommunitySize << "\n";
|
||||
std::cerr << "generationToCommunitySize: " << generationToCommunitySize << "\n";
|
||||
std::cerr << "consumptionFromCommunitySize: " << consumptionFromCommunitySize << "\n";
|
||||
std::cerr << "communityConsumptionSize: " << communityConsumptionSize << "\n";
|
||||
std::cerr << "communityGenerationSize: " << communityGenerationSize << "\n";
|
||||
|
||||
throw std::runtime_error("Mismatch in vector sizes for CalculateSurplusCommunity()");
|
||||
}
|
||||
|
||||
|
||||
for (auto &&[needed_g, needed_c, con_after,gen_after,con_from,gen_to, con_available, gen_available, isGenBigger]:
|
||||
std::views::zip(
|
||||
base.values()->needed_gen(),
|
||||
base.values()->needed_con(),
|
||||
base.values()->consumption_after_community(),
|
||||
base.values()->generation_after_community(),
|
||||
base.values()->generation_to_community(),
|
||||
base.values()->consumption_from_community(),
|
||||
community.consumption_available(),
|
||||
community.generation_available(),
|
||||
community.is_gen_bigger_than_con()
|
||||
)) {
|
||||
if (isGenBigger) {
|
||||
con_from = needed_g;
|
||||
gen_to = needed_g / gen_available * con_available;
|
||||
} else {
|
||||
con_from = needed_c / con_available * gen_available;
|
||||
gen_to = needed_c;
|
||||
}
|
||||
con_after = needed_c - con_from;
|
||||
gen_after = needed_g - gen_to;
|
||||
}
|
||||
|
||||
if (base.metadata()->annual_consumption() != 0) {
|
||||
base.values()->set_con_from_community_relative(
|
||||
std::accumulate(base.values()->consumption_from_community().begin(),
|
||||
base.values()->consumption_from_community().end(),
|
||||
0.0f) / base.metadata()->annual_consumption());
|
||||
}
|
||||
if (base.metadata()->annual_generation() != 0) {
|
||||
base.values()->set_gen_to_community_relative(
|
||||
std::accumulate(base.values()->generation_to_community().begin(),
|
||||
base.values()->generation_to_community().end(),
|
||||
0.0f) / base.metadata()->annual_generation());
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,20 +16,18 @@ private:
|
||||
std::vector<std::unique_ptr<Community> > &communities;
|
||||
std::vector<float> consumptionAvailable;
|
||||
std::vector<float> generationAvailable;
|
||||
std::vector<bool> isGenBigger;
|
||||
|
||||
public:
|
||||
Surplus(std::vector<std::unique_ptr<Community> > &communities) : communities(communities),
|
||||
consumptionAvailable(VALUE_COUNT, 0.0f),
|
||||
generationAvailable(VALUE_COUNT, 0.0f),
|
||||
isGenBigger(VALUE_COUNT, false) {
|
||||
generationAvailable(VALUE_COUNT, 0.0f) {
|
||||
}
|
||||
|
||||
void CalculateSurplus();
|
||||
|
||||
void CalculateBuildingSurplus(Community &community, Building::Base &);
|
||||
|
||||
void CalculateSurplusCommunity(const Community & community, const Building::Base & base);
|
||||
void CalculateSurplusCommunity(Community &community, Building::Base &base);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user