Last change
on this file since 15304 was
5207,
checked in by cneumuel, 14 years ago
|
#1215
- lots of memory-consumption improvements
- validValues -> validTypes (this saves memory!)
- changed manipulators; modifications are less significant, out-of-bound-values are resampled instead of set to lower or upper bound
- changed the way a base-level algorithm gets executed -> introduced AlgorithmExecutor
|
File size:
1.5 KB
|
Rev | Line | |
---|
[5207] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 |
|
---|
| 6 | namespace HeuristicLab.MetaOptimization.Test {
|
---|
| 7 | public class TableBuilder {
|
---|
| 8 | private List<string> columnNames;
|
---|
| 9 | private List<string[]> rows = new List<string[]>();
|
---|
| 10 |
|
---|
| 11 | public TableBuilder(params string[] columnNames) {
|
---|
| 12 | this.columnNames = new List<string>(columnNames);
|
---|
| 13 | AppendRow(columnNames);
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public void AppendRow(params string[] values) {
|
---|
| 17 | if (values.Length != columnNames.Count)
|
---|
| 18 | throw new ArgumentException("Value count does not match column name count");
|
---|
| 19 | this.rows.Add(values);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | public override string ToString() {
|
---|
| 23 | StringBuilder sb = new StringBuilder();
|
---|
| 24 | int[] columnSizes = GetColumnSizes();
|
---|
| 25 |
|
---|
| 26 | for (int rowIdx = 0; rowIdx < rows.Count; rowIdx++) {
|
---|
| 27 | if (rowIdx == 1) {
|
---|
| 28 | sb.AppendLine(string.Join("", Enumerable.Repeat("-", columnSizes.Sum() + columnSizes.Count())));
|
---|
| 29 | }
|
---|
| 30 | for (int colIdx = 0; colIdx < rows[rowIdx].Length; colIdx++) {
|
---|
| 31 | sb.AppendFormat("{0} ", rows[rowIdx][colIdx].PadLeft(columnSizes[colIdx]));
|
---|
| 32 | }
|
---|
| 33 | sb.AppendLine();
|
---|
| 34 | }
|
---|
| 35 | return sb.ToString();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | private int[] GetColumnSizes() {
|
---|
| 39 | int[] sizes = new int[columnNames.Count];
|
---|
| 40 | for (int i = 0; i < columnNames.Count; i++) {
|
---|
| 41 | foreach (var row in rows) {
|
---|
| 42 | if (row[i].Length > sizes[i])
|
---|
| 43 | sizes[i] = row[i].Length;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | return sizes;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.