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