various adjustments
This commit is contained in:
@ -21,8 +21,9 @@ add_executable(Sim_C__
|
|||||||
src/services/Cost/TaxComponent.cpp
|
src/services/Cost/TaxComponent.cpp
|
||||||
src/services/Cost/TaxComponent.h
|
src/services/Cost/TaxComponent.h
|
||||||
src/helper/Curry.h
|
src/helper/Curry.h
|
||||||
src/enums/Aut.h
|
|
||||||
src/config.h
|
src/config.h
|
||||||
|
src/services/Cost/NetworkProvider.cpp
|
||||||
|
src/services/Cost/NetworkProvider.h
|
||||||
)
|
)
|
||||||
find_package(doctest CONFIG REQUIRED)
|
find_package(doctest CONFIG REQUIRED)
|
||||||
find_package(spdlog CONFIG REQUIRED)
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
|
|||||||
@ -8,9 +8,10 @@
|
|||||||
#define LOG_DEBUG_INFO(...)
|
#define LOG_DEBUG_INFO(...)
|
||||||
#define LOG_DEBUG_ERROR(...)
|
#define LOG_DEBUG_ERROR(...)
|
||||||
#else
|
#else
|
||||||
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||||
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
#define VALUE_COUNT (4*24*365)
|
#define VALUE_COUNT ((size_t)(4 * 24 * 365))
|
||||||
|
#define MAX_CONDITIONS 2560
|
||||||
|
|
||||||
#endif //CONFIG_H
|
#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
|
#ifndef CURRY_H
|
||||||
#define CURRY_H
|
#define CURRY_H
|
||||||
|
|
||||||
template <typename Func1, typename Func2>
|
template<typename Func1, typename Func2>
|
||||||
auto curry(Func1 f1, Func2 f2)
|
auto curry(Func1 f1, Func2 f2) {
|
||||||
{
|
return [=](auto... args) {
|
||||||
return [=](auto... args)
|
|
||||||
{
|
|
||||||
auto result1 = f1(args...);
|
auto result1 = f1(args...);
|
||||||
return f2(result1);
|
return f2(result1);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,15 +1,21 @@
|
|||||||
//
|
|
||||||
// Created by stani on 3/10/2025.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef ICOSTCOMPONENT_H
|
#ifndef ICOSTCOMPONENT_H
|
||||||
#define ICOSTCOMPONENT_H
|
#define ICOSTCOMPONENT_H
|
||||||
#include "../model/Community.h"
|
|
||||||
|
|
||||||
class ICostComponent
|
#include <bitset>
|
||||||
{
|
#include "../model/Community.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
|
||||||
|
class ICostComponent {
|
||||||
public:
|
public:
|
||||||
|
std::bitset<MAX_CONDITIONS> applicableConditions;
|
||||||
|
|
||||||
|
template<typename... Conditions>
|
||||||
|
ICostComponent(Conditions... conditions) {
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~ICostComponent() = default;
|
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
|
#endif //ICOSTCOMPONENT_H
|
||||||
|
|||||||
@ -4,29 +4,141 @@
|
|||||||
|
|
||||||
#include "Building.h"
|
#include "Building.h"
|
||||||
|
|
||||||
float Building::Cost::special_rate_consumption() const {
|
float Building::Metadata::special_rate_consumption() const {
|
||||||
return SpecialRateConsumption;
|
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;
|
SpecialRateConsumption = special_rate_consumption;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Building::Cost::special_rate_generation() const {
|
float Building::Metadata::special_rate_generation() const {
|
||||||
return SpecialRateGeneration;
|
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;
|
SpecialRateGeneration = special_rate_generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> &Building::Simulation_Values::community_coverage() {
|
std::vector<float> &Building::Simulation_Values::generation_after_community() {
|
||||||
return CommunityCoverage;
|
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::
|
void Building::Simulation_Values::
|
||||||
set_community_coverage(std::vector<float> community_coverage) {
|
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() {
|
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() {
|
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) {
|
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() {
|
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) {
|
void Building::Simulation_Values::set_relativeSelfGeneration(float const relativeSelfGeneration) {
|
||||||
this->RelativeGeneration = relativeSelfGeneration;
|
this->RelativeGeneration = relativeSelfGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Building::Metadata::name() const {
|
std::string Building::Metadata::name() const {
|
||||||
return Name;
|
return Name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,41 +4,70 @@
|
|||||||
|
|
||||||
#ifndef BUILDING_H
|
#ifndef BUILDING_H
|
||||||
#define BUILDING_H
|
#define BUILDING_H
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Building {
|
namespace Building {
|
||||||
class Cost {
|
class CostValues {
|
||||||
private:
|
private:
|
||||||
float SpecialRateConsumption;
|
float Consumption{0.0f};
|
||||||
float SpecialRateGeneration;
|
float Generation{0.0f};
|
||||||
|
float ConsumptionWithCommunity{0.0f};
|
||||||
|
float GenerationWithCommunity{0.0f};
|
||||||
|
|
||||||
public:
|
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);
|
class Cost {
|
||||||
|
private:
|
||||||
float special_rate_generation() const;
|
std::shared_ptr<CostValues> CostValuesWith{};
|
||||||
|
std::shared_ptr<CostValues> CostValuesWithOut{};
|
||||||
void set_special_rate_generation(float special_rate_generation);
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<CostValues> &get_cost_values_with() { return CostValuesWith; }
|
||||||
|
std::shared_ptr<CostValues> &get_cost_values_without() { return CostValuesWithOut; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Simulation_Values {
|
class Simulation_Values {
|
||||||
private:
|
private:
|
||||||
std::vector<float> CommunityCoverage;
|
std::vector<float> ConsumptionAfterOwnCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> OwnUsage;
|
std::vector<float> OwnUsage = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> Needed_con;
|
std::vector<float> NeededCon = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> NeededGen;
|
std::vector<float> NeededGen = std::vector(VALUE_COUNT, 0.0f);
|
||||||
float RelativeSelfConsumption{0.0f};
|
float RelativeSelfConsumption{0.0f};
|
||||||
float RelativeGeneration{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:
|
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);
|
void set_community_coverage(std::vector<float> community_coverage);
|
||||||
|
|
||||||
@ -55,24 +84,72 @@ namespace Building {
|
|||||||
void set_needed_gen(std::vector<float> needed_gen);
|
void set_needed_gen(std::vector<float> needed_gen);
|
||||||
|
|
||||||
float relativeSelfConsumption() const;
|
float relativeSelfConsumption() const;
|
||||||
|
|
||||||
void set_relativeSelfConsumption(float relativeSelfConsumption);
|
void set_relativeSelfConsumption(float relativeSelfConsumption);
|
||||||
|
|
||||||
float relativeSelfGeneration() const;
|
float relativeSelfGeneration() const;
|
||||||
|
|
||||||
void set_relativeSelfGeneration(float relativeSelfGeneration);
|
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 {
|
class Metadata {
|
||||||
private:
|
private:
|
||||||
std::string Name;
|
std::string Name{};
|
||||||
float AnnualConsumption;
|
float AnnualConsumption{0.0f};
|
||||||
float AnnualGeneration;
|
float AnnualGeneration{0.0f};
|
||||||
std::vector<float> ConsumptionProfile;
|
std::vector<float> ConsumptionProfile = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> GenerationProfile;
|
std::vector<float> GenerationProfile = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::string ConsumptionProfileName;
|
std::string ConsumptionProfileName{};
|
||||||
std::string GenerationProfileName;
|
std::string GenerationProfileName{};
|
||||||
short ConnectionPower;
|
short ConnectionPower{0};
|
||||||
short GridPower;
|
short GridPower{0};
|
||||||
|
float SpecialRateConsumption{0.0f};
|
||||||
|
float SpecialRateGeneration{0.0f};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Metadata() = default;
|
||||||
|
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
|
||||||
void set_name(const std::string &name);
|
void set_name(const std::string &name);
|
||||||
@ -108,13 +185,21 @@ namespace Building {
|
|||||||
short grid_power() const;
|
short grid_power() const;
|
||||||
|
|
||||||
void set_grid_power(short grid_power);
|
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> {
|
class Base : public Model<Base> {
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Cost> Cost;
|
std::unique_ptr<Cost> Cost{};
|
||||||
std::unique_ptr<Simulation_Values> Values;
|
std::unique_ptr<Simulation_Values> Values{};
|
||||||
std::unique_ptr<Metadata> Metadata;
|
std::unique_ptr<Metadata> Metadata{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<Building::Cost> &cost();
|
std::unique_ptr<Building::Cost> &cost();
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#include "Community.h"
|
#include "Community.h"
|
||||||
|
|
||||||
#include "../helper/Curry.h"
|
|
||||||
|
|
||||||
std::string Community::name() const {
|
std::string Community::name() const {
|
||||||
return Name;
|
return Name;
|
||||||
@ -27,43 +26,44 @@ void Community::set_energy_tariff(const Energy_Tariff &energy_tariff) {
|
|||||||
energy_Tariff = energy_tariff;
|
energy_Tariff = energy_tariff;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> Community::GenerationAvailable() const {
|
std::vector<float> &Community::generation_available() {
|
||||||
return generationAvailable;
|
return GenerationAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Community::set_generation_available(std::vector<float> &generationAvailable) {
|
void Community::set_generation_available(std::vector<float> &generationAvailable) {
|
||||||
this->generationAvailable = generationAvailable;
|
this->GenerationAvailable = generationAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> Community::ConsumptionAvailable() const {
|
std::vector<float> &Community::consumption_available() {
|
||||||
return consumptionAvailable;
|
return ConsumptionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Community::set_consumption_available(std::vector<float> &consumptionAvailable) {
|
void Community::set_consumption_available(std::vector<float> &consumptionAvailable) {
|
||||||
this->consumptionAvailable = consumptionAvailable;
|
this->ConsumptionAvailable = consumptionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<bool> Community::IsGenBiggerThanCon() const {
|
std::vector<bool> &Community::is_gen_bigger_than_con() {
|
||||||
return isGenBiggerThanCon;
|
return IsGenBiggerThanCon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Community::set_is_gen_bigger_than_con(std::vector<bool> &isGenBiggerThanCon) {
|
void Community::set_is_gen_bigger_than_con(std::vector<bool> &isGenBiggerThanCon) {
|
||||||
this->isGenBiggerThanCon=isGenBiggerThanCon;
|
this->IsGenBiggerThanCon = isGenBiggerThanCon;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Community::iterateBuildings(
|
auto Community::iterateBuildings(
|
||||||
std::vector<std::unique_ptr<Community> > &Communities)
|
std::vector<std::unique_ptr<Community> > &Communities)
|
||||||
-> std::function<std::function<void(const std::function<void(
|
-> std::function<std::function<void(const std::function<void(Community &, Building::Base &)> &)>(
|
||||||
Community &, Building::Base &)> &)>(const std::function<void(Community &)> &)> {
|
const std::function<void(Community &)> &)> {
|
||||||
return [&](const std::function<void(Community &)> &func1) {
|
return [&](const std::function<void(Community &)> &func1) {
|
||||||
return [&, func1](const std::function<void(Community &, Building::Base &)> &func2) {
|
return [&, func1](const std::function<void(Community &, Building::Base &)> &func2) {
|
||||||
iterateVector(Communities, func1);
|
for (auto &community: Communities) {
|
||||||
|
func1(*community);
|
||||||
iterateVector(Communities, [&](Community &community) {
|
for (auto &building: community->buildings()) {
|
||||||
for (auto &building: community.buildings()) {
|
func2(*community, *building);
|
||||||
func2(community, *building);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#ifndef COMMUNITY_H
|
#ifndef COMMUNITY_H
|
||||||
#define COMMUNITY_H
|
#define COMMUNITY_H
|
||||||
|
#include <bitset>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -14,7 +15,6 @@
|
|||||||
|
|
||||||
class Community : public Model<Community> {
|
class Community : public Model<Community> {
|
||||||
public:
|
public:
|
||||||
Community():generationAvailable(VALUE_COUNT, 0.0f),consumptionAvailable(VALUE_COUNT,0.0f){};
|
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
|
||||||
void set_name(const std::string &name);
|
void set_name(const std::string &name);
|
||||||
@ -27,29 +27,32 @@ public:
|
|||||||
|
|
||||||
void set_energy_tariff(const Energy_Tariff &energy_tariff);
|
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);
|
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);
|
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);
|
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::
|
static std::function<std::function<void(const std::function<void(Community &, Building::Base &)> &)>(const std::
|
||||||
function<void(
|
function<void(
|
||||||
Community &)> &)>
|
Community &)> &)>
|
||||||
iterateBuildings(std::vector<std::unique_ptr<Community> > &Communities);
|
iterateBuildings(std::vector<std::unique_ptr<Community> > &Communities);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::vector<std::unique_ptr<Building::Base> > Buildings;
|
std::vector<std::unique_ptr<Building::Base> > Buildings;
|
||||||
std::vector<float> generationAvailable;
|
std::vector<float> GenerationAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> consumptionAvailable;
|
std::vector<float> ConsumptionAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<bool> isGenBiggerThanCon;
|
std::vector<bool> IsGenBiggerThanCon = std::vector(VALUE_COUNT, false);
|
||||||
|
|
||||||
|
|
||||||
Energy_Tariff energy_Tariff;
|
Energy_Tariff energy_Tariff;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
|
|
||||||
class Energy_Tariff {
|
class Energy_Tariff {
|
||||||
|
public:
|
||||||
|
float consumption_tariff{0.0f};
|
||||||
|
float generation_tariff{0.0f};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,15 +5,12 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
class Model
|
class Model {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static void iterateVector(std::vector<std::unique_ptr<T>>& vector,
|
static void iterateVector(std::vector<std::unique_ptr<T> > &vector,
|
||||||
const std::function<void(T&)>& function)
|
const std::function<void(T &)> &function) {
|
||||||
{
|
for (auto &item: vector) {
|
||||||
for (auto& item : vector)
|
|
||||||
{
|
|
||||||
function(*item);
|
function(*item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,15 +4,25 @@
|
|||||||
|
|
||||||
#include "CostPipeline.h"
|
#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);
|
this->components.push_back(components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CostPipeline::calculateFinalCost()
|
void CostPipeline::calculateFinalCost() {
|
||||||
{
|
for (auto &component: this->components) {
|
||||||
for (auto& component : this->components)
|
iterateCommunity(component);
|
||||||
{
|
}
|
||||||
component->apply(this->communities);
|
}
|
||||||
|
|
||||||
|
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
|
#define COSTPIPELINE_H
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "NetworkProvider.h"
|
||||||
#include "../../interfaces/ICostComponent.h"
|
#include "../../interfaces/ICostComponent.h"
|
||||||
#include "../../model/Community.h"
|
#include "../../model/Community.h"
|
||||||
|
|
||||||
class CostPipeline
|
class CostPipeline {
|
||||||
{
|
std::vector<std::unique_ptr<Community> > &communities;
|
||||||
std::vector<std::unique_ptr<Community>>& communities;
|
std::vector<std::shared_ptr<ICostComponent> > components;
|
||||||
std::vector<std::shared_ptr<ICostComponent>> components;
|
|
||||||
|
|
||||||
public:
|
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 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"
|
#include "TaxComponent.h"
|
||||||
|
|
||||||
void TaxComponent::applyCost(std::vector<std::unique_ptr<Community>>& communities)
|
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) {
|
||||||
{
|
|
||||||
Community::iterateVector(communities, [&](Community& community)
|
|
||||||
{
|
|
||||||
Building::Base::iterateVector(community.buildings(), [&](Building::Base& building)
|
|
||||||
{
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,16 +7,14 @@
|
|||||||
#include "../../interfaces/ICostComponent.h"
|
#include "../../interfaces/ICostComponent.h"
|
||||||
|
|
||||||
|
|
||||||
class TaxComponent : public ICostComponent
|
class TaxComponent : public ICostComponent {
|
||||||
{
|
|
||||||
double taxRate;
|
double taxRate;
|
||||||
|
|
||||||
public:
|
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 <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Surplus.h"
|
#include "Surplus.h"
|
||||||
#include "../model/Building.h"
|
#include "../model/Building.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void Surplus::CalculateSurplus() {
|
void Surplus::CalculateSurplus() {
|
||||||
auto iterateFunc = Community::iterateBuildings(communities);
|
auto iterateFunc = Community::iterateBuildings(communities);
|
||||||
|
|
||||||
auto modifyCommunity = [this](Community &c) {
|
auto modifyCommunity = [this](Community &c) {
|
||||||
this->consumptionAvailable=std::vector<float>(VALUE_COUNT, 00.f);
|
this->consumptionAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||||
this->generationAvailable=std::vector<float>(VALUE_COUNT, 00.f);
|
this->generationAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||||
this->isGenBigger=std::vector<bool>(VALUE_COUNT, false);
|
|
||||||
|
assert(!c.name().empty() && "Community name is empty!");
|
||||||
LOG_DEBUG_INFO("Calculating Surplus for Community: {}", c.name());
|
LOG_DEBUG_INFO("Calculating Surplus for Community: {}", c.name());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
auto modifyBuildingSurplus = [this](Community &community, Building::Base &building) {
|
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: {}",
|
LOG_DEBUG_INFO("Calculating Surplus for Building: {} in Community: {}",
|
||||||
building.metadata()->name(), community.name());
|
building.metadata()->name(), community.name());
|
||||||
|
|
||||||
CalculateBuildingSurplus(community, building);
|
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_consumption_available(this->consumptionAvailable);
|
||||||
community.set_generation_available(this->generationAvailable);
|
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) {
|
void Surplus::CalculateBuildingSurplus(Community &community, Building::Base &building) {
|
||||||
std::vector<float> ownCoverage;
|
std::vector<float> ownCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> neededConsumption;
|
std::vector<float> neededConsumption = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> neededGeneration;
|
std::vector<float> neededGeneration = std::vector(VALUE_COUNT, 0.0f);
|
||||||
std::vector<float> ownUsage;
|
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 &consumption = building.metadata()->consumption_profile();
|
||||||
const auto &generation = building.metadata()->generation_profile();
|
const auto &generation = building.metadata()->generation_profile();
|
||||||
|
|
||||||
ownCoverage.reserve(consumption.size());
|
size_t i = 0; // Fixed static variable issue
|
||||||
neededConsumption.reserve(consumption.size());
|
|
||||||
neededGeneration.reserve(consumption.size());
|
|
||||||
ownUsage.reserve(consumption.size());
|
|
||||||
|
|
||||||
std::ranges::for_each(consumption, [&](auto c_ptr) {
|
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 c = c_ptr ? c_ptr : 0.0f;
|
||||||
const float g = (i < generation.size() && generation[i]) ? generation[i] : 0.0f;
|
const float g = i < generation.size() ? generation[i] : 0.0f;
|
||||||
const float c_community = (i < consumptionAvailable.size() && consumptionAvailable[i])
|
const float c_community = (i < consumptionAvailable.size()) ? consumptionAvailable[i] : 0.0f;
|
||||||
? consumptionAvailable[i]
|
const float g_community = (i < generationAvailable.size()) ? generationAvailable[i] : 0.0f;
|
||||||
: 0.0f;
|
|
||||||
const float g_community = (i < generationAvailable.size() && generationAvailable[i])
|
|
||||||
? generationAvailable[i]
|
|
||||||
: 0.0f;
|
|
||||||
|
|
||||||
const auto ownCov = (c - g);
|
const auto ownCov = (c - g);
|
||||||
const auto neededCons = ((c > 0.0f) ? c : 0.0f);
|
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 communityConsumption = c_community + neededCons;
|
||||||
const auto generationConsumption = g_community + neededGen;
|
const auto generationConsumption = g_community + neededGen;
|
||||||
|
|
||||||
ownCoverage.push_back(ownCov);
|
ownCoverage[i] = ownCov;
|
||||||
neededConsumption.push_back(neededCons);
|
neededConsumption[i] = neededCons;
|
||||||
neededGeneration.push_back(neededGen);
|
neededGeneration[i] = neededGen;
|
||||||
ownUsage.push_back(ownUs);
|
ownUsage[i] = ownUs;
|
||||||
this->consumptionAvailable[i] = communityConsumption;
|
if (i < consumptionAvailable.size()) this->consumptionAvailable[i] = communityConsumption;
|
||||||
this->generationAvailable[i] = generationConsumption;
|
if (i < generationAvailable.size()) this->generationAvailable[i] = generationConsumption;
|
||||||
this->isGenBigger[i] = generationAvailable[i] > consumptionAvailable[i];
|
|
||||||
++i;
|
++i;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -88,24 +91,92 @@ void Surplus::CalculateBuildingSurplus(Community &community, Building::Base &bui
|
|||||||
building.values()->set_needed_gen(std::move(neededGeneration));
|
building.values()->set_needed_gen(std::move(neededGeneration));
|
||||||
building.values()->set_own_usage(std::move(ownUsage));
|
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(
|
building.values()->set_relativeSelfConsumption(
|
||||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||||
std::accumulate(building.metadata()->consumption_profile().begin(),
|
totalConsumption);
|
||||||
building.metadata()->consumption_profile().end(), 0.0f));
|
|
||||||
} else {
|
} else {
|
||||||
building.values()->set_relativeSelfConsumption(0.0f);
|
building.values()->set_relativeSelfConsumption(0.0f);
|
||||||
}
|
}
|
||||||
if (building.metadata()->annual_generation() > 0.0f) {
|
|
||||||
|
if (totalGeneration > 0.0f) {
|
||||||
building.values()->set_relativeSelfGeneration(
|
building.values()->set_relativeSelfGeneration(
|
||||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||||
std::accumulate(building.metadata()->generation_profile().begin(),
|
totalGeneration);
|
||||||
building.metadata()->generation_profile().end(), 0.0f));
|
|
||||||
} else {
|
} else {
|
||||||
building.values()->set_relativeSelfGeneration(0.0f);
|
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<std::unique_ptr<Community> > &communities;
|
||||||
std::vector<float> consumptionAvailable;
|
std::vector<float> consumptionAvailable;
|
||||||
std::vector<float> generationAvailable;
|
std::vector<float> generationAvailable;
|
||||||
std::vector<bool> isGenBigger;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Surplus(std::vector<std::unique_ptr<Community> > &communities) : communities(communities),
|
Surplus(std::vector<std::unique_ptr<Community> > &communities) : communities(communities),
|
||||||
consumptionAvailable(VALUE_COUNT, 0.0f),
|
consumptionAvailable(VALUE_COUNT, 0.0f),
|
||||||
generationAvailable(VALUE_COUNT, 0.0f),
|
generationAvailable(VALUE_COUNT, 0.0f) {
|
||||||
isGenBigger(VALUE_COUNT, false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalculateSurplus();
|
void CalculateSurplus();
|
||||||
|
|
||||||
void CalculateBuildingSurplus(Community &community, Building::Base &);
|
void CalculateBuildingSurplus(Community &community, Building::Base &);
|
||||||
|
|
||||||
void CalculateSurplusCommunity(const Community & community, const Building::Base & base);
|
void CalculateSurplusCommunity(Community &community, Building::Base &base);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,12 +15,6 @@ namespace Building {
|
|||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<Building::Cost> static create_test_cost() {
|
|
||||||
auto cost = std::make_unique<Building::Cost>();
|
|
||||||
cost->set_special_rate_consumption(0.15f);
|
|
||||||
cost->set_special_rate_generation(0.10f);
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Building::Simulation_Values> static create_test_simulation_values() {
|
std::unique_ptr<Building::Simulation_Values> static create_test_simulation_values() {
|
||||||
auto values = std::make_unique<Building::Simulation_Values>();
|
auto values = std::make_unique<Building::Simulation_Values>();
|
||||||
@ -56,6 +50,9 @@ public:
|
|||||||
metadata->set_connection_power(100);
|
metadata->set_connection_power(100);
|
||||||
metadata->set_grid_power(50);
|
metadata->set_grid_power(50);
|
||||||
|
|
||||||
|
metadata->set_special_rate_consumption(0.15f);
|
||||||
|
metadata->set_special_rate_generation(0.10f);
|
||||||
|
|
||||||
auto consumptionProfile = std::vector<float>();
|
auto consumptionProfile = std::vector<float>();
|
||||||
auto generationProfile = std::vector<float>();
|
auto generationProfile = std::vector<float>();
|
||||||
|
|
||||||
@ -74,7 +71,6 @@ public:
|
|||||||
std::unique_ptr<Building::Base> static create_test_building() {
|
std::unique_ptr<Building::Base> static create_test_building() {
|
||||||
auto building = std::make_unique<Building::Base>();
|
auto building = std::make_unique<Building::Base>();
|
||||||
|
|
||||||
building->set_cost(create_test_cost());
|
|
||||||
building->set_values(create_test_simulation_values());
|
building->set_values(create_test_simulation_values());
|
||||||
building->set_metadata(create_test_metadata());
|
building->set_metadata(create_test_metadata());
|
||||||
|
|
||||||
@ -90,7 +86,7 @@ public:
|
|||||||
community->set_name("Test Community");
|
community->set_name("Test Community");
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Building::Base> > buildings;
|
std::vector<std::unique_ptr<Building::Base> > buildings;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
buildings.push_back(create_test_building());
|
buildings.push_back(create_test_building());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,15 +3,19 @@
|
|||||||
//
|
//
|
||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
#include "../../src/services/Surplus.h"
|
#include "../../src/services/Surplus.h"
|
||||||
|
#include "../../src/services/Cost/CostPipeline.h"
|
||||||
|
#include "../../src/services/Cost/NetworkProvider.h"
|
||||||
#include "doctest/doctest.h"
|
#include "doctest/doctest.h"
|
||||||
#include "../model/Factory.h"
|
#include "../model/Factory.h"
|
||||||
|
|
||||||
TEST_CASE("Testing add function") {
|
TEST_CASE("Testing add function") {
|
||||||
std::vector<std::unique_ptr<Community> > communities;
|
std::vector<std::unique_ptr<Community> > communities;
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
communities.push_back(Factory::create_test_community());
|
communities.push_back(Factory::create_test_community());
|
||||||
}
|
}
|
||||||
Surplus surplus(communities);
|
Surplus surplus(communities);
|
||||||
surplus.CalculateSurplus();
|
surplus.CalculateSurplus();
|
||||||
|
CostPipeline costPipeline(communities);
|
||||||
|
costPipeline.addCostComponent(std::make_shared<NetworkProvider>());
|
||||||
CHECK(true);
|
CHECK(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user