COIN-OR::LEMON - Graph Library

source: glemon/gui_writer.cc @ 2:fdb8a163000f

Last change on this file since 2:fdb8a163000f was 1:67188bd752db, checked in by Peter Hegyi <hegyi@…>, 16 years ago

SVN revision 3500 made compilable with Lemon 1.0.

File size: 8.6 KB
RevLine 
[1]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#include "gui_writer.h"
20#include "io_helper.h"
21#include "mapstorage.h"
22#include "xml.h"
23#include <lemon/dim2.h>
24#include <vector>
25
26#include <gui_writer.h>
27#include <mapstorage.h>
28
29// std::string GuiWriter::header()
30// {
31//   return "@gui";
32// }
33
34void GuiWriter::write(std::ostream& os)
35{
36  using std::vector;
37  using std::string;
38  using std::map;
39  using std::string;
40
41  os << "@gui" << std::endl;
42
43  XmlIo x(os);
44
45  vector<string> all_node_map_names = mapstorage->getNodeMapList();
46  // name of the maps saved to the nodeset section
47  vector<string> main_node_map_names;
48  // name of the maps saved to the gui section
49  vector<string> gui_node_map_names;
50
51  for (vector<string>::const_iterator it = all_node_map_names.begin();
52      it != all_node_map_names.end(); ++it)
53  {
54    if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT)
55      main_node_map_names.push_back(*it);
56    else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT)
57      gui_node_map_names.push_back(*it);
58  }
59
60  { x("main_node_map_names", main_node_map_names); }
61  { x("gui_node_map_names", gui_node_map_names); }
62
63  map<string, MapValue::Type> node_map_types;
64  for (vector<string>::const_iterator it = main_node_map_names.begin();
65      it != main_node_map_names.end(); ++it)
66  {
67    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
68  }
69  for (vector<string>::const_iterator it = gui_node_map_names.begin();
70      it != gui_node_map_names.end(); ++it)
71  {
72    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
73  }
74
75  { x("node_map_types", node_map_types); }
76
77
78  vector<string> all_arc_map_names = mapstorage->getArcMapList();
79  // name of the maps saved to the arcset section
80  vector<string> main_arc_map_names;
81  // name of the maps saved to the gui section
82  vector<string> gui_arc_map_names;
83
84  for (vector<string>::const_iterator it = all_arc_map_names.begin();
85      it != all_arc_map_names.end(); ++it)
86  {
87    if (mapstorage->getArcMapSaveDest(*it) == MapStorage::NESET_SECT)
88      main_arc_map_names.push_back(*it);
89    if (mapstorage->getArcMapSaveDest(*it) == MapStorage::GUI_SECT)
90      gui_arc_map_names.push_back(*it);
91  }
92
93  { x("main_arc_map_names", main_arc_map_names); }
94  { x("gui_arc_map_names", gui_arc_map_names); }
95
96  map<string, MapValue::Type> arc_map_types;
97  for (vector<string>::const_iterator it = main_arc_map_names.begin();
98      it != main_arc_map_names.end(); ++it)
99  {
100    arc_map_types[*it] = mapstorage->getArcMapElementType(*it);
101  }
102  for (vector<string>::const_iterator it = gui_arc_map_names.begin();
103      it != gui_arc_map_names.end(); ++it)
104  {
105    arc_map_types[*it] = mapstorage->getArcMapElementType(*it);
106  }
107
108  { x("arc_map_types", arc_map_types); }
109
110  // write the gui node maps
111  for (vector<string>::const_iterator it = gui_node_map_names.begin();
112      it != gui_node_map_names.end(); ++it)
113  {
114    MapValue::Type type = mapstorage->getNodeMapElementType(*it);
115    const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
116    switch (type)
117    {
118      case MapValue::NUMERIC:
119        {
120          std::map<int, double> map_data;
121          MapStorage::NumericNodeMap& map =
122            mapstorage->getNumericNodeMap(*it);
123          for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
124          {
125            map_data[labels[n]] = map[n];
126          }
127          { x(*it, map_data); }
128        }
129        break;
130      case MapValue::STRING:
131        {
132          std::map<int, std::string> map_data;
133          MapStorage::StringNodeMap& map =
134            mapstorage->getStringNodeMap(*it);
135          for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
136          {
137            map_data[labels[n]] = map[n];
138          }
139          { x(*it, map_data); }
140        }
141        break;
142    }
143  }
144
145  // write the gui arc maps
146  for (vector<string>::const_iterator it = gui_arc_map_names.begin();
147      it != gui_arc_map_names.end(); ++it)
148  {
149    MapValue::Type type = mapstorage->getArcMapElementType(*it);
150    const MapStorage::ArcLabelMap& labels = mapstorage->getArcLabelMap();
151    switch (type)
152    {
153      case MapValue::NUMERIC:
154        {
155          std::map<int, double> map_data;
156          MapStorage::NumericArcMap& map =
157            mapstorage->getNumericArcMap(*it);
158          for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
159          {
160            map_data[labels[e]] = map[e];
161          }
162          { x(*it, map_data); }
163        }
164        break;
165      case MapValue::STRING:
166        {
167          std::map<int, std::string> map_data;
168          MapStorage::StringArcMap& map =
169            mapstorage->getStringArcMap(*it);
170          for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
171          {
172            map_data[labels[e]] = map[e];
173          }
174          { x(*it, map_data); }
175        }
176        break;
177    }
178  }
179
180  {
181    switch (mapstorage->getNodeCoordsSaveDest())
182    {
183      case MapStorage::SpecMapSaveOpts::GUI_SECT:
184        { x("node_coords_save_dest", string("gui_sect")); }
185        // write the node coorinates
186        {
187          const MapStorage::NodeLabelMap& labels =
188            mapstorage->getNodeLabelMap();
189          std::map<int, XY> node_coord_map;
190          MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
191          for (NodeIt n(mapstorage->getDigraph()); n != INVALID; ++n)
192          {
193            node_coord_map[labels[n]] = map[n];
194          }
195          { x("node_coord_map", node_coord_map); }
196        }
197        break;
198      case MapStorage::SpecMapSaveOpts::NESET_SECT:
199        switch (mapstorage->getNodeCoordsSaveMapNum())
200        {
201          case MapStorage::SpecMapSaveOpts::ONE_MAP:
202            { x("node_coords_save_dest", string("nodeset_sect_1_map")); }
203            { x("map_name", mapstorage->getNodeCoordsOneMapName()); }
204            break;
205          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
206            { x("node_coords_save_dest", string("nodeset_sect_2_maps")); }
207            { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); }
208            { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); }
209            break;
210        }
211        break;
212    }
213  }
214
215  {
216    switch (mapstorage->getArrowCoordsSaveDest())
217    {
218      case MapStorage::SpecMapSaveOpts::GUI_SECT:
219        { x("arrow_coords_save_dest", string("gui_sect")); }
220        // write the arrow coorinates
221        {
222          const MapStorage::ArcLabelMap& labels =
223            mapstorage->getArcLabelMap();
224          std::map<int, XY> arrow_coord_map;
225          MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
226          for (ArcIt e(mapstorage->getDigraph()); e != INVALID; ++e)
227          {
228            arrow_coord_map[labels[e]] = map[e];
229          }
230          { x("arrow_coord_map", arrow_coord_map); }
231        }
232        break;
233      case MapStorage::SpecMapSaveOpts::NESET_SECT:
234        switch (mapstorage->getArrowCoordsSaveMapNum())
235        {
236          case MapStorage::SpecMapSaveOpts::ONE_MAP:
237            { x("arrow_coords_save_dest", string("arcset_sect_1_map")); }
238            { x("map_name", mapstorage->getArrowCoordsOneMapName()); }
239            break;
240          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
241            { x("arrow_coords_save_dest", string("arcset_sect_2_maps")); }
242            { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); }
243            { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); }
244            break;
245        }
246        break;
247    }
248  }
249
250
251  std::map<int, std::string> nm;
252  for(int i=0;i<NODE_PROPERTY_NUM;i++)
253    {
254      nm[i]=mapstorage->active_nodemaps[i];
255    }
256  { x("active_nodemaps", nm); }
257
258  std::map<int, std::string> em;
259  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
260    {
261      em[i]=mapstorage->active_arcmaps[i];
262    }
263  { x("active_arcmaps", em); }
264
265  double attraction;
266  double propulsation;
267  int iteration;
268
269  mapstorage->get_design_data(attraction, propulsation, iteration);
270
271  { x("redesign-attraction", attraction); }
272  { x("redesign-propulsation", propulsation); }
273  { x("redesign-iteration", iteration); }
274}
275
276//GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) :
277GuiWriter::GuiWriter(MapStorage* ms) :
278  //Parent(writer),
279  mapstorage(ms)
280{
281}
Note: See TracBrowser for help on using the repository browser.