aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-12-12 05:55:22 -0500
committerBjoern Brandenburg <bbb@mpi-sws.org>2013-02-12 06:55:16 -0500
commit299ad40e3f0ae8fe2a8436371cce7edd22d98b8c (patch)
treea5ffc97a871cceba73e2d40183ad94bb4c0fe8bd
parent7c79568606ee9bfdc22666954feac8d16fe37beb (diff)
C++ LP analysis: add LP debugging helper
Dump a LP solution to a stream for inspection.
-rw-r--r--native/include/linprog/io.h10
-rw-r--r--native/src/linprog/io.cpp61
2 files changed, 71 insertions, 0 deletions
diff --git a/native/include/linprog/io.h b/native/include/linprog/io.h
index 1e9a3cc..1e8885f 100644
--- a/native/include/linprog/io.h
+++ b/native/include/linprog/io.h
@@ -4,7 +4,17 @@
4#include <ostream> 4#include <ostream>
5 5
6#include "linprog/model.h" 6#include "linprog/model.h"
7#include "linprog/solver.h"
8#include "lp_common.h"
7 9
8std::ostream& operator<<(std::ostream &os, const LinearExpression &exp); 10std::ostream& operator<<(std::ostream &os, const LinearExpression &exp);
9 11
12void dump_lp_solution(
13 VarMapper& vars,
14 const ResourceSharingInfo& info,
15 const TaskInfo& ti,
16 const Solution& solution,
17 std::ostream& out,
18 bool show_zeros = false);
19
10#endif 20#endif
diff --git a/native/src/linprog/io.cpp b/native/src/linprog/io.cpp
index 1b5d503..14eeca5 100644
--- a/native/src/linprog/io.cpp
+++ b/native/src/linprog/io.cpp
@@ -1,5 +1,6 @@
1#include <iostream> 1#include <iostream>
2 2
3#include "linprog/solver.h"
3#include "linprog/io.h" 4#include "linprog/io.h"
4 5
5std::ostream& operator<<(std::ostream &os, const LinearExpression &exp) 6std::ostream& operator<<(std::ostream &os, const LinearExpression &exp)
@@ -20,3 +21,63 @@ std::ostream& operator<<(std::ostream &os, const LinearExpression &exp)
20 21
21 return os; 22 return os;
22} 23}
24
25void dump_lp_solution(
26 VarMapper& vars,
27 const ResourceSharingInfo& info,
28 const TaskInfo& ti,
29 const Solution& solution,
30 std::ostream& out,
31 bool show_zeros)
32{
33 foreach_task_except(info.get_tasks(), ti, tx)
34 {
35 unsigned int t = tx->get_id();
36
37 out << "T" << t << " part=" << tx->get_cluster() << std::endl;
38
39 foreach(tx->get_requests(), request)
40 {
41 unsigned int q = request->get_resource_id();
42
43 out << " res=" << q
44 << " L=" << request->get_request_length()
45 << std::endl;
46
47 foreach_request_instance(*request, ti, v)
48 {
49 unsigned int var_id;
50 bool newline = false;
51
52 var_id = vars.lookup(t, q, v, BLOCKING_DIRECT);
53 if (solution.get_value(var_id) || show_zeros)
54 {
55 out << " XD_" << t << "_" << q << "_" << v
56 << "=" << solution.get_value(var_id);
57 newline = true;
58 }
59
60 var_id = vars.lookup(t, q, v, BLOCKING_INDIRECT);
61 if (solution.get_value(var_id) || show_zeros)
62 {
63 out << " XI_" << t << "_" << q << "_" << v
64 << "=" << solution.get_value(var_id);
65 newline = true;
66 }
67
68
69 var_id = vars.lookup(t, q, v, BLOCKING_PREEMPT);
70 if (solution.get_value(var_id) || show_zeros)
71 {
72 out << " XP_" << t << "_" << q << "_" << v
73 << "=" << solution.get_value(var_id);
74 newline = true;
75 }
76
77 if (newline)
78 out << std::endl;
79 }
80 }
81 }
82}
83