Antares Simulator
Power System Simulator
variable-print-info.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 
22 #ifndef __SOLVER_VARIABLE_PRINT_POLICY_H__
23 #define __SOLVER_VARIABLE_PRINT_POLICY_H__
24 
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 #include <yuni/yuni.h>
30 #include <yuni/core/fwd.h>
31 #include <yuni/core/string.h>
32 
33 namespace Antares::Data
34 {
35 // Represents an output variable (wears the same name) and mainly answers the question :
36 // Is the real variable printed in all output reports ? Or is it not printed in any report ?
37 class VariablePrintInfo final
38 {
39 public:
40  VariablePrintInfo(uint dataLvl, uint fileLvl);
41  ~VariablePrintInfo() = default;
42 
43  // Do we enable or disable variable's print in output reports ?
44  void enablePrint(bool b);
45  bool isPrinted() const;
46  void reverse();
47 
48  uint getMaxColumnsCount();
49  void setMaxColumns(uint maxColumnsNumber);
50 
51  bool isPrintedOnDataLevel(uint dataLevel) const
52  {
53  return dataLevel_ & dataLevel;
54  }
55 
56  bool isPrintedOnFileLevel(uint fileLevel) const
57  {
58  return fileLevel_ & fileLevel;
59  }
60 
61 private:
62  // Is the variable printed ?
63  bool to_be_printed_ = true;
64 
65  // The number of columns the output variable takes in a SYNTHESIS report.
66  // Recall that synthesis reports always contain more columns than
67  // any other reports (for instance year-by-year reports)
68  uint maxNumberColumns_ = 0;
69 
70  // Which reports the output variable has columns in ?
71  // Example : areas/values-<time-interval>.txt
72  // dataLevel can be : areas, links, bindingConstraint
73  // fileLevel can be : values-<time-interval>.txt, details-<time-interval>.txt,
74  // id-<time-interval>.txt, ...
75  uint dataLevel_ = 0;
76  uint fileLevel_ = 0;
77 };
78 
80 
82 {
83 public:
85  void add(const AnyString& name, uint dataLevel, uint fileLevel);
86 
87 private:
88  AllVariablesPrintInfo* allvarsinfo;
89 };
90 
91 // Variables print info collection. Mainly a vector of pointers to print info.
92 // This collection is filled with as many print info as we can find output variables in the output
93 // variables Antares's static list.
95 {
96 public:
97  // Public methods
98  AllVariablesPrintInfo() = default;
99  ~AllVariablesPrintInfo() = default;
100 
101  void add(std::string name, VariablePrintInfo v);
102  void clear();
103  VariablePrintInfo& operator[](uint i);
104  size_t size() const;
105  bool exists(std::string name);
106 
107  void setPrintStatus(std::string varname, bool printStatus);
108  void setPrintStatus(unsigned int index, bool printStatus);
109 
110  void setMaxColumns(std::string varname, uint maxColumnsNumber);
111  std::string name_of(unsigned int index) const;
112 
113  void prepareForSimulation(bool isThematicTrimmingEnabled,
114  const std::vector<std::string>& excluded_vars = {});
115 
116  // Classic search, then get the print status
117  bool isPrinted(std::string var_name) const;
118 
119  uint getTotalMaxColumnsCount() const
120  {
121  return totalMaxColumnsCount_;
122  }
123 
124  uint getNbSelectedZonalVars() const
125  {
126  return numberSelectedAreaVariables;
127  }
128 
129  uint getNbSelectedLinkVars() const
130  {
131  return numberSelectedLinkVariables;
132  }
133 
134  void computeMaxColumnsCountInReports();
135  void setAllPrintStatusesTo(bool b);
136  void reverseAll();
137 
138  unsigned int numberOfEnabledVariables();
139  std::vector<std::string> namesOfEnabledVariables();
140  std::vector<std::string> namesOfDisabledVariables();
141 
142 private:
143  std::vector<std::string> namesOfVariablesWithPrintStatus(bool printStatus);
144  void countSelectedAreaVars();
145  void countSelectedLinkVars();
146 
147 private:
148  // Contains print info for all variables
149  std::map<std::string, VariablePrintInfo> allVarsPrintInfo;
150  std::map<unsigned int, std::string> index_to_name;
151 
152  // Max columns count a report of any kind can contain, depending on the number of selected
153  // variables. The less variables are selected, the smallest this count is.
154  uint totalMaxColumnsCount_ = 0;
155 
156  // Number of selected zonal variables
157  uint numberSelectedAreaVariables = 0;
158  // Number of selected link variables
159  uint numberSelectedLinkVariables = 0;
160 };
161 
162 } // namespace Antares::Data
163 
164 #endif // __SOLVER_VARIABLE_PRINT_POLICY_H__
Definition: variable-print-info.h:95
Definition: variable-print-info.h:38
Definition: variable-print-info.h:82