Skip to content

Commit

Permalink
3)LineFlowRounding
Browse files Browse the repository at this point in the history
Signed-off-by: arnaud <[email protected]>
  • Loading branch information
ARnDOSrte committed Dec 11, 2023
1 parent c535a6b commit fb1c01b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions metrix-simulator/src/calcul.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Calculer
int metrix2Assess(const std::shared_ptr<Variante>& var, const vector<double>& theta, int status);
void printCutDetailed(FILE* fr);
void printCut(FILE* fr);
static double cutDecimals(double x); //utilisé quand le round ne suffit pas, pour R3 et R3B
int getClosestTapPosition(TransformateurDephaseur* td, double angleFinal);
bool calculVariationsMarginales(FILE* fr, const std::map<std::shared_ptr<Incident>, int>& incidentsContraignants);
static double round(double x, double prec); // utiliser pour arrondir les calculs
Expand Down
34 changes: 31 additions & 3 deletions metrix-simulator/src/metrix2assess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <iostream>
#include <numeric>
#include <string>
#include <iomanip>

using cte::c_fmt;

Expand All @@ -40,6 +41,33 @@ static const string EMPTY_STRING;
static const string PREC_FLOAT_BIS = "%.4f";
static constexpr double EPSILON_SORTIES_BIS = 0.0001;

double Calculer::cutDecimals(double x)
{
std::stringstream stream;
stream << std::fixed << std::setprecision(15)<<x;
std::string x_string = stream.str();
if (x_string.find("9999") != std::string::npos and x_string.find(".") != std::string::npos){

int dot_position = x_string.find(".");
int substr_position = x_string.find("9999");
if (dot_position < substr_position){
if (dot_position + 1 == substr_position){
return x;
}else{
int precision = dot_position - substr_position;
if (x>=0){
return x + 2*pow(10,precision);
}else{
return x - 2*pow(10,precision);
}
}
}else{
return x;
}
}
return x;
}

static void print_threats(FILE* file,
const Menace& threat_before,
const std::map<std::shared_ptr<Incident>, int>& constraints_incidents,
Expand All @@ -52,14 +80,14 @@ static void print_threats(FILE* file,
if (threat_before.defaut_ != nullptr) {
double value_transit = (fabs(threat_before.transit_) < EPSILON_SORTIES) ? 0.0 : threat_before.transit_;
const auto& inc = threat_before.defaut_->parade_ ? threat_before.defaut_->incTraiteCur_ : threat_before.defaut_;
fprintf(file, "%d;%.1f;", constraints_incidents.find(inc)->second, value_transit);
fprintf(file, "%d;%.1f;", constraints_incidents.find(inc)->second, Calculer::cutDecimals(value_transit));
} else {
fprintf(file, ";;");
}
for (auto rit = threats.crbegin(); rit != threats.crend(); ++rit) {
const auto& inc = rit->defaut_->parade_ ? rit->defaut_->incTraiteCur_ : rit->defaut_;
double value_transit = (fabs(rit->transit_) < EPSILON_SORTIES) ? 0.0 : rit->transit_;
fprintf(file, "%d;%.1f;", constraints_incidents.find(inc)->second, value_transit);
fprintf(file, "%d;%.1f;", constraints_incidents.find(inc)->second, Calculer::cutDecimals(value_transit));
}

for (unsigned int j = 0; j < config::configuration().nbThreats() - threats.size(); ++j) {
Expand Down Expand Up @@ -836,7 +864,7 @@ int Calculer::metrix2Assess(const std::shared_ptr<Variante>& var, const vector<d
transitN = 0.0;
}

fprintf(fr, ("R3 ;;%s;" + PREC_FLOAT + ";\n").c_str(), quad->nom_.c_str(), transitN);
fprintf(fr, ("R3 ;;%s;" + PREC_FLOAT + ";\n").c_str(), quad->nom_.c_str(), Calculer::cutDecimals(transitN));
} else {
fprintf(fr,
"R3 ;;%s;%.1f;%.1f;%.1f;%.1f;\n",
Expand Down

0 comments on commit fb1c01b

Please sign in to comment.