line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
| Copyright (c) 2013-2017, Nucleic Development Team. |
3
|
|
|
|
|
|
|
| |
4
|
|
|
|
|
|
|
| Distributed under the terms of the Modified BSD License. |
5
|
|
|
|
|
|
|
| |
6
|
|
|
|
|
|
|
| The full license is in the file LICENSE, distributed with this software. |
7
|
|
|
|
|
|
|
|----------------------------------------------------------------------------*/ |
8
|
|
|
|
|
|
|
#pragma once |
9
|
|
|
|
|
|
|
#include <iostream> |
10
|
|
|
|
|
|
|
#include <sstream> |
11
|
|
|
|
|
|
|
#include <vector> |
12
|
|
|
|
|
|
|
#include "constraint.h" |
13
|
|
|
|
|
|
|
#include "solverimpl.h" |
14
|
|
|
|
|
|
|
#include "term.h" |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
namespace kiwi |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
namespace impl |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
class DebugHelper |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
public: |
26
|
0
|
|
|
|
|
|
static void dump(const SolverImpl &solver, std::ostream &out) |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
|
|
|
|
|
out << "Objective" << std::endl; |
29
|
0
|
|
|
|
|
|
out << "---------" << std::endl; |
30
|
0
|
|
|
|
|
|
dump(*solver.m_objective, out); |
31
|
0
|
|
|
|
|
|
out << std::endl; |
32
|
0
|
|
|
|
|
|
out << "Tableau" << std::endl; |
33
|
0
|
|
|
|
|
|
out << "-------" << std::endl; |
34
|
0
|
|
|
|
|
|
dump(solver.m_rows, out); |
35
|
0
|
|
|
|
|
|
out << std::endl; |
36
|
0
|
|
|
|
|
|
out << "Infeasible" << std::endl; |
37
|
0
|
|
|
|
|
|
out << "----------" << std::endl; |
38
|
0
|
|
|
|
|
|
dump(solver.m_infeasible_rows, out); |
39
|
0
|
|
|
|
|
|
out << std::endl; |
40
|
0
|
|
|
|
|
|
out << "Variables" << std::endl; |
41
|
0
|
|
|
|
|
|
out << "---------" << std::endl; |
42
|
0
|
|
|
|
|
|
dump(solver.m_vars, out); |
43
|
0
|
|
|
|
|
|
out << std::endl; |
44
|
0
|
|
|
|
|
|
out << "Edit Variables" << std::endl; |
45
|
0
|
|
|
|
|
|
out << "--------------" << std::endl; |
46
|
0
|
|
|
|
|
|
dump(solver.m_edits, out); |
47
|
0
|
|
|
|
|
|
out << std::endl; |
48
|
0
|
|
|
|
|
|
out << "Constraints" << std::endl; |
49
|
0
|
|
|
|
|
|
out << "-----------" << std::endl; |
50
|
0
|
|
|
|
|
|
dump(solver.m_cns, out); |
51
|
0
|
|
|
|
|
|
out << std::endl; |
52
|
0
|
|
|
|
|
|
out << std::endl; |
53
|
0
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
static void dump(const SolverImpl::RowMap &rows, std::ostream &out) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
0
|
|
|
|
|
for (const auto &rowPair : rows) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
0
|
|
|
|
|
dump(rowPair.first, out); |
60
|
0
|
0
|
|
|
|
|
out << " | "; |
61
|
0
|
0
|
|
|
|
|
dump(*rowPair.second, out); |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
static void dump(const std::vector<Symbol> &symbols, std::ostream &out) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
0
|
|
|
|
|
for (const auto &symbol : symbols) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
0
|
|
|
|
|
dump(symbol, out); |
70
|
0
|
0
|
|
|
|
|
out << std::endl; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
static void dump(const SolverImpl::VarMap &vars, std::ostream &out) |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
0
|
|
|
|
|
for (const auto &varPair : vars) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
0
|
|
|
|
|
out << varPair.first.name() << " = "; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
dump(varPair.second, out); |
80
|
0
|
0
|
|
|
|
|
out << std::endl; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
static void dump(const SolverImpl::CnMap &cns, std::ostream &out) |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
0
|
|
|
|
|
for (const auto &cnPair : cns) |
87
|
0
|
0
|
|
|
|
|
dump(cnPair.first, out); |
88
|
0
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
static void dump(const SolverImpl::EditMap &edits, std::ostream &out) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
0
|
|
|
|
|
for (const auto &editPair : edits) |
93
|
0
|
0
|
|
|
|
|
out << editPair.first.name() << std::endl; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
static void dump(const Row &row, std::ostream &out) |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
0
|
|
|
|
|
for (const auto &rowPair : row.cells()) |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
0
|
|
|
|
|
out << " + " << rowPair.second << " * "; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
dump(rowPair.first, out); |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
out << std::endl; |
104
|
0
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
static void dump(const Symbol &symbol, std::ostream &out) |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
|
|
|
switch (symbol.type()) |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
case Symbol::Invalid: |
111
|
0
|
|
|
|
|
|
out << "i"; |
112
|
0
|
|
|
|
|
|
break; |
113
|
|
|
|
|
|
|
case Symbol::External: |
114
|
0
|
|
|
|
|
|
out << "v"; |
115
|
0
|
|
|
|
|
|
break; |
116
|
|
|
|
|
|
|
case Symbol::Slack: |
117
|
0
|
|
|
|
|
|
out << "s"; |
118
|
0
|
|
|
|
|
|
break; |
119
|
|
|
|
|
|
|
case Symbol::Error: |
120
|
0
|
|
|
|
|
|
out << "e"; |
121
|
0
|
|
|
|
|
|
break; |
122
|
|
|
|
|
|
|
case Symbol::Dummy: |
123
|
0
|
|
|
|
|
|
out << "d"; |
124
|
0
|
|
|
|
|
|
break; |
125
|
|
|
|
|
|
|
default: |
126
|
0
|
|
|
|
|
|
break; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
out << symbol.id(); |
129
|
0
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
static void dump(const Constraint &cn, std::ostream &out) |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
0
|
|
|
|
|
for (const auto &term : cn.expression().terms()) |
|
|
0
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
135
|
0
|
0
|
|
|
|
|
out << term.coefficient() << " * "; |
|
|
0
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
out << term.variable().name() << " + "; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
out << cn.expression().constant(); |
139
|
0
|
|
|
|
|
|
switch (cn.op()) |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
case OP_LE: |
142
|
0
|
|
|
|
|
|
out << " <= 0 "; |
143
|
0
|
|
|
|
|
|
break; |
144
|
|
|
|
|
|
|
case OP_GE: |
145
|
0
|
|
|
|
|
|
out << " >= 0 "; |
146
|
0
|
|
|
|
|
|
break; |
147
|
|
|
|
|
|
|
case OP_EQ: |
148
|
0
|
|
|
|
|
|
out << " == 0 "; |
149
|
0
|
|
|
|
|
|
break; |
150
|
|
|
|
|
|
|
default: |
151
|
0
|
|
|
|
|
|
break; |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
out << " | strength = " << cn.strength() << std::endl; |
154
|
0
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} // namespace impl |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
namespace debug |
160
|
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
template <typename T> |
163
|
0
|
|
|
|
|
|
void dump(const T &value) |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
|
impl::DebugHelper::dump(value, std::cout); |
166
|
0
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
template <typename T> |
169
|
|
|
|
|
|
|
void dump(const T &value, std::ostream &out) |
170
|
|
|
|
|
|
|
{ |
171
|
|
|
|
|
|
|
impl::DebugHelper::dump(value, out); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
template <typename T> |
175
|
0
|
|
|
|
|
|
std::string dumps(const T &value) |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
0
|
|
|
|
|
std::stringstream stream; |
178
|
0
|
0
|
|
|
|
|
impl::DebugHelper::dump(value, stream); |
179
|
0
|
0
|
|
|
|
|
return stream.str(); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} // namespace debug |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} // namespace kiwi |