-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearOptimizationResult.cpp
More file actions
44 lines (36 loc) · 1.45 KB
/
LinearOptimizationResult.cpp
File metadata and controls
44 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by а on 13.03.2020.
//
#include <fstream>
#include "LinearOptimizationResult.hpp"
using namespace std;
/// Wrapper over result of LinearOptimizationProblem
///
/// \param result - resulting point x
/// \param intermediates - intermediate points x_k
/// \param x_0 - initial point
/// \param gamma - step size coefficient. Must be 0 < gamma < 1.
/// \param steps_num - steps number of algorithm
LinearOptimizationResult::LinearOptimizationResult(const vec result,
const std::vector<vec> intermediates,
const vec x_0,
const double_t gamma,
const size_t steps_num)
: result(result), intermediates(intermediates), x_0(x_0), gamma(gamma), steps_num(steps_num) {
}
/// Writes intermediate points to csv file. Intended for algorithm visualization.
void LinearOptimizationResult::intermediates_to_csv(string filename) {
ofstream file;
file.open(filename, ios::trunc);
for (size_t i = 0; i != intermediates[0].size() - 1; ++i) {
file << "x" << i << ",";
}
file << "x" << intermediates[0].size() - 1 << "\n";
for (auto& inter: intermediates) {
for (size_t i = 0; i != inter.size() - 1; ++i) {
file << inter[i] << ",";
}
file << inter[inter.size() - 1] << "\n";
}
file.close();
}