54 std::vector<std::pair<VariablePtr, Value>> fixed = {},
60 std::vector<std::pair<VariablePtr, Value>> fixed = {})
61 :
LineEvaluator(
Model(std::move(model)), std::move(variables), std::move(fixed), {}) {}
64 std::vector<std::pair<VariablePtr, Value>> fixed = {},
66 : base_(std::move(model)), variables_(std::move(variables)),
67 fixed_(std::move(fixed)), solve_(std::move(
solve)) {
72 std::size_t dimension = 0;
74 offsets_.push_back(dimension);
75 dimension += variable->dimension();
77 dimension_ = dimension;
81 return std::holds_alternative<lqn::LqnModel<double>>(base_);
84 std::vector<std::pair<double, double>>
bounds()
const {
85 return std::vector<std::pair<double, double>>(dimension_, {0.0, 1.0});
89 for (std::size_t i = 0; i < variables_.size(); ++i) {
90 const auto begin = x.begin() + offsets_[i];
91 out[variables_[i]->name()] = variables_[i]->decode(
92 std::vector<double>(begin, begin + variables_[i]->dimension()));
99 const auto start = std::chrono::steady_clock::now();
103 evaluate_layered(values, out);
105 evaluate_flat(values, out);
107 }
catch (
const std::exception&) {
110 out.
solve_time = std::chrono::duration<double>(
111 std::chrono::steady_clock::now() - start).count();
120 apply_layered(model, values);
126 for (
const auto& row : table.rows)
127 out[
metric_key(layered_name(row.station), layered_name(row.jobclass))] = {
128 row.dTput, row.dRespT, row.dQLen, row.dUtil};
130 }
catch (
const std::exception&) {
143 static std::string layered_name(
const std::string& value) {
144 if (value.size() > 2 && value[1] ==
':' &&
145 std::string(
"PTERA").find(value[0]) != std::string::npos)
146 return value.substr(2);
150 void evaluate_flat(
const VariableValues& values, EvaluationResult& out)
const {
152 for (
const auto& fixed : fixed_) fixed.first->apply(model, fixed.second);
154 const auto found = values.find(variable->name());
155 if (found != values.end()) variable->apply(model, found->second);
157 const qn::NetworkStruct<double>& structure = model.
get_struct();
158 const mva::AvgResult<double> average = solve_(structure);
159 out.solver_used = average.actualmethod;
160 for (std::size_t i = 0; i < structure.nstations; ++i) {
161 double utilization = 0.0;
162 for (std::size_t r = 0; r < structure.nclasses; ++r) {
163 const std::string& station = structure.stations[i].name;
164 const std::string& jobclass = structure.classes[r].name;
165 if (!average.RN.empty()) out.set_response_time(station, jobclass, average.RN(i, r));
166 if (!average.TN.empty()) out.set_throughput(station, jobclass, average.TN(i, r));
167 if (!average.QN.empty()) out.set_queue_length(station, jobclass, average.QN(i, r));
168 if (!average.UN.empty()) utilization += average.UN(i, r);
170 out.utilizations[structure.stations[i].name] = utilization;
173 for (std::size_t c = 0; c < structure.nchains; ++c) {
174 double response = c < system.CN.size()
176 : std::numeric_limits<double>::quiet_NaN();
177 const double throughput = c < system.XN.size() ? system.XN[c] : 0.0;
180 for (
const std::size_t member : structure.inchain[c]) {
181 open = open || std::isinf(structure.classes[member - 1].population);
182 for (std::size_t i = 0; i < structure.nstations; ++i)
183 jobs += out.queue_length(structure.stations[i].name,
184 structure.classes[member - 1].name);
186 if (open && throughput > 0.0)
response = jobs / throughput;
187 for (
const std::size_t member : structure.inchain[c]) {
188 out.system_response_times[structure.classes[member - 1].name] =
response;
189 out.system_throughputs[structure.classes[member - 1].name] = throughput;
192 const std::optional<SensitivityData> sensitivity =
195 out.sensitivities = std::make_shared<SensitivityData>(*sensitivity);
198 void apply_layered(lqn::LqnModel<double>& model,
const VariableValues& values)
const {
199 for (
const auto& fixed : fixed_) fixed.first->apply(model, fixed.second);
201 const auto found = values.find(variable->name());
202 if (found != values.end()) variable->apply(model, found->second);
206 void evaluate_layered(
const VariableValues& values, EvaluationResult& out)
const {
207 lqn::LqnModel<double> model = std::get<lqn::LqnModel<double>>(base_);
208 apply_layered(model, values);
210 ln::SolverLN<double> solver(structure, lqn_options_);
211 const ln::LnSolution<double> average = solver.get_ensemble_avg();
212 out.solver_used =
"SolverLN";
213 for (std::size_t i = 1; i <= structure.nidx; ++i) {
214 const std::string&
name = structure.names[i];
215 if (i < average.RN.size() && i < average.defined_R.size() &&
216 average.defined_R[i] && std::isfinite(average.RN[i]))
217 out.set_response_time(name, name, average.RN[i]);
218 if (i < average.TN.size() && i < average.defined_T.size() &&
219 average.defined_T[i] && std::isfinite(average.TN[i]))
220 out.set_throughput(name, name, average.TN[i]);
221 if (i < average.QN.size() && i < average.defined_Q.size() &&
222 average.defined_Q[i] && std::isfinite(average.QN[i]))
223 out.set_queue_length(name, name, average.QN[i]);
224 if (i < average.UN.size() && i < average.defined_U.size() &&
225 average.defined_U[i] && std::isfinite(average.UN[i]))
226 out.utilizations[
name] = average.UN[i];
228 for (std::size_t task = 1; task <= structure.ntasks; ++task) {
229 const std::size_t index = structure.tshift + task;
230 if (index >= structure.isref.size() || !structure.isref[index])
continue;
231 const std::string&
name = structure.names[index];
232 const double throughput = out.throughput(name, name);
233 if (throughput > 0.0) out.system_throughputs[
name] = throughput;
235 bool have_response =
false;
236 for (
const std::size_t entry : structure.entriesof[index]) {
237 const double value = out.response_time(structure.names[entry],
238 structure.names[entry]);
239 if (std::isfinite(value)) {
241 have_response =
true;
244 if (have_response) out.system_response_times[
name] =
response;
249 std::vector<VariablePtr> variables_;
250 std::vector<std::pair<VariablePtr, Value>> fixed_;
252 ln::LnOptions lqn_options_;
253 std::vector<std::size_t> offsets_;
254 std::size_t dimension_ = 0;
255 std::size_t count_ = 0;