Skip to content

Commit

Permalink
Bugfix: no solution at initial overvoltage (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-xmr committed Jul 24, 2022
1 parent 3d9a6b5 commit b4a07eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/opti-lib/src/OptiEnProfitSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct BatterySimulation
double num_undervolted = 0;
double num_undervolted_initial = 0;
double num_overvolted = 0;
double num_overvolted_initial = 0;
double num_overused = 0;
double m_mulPowerToCapacity = 0;
double m_dischargePerHour = 0;
Expand Down Expand Up @@ -98,22 +99,27 @@ double BatterySimulation::iter_get_load(double inp, double out, double hours)
if (load > m_maxCapacityAmph)
{
load = m_maxCapacityAmph;
++num_overvolted;
if (initial_load)
++num_overvolted_initial; /// TODO: Unit test this, as lack of this should cause a crash
else
++num_overvolted;
}
if (load < pars.MIN_LOAD_AMPH)
{
if (initial_load)
num_undervolted_initial += 1;
++num_undervolted_initial;
else
++num_undervolted;
++num_undervolted;

}
//if (load < 0)
// load = 0;

if (initial_load)
if (load > pars.MIN_LOAD_AMPH)
if (pars.MIN_LOAD_AMPH < load && load < m_maxCapacityAmph)
//if (load > pars.MIN_LOAD_AMPH)
{
/// TODO: Unit test this, as lack of this should cause a crash
//LOGL << "Initial load done.\n";
initial_load = false;
}
Expand Down Expand Up @@ -156,7 +162,7 @@ double OptiSubjectEnProfit::GetVerbose(const EnjoLib::Matrix & dataMat, bool ver
const double load = battery.iter_get_load(powerProd, resLocal.sumPowerUsage);
//const double pentalityUndervolted = load < 0 ? GMat().Fabs(load * load * load) : 0;
const double pentalityUndervolted = battery.num_undervolted;
const double pentalityOvervolted = battery.num_overvolted;
const double pentalityOvervolted = battery.num_overvolted;

if (not sys.buying)
{
Expand Down
7 changes: 7 additions & 0 deletions src/opti-lib/src/OptimizerEnProfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <Util/ToolsMixed.hpp>
#include <Util/Except.hpp>
#include <Util/CoutBuf.hpp>
#include <Util/StrColour.hpp>
#include <Statistical/Statistical.hpp>
#include <Statistical/Distrib.hpp>
#include <Template/CorradePointer.h>
Expand Down Expand Up @@ -193,6 +194,12 @@ void OptimizerEnProfit::RandomSearch()
break;
}
}
if (not foundFirstSolution)
{
// TODO: Unit test it.
//Assertions::Throw("Couldn't find a solution!", "OptimizerEnProfit::RandomSearch");
LOGL << StrColour::GenWarn("Couldn't find a solution!") << "\n... in OptimizerEnProfit::RandomSearch()";
}

PrintSolution(binarBest);
}
Expand Down
4 changes: 2 additions & 2 deletions src/system-cfg/arrays-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"arrays": [
{
"name" : "South",
"count" : 3,
"count" : 1,
"watt_peak" : 200,
"surface_tilt" : 87,
"surface_azimuth" : 193
},
{
"name" : "South-West",
"count" : 2,
"count" : 1,
"watt_peak" : 200,
"surface_tilt" : 87,
"surface_azimuth" : 200
Expand Down

0 comments on commit b4a07eb

Please sign in to comment.