Skip to content

Commit

Permalink
BC marginal cost : remove "return"s that break the static chain (#2121)
Browse files Browse the repository at this point in the history
Everything is in the title
  • Loading branch information
guilpier-code authored May 28, 2024
1 parent 5aedce3 commit 85a86f7
Showing 1 changed file with 83 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,26 @@ class BindingConstMarginCost

void yearEnd(unsigned int year, unsigned int numSpace)
{
if (!isInitialized())
if (isInitialized())
{
return;
}

// Compute statistics for the current year depending on
// the BC type (hourly, daily, weekly)
using namespace Data;
switch (associatedBC_->type())
{
case BindingConstraint::typeHourly:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromHourlyResults();
break;
case BindingConstraint::typeDaily:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromDailyResults();
break;
case BindingConstraint::typeWeekly:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromWeeklyResults();
break;
case BindingConstraint::typeUnknown:
case BindingConstraint::typeMax:
break;
// Compute statistics for the current year depending on
// the BC type (hourly, daily, weekly)
using namespace Data;
switch (associatedBC_->type())
{
case BindingConstraint::typeHourly:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromHourlyResults();
break;
case BindingConstraint::typeDaily:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromDailyResults();
break;
case BindingConstraint::typeWeekly:
pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromWeeklyResults();
break;
case BindingConstraint::typeUnknown:
case BindingConstraint::typeMax:
break;
}
}

// Next variable
Expand All @@ -232,53 +230,52 @@ class BindingConstMarginCost

void weekBegin(State& state)
{
if (!isInitialized())
if (isInitialized())
{
return;
}

auto numSpace = state.numSpace;
// For daily binding constraints, getting daily marginal price
using namespace Data;
switch (associatedBC_->type())
{
case BindingConstraint::typeHourly:
case BindingConstraint::typeUnknown:
case BindingConstraint::typeMax:
return;

case BindingConstraint::typeDaily:
{
int dayInTheYear = state.weekInTheYear * 7;
for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++)
auto numSpace = state.numSpace;
// For daily binding constraints, getting daily marginal price
using namespace Data;
switch (associatedBC_->type())
{
pValuesForTheCurrentYear[numSpace].day[dayInTheYear]
-= state.problemeHebdo
->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek];
case BindingConstraint::typeHourly:
case BindingConstraint::typeUnknown:
case BindingConstraint::typeMax:
break;

dayInTheYear++;
case BindingConstraint::typeDaily:
{
int dayInTheYear = state.weekInTheYear * 7;
for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++)
{
pValuesForTheCurrentYear[numSpace].day[dayInTheYear]
-= state.problemeHebdo
->ResultatsContraintesCouplantes[associatedBC_][dayInTheWeek];

dayInTheYear++;
}
break;
}
break;
}

// For weekly binding constraints, getting weekly marginal price
case BindingConstraint::typeWeekly:
{
uint weekInTheYear = state.weekInTheYear;
double weeklyValue = -state.problemeHebdo
->ResultatsContraintesCouplantes[associatedBC_][0];

pValuesForTheCurrentYear[numSpace].week[weekInTheYear] = weeklyValue;

int dayInTheYear = state.weekInTheYear * 7;
for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++)
// For weekly binding constraints, getting weekly marginal price
case BindingConstraint::typeWeekly:
{
pValuesForTheCurrentYear[numSpace].day[dayInTheYear] = weeklyValue;
dayInTheYear++;
uint weekInTheYear = state.weekInTheYear;
double weeklyValue = -state.problemeHebdo
->ResultatsContraintesCouplantes[associatedBC_][0];

pValuesForTheCurrentYear[numSpace].week[weekInTheYear] = weeklyValue;

int dayInTheYear = state.weekInTheYear * 7;
for (int dayInTheWeek = 0; dayInTheWeek < 7; dayInTheWeek++)
{
pValuesForTheCurrentYear[numSpace].day[dayInTheYear] = weeklyValue;
dayInTheYear++;
}
break;
}
}
break;
}
}
NextType::weekBegin(state);
}

void hourBegin(unsigned int hourInTheYear)
Expand All @@ -289,18 +286,16 @@ class BindingConstMarginCost

void hourEnd(State& state, unsigned int hourInTheYear)
{
if (!isInitialized())
if (isInitialized())
{
return;
}

auto numSpace = state.numSpace;
if (associatedBC_->type() == Data::BindingConstraint::typeHourly)
{
pValuesForTheCurrentYear[numSpace][hourInTheYear] -= state.problemeHebdo
->ResultatsContraintesCouplantes
[associatedBC_]
[state.hourInTheWeek];
auto numSpace = state.numSpace;
if (associatedBC_->type() == Data::BindingConstraint::typeHourly)
{
pValuesForTheCurrentYear[numSpace][hourInTheYear] -= state.problemeHebdo
->ResultatsContraintesCouplantes
[associatedBC_]
[state.hourInTheWeek];
}
}

NextType::hourEnd(state, hourInTheYear);
Expand Down Expand Up @@ -344,26 +339,25 @@ class BindingConstMarginCost
{
// Building syntheses results
// ------------------------------
if (!(precision & associatedBC_->yearByYearFilter()))
{
return;
}

// And only if we match the current data level _and_ precision level
if ((dataLevel & VCardType::categoryDataLevel) && (fileLevel & VCardType::categoryFileLevel)
&& (precision & VCardType::precision))
if (precision & associatedBC_->yearByYearFilter())
{
results.isPrinted = AncestorType::isPrinted;
results.isCurrentVarNA[0] = isCurrentOutputNonApplicable(precision);
results.variableCaption = getBindConstraintCaption();

VariableAccessorType::template BuildSurveyReport<VCardType>(results,
AncestorType::pResults,
dataLevel,
fileLevel,
precision,
false);
// And only if we match the current data level _and_ precision level
if ((dataLevel & VCardType::categoryDataLevel) && (fileLevel & VCardType::categoryFileLevel)
&& (precision & VCardType::precision))
{
results.isPrinted = AncestorType::isPrinted;
results.isCurrentVarNA[0] = isCurrentOutputNonApplicable(precision);
results.variableCaption = getBindConstraintCaption();

VariableAccessorType::template BuildSurveyReport<VCardType>(results,
AncestorType::pResults,
dataLevel,
fileLevel,
precision,
false);
}
}
NextType::buildSurveyReport(results, dataLevel, fileLevel, precision);
}

private:
Expand Down

0 comments on commit 85a86f7

Please sign in to comment.