formatting
This commit is contained in:
@ -4,9 +4,12 @@
|
||||
|
||||
#ifndef CURRY_H
|
||||
#define CURRY_H
|
||||
|
||||
template <typename Func1, typename Func2>
|
||||
auto curry(Func1 f1, Func2 f2) {
|
||||
return [=](auto... args) {
|
||||
auto curry(Func1 f1, Func2 f2)
|
||||
{
|
||||
return [=](auto... args)
|
||||
{
|
||||
auto result1 = f1(args...);
|
||||
return f2(result1);
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
class ICostComponent
|
||||
{
|
||||
public:
|
||||
public:
|
||||
virtual ~ICostComponent() = default;
|
||||
virtual double apply(std::vector<std::unique_ptr<Community>>& communities) const = 0;
|
||||
};
|
||||
|
||||
@ -4,148 +4,184 @@
|
||||
|
||||
#include "Building.h"
|
||||
|
||||
float Building::Cost::special_rate_consumption() const {
|
||||
float Building::Cost::special_rate_consumption() const
|
||||
{
|
||||
return SpecialRateConsumption;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_consumption(float special_rate_consumption) {
|
||||
void Building::Cost::set_special_rate_consumption(float special_rate_consumption)
|
||||
{
|
||||
SpecialRateConsumption = special_rate_consumption;
|
||||
}
|
||||
|
||||
float Building::Cost::special_rate_generation() const {
|
||||
float Building::Cost::special_rate_generation() const
|
||||
{
|
||||
return SpecialRateGeneration;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_generation(float special_rate_generation) {
|
||||
void Building::Cost::set_special_rate_generation(float special_rate_generation)
|
||||
{
|
||||
SpecialRateGeneration = special_rate_generation;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::community_coverage() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::community_coverage()
|
||||
{
|
||||
return CommunityCoverage;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::
|
||||
set_community_coverage(std::vector<std::unique_ptr<float>> community_coverage) {
|
||||
set_community_coverage(std::vector<std::unique_ptr<float>> community_coverage)
|
||||
{
|
||||
CommunityCoverage = std::move(community_coverage);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::own_usage() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::own_usage()
|
||||
{
|
||||
return OwnUsage;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_own_usage(std::vector<std::unique_ptr<float>> own_usage) {
|
||||
OwnUsage = std::move(own_usage) ;
|
||||
void Building::Simulation_Values::set_own_usage(std::vector<std::unique_ptr<float>> own_usage)
|
||||
{
|
||||
OwnUsage = std::move(own_usage);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::needed_con() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::needed_con()
|
||||
{
|
||||
return Needed_con;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_con(std::vector<std::unique_ptr<float>> needed_con) {
|
||||
Needed_con = std::move(needed_con) ;
|
||||
void Building::Simulation_Values::set_needed_con(std::vector<std::unique_ptr<float>> needed_con)
|
||||
{
|
||||
Needed_con = std::move(needed_con);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::needed_gen() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Simulation_Values::needed_gen()
|
||||
{
|
||||
return NeededGen;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_gen(std::vector<std::unique_ptr<float>> needed_gen) {
|
||||
void Building::Simulation_Values::set_needed_gen(std::vector<std::unique_ptr<float>> needed_gen)
|
||||
{
|
||||
NeededGen = std::move(needed_gen);
|
||||
}
|
||||
|
||||
std::string Building::Metadata::name() const {
|
||||
std::string Building::Metadata::name() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_name(const std::string &name) {
|
||||
Name = name;
|
||||
void Building::Metadata::set_name(const std::string& name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
float Building::Metadata::annual_consumption() const {
|
||||
float Building::Metadata::annual_consumption() const
|
||||
{
|
||||
return AnnualConsumption;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_annual_consumption(float annual_consumption) {
|
||||
void Building::Metadata::set_annual_consumption(float annual_consumption)
|
||||
{
|
||||
AnnualConsumption = annual_consumption;
|
||||
}
|
||||
|
||||
float Building::Metadata::annual_generation() const {
|
||||
float Building::Metadata::annual_generation() const
|
||||
{
|
||||
return AnnualGeneration;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_annual_generation(float annual_generation) {
|
||||
void Building::Metadata::set_annual_generation(float annual_generation)
|
||||
{
|
||||
AnnualGeneration = annual_generation;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Metadata::consumption_profile() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Metadata::consumption_profile()
|
||||
{
|
||||
return ConsumptionProfile;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_consumption_profile(std::vector<std::unique_ptr<float>> consumption_profile) {
|
||||
void Building::Metadata::set_consumption_profile(std::vector<std::unique_ptr<float>> consumption_profile)
|
||||
{
|
||||
ConsumptionProfile = std::move(consumption_profile);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float>>& Building::Metadata::generation_profile() {
|
||||
std::vector<std::unique_ptr<float>>& Building::Metadata::generation_profile()
|
||||
{
|
||||
return GenerationProfile;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_generation_profile(std::vector<std::unique_ptr<float>> generation_profile) {
|
||||
void Building::Metadata::set_generation_profile(std::vector<std::unique_ptr<float>> generation_profile)
|
||||
{
|
||||
GenerationProfile = std::move(generation_profile);
|
||||
}
|
||||
|
||||
std::string Building::Metadata::consumption_profile_name() const {
|
||||
std::string Building::Metadata::consumption_profile_name() const
|
||||
{
|
||||
return ConsumptionProfileName;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_consumption_profile_name(const std::string &consumption_profile_name) {
|
||||
void Building::Metadata::set_consumption_profile_name(const std::string& consumption_profile_name)
|
||||
{
|
||||
ConsumptionProfileName = consumption_profile_name;
|
||||
}
|
||||
|
||||
std::string Building::Metadata::generation_profile_name() const {
|
||||
std::string Building::Metadata::generation_profile_name() const
|
||||
{
|
||||
return GenerationProfileName;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_generation_profile_name(const std::string &generation_profile_name) {
|
||||
void Building::Metadata::set_generation_profile_name(const std::string& generation_profile_name)
|
||||
{
|
||||
GenerationProfileName = generation_profile_name;
|
||||
}
|
||||
|
||||
short Building::Metadata::connection_power() const {
|
||||
short Building::Metadata::connection_power() const
|
||||
{
|
||||
return ConnectionPower;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_connection_power(short connection_power) {
|
||||
void Building::Metadata::set_connection_power(short connection_power)
|
||||
{
|
||||
ConnectionPower = connection_power;
|
||||
}
|
||||
|
||||
short Building::Metadata::grid_power() const {
|
||||
short Building::Metadata::grid_power() const
|
||||
{
|
||||
return GridPower;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_grid_power(short grid_power) {
|
||||
void Building::Metadata::set_grid_power(short grid_power)
|
||||
{
|
||||
GridPower = grid_power;
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Cost>& Building::Base::cost() {
|
||||
std::unique_ptr<Building::Cost>& Building::Base::cost()
|
||||
{
|
||||
return Cost;
|
||||
}
|
||||
|
||||
void Building::Base::set_cost(std::unique_ptr<Building::Cost> cost) {
|
||||
void Building::Base::set_cost(std::unique_ptr<Building::Cost> cost)
|
||||
{
|
||||
Cost = std::move(cost);
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Simulation_Values>& Building::Base::values() {
|
||||
std::unique_ptr<Building::Simulation_Values>& Building::Base::values()
|
||||
{
|
||||
return Values;
|
||||
}
|
||||
|
||||
void Building::Base::set_values(std::unique_ptr<Simulation_Values> values) {
|
||||
void Building::Base::set_values(std::unique_ptr<Simulation_Values> values)
|
||||
{
|
||||
Values = std::move(values);
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Metadata>& Building::Base::metadata() {
|
||||
std::unique_ptr<Building::Metadata>& Building::Base::metadata()
|
||||
{
|
||||
return Metadata;
|
||||
}
|
||||
|
||||
void Building::Base::set_metadata(std::unique_ptr<Building::Metadata> metadata) {
|
||||
void Building::Base::set_metadata(std::unique_ptr<Building::Metadata> metadata)
|
||||
{
|
||||
Metadata = std::move(metadata);
|
||||
}
|
||||
|
||||
|
||||
@ -1,91 +1,100 @@
|
||||
//
|
||||
// Created by Stani on 09/03/2025.
|
||||
//
|
||||
//
|
||||
// Created by Stani on 09/03/2025.
|
||||
//
|
||||
|
||||
#ifndef BUILDING_H
|
||||
#define BUILDING_H
|
||||
#ifndef BUILDING_H
|
||||
#define BUILDING_H
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Model.h"
|
||||
|
||||
|
||||
namespace Building {
|
||||
class Cost {
|
||||
private:
|
||||
float SpecialRateConsumption;
|
||||
float SpecialRateGeneration;
|
||||
public:
|
||||
namespace Building
|
||||
{
|
||||
class Cost
|
||||
{
|
||||
private:
|
||||
float SpecialRateConsumption;
|
||||
float SpecialRateGeneration;
|
||||
|
||||
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 Simulation_Values {
|
||||
private:
|
||||
std::vector<std::unique_ptr<float>> CommunityCoverage;
|
||||
std::vector<std::unique_ptr<float>> OwnUsage;
|
||||
std::vector<std::unique_ptr<float>> Needed_con;
|
||||
std::vector<std::unique_ptr<float>> NeededGen;
|
||||
public:
|
||||
std::vector<std::unique_ptr<float>>& community_coverage();
|
||||
void set_community_coverage(std::vector<std::unique_ptr<float>> community_coverage);
|
||||
std::vector<std::unique_ptr<float>>& own_usage();
|
||||
void set_own_usage(std::vector<std::unique_ptr<float>> own_usage);
|
||||
std::vector<std::unique_ptr<float>>& needed_con();
|
||||
void set_needed_con(std::vector<std::unique_ptr<float>> needed_con);
|
||||
std::vector<std::unique_ptr<float>>& needed_gen();
|
||||
void set_needed_gen(std::vector<std::unique_ptr<float>> needed_gen);
|
||||
};
|
||||
class Metadata {
|
||||
private:
|
||||
std::string Name;
|
||||
float AnnualConsumption;
|
||||
float AnnualGeneration;
|
||||
std::vector<std::unique_ptr<float>> ConsumptionProfile;
|
||||
std::vector<std::unique_ptr<float>> GenerationProfile;
|
||||
std::string ConsumptionProfileName;
|
||||
std::string GenerationProfileName;
|
||||
short ConnectionPower;
|
||||
short GridPower;
|
||||
public:
|
||||
std::string name() const;
|
||||
void set_name(const std::string &name);
|
||||
float annual_consumption() const;
|
||||
void set_annual_consumption(float annual_consumption);
|
||||
float annual_generation() const;
|
||||
void set_annual_generation(float annual_generation);
|
||||
std::vector<std::unique_ptr<float>>& consumption_profile();
|
||||
void set_consumption_profile(std::vector<std::unique_ptr<float>> consumption_profile);
|
||||
std::vector<std::unique_ptr<float>>& generation_profile();
|
||||
void set_generation_profile(std::vector<std::unique_ptr<float>> generation_profile);
|
||||
std::string consumption_profile_name() const;
|
||||
void set_consumption_profile_name(const std::string &consumption_profile_name);
|
||||
std::string generation_profile_name() const;
|
||||
void set_generation_profile_name(const std::string &generation_profile_name);
|
||||
short connection_power() const;
|
||||
void set_connection_power(short connection_power);
|
||||
short grid_power() const;
|
||||
void set_grid_power(short grid_power);
|
||||
};
|
||||
public:
|
||||
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;
|
||||
public:
|
||||
std::unique_ptr<Building::Cost>& cost();
|
||||
void set_cost(std::unique_ptr<Building::Cost> cost);
|
||||
std::unique_ptr<Simulation_Values> & values();
|
||||
void set_values(std::unique_ptr<Simulation_Values> values);
|
||||
std::unique_ptr<Building::Metadata> & metadata();
|
||||
void set_metadata(std::unique_ptr<Building::Metadata> metadata);
|
||||
};
|
||||
}
|
||||
class Simulation_Values
|
||||
{
|
||||
private:
|
||||
std::vector<std::unique_ptr<float>> CommunityCoverage;
|
||||
std::vector<std::unique_ptr<float>> OwnUsage;
|
||||
std::vector<std::unique_ptr<float>> Needed_con;
|
||||
std::vector<std::unique_ptr<float>> NeededGen;
|
||||
|
||||
public:
|
||||
std::vector<std::unique_ptr<float>>& community_coverage();
|
||||
void set_community_coverage(std::vector<std::unique_ptr<float>> community_coverage);
|
||||
std::vector<std::unique_ptr<float>>& own_usage();
|
||||
void set_own_usage(std::vector<std::unique_ptr<float>> own_usage);
|
||||
std::vector<std::unique_ptr<float>>& needed_con();
|
||||
void set_needed_con(std::vector<std::unique_ptr<float>> needed_con);
|
||||
std::vector<std::unique_ptr<float>>& needed_gen();
|
||||
void set_needed_gen(std::vector<std::unique_ptr<float>> needed_gen);
|
||||
};
|
||||
|
||||
class Metadata
|
||||
{
|
||||
private:
|
||||
std::string Name;
|
||||
float AnnualConsumption;
|
||||
float AnnualGeneration;
|
||||
std::vector<std::unique_ptr<float>> ConsumptionProfile;
|
||||
std::vector<std::unique_ptr<float>> GenerationProfile;
|
||||
std::string ConsumptionProfileName;
|
||||
std::string GenerationProfileName;
|
||||
short ConnectionPower;
|
||||
short GridPower;
|
||||
|
||||
public:
|
||||
std::string name() const;
|
||||
void set_name(const std::string& name);
|
||||
float annual_consumption() const;
|
||||
void set_annual_consumption(float annual_consumption);
|
||||
float annual_generation() const;
|
||||
void set_annual_generation(float annual_generation);
|
||||
std::vector<std::unique_ptr<float>>& consumption_profile();
|
||||
void set_consumption_profile(std::vector<std::unique_ptr<float>> consumption_profile);
|
||||
std::vector<std::unique_ptr<float>>& generation_profile();
|
||||
void set_generation_profile(std::vector<std::unique_ptr<float>> generation_profile);
|
||||
std::string consumption_profile_name() const;
|
||||
void set_consumption_profile_name(const std::string& consumption_profile_name);
|
||||
std::string generation_profile_name() const;
|
||||
void set_generation_profile_name(const std::string& generation_profile_name);
|
||||
short connection_power() const;
|
||||
void set_connection_power(short connection_power);
|
||||
short grid_power() const;
|
||||
void set_grid_power(short grid_power);
|
||||
};
|
||||
|
||||
class Base : public Model<Base>
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<Cost> Cost;
|
||||
std::unique_ptr<Simulation_Values> Values;
|
||||
std::unique_ptr<Metadata> Metadata;
|
||||
|
||||
public:
|
||||
std::unique_ptr<Building::Cost>& cost();
|
||||
void set_cost(std::unique_ptr<Building::Cost> cost);
|
||||
std::unique_ptr<Simulation_Values>& values();
|
||||
void set_values(std::unique_ptr<Simulation_Values> values);
|
||||
std::unique_ptr<Building::Metadata>& metadata();
|
||||
void set_metadata(std::unique_ptr<Building::Metadata> metadata);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //BUILDING_H
|
||||
#endif //BUILDING_H
|
||||
|
||||
@ -2,42 +2,52 @@
|
||||
|
||||
#include "../helper/Curry.h"
|
||||
|
||||
std::string Community::name() const {
|
||||
std::string Community::name() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
void Community::set_name(const std::string& name) {
|
||||
void Community::set_name(const std::string& name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Building::Base>>& Community::buildings() {
|
||||
std::vector<std::unique_ptr<Building::Base>>& Community::buildings()
|
||||
{
|
||||
return Buildings;
|
||||
}
|
||||
|
||||
// Use move semantics for efficiency
|
||||
void Community::set_buildings(std::vector<std::unique_ptr<Building::Base>> buildings) {
|
||||
void Community::set_buildings(std::vector<std::unique_ptr<Building::Base>> buildings)
|
||||
{
|
||||
Buildings = std::move(buildings);
|
||||
}
|
||||
|
||||
Energy_Tariff Community::energy_tariff() const {
|
||||
Energy_Tariff Community::energy_tariff() const
|
||||
{
|
||||
return energy_Tariff;
|
||||
}
|
||||
|
||||
void Community::set_energy_tariff(const Energy_Tariff& energy_tariff) {
|
||||
void Community::set_energy_tariff(const Energy_Tariff& energy_tariff)
|
||||
{
|
||||
energy_Tariff = energy_tariff;
|
||||
}
|
||||
|
||||
auto Community::iterateBuildings(std::vector<std::unique_ptr<Community>>& Communities) -> std::function<std::function<void(const std::function<void(Building::Base&)>&)>(const std::function<void(Community&)>&)>
|
||||
auto Community::iterateBuildings(
|
||||
std::vector<std::unique_ptr<Community>>& Communities) -> std::function<std::function<void(
|
||||
const std::function<void(Building::Base&)>&)>(const std::function<void(Community&)>&)>
|
||||
{
|
||||
return [&](const std::function<void(Community&)>& func1) {
|
||||
return [&, func1](const std::function<void(Building::Base&)>& func2) {
|
||||
// First apply func1 to each Community
|
||||
return [&](const std::function<void(Community&)>& func1)
|
||||
{
|
||||
return [&, func1](const std::function<void(Building::Base&)>& func2)
|
||||
{
|
||||
iterateVector(Communities, func1);
|
||||
|
||||
// Second apply func2 to each building inside each Community
|
||||
iterateVector(Communities, [&](Community& community) {
|
||||
for (auto& building : community.buildings()) {
|
||||
func2(*building); // Apply func2 to each Building::Base
|
||||
iterateVector(Communities, [&](Community& community)
|
||||
{
|
||||
for (auto& building : community.buildings())
|
||||
{
|
||||
func2(*building);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -6,11 +6,9 @@
|
||||
#define ENERGY_TARIFF_H
|
||||
|
||||
|
||||
|
||||
class Energy_Tariff {
|
||||
|
||||
class Energy_Tariff
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //ENERGY_TARIFF_H
|
||||
|
||||
@ -6,12 +6,14 @@
|
||||
#include <vector>
|
||||
|
||||
template <class T>
|
||||
class Model {
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
static void iterateVector(std::vector<std::unique_ptr<T>>& vector,
|
||||
const std::function<void(T&)>& function)
|
||||
{
|
||||
for (auto& item : vector) {
|
||||
for (auto& item : vector)
|
||||
{
|
||||
function(*item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent>& compo
|
||||
|
||||
void CostPipeline::calculateFinalCost()
|
||||
{
|
||||
for (auto& component: this->components)
|
||||
for (auto& component : this->components)
|
||||
{
|
||||
component->apply(this->communities);
|
||||
}
|
||||
|
||||
@ -9,15 +9,19 @@
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
#include "../../model/Community.h"
|
||||
|
||||
class CostPipeline {
|
||||
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){}
|
||||
|
||||
public:
|
||||
CostPipeline(std::vector<std::unique_ptr<Community>>& communities) : communities(communities)
|
||||
{
|
||||
}
|
||||
|
||||
void addCostComponent(const std::shared_ptr<ICostComponent>& components);
|
||||
void calculateFinalCost();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //COSTPIPELINE_H
|
||||
|
||||
@ -10,7 +10,6 @@ void TaxComponent::applyCost(std::vector<std::unique_ptr<Community>>& communitie
|
||||
{
|
||||
Building::Base::iterateVector(community.buildings(), [&](Building::Base& building)
|
||||
{
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,17 @@
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class TaxComponent : public ICostComponent{
|
||||
class TaxComponent : public ICostComponent
|
||||
{
|
||||
double taxRate;
|
||||
public:
|
||||
TaxComponent(double rate) : taxRate(rate){}
|
||||
|
||||
public:
|
||||
TaxComponent(double rate) : taxRate(rate)
|
||||
{
|
||||
}
|
||||
|
||||
void applyCost(std::vector<std::unique_ptr<Community>>& communities);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //TAXCOMPONENT_H
|
||||
|
||||
@ -11,22 +11,25 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
void Surplus::CalculateSurplus(std::vector<std::unique_ptr<Community>>& communities) {
|
||||
void Surplus::CalculateSurplus(std::vector<std::unique_ptr<Community>>& communities)
|
||||
{
|
||||
std::vector<float> consumptionAvailable(VALUE_COUNT, 0.0);
|
||||
std::vector<float> generationAvailable(VALUE_COUNT, 0.0);
|
||||
auto iterateFunc = Community::iterateBuildings(communities);
|
||||
auto modifyCommunity = [](Community& c) {
|
||||
auto modifyCommunity = [](Community& c)
|
||||
{
|
||||
std::cout << "Processing Community\n";
|
||||
};
|
||||
auto modifyBuilding = [](Building::Base& building) {
|
||||
auto modifyBuilding = [](Building::Base& building)
|
||||
{
|
||||
std::cout << "Processing Building\n";
|
||||
CalculateBuildingSurplus(building);
|
||||
};
|
||||
auto nestedFunc = iterateFunc(modifyCommunity);
|
||||
nestedFunc(modifyBuilding);
|
||||
iterateFunc(modifyCommunity)(modifyBuilding);
|
||||
}
|
||||
|
||||
void Surplus::CalculateBuildingSurplus(Building::Base& building) {
|
||||
void Surplus::CalculateBuildingSurplus(Building::Base& building)
|
||||
{
|
||||
std::vector ownCoverage(VALUE_COUNT, 0.0f);
|
||||
std::vector neededConsumption(VALUE_COUNT, 0.0f);
|
||||
std::vector neededGeneration(VALUE_COUNT, 0.0f);
|
||||
@ -37,10 +40,11 @@ void Surplus::CalculateBuildingSurplus(Building::Base& building) {
|
||||
|
||||
std::transform(consumption.begin(), consumption.end(),
|
||||
generation.begin(), ownCoverage.begin(),
|
||||
[&](const std::unique_ptr<float>& c, const std::unique_ptr<float>& g) {
|
||||
[&](const std::unique_ptr<float>& c, const std::unique_ptr<float>& g)
|
||||
{
|
||||
ownCoverage.push_back((c ? *c : 0.0f) - (g ? *g : 0.0f));
|
||||
neededConsumption.push_back((c && *c> 0.0f?*c:0.0f));
|
||||
neededGeneration.push_back((g && *g<0.0f?-*g:0.0f));
|
||||
neededConsumption.push_back((c && *c > 0.0f ? *c : 0.0f));
|
||||
neededGeneration.push_back((g && *g < 0.0f ? -*g : 0.0f));
|
||||
ownUsage.push_back((c ? *c : 0.0f) - (neededConsumption.back()));
|
||||
return 0.0f;
|
||||
});
|
||||
|
||||
@ -12,11 +12,15 @@
|
||||
|
||||
class Community;
|
||||
|
||||
class Surplus {
|
||||
class Surplus
|
||||
{
|
||||
private:
|
||||
std::vector<std::unique_ptr<Community>>& communities;
|
||||
|
||||
public:
|
||||
Surplus(std::vector<std::unique_ptr<Community>>& communities) : communities(communities) {}
|
||||
Surplus(std::vector<std::unique_ptr<Community>>& communities) : communities(communities)
|
||||
{
|
||||
}
|
||||
|
||||
void static CalculateSurplus(std::vector<std::unique_ptr<Community>>& communities);
|
||||
|
||||
@ -24,5 +28,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //SURPLUS_H
|
||||
|
||||
@ -14,16 +14,19 @@ namespace Building
|
||||
class Cost;
|
||||
}
|
||||
|
||||
class Factory {
|
||||
public:
|
||||
std::unique_ptr<Building::Cost> static create_test_cost() {
|
||||
class Factory
|
||||
{
|
||||
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 communityCoverage = std::vector<std::unique_ptr<float>>();
|
||||
@ -31,7 +34,9 @@ class Factory {
|
||||
auto neededCon = std::vector<std::unique_ptr<float>>();
|
||||
auto neededGen = std::vector<std::unique_ptr<float>>();
|
||||
|
||||
for (int i = 0; i < 5; i++) { // Populate with test values
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// Populate with test values
|
||||
communityCoverage.push_back(std::make_unique<float>(i * 10.0f));
|
||||
ownUsage.push_back(std::make_unique<float>(i * 5.0f));
|
||||
neededCon.push_back(std::make_unique<float>(i * 3.0f));
|
||||
@ -46,7 +51,8 @@ class Factory {
|
||||
return values;
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Metadata> static create_test_metadata() {
|
||||
std::unique_ptr<Building::Metadata> static create_test_metadata()
|
||||
{
|
||||
auto metadata = std::make_unique<Building::Metadata>();
|
||||
metadata->set_name("Test Building");
|
||||
metadata->set_annual_consumption(12000.0f);
|
||||
@ -59,7 +65,9 @@ class Factory {
|
||||
auto consumptionProfile = std::vector<std::unique_ptr<float>>();
|
||||
auto generationProfile = std::vector<std::unique_ptr<float>>();
|
||||
|
||||
for (int i = 0; i < 5; i++) { // Populate with test values
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// Populate with test values
|
||||
consumptionProfile.push_back(std::make_unique<float>(i * 100.0f));
|
||||
generationProfile.push_back(std::make_unique<float>(i * 50.0f));
|
||||
}
|
||||
@ -70,24 +78,30 @@ class Factory {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
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>();
|
||||
|
||||
building->set_cost( create_test_cost());
|
||||
building->set_cost(create_test_cost());
|
||||
building->set_values(create_test_simulation_values());
|
||||
building->set_metadata(create_test_metadata());
|
||||
|
||||
return building;
|
||||
}
|
||||
Energy_Tariff static create_test_energy_tariff() {
|
||||
|
||||
Energy_Tariff static create_test_energy_tariff()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
std::unique_ptr<Community> static create_test_community() {
|
||||
|
||||
std::unique_ptr<Community> static create_test_community()
|
||||
{
|
||||
auto community = std::make_unique<Community>();
|
||||
community->set_name("Test Community");
|
||||
|
||||
std::vector<std::unique_ptr<Building::Base>> buildings;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
buildings.push_back(create_test_building());
|
||||
}
|
||||
|
||||
@ -96,9 +110,7 @@ class Factory {
|
||||
|
||||
return community;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //FACTORY_H
|
||||
|
||||
@ -6,9 +6,10 @@
|
||||
#include "doctest/doctest.h"
|
||||
#include "../model/Factory.h"
|
||||
|
||||
TEST_CASE("Testing add function") {
|
||||
TEST_CASE("Testing add function")
|
||||
{
|
||||
std::vector<std::unique_ptr<Community>> communities;
|
||||
communities.push_back(Factory::create_test_community());
|
||||
Surplus::CalculateSurplus(communities);
|
||||
CHECK(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user