-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlotGraph.cpp
More file actions
231 lines (183 loc) · 6.74 KB
/
Copy pathPlotGraph.cpp
File metadata and controls
231 lines (183 loc) · 6.74 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "PlotGraph.h"
#include <sstream>
#include <iomanip>
//#define SAVE_PLOTS
int Cnt = 0;
void
PlotGraph::PlotBipartiteGraph(BipartiteGraph& _bg,
vector<VID>& _S,
vector<VID>& _T,
vector<VID>& _N,
vector<EID>& _EG,
vector<EID>& _M,
int target_task){
//get assignment size, assume the sizes of agents and tasks are identical
size_t as_size = _bg.GetNumAgents();
double plx[as_size];
double ply[as_size];
//g=gnuplot_init();
gnuplot_resetplot(g);
gnuplot_cmd(g, (char*)"unset label");
gnuplot_cmd(g, (char*)"set xrange [-0.25:%f]", as_size-1+.25);
gnuplot_cmd(g, (char*)"set yrange [-0.25:1.25]");
gnuplot_cmd(g, (char*)"set xtics 0");
gnuplot_cmd(g, (char*)"set ytics 0");
gnuplot_cmd(g, (char*)"set nokey");
// Plot matching
//cout<<endl<<"Set M: "<<endl;
//DisplayData(_M);
for (unsigned int i = 0; i < _M.size(); i++){
plx[0] = _M[i].first;
ply[0] = 0.0;
plx[1] = _M[i].second;
ply[1] = 1.0;
gnuplot_setstyle(g, (char*)"lines lc rgb \"red\" lw 3");
gnuplot_plot_xy(g, plx, ply, 2, NULL);
}
// Plot admissible edges (EG)
//cout<<"EG: "<<endl;
//DisplayData(_EG);
for(unsigned int i=0; i<_EG.size(); i++){
plx[0] = _EG[i].first;
ply[0] = 0.0;
plx[1] = _EG[i].second;
ply[1] = 1.0;
gnuplot_setstyle(g, (char*)"lines lc rgb \"gray\"");
gnuplot_plot_xy(g, plx, ply, 2, NULL);
plx[0] = (0.9*plx[0] + 0.1*plx[1]);
ply[0] = 0.11;
gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#FFFFFF\" pt 7");
gnuplot_plot_xy(g, plx, ply, 1, NULL);
//cout<<"EG "<<i<<": "<<_bg.GetMatrix(_EG[i])->GetWeight()<<endl;
gnuplot_cmd(g, (char*)"set label \"%d\" at %f-0.04,0.1 front tc rgb \"#4682B4\" font \",8\"", int(_bg.GetMatrix(_EG[i])->GetWeight()), plx[0]);
}
// Plot membership of set S
//cout<<"S: "<<endl;
//DisplayData(_S);
for(unsigned int i=0; i<_S.size(); i++){
plx[0] = _S[i];
ply[0] = 0.0;
gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"green\" pt 7");
gnuplot_plot_xy(g, plx, ply, 1, NULL);
}
// Plot membership of the set T
//cout<<"T: "<<endl;
//DisplayData(_T);
for(unsigned int i=0; i<_T.size(); i++){
plx[0] = _T[i];
ply[0] = 1.0;
gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"#00BFFF\" pt 7");
gnuplot_plot_xy(g, plx, ply, 1, NULL);
}
if (target_task != -1) // not yet unioned, but the reversal point for the
{ // alternating path
plx[0] = target_task;
ply[0] = 1.0;
gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"grey\" pt 7");
gnuplot_plot_xy(g, plx, ply, 1, NULL);
}
// Plot nodes
for(unsigned int i = 0; i < as_size; i++)
{
plx[i] = i;
ply[i] = 0.0;
}
gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
gnuplot_plot_xy(g, plx, ply, as_size, NULL);
for(unsigned int i = 0; i < as_size; i++)
{
plx[i] = i;
ply[i] = 1.0;
}
gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
gnuplot_plot_xy(g, plx, ply, as_size, NULL);
for (unsigned int i = 0; i < as_size; i++)
{
gnuplot_cmd(g, (char*)"set label \"x%d\" at %d-0.025,-0.08 tc rgb \"black\"", i, i);
gnuplot_cmd(g, (char*)"set label \"y%d\" at %d-0.025,1.08 tc rgb \"black\"", i, i);
//cout<<"Label "<<i<<": "<<_bg.GetAgent(i)->GetLabel()<<endl;
//cout<<"Label "<<i<<": "<<_bg.GetTask(i)->GetLabel()<<endl;
gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,-0.15 tc rgb \"#112244\"", int(_bg.GetAgent(i)->GetLabel()), i);
gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,1.15 tc rgb \"#112244\"", int(_bg.GetTask(i)->GetLabel()), i);
}
/* //image setting
set terminal png
{{no}transparent} {{no}interlace}
{tiny | small | medium | large | giant}
{font <face> {<pointsize>}}
{size <x>,<y>} {{no}crop}
{{no}enhanced}
{<color0> <color1> <color2> ...}
*/
#ifdef SAVE_PLOTS
stringstream ss;
ss << setw(3) << setfill('0') << Cnt++;
string postfix = ss.str();
string name="save/plot"+postfix+".jpeg";
gnuplot_cmd(g, (char*)"set terminal jpeg");
//gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
printf("saved jpeg: \"%s\"\n", name.c_str());
#endif
gnuplot_cmd(g, (char*)"replot");
sleep(period);
//gnuplot_close(g);
}
void
PlotGraph::PlotAugmentingPath(BipartiteGraph& _bg, vector<EID>& _path){
//get assignment size, assume the sizes of agents and tasks are identical
size_t as_size = _bg.GetNumAgents();
double plx[as_size];
double ply[as_size];
/*
//gnuplot_resetplot(g);
gnuplot_cmd(g, (char*)"unset label");
gnuplot_cmd(g, (char*)"set xrange [-0.25:1.25]");
gnuplot_cmd(g, (char*)"set yrange [-0.25:%f]", as_size-1+.25);
gnuplot_cmd(g, (char*)"set xtics 0");
gnuplot_cmd(g, (char*)"set ytics 0");
gnuplot_cmd(g, (char*)"set nokey");
*/
//gnuplot_cmd(g, (char*)"set style line 2 lt 2 lc rgb \"blue\" lw 3");
// Plot matching
//cout<<endl<<"Set M: "<<endl;
//DisplayData(_M);
bool alter = true;
for (unsigned int i = 0; i < _path.size(); i++){
plx[0] = _path[i].first;
ply[0] = 0.0;
plx[1] = _path[i].second;
ply[1] = 1.0;
//gnuplot_setstyle(g, (char*)"linespoints lc rgb \"#55DD99\" lw 3");
if(alter)
gnuplot_setstyle(g, (char*)"lines lc rgb \"#458B74\" lw 3");
else
gnuplot_setstyle(g, (char*)"lines lc rgb \"#7CCD7C\" lw 3");
alter = !alter;
gnuplot_plot_xy(g, plx, ply, 2, NULL);
}
#ifdef SAVE_PLOTS
stringstream ss;
ss << setw(3) << setfill('0') << Cnt++;
string postfix = ss.str();
string name="save/plot"+postfix+".jpeg";
gnuplot_cmd(g, (char*)"set terminal jpeg");
//gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
printf("saved jpeg: \"%s\"\n", name.c_str());
#endif
gnuplot_cmd(g, (char*)"replot");
sleep(period);
}
void
PlotGraph::DisplayData(const vector<VID>& vs){
for(vector<VID>::const_iterator itr = vs.begin(); itr != vs.end(); itr++)
cout<<*itr<<" ";
cout<<endl;
}
void
PlotGraph::DisplayData(const vector<EID>& es){
for(vector<EID>::const_iterator itr = es.begin(); itr != es.end(); itr++)
cout<<"("<<itr->first<<","<<itr->second<<") ";
cout<<endl;
}