dyng
draw.hxx
Go to the documentation of this file.
1 
9 /*
10  * Copyright:: Copyright (c) 2013, 2014, 2015, Frank Fischer
11  *
12  * This file is part of DynG.
13  *
14  * DynG is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * DynG is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with DynG. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef __DYNG_DRAW_HXX__
29 #define __DYNG_DRAW_HXX__
30 
31 #include <iosfwd>
32 #include <string>
33 #include <vector>
34 #include <memory>
35 
36 namespace Dyng {
37 
39 typedef int index_type;
40 
41 class Net;
42 
50 void write_basegraph_tikz(const Net& net, bool withdoc, std::ostream& out);
51 
60 void write_basegraph_grav(const Net& net,
61  const std::string& name,
62  std::ostream& out);
63 
71 void write_rgraph(const Net& net, std::ostream& out);
72 
73 
78 {
79 public:
81  struct Color { uint8_t r, g, b; };
82 
84  enum NodeShape { Disc, Circ };
85 
86 public:
93  GravWriter(const Net& net, const std::string& name);
94 
96  virtual ~GravWriter();
97 
107  virtual bool append() const;
108 
110  virtual bool node(index_type nodeid,
111  Color& color,
112  NodeShape& shape,
113  std::string& desc) = 0;
114 
116  virtual bool arc(index_type arcid,
117  double& cost,
118  double& flow,
119  Color& color,
120  std::string& desc) = 0;
121 
123  virtual void write(std::ostream& out);
124 
125 protected:
126  const Net& _net;
127  const std::string _name;
128 };
129 
134 {
135 public:
136  CorridorGravWriter(const Net& net, const std::string& name, bool addgraph = false);
137 
139 
140  bool append() const;
141 
142  bool node(index_type nodeid,
143  Color& color,
144  NodeShape& shape,
145  std::string& desc);
146 
147  bool arc(index_type arcid,
148  double& cost,
149  double& flow,
150  Color& color,
151  std::string& desc);
152 
153  void write(std::ostream& out);
154 
155 private:
156  enum State { Exist, NotExist, Active, Corr };
157 
158  void init();
159 
160  void node_state(index_type bnodeid, int time,
161  State& state, State& old_state) const;
162 
163 private:
164  struct Data;
165  std::unique_ptr<Data> data;
166 };
167 
168 
170 enum Attribute : int {
171  COST = 0,
172  BASECOST = 1,
173  AUGCOST = 2,
174  FLOW = 3,
175  NODE = 4,
176  TIME = 5,
177 };
178 
179 class Description;
180 
185 {
186 public:
187  PathGravWriter(const Net& net, const std::string& name,
188  const std::vector<index_type>& path);
189 
190  PathGravWriter(const Net& net, const std::string& name,
191  const std::vector<double>& basecosts,
192  const std::vector<double>& augcosts,
193  const std::vector<index_type>& path);
194 
195  PathGravWriter(const Net& net, const std::string& name,
196  int (*getattr)(Attribute attr, index_type id, void* value),
197  const std::vector<index_type>& path);
198 
199  PathGravWriter(const Net& net, const std::string& name,
200  const std::vector<const char*>& nodedesc,
201  const std::vector<const char*>& arcdesc,
202  const std::vector<index_type>& path);
203 
204  PathGravWriter(const Net& net, const std::string& name,
205  const std::vector<double>& basecosts,
206  const std::vector<double>& augcosts,
207  const std::vector<const char*>& nodedesc,
208  const std::vector<const char*>& arcdesc,
209  const std::vector<index_type>& path);
210 
211  ~PathGravWriter();
212 
213  bool node(index_type nodeid,
214  Color& color,
215  NodeShape& shape,
216  std::string& desc);
217 
218  bool arc(index_type arcid,
219  double& cost,
220  double& flow,
221  Color& color,
222  std::string& desc);
223 
224 private:
225  void init_path();
226 
227 private:
228  std::vector<index_type> _path;
229  std::vector<index_type> _pathnodes;
230  std::vector<double> _basecosts;
231  std::vector<double> _augcosts;
232  std::unique_ptr<Description> _desc;
233 };
234 
237 {
238 public:
239  FlowGravWriter(const Net& net, const std::string& name,
240  const std::vector<double>& basecosts,
241  const std::vector<double>& augcosts,
242  const std::vector<const char*>& nodedesc,
243  const std::vector<const char*>& arcdesc,
244  const std::vector<double>& flows,
245  bool append = false);
246 
247  ~FlowGravWriter();
248 
249  bool append() const { return _append; }
250 
251  bool node(index_type nodeid,
252  Color& color,
253  NodeShape& shape,
254  std::string& desc);
255 
256  bool arc(index_type arcid,
257  double& cost,
258  double& flow,
259  Color& color,
260  std::string& desc);
261 
262 private:
263  bool _append;
264  std::vector<double> _flow;
265  std::vector<double> _basecosts;
266  std::vector<double> _augcosts;
267  std::unique_ptr<Description> _desc;
268 };
269 
282 void write_corridor_grav(std::ostream& out, const Net& net, const std::string& name, bool addgraph = false);
283 
296 void write_grav(const Net& net, const std::string& name,
297  const std::vector<index_type>& path,
298  std::ostream& out);
299 
316 void write_grav(const Net& net, const std::string& name,
317  const std::vector<double>& basecosts,
318  const std::vector<double>& augcosts,
319  const std::vector<index_type>& path,
320  std::ostream& out);
321 
322 
337 void write_grav(const Net& net, const std::string& name,
338  int (*getattr)(Attribute attr, index_type id, void* value),
339  const std::vector<index_type>& path,
340  std::ostream& out);
341 
357 void write_grav(const Net& net, const std::string& name,
358  const std::vector<const char*>& nodedesc,
359  const std::vector<const char*>& arcdesc,
360  const std::vector<index_type>& path,
361  std::ostream& out);
362 
380 void write_grav(const Net& net, const std::string& name,
381  const std::vector<double>& basecosts,
382  const std::vector<double>& augcosts,
383  const std::vector<const char*>& nodedesc,
384  const std::vector<const char*>& arcdesc,
385  const std::vector<index_type>& path,
386  std::ostream& out);
387 
403 void write_flow_grav(std::ostream& out,
404  const Net& net, const std::string& name,
405  const std::vector<double>& basecosts,
406  const std::vector<double>& augcosts,
407  const std::vector<const char*>& nodedesc,
408  const std::vector<const char*>& arcdesc,
409  const std::vector<double>& flow,
410  bool append = false);
411 
412 }
413 
414 #endif
void write_basegraph_tikz(const Net &net, bool withdoc, std::ostream &out)
Write base graph in Tikz format.
virtual bool node(index_type nodeid, Color &color, NodeShape &shape, std::string &desc)=0
Get node info.
NodeShape
The shape of a node.
Definition: draw.hxx:84
Writes the Grav with the corridor and active graph highlighted.
Definition: draw.hxx:133
virtual ~GravWriter()
Destructor.
An RGB color.
Definition: draw.hxx:81
virtual bool arc(index_type arcid, double &cost, double &flow, Color &color, std::string &desc)=0
Get arc info.
const std::string _name
name of the graph in the grav file
Definition: draw.hxx:127
void write_corridor_grav(std::ostream &out, const Net &net, const std::string &name, bool addgraph=false)
Write time expansion in grav format.
void write_basegraph_grav(const Net &net, const std::string &name, std::ostream &out)
Write base graph in grav format.
void write_flow_grav(std::ostream &out, const Net &net, const std::string &name, const std::vector< double > &basecosts, const std::vector< double > &augcosts, const std::vector< const char *> &nodedesc, const std::vector< const char *> &arcdesc, const std::vector< double > &flow, bool append=false)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Writes a path.
Definition: draw.hxx:184
GravWriter(const Net &net, const std::string &name)
Create a GravWriter for a network.
base cost of an arc, double
Definition: draw.hxx:172
time description, c string of size 80
Definition: draw.hxx:176
cost of an arc, double
Definition: draw.hxx:171
Attribute
Attribute for building node/arc descriptions.
Definition: draw.hxx:170
virtual bool append() const
Returns true iff the graph to be written should be appended.
Grav writer for fractional flows.
Definition: draw.hxx:236
int index_type
Type of indices.
Definition: draw.hxx:39
void write_grav(const Net &net, const std::string &name, const std::vector< index_type > &path, std::ostream &out)
Write time expansion in grav format with some highlighted path.
A dynamic time expanded network.
Definition: Net.hxx:458
node description, c string of size 80
Definition: draw.hxx:175
void write_rgraph(const Net &net, std::ostream &out)
Write time expansion in rgraph format.
Base class for writing to Grav files.
Definition: draw.hxx:77
const Net & _net
the network to be drawn
Definition: draw.hxx:126
The namespace of DynG.
Definition: draw.hxx:36
flow of an arc, double
Definition: draw.hxx:174
virtual void write(std::ostream &out)
Write the graph to the given output stream.
augmented cost of an arc, double
Definition: draw.hxx:173
bool append() const
Returns true iff the graph to be written should be appended.
Definition: draw.hxx:249