-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.cs
180 lines (174 loc) · 5.49 KB
/
Tests.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.VisualBasic.FileIO;
namespace CopasiApi
{
public class Tests
{
private string SOURCE_FOLDER = "tests";
private string SOURCE_EXPERIMENTS = "Experiments.csv";
private string SOURCE_FIT = "fit.csv";
private string SOURCE_OBJ_FUNC_VALS = "obj-func-vals.csv";
private string TARGET_OBJ_FUNC_VALS_LOWS = "obj-func-vals-lows.csv";
private string TARGET_OBJ_FUNC_VALS_HIGHS = "obj-func-vals-highs.csv";
private string TARGET_EXPERIMENTS_LOWS = "Experiments-lows.csv";
private string TARGET_EXPERIMENTS_HIGHS = "Experiments-highs.csv";
private string TARGET_FIT_LOWS = "fit-lows.csv";
private string TARGET_FIT_HIGHS = "fit-highs.csv";
private List<string> linesLowers;
private List<double> valuesLowers;
private List<string> linesHighers;
private List<double> valuesHighers;
private double PIVOT = 0.1;
public Tests()
{
processObjFuncVals();
processExperiments();
processFit();
}
private void processObjFuncVals()
{
var path = SOURCE_FOLDER + "/" + SOURCE_OBJ_FUNC_VALS;
try
{
using (var parser = new TextFieldParser(path))
{
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
var row = parser.ReadFields();
if (row[0] == "Line")
{
linesLowers = new List<string>();
valuesLowers = new List<double>();
linesHighers = new List<string>();
valuesHighers = new List<double>();
}
else
{
var line = row[0];
var value = Double.Parse(row[1]);
if (value < PIVOT)
{
linesLowers.Add(line);
valuesLowers.Add(value);
}
else
{
linesHighers.Add(line);
valuesHighers.Add(value);
}
}
}
}
var csv = new StringBuilder();
csv.AppendLine("Line,Value");
var index = 0;
linesLowers.ForEach((line) =>
{
csv.AppendLine(line + "," + valuesLowers[index]);
++index;
});
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_OBJ_FUNC_VALS_LOWS, csv.ToString());
csv = new StringBuilder();
csv.AppendLine("Line,Value");
index = 0;
linesHighers.ForEach((line) =>
{
csv.AppendLine(line + "," + valuesHighers[index]);
++index;
});
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_OBJ_FUNC_VALS_HIGHS, csv.ToString());
}
catch (Exception exception)
{
printError(exception, "processObjFuncVals");
}
}
private void processExperiments()
{
var path = SOURCE_FOLDER + "/" + SOURCE_EXPERIMENTS;
try
{
var csvLows = new StringBuilder();
var csvHighs = new StringBuilder();
using (var parser = new TextFieldParser(path))
{
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
var row = parser.ReadFields();
if (row[0] == "Line") {
var headers = String.Join(",", row);
csvLows.AppendLine(headers);
csvHighs.AppendLine(headers);
}
else
{
var line = row[0];
if (linesLowers.Contains(line)) {
csvLows.AppendLine(String.Join(",", row));
} else if (linesHighers.Contains(line)) {
csvHighs.AppendLine(String.Join(",", row));
} else {
Console.WriteLine("Warning -> " + line);
}
}
}
}
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_EXPERIMENTS_LOWS, csvLows.ToString());
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_EXPERIMENTS_HIGHS, csvHighs.ToString());
}
catch (Exception exception)
{
printError(exception, "processExperiments");
}
}
private void processFit()
{
var path = SOURCE_FOLDER + "/" + SOURCE_FIT;
try
{
var csvLows = new StringBuilder();
var csvHighs = new StringBuilder();
using (var parser = new TextFieldParser(path))
{
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
var row = parser.ReadFields();
if (row[0] == "LINE") {
var headers = String.Join(",", row);
csvLows.AppendLine(headers);
csvHighs.AppendLine(headers);
}
else
{
var line = row[0];
if (linesLowers.Contains(line)) {
csvLows.AppendLine(String.Join(",", row));
} else if (linesHighers.Contains(line)) {
csvHighs.AppendLine(String.Join(",", row));
} else {
Console.WriteLine("Warning -> " + line);
}
}
}
}
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_FIT_LOWS, csvLows.ToString());
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_FIT_HIGHS, csvHighs.ToString());
}
catch (Exception exception)
{
printError(exception, "processFit");
}
}
private void printError(Exception exception, string source)
{
Console.Error.WriteLine("ERROR (" + source + "): " + exception);
Environment.Exit(1);
}
}
}