Commit 2f3e5aa7 authored by Chinmay Garde's avatar Chinmay Garde

Add toString() overrides to internal solver members

parent 9d075ada
......@@ -24,4 +24,29 @@ class Constraint {
required ? requiredPriority : p.clamp(0.0, requiredPriority - 1.0);
Constraint operator |(double p) => this..priority = p;
String toString() {
StringBuffer buffer = new StringBuffer();
buffer.write(expression.toString());
switch (relation) {
case Relation.equalTo:
buffer.write(" <= 0 ");
break;
case Relation.greaterThanOrEqualTo:
buffer.write(" >= 0 ");
break;
case Relation.lessThanOrEqualTo:
buffer.write(" <= 0 ");
break;
}
buffer.write(" | priority = ${priority}");
if (required) {
buffer.write(" (required)");
}
return buffer.toString();
}
}
......@@ -156,4 +156,17 @@ class Expression extends _EquationMember {
return this._applyMultiplicand(1.0 / m.value);
}
String toString() {
StringBuffer buffer = new StringBuffer();
terms.forEach((t) => buffer.write("${t}"));
if (constant != 0.0) {
buffer.write(constant.sign > 0.0 ? "+" : "-");
buffer.write(constant.abs());
}
return buffer.toString();
}
}
......@@ -14,5 +14,8 @@ class Param extends _EquationMember {
double get value => variable.value;
String get name => variable.name;
set name(String name) => variable.name = name;
Expression asExpression() => new Expression([new Term(variable, 1.0)], 0.0);
}
......@@ -61,4 +61,15 @@ class _Row {
cells.remove(symbol);
insertRow(row, coefficient);
}
String toString() {
StringBuffer buffer = new StringBuffer();
buffer.write(constant);
cells.forEach((symbol, value) =>
buffer.write(" + " + value.toString() + " * " + symbol.toString()));
return buffer.toString();
}
}
......@@ -550,6 +550,42 @@ class Solver {
return _elvis(entering, new _Symbol(_SymbolType.invalid, 0));
}
String toString() {
StringBuffer buffer = new StringBuffer();
String separator = "\n~~~~~~~~~";
// Objective
buffer.writeln(separator + " Objective");
buffer.writeln(_objective.toString());
// Tableau
buffer.writeln(separator + " Tableau");
_rows.forEach((symbol, row) {
buffer.write(symbol.toString());
buffer.write(" | ");
buffer.writeln(row.toString());
});
// Infeasible
buffer.writeln(separator + " Infeasible");
_infeasibleRows.forEach((symbol) => buffer.writeln(symbol.toString()));
// Variables
buffer.writeln(separator + " Variables");
_vars.forEach((variable, symbol) =>
buffer.writeln("${variable.toString()} = ${symbol.toString()}"));
// Edit Variables
buffer.writeln(separator + " Edit Variables");
_edits.forEach((variable, editinfo) => buffer.writeln(variable));
// Constraints
buffer.writeln(separator + " Constraints");
_constraints.forEach((constraint, _) => buffer.writeln(constraint));
return buffer.toString();
}
}
class _Tag {
......
......@@ -11,4 +11,26 @@ class _Symbol {
int tick;
_Symbol(this.type, this.tick);
String toString() {
String typeString = "unknown";
switch (type) {
case _SymbolType.invalid:
typeString = "i";
break;
case _SymbolType.external:
typeString = "v";
break;
case _SymbolType.slack:
typeString = "s";
break;
case _SymbolType.error:
typeString = "e";
break;
case _SymbolType.dummy:
typeString = "d";
break;
}
return "${typeString}${tick}";
}
}
......@@ -16,4 +16,19 @@ class Term extends _EquationMember {
Expression asExpression() =>
new Expression([new Term(this.variable, this.coefficient)], 0.0);
String toString() {
StringBuffer buffer = new StringBuffer();
buffer.write(coefficient.sign > 0.0 ? "+" : "-");
if (coefficient.abs() != 1.0) {
buffer.write(coefficient.abs());
buffer.write("*");
}
buffer.write(variable);
return buffer.toString();
}
}
......@@ -6,7 +6,16 @@ part of cassowary;
class Variable {
double value = 0.0;
Variable(this.value);
String name;
int _tick;
static int _total = 0;
Variable(this.value) : _tick = _total++;
// TODO(csg): Add external variable update callbacks here
String get debugName => _elvis(name, "variable${_tick}");
String toString() => "${debugName}(=${value})";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment